java.lang.Package.getName()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(190)

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

Package.getName介绍

[英]Returns the name of this package in the standard dot notation; for example: "java.lang".
[中]以标准点符号返回此包的名称;例如:“java.lang”。

代码示例

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

/**
   * {@inheritDoc}
   */
  public String getName() {
    return aPackage.getName();
  }
}

代码示例来源:origin: prestodb/presto

/**
 * @since 2.7
 */
public static String getPackageName(Class<?> cls) {
  Package pkg = cls.getPackage();
  return (pkg == null) ? null : pkg.getName();
}

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

/**
 * @since 2.7
 */
public static String getPackageName(Class<?> cls) {
  Package pkg = cls.getPackage();
  return (pkg == null) ? null : pkg.getName();
}

代码示例来源:origin: ch.qos.logback/logback-classic

/**
 * {@inheritDoc}
 */
public void setLoggerContext(LoggerContext lc) {
  this.lc = lc;
  this.logger = lc.getLogger(getClass().getPackage().getName());
}

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

private String resolveName(String templateName) {
    if (templateName.startsWith("/")) {
      return templateName;
    }
    final String packagePath = getClass().getPackage().getName().replace('.', '/');
    return String.format("/%s/%s", packagePath, templateName);
  }
}

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

public String toPath(Package packageName) {
  return toPath(packageName.getName());
}

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

private List<Class<?>> loadClassesInPackage() throws IOException {
 List<Class<?>> classes = Lists.newArrayList();
 String packageName = getClass().getPackage().getName();
 for (ClassPath.ClassInfo classInfo :
   ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(packageName)) {
  Class<?> cls;
  try {
   cls = classInfo.load();
  } catch (NoClassDefFoundError e) {
   // In case there were linking problems, this is probably not a class we care to test anyway.
   logger.log(Level.SEVERE, "Cannot load class " + classInfo + ", skipping...", e);
   continue;
  }
  if (!cls.isInterface()) {
   classes.add(cls);
  }
 }
 return classes;
}

代码示例来源:origin: org.mockito/mockito-core

@Override
boolean isExported(Class<?> source) {
  if (source.getPackage() == null) {
    return true;
  }
  return (Boolean) invoke(isExportedUnqualified, invoke(getModule, source), source.getPackage().getName());
}

代码示例来源:origin: org.mockito/mockito-core

@Override
boolean isExported(Class<?> source, Class<?> target) {
  if (source.getPackage() == null) {
    return true;
  }
  return (Boolean) invoke(isExported, invoke(getModule, source), source.getPackage().getName(), invoke(getModule, target));
}

代码示例来源:origin: org.mockito/mockito-core

@Override
boolean isOpened(Class<?> source, Class<?> target) {
  if (source.getPackage() == null) {
    return true;
  }
  return (Boolean) invoke(isOpen, invoke(getModule, source), source.getPackage().getName(), invoke(getModule, target));
}

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

private static ClassLoader getClassLoader(final Set<String> disallowedClassNames) {
  final String concurrentPackage = SettableFuture.class.getPackage().getName();
  ClassLoader classLoader = AbstractFutureFallbackAtomicHelperTest.class.getClassLoader();
  // we delegate to the current classloader so both loaders agree on classes like TestCase
  return new URLClassLoader(ClassPathUtil.getClassPathUrls(), classLoader) {
   @Override
   public Class<?> loadClass(String name) throws ClassNotFoundException {
    if (disallowedClassNames.contains(name)) {
     throw new ClassNotFoundException("I'm sorry Dave, I'm afraid I can't do that.");
    }
    if (name.startsWith(concurrentPackage)) {
     Class<?> c = findLoadedClass(name);
     if (c == null) {
      return super.findClass(name);
     }
     return c;
    }
    return super.loadClass(name);
   }
  };
 }
}

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

