com.google.common.reflect.Reflection.getPackageName()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中com.google.common.reflect.Reflection.getPackageName方法的一些代码示例,展示了Reflection.getPackageName的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reflection.getPackageName方法的具体详情如下:
包路径:com.google.common.reflect.Reflection
类名称:Reflection
方法名:getPackageName

Reflection.getPackageName介绍

[英]Returns the package name of clazz according to the Java Language Specification (section 6.7). Unlike Class#getPackage, this method only parses the class name, without attempting to define the Package and hence load files.
[中]根据Java语言规范(第6.7节)返回clazz的包名。与类#getPackage不同,该方法只解析类名,而不尝试定义包,从而加载文件。

代码示例

代码示例来源:origin: google/guava

/**
 * Returns the package name of the class, without attempting to load the class.
 *
 * <p>Behaves identically to {@link Package#getName()} but does not require the class (or
 * package) to be loaded.
 */
public String getPackageName() {
 return Reflection.getPackageName(className);
}

代码示例来源:origin: google/guava

/**
 * Returns the package name of {@code clazz} according to the Java Language Specification (section
 * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
 * attempting to define the {@link Package} and hence load files.
 */
public static String getPackageName(Class<?> clazz) {
 return getPackageName(clazz.getName());
}

代码示例来源:origin: google/guava

private FactoryMethodReturnValueTester(
  Class<?> declaringClass,
  ImmutableList<Invokable<?, ?>> factories,
  String factoryMethodsDescription) {
 this.declaringClass = declaringClass;
 this.factories = factories;
 this.factoryMethodsDescription = factoryMethodsDescription;
 packagesToTest.add(Reflection.getPackageName(declaringClass));
}

代码示例来源:origin: google/j2objc

/**
 * Returns the package name of the class, without attempting to load the class.
 *
 * <p>Behaves identically to {@link Package#getName()} but does not require the class (or
 * package) to be loaded.
 */
public String getPackageName() {
 return Reflection.getPackageName(className);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns the package name of the class, without attempting to load the class.
 *
 * <p>Behaves identically to {@link Package#getName()} but does not require the class (or
 * package) to be loaded.
 */
public String getPackageName() {
 return Reflection.getPackageName(className);
}

代码示例来源:origin: google/j2objc

/**
 * Returns the package name of {@code clazz} according to the Java Language Specification (section
 * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
 * attempting to define the {@link Package} and hence load files.
 */
public static String getPackageName(Class<?> clazz) {
 return getPackageName(clazz.getName());
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns the package name of {@code clazz} according to the Java Language Specification (section
 * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
 * attempting to define the {@link Package} and hence load files.
 */
public static String getPackageName(Class<?> clazz) {
 return getPackageName(clazz.getName());
}

代码示例来源:origin: google/guava

private ImmutableList<Method> getVisibleMethods(Class<?> cls) {
  // Don't use cls.getPackage() because it does nasty things like reading
  // a file.
  String visiblePackage = Reflection.getPackageName(cls);
  ImmutableList.Builder<Method> builder = ImmutableList.builder();
  for (Class<?> type : TypeToken.of(cls).getTypes().rawTypes()) {
   if (!Reflection.getPackageName(type).equals(visiblePackage)) {
    break;
   }
   for (Method method : type.getDeclaredMethods()) {
    if (!method.isSynthetic() && isVisible(method)) {
     builder.add(method);
    }
   }
  }
  return builder.build();
 }
}

代码示例来源:origin: google/guava

/**
 * Tests null checks against the instance methods of the return values, if any.
 *
 * <p>Test fails if default value cannot be determined for a constructor or factory method
 * parameter, or if the constructor or factory method throws exception.
 *
 * @return this tester
 */
public FactoryMethodReturnValueTester testNulls() throws Exception {
 for (Invokable<?, ?> factory : getFactoriesToTest()) {
  Object instance = instantiate(factory);
  if (instance != null
    && packagesToTest.contains(Reflection.getPackageName(instance.getClass()))) {
   try {
    nullPointerTester.testAllPublicInstanceMethods(instance);
   } catch (AssertionError e) {
    AssertionError error =
      new AssertionFailedError("Null check failed on return value of " + factory);
    error.initCause(e);
    throw error;
   }
  }
 }
 return this;
}

代码示例来源:origin: google/guava

public void testGetPackageName() throws Exception {
 assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
 assertEquals("java", Reflection.getPackageName("java.MyType"));
 assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
 assertEquals("", Reflection.getPackageName("NoPackage"));
 assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
}

代码示例来源:origin: glowroot/glowroot

public Class<?> weaveAndDefineClass(String name, byte[] bytes,
    @Nullable CodeSource codeSource) {
  byte[] wovenBytes = weaveClass(name, bytes);
  String packageName = Reflection.getPackageName(name);
  if (!packages.containsKey(packageName)) {
    Method getDefinedPackageMethod;

代码示例来源:origin: google/bundletool

@Test
public void eachSubValidatorIsRegistered() throws Exception {
 // Load sub-classes of SubValidator that live within the same package as top-level classes.
 ImmutableSet<Class<?>> existingSubValidators =
   ClassPath.from(SubValidator.class.getClassLoader())
     .getTopLevelClasses(Reflection.getPackageName(SubValidator.class))
     .stream()
     .map(ClassInfo::load)
     .filter(clazz -> isConcreteSubValidator(clazz))
     .collect(toImmutableSet());
 ImmutableSet<Class<?>> registeredSubValidators =
   ImmutableSet.<Class<?>>builder()
     .addAll(toClasses(AppBundleValidator.BUNDLE_FILE_SUB_VALIDATORS))
     .addAll(toClasses(AppBundleValidator.BUNDLE_SUB_VALIDATORS))
     .addAll(toClasses(BundleModulesValidator.MODULE_FILE_SUB_VALIDATORS))
     .addAll(toClasses(BundleModulesValidator.MODULES_SUB_VALIDATORS))
     .build();
 assertThat(existingSubValidators).containsExactlyElementsIn(registeredSubValidators);
}

代码示例来源:origin: co.cask.cdap/cdap-common

/** 
 * Returns the package name of the class, without attempting to load the class.
 * 
 * <p>Behaves identically to {@link Package#getName()} but does not require the class (or 
 * package) to be loaded.
 */
public String getPackageName() {
 return Reflection.getPackageName(className);
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * Returns the package name of the class, without attempting to load the class.
 *
 * <p>Behaves identically to {@link Package#getName()} but does not require the class (or
 * package) to be loaded.
 */
public String getPackageName() {
 return Reflection.getPackageName(className);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava

/** Returns the package name of the class, without attempting to load the class. */
public String getPackageName() {
 return Reflection.getPackageName(className);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** Returns the package name of the class, without attempting to load the class. */
public String getPackageName() {
 return Reflection.getPackageName(className);
}

代码示例来源:origin: com.google.guava/guava-jdk5

/**
 * Returns the package name of {@code clazz} according to the Java Language Specification (section
 * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
 * attempting to define the {@link Package} and hence load files.
 */
public static String getPackageName(Class<?> clazz) {
 return getPackageName(clazz.getName());
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava

/**
 * Returns the package name of {@code clazz} according to the Java Language Specification (section
 * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
 * attempting to define the {@link Package} and hence load files.
 */
public static String getPackageName(Class<?> clazz) {
 return getPackageName(clazz.getName());
}

代码示例来源:origin: com.google.guava/guava-testlib-jdk5

private FactoryMethodReturnValueTester(
  Class<?> declaringClass,
  ImmutableList<Invokable<?, ?>> factories,
  String factoryMethodsDescription) {
 this.declaringClass = declaringClass;
 this.factories = factories;
 this.factoryMethodsDescription = factoryMethodsDescription;
 packagesToTest.add(Reflection.getPackageName(declaringClass));
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * Returns the package name of {@code clazz} according to the Java Language Specification (section
 * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
 * attempting to define the {@link Package} and hence load files.
 */
public static String getPackageName(Class<?> clazz) {
 return getPackageName(clazz.getName());
}

相关文章