private static ClassLoader getClassLoader(final Set<String> blocklist) {
  final String concurrentPackage = SettableFuture.class.getPackage().getName();
  ClassLoader classLoader = AggregateFutureStateFallbackAtomicHelperTest.class.getClassLoader();
  // we delegate to the current classloader so both loaders agree on classes like TestCase
  return new URLClassLoader(ClassPathUtil.getClassPathUrls(), classLoader) {
   @Override
   public Class<?> loadClass(String name) throws ClassNotFoundException {
    if (blocklist.contains(name)) {
     throw new ClassNotFoundException("I'm sorry Dave, I'm afraid I can't do that.");
    }
    if (name.startsWith(concurrentPackage)) {
     Class<?> c = findLoadedClass(name);
     if (c == null) {
      return super.findClass(name);
     }
     return c;
    }
    return super.loadClass(name);
   }
  };
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void shouldNotScanTwice() {
  TestImport.scanned = false;
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
  context.scan(TestImport.class.getPackage().getName());
  context.refresh();
  context.getBean(TestConfiguration.class);
}

代码示例来源:origin: bumptech/glide

@Test
public void testHasValidTag() {
 assertEquals(RequestManagerRetriever.class.getPackage().getName(),
   RequestManagerRetriever.FRAGMENT_TAG);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Prior to the fix for SPR-8761, this test threw because the nested MyComponent
 * annotation was being falsely considered as a 'lite' Configuration class candidate.
 */
@Test
public void repro() {
  AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  ctx.scan(getClass().getPackage().getName());
  ctx.refresh();
  assertThat(ctx.containsBean("withNestedAnnotation"), is(true));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testGetPackageName() {
  assertEquals("java.lang", ClassUtils.getPackageName(String.class));
  assertEquals(getClass().getPackage().getName(), ClassUtils.getPackageName(getClass()));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Prior to fixing SPR-10546 this might have succeeded depending on the ordering the
 * classes were picked up. If they are picked up in the same order as
 * {@link #enclosingConfigFirstParentDefinesBean()} then it would fail. This test is
 * mostly for illustration purposes, but doesn't hurt to continue using it.
 *
 * <p>We purposely use the {@link AEnclosingConfig} to make it alphabetically prior to the
 * {@link AEnclosingConfig.ChildConfig} which encourages this to occur with the
 * classpath scanning implementation being used by the author of this test.
 */
@Test
public void enclosingConfigFirstParentDefinesBeanWithScanning() {
  AnnotationConfigApplicationContext ctx= new AnnotationConfigApplicationContext();
  context = ctx;
  ctx.scan(AEnclosingConfig.class.getPackage().getName());
  ctx.refresh();
  assertThat(context.getBean("myBean",String.class), equalTo("myBean"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void controlScan() {
  AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  ctx.scan(example.scannable._package.class.getPackage().getName());
  ctx.refresh();
  assertThat("control scan for example.scannable package failed to register FooServiceImpl bean",
      ctx.containsBean("fooServiceImpl"), is(true));
}

代码示例来源:origin: spring-projects/spring-framework

private ApplicationContext createContext(ScopedProxyMode scopedProxyMode) {
  GenericWebApplicationContext context = new GenericWebApplicationContext();
  ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
  scanner.setIncludeAnnotationConfig(false);
  scanner.setBeanNameGenerator((definition, registry) -> definition.getScope());
  scanner.setScopedProxyMode(scopedProxyMode);
  // Scan twice in order to find errors in the bean definition compatibility check.
  scanner.scan(getClass().getPackage().getName());
  scanner.scan(getClass().getPackage().getName());
  context.refresh();
  return context;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void naming() throws MalformedObjectNameException {
  JmxTestBean bean = new JmxTestBean();
  IdentityNamingStrategy strategy = new IdentityNamingStrategy();
  ObjectName objectName = strategy.getObjectName(bean, "null");
  assertEquals("Domain is incorrect", bean.getClass().getPackage().getName(),
      objectName.getDomain());
  assertEquals("Type property is incorrect", ClassUtils.getShortName(bean.getClass()),
      objectName.getKeyProperty(IdentityNamingStrategy.TYPE_KEY));
  assertEquals("HashCode property is incorrect", ObjectUtils.getIdentityHexString(bean),
      objectName.getKeyProperty(IdentityNamingStrategy.HASH_CODE_KEY));
}

相关文章