本文整理匯總了Java中com.google.common.reflect.ClassPath.ClassInfo類的典型用法代碼示例。如果您正苦於以下問題:Java ClassInfo類的具體用法?Java ClassInfo怎麽用?Java ClassInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClassInfo類屬於com.google.common.reflect.ClassPath包,在下文中一共展示了ClassInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetSimpleName
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
public void testGetSimpleName() {
ClassLoader classLoader = getClass().getClassLoader();
assertEquals("Foo",
new ClassInfo("Foo.class", classLoader).getSimpleName());
assertEquals("Foo",
new ClassInfo("a/b/Foo.class", classLoader).getSimpleName());
assertEquals("Foo",
new ClassInfo("a/b/Bar$Foo.class", classLoader).getSimpleName());
assertEquals("",
new ClassInfo("a/b/Bar$1.class", classLoader).getSimpleName());
assertEquals("Foo",
new ClassInfo("a/b/Bar$Foo.class", classLoader).getSimpleName());
assertEquals("",
new ClassInfo("a/b/Bar$1.class", classLoader).getSimpleName());
assertEquals("Local",
new ClassInfo("a/b/Bar$1Local.class", classLoader).getSimpleName());
}
示例2: findMessageClasses
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private Iterable<Class<? extends AbstractMessage>> findMessageClasses() {
try {
List<Class<? extends AbstractMessage>> result = new ArrayList<>();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
ClassPath classpath = ClassPath.from(classloader);
ImmutableSet<ClassInfo> xx =
classpath.getTopLevelClassesRecursive("net.wizardsoflua.testenv.net");
Iterable<ClassInfo> yy = Iterables.filter(xx, input -> {
Class<?> cls = input.load();
return AbstractMessage.class.isAssignableFrom(cls)
&& !Modifier.isAbstract(cls.getModifiers());
});
for (ClassInfo classInfo : yy) {
result.add((Class<? extends AbstractMessage>) classInfo.load());
}
return result;
} catch (IOException e) {
throw new UndeclaredThrowableException(e);
}
}
示例3: getClasses
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
@API public static List<Class<?>> getClasses(String path)
{
try
{
ClassPath classPath = ClassPath.from(ClassUtil.class.getClassLoader());
Set<ClassInfo> classInfo = classPath.getTopLevelClassesRecursive(path);
Iterator<ClassInfo> iterator = classInfo.iterator();
List<Class<?>> classes = new ArrayList<>();
while(iterator.hasNext())
{
ClassInfo ci = iterator.next();
Optional<Class<?>> classOptional = getClass(ci.getName());
classOptional.ifPresent(classes::add);
}
return classes;
}
catch(IOException e)
{
throw new UncheckedIOException(e);
}
}
示例4: getCheckstyleModulesRecursive
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
/**
* Gets checkstyle's modules in the given package recursively.
* @param packageName the package name to use
* @param loader the class loader used to load Checkstyle package name
* @return the set of checkstyle's module classes
* @throws IOException if the attempt to read class path resources failed
* @see ModuleReflectionUtils#isCheckstyleModule(Class)
*/
private static Set<Class<?>> getCheckstyleModulesRecursive(
String packageName, ClassLoader loader) throws IOException {
final ClassPath classPath = ClassPath.from(loader);
final Set<Class<?>> result = new HashSet<Class<?>>();
for (ClassInfo clsInfo : classPath.getTopLevelClassesRecursive(packageName)) {
final Class<?> cls = clsInfo.load();
if (ModuleReflectionUtils.isCheckstyleModule(cls)
&& !cls.getName().endsWith("Stub")
&& !cls.getCanonicalName()
.startsWith("com.puppycrawl.tools.checkstyle.internal.testmodules")
&& !cls.getCanonicalName()
.startsWith("com.puppycrawl.tools.checkstyle.packageobjectfactory")) {
result.add(cls);
}
}
return result;
}
示例5: loadAllProvider
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
@Unsafe(Unsafe.ASM_API)
private static void loadAllProvider() throws Exception {
ClassPath path = ClassPath.from(AlchemyTransformerManager.class.getClassLoader());
for (ClassInfo info : path.getAllClasses())
if (info.getName().startsWith(MOD_PACKAGE)) {
ClassReader reader = new ClassReader(info.url().openStream());
ClassNode node = new ClassNode(ASM5);
reader.accept(node, 0);
if (checkSideOnly(node)) {
loadPatch(node);
loadField(node);
loadProxy(node);
loadHook(node);
loadTransform(node, info);
}
}
}
示例6: getAllCommandClasses
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
/**
* Gets the set of all non-abstract classes implementing the {@link Command} interface (abstract
* class and interface subtypes of Command aren't expected to have cli commands). Note that this
* also filters out HelpCommand, which has special handling in {@link RegistryCli} and isn't in
* the command map.
*
* @throws IOException if reading the classpath resources fails.
*/
@SuppressWarnings("unchecked")
private ImmutableSet<Class<? extends Command>> getAllCommandClasses() throws IOException {
ImmutableSet.Builder<Class<? extends Command>> builder = new ImmutableSet.Builder<>();
for (ClassInfo classInfo : ClassPath
.from(getClass().getClassLoader())
.getTopLevelClassesRecursive(getPackageName(getClass()))) {
Class<?> clazz = classInfo.load();
if (Command.class.isAssignableFrom(clazz)
&& !Modifier.isAbstract(clazz.getModifiers())
&& !Modifier.isInterface(clazz.getModifiers())
&& !clazz.equals(HelpCommand.class)) {
builder.add((Class<? extends Command>) clazz);
}
}
return builder.build();
}
示例7: printActor
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
protected void printActor(Digraph digraph, ClassInfo ci, JavaProjectBuilder builder) {
// final String options =
// "shape=box, style=invis, shapefile=\"Turing.png\"";
final String url = ", URL=\"" + (SCM_BASE_URL + "/" + SOURCE_TREE + "/") + toPath(ci) + "\"";
final String options = "shape=box, style=filled,fillcolor=\"#C0D0C0\"" + url;
final ExternalActor[] actors = ci.load().getAnnotationsByType(ExternalActor.class);
for (ExternalActor actor : actors) {
digraph.addNode(ci.getName()).setLabel(wrap(actor.name(), 19)).setComment(ci.getSimpleName())
.setOptions(options); // .addStereotype(actorType(actor.type()))
final String label = getComment(ci, builder);
switch (actor.direction()) {
case API:
digraph.addAssociation(ci.getName(), "system").setLabel(label).setOptions(NOTE_EDGE_STYLE);
break;
case SPI:
digraph.addAssociation("system", ci.getName()).setLabel(label).setOptions(NOTE_EDGE_STYLE);
break;
default:
digraph.addAssociation("system", ci.getName()).setLabel(label).setOptions(NOTE_EDGE_STYLE);
digraph.addAssociation(ci.getName(), "system").setLabel(label).setOptions(NOTE_EDGE_STYLE);
}
}
}
示例8: testGetTopLevelClasses
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
public void testGetTopLevelClasses() throws Exception {
Set<String> names = Sets.newHashSet();
Set<String> strings = Sets.newHashSet();
Set<Class<?>> classes = Sets.newHashSet();
Set<String> packageNames = Sets.newHashSet();
Set<String> simpleNames = Sets.newHashSet();
ClassPath classpath = ClassPath.from(getClass().getClassLoader());
for (ClassInfo classInfo
: classpath.getTopLevelClasses(ClassPathTest.class.getPackage().getName())) {
names.add(classInfo.getName());
strings.add(classInfo.toString());
classes.add(classInfo.load());
packageNames.add(classInfo.getPackageName());
simpleNames.add(classInfo.getSimpleName());
}
assertThat(names).containsAllOf(ClassPath.class.getName(), ClassPathTest.class.getName());
assertThat(strings).containsAllOf(ClassPath.class.getName(), ClassPathTest.class.getName());
assertThat(classes).containsAllOf(ClassPath.class, ClassPathTest.class);
assertThat(packageNames).contains(ClassPath.class.getPackage().getName());
assertThat(simpleNames).containsAllOf("ClassPath", "ClassPathTest");
assertFalse(classes.contains(ClassInSubPackage.class));
}
示例9: testGetSimpleName
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
public void testGetSimpleName() {
assertEquals("Foo",
new ClassInfo("Foo.class", getClass().getClassLoader()).getSimpleName());
assertEquals("Foo",
new ClassInfo("a/b/Foo.class", getClass().getClassLoader()).getSimpleName());
assertEquals("Foo",
new ClassInfo("a/b/Bar$Foo.class", getClass().getClassLoader()).getSimpleName());
assertEquals("",
new ClassInfo("a/b/Bar$1.class", getClass().getClassLoader()).getSimpleName());
assertEquals("Foo",
new ClassInfo("a/b/Bar$Foo.class", getClass().getClassLoader()).getSimpleName());
assertEquals("",
new ClassInfo("a/b/Bar$1.class", getClass().getClassLoader()).getSimpleName());
assertEquals("Local",
new ClassInfo("a/b/Bar$1Local.class", getClass().getClassLoader()).getSimpleName());
}
示例10: serializableClassesMustDefineSerialVersionUID
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
@Test
public void serializableClassesMustDefineSerialVersionUID() throws IOException {
List<Class<?>> serializableClassesWithoutSerialVersionUID = ClassPath
.from(SerializableClassesTest.class.getClassLoader())
.getTopLevelClassesRecursive("no.digipost")
.stream().map(ClassInfo::load)
.flatMap(c -> Stream.concat(Stream.of(c), Stream.of(c.getDeclaredClasses())))
.filter(c -> !c.getName().contains("Test"))
.filter(c -> !Enum.class.isAssignableFrom(c))
.filter(Serializable.class::isAssignableFrom)
.filter(c -> {
try {
c.getDeclaredField("serialVersionUID");
return false;
} catch (NoSuchFieldException e) {
return true;
}
}).collect(toList());
assertThat(serializableClassesWithoutSerialVersionUID, empty());
}
示例11: allClasses
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
private Set<ClassInfo> allClasses() {
ClassPath cpScanner;
try {
cpScanner = ClassPath.from(ClasspathConstantScanner.class.getClassLoader());
} catch (IOException e) {
LOGGER.warn("Cannot scan classes. No Constants will be returned.");
return Collections.emptySet();
}
return cpScanner.getTopLevelClasses().stream().filter(ci -> {
if (basePackages.isEmpty()) {
return true;
} else {
return basePackages.stream().anyMatch(p -> ci.getPackageName().startsWith(p));
}
}).collect(Collectors.toSet());
}
示例12: initialize
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
@PostConstruct
public void initialize() {
annotationByServiceInterface = new HashMap<>();
ImmutableSet<ClassInfo> classInfos;
try {
classInfos =
ClassPath.from(DiqubeThriftServiceInfoManager.class.getClassLoader()).getTopLevelClassesRecursive(BASE_PKG);
} catch (IOException e) {
throw new RuntimeException("Could not parse ClassPath.");
}
for (ClassInfo classInfo : classInfos) {
Class<?> clazz = classInfo.load();
DiqubeThriftService annotation = clazz.getAnnotation(DiqubeThriftService.class);
if (annotation != null)
annotationByServiceInterface.put(annotation.serviceInterface(), new DiqubeThriftServiceInfo<>(annotation));
}
logger.info("Found {} diqube services in {} scanned classes.", annotationByServiceInterface.size(),
classInfos.size());
}
示例13: main
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException {
Collection<ClassInfo> classInfos =
ClassPath.from(Tool.class.getClassLoader()).getTopLevelClassesRecursive(BASE_PKG);
Map<String, ToolFunction> toolFunctions = new HashMap<>();
for (ClassInfo classInfo : classInfos) {
Class<?> clazz = classInfo.load();
ToolFunctionName toolFunctionName = clazz.getAnnotation(ToolFunctionName.class);
if (toolFunctionName != null) {
ToolFunction functionInstance = (ToolFunction) clazz.newInstance();
toolFunctions.put(toolFunctionName.value(), functionInstance);
}
}
new Tool(toolFunctions).execute(args);
}
示例14: loadActualFunctions
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
private Map<String, Pair<AbstractActualIdentityToolFunction, IsActualIdentityToolFunction>> loadActualFunctions() {
try {
Collection<ClassInfo> classInfos =
ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive(BASE_PKG);
Map<String, Pair<AbstractActualIdentityToolFunction, IsActualIdentityToolFunction>> toolFunctions =
new HashMap<>();
for (ClassInfo classInfo : classInfos) {
Class<?> clazz = classInfo.load();
IsActualIdentityToolFunction isActualIdentityToolFunctionAnnotation =
clazz.getAnnotation(IsActualIdentityToolFunction.class);
if (isActualIdentityToolFunctionAnnotation != null) {
AbstractActualIdentityToolFunction functionInstance =
(AbstractActualIdentityToolFunction) clazz.newInstance();
toolFunctions.put(isActualIdentityToolFunctionAnnotation.identityFunctionName(),
new Pair<>(functionInstance, isActualIdentityToolFunctionAnnotation));
}
}
return toolFunctions;
} catch (IOException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
示例15: testCopy
import com.google.common.reflect.ClassPath.ClassInfo; //導入依賴的package包/類
@Test
public void testCopy() throws IOException {
// We use top level classes to ignore node types defined as inner classes for tests.
ImmutableSet<ClassInfo> topLevelClasses =
ClassPath.from(ClassLoader.getSystemClassLoader()).getTopLevelClasses();
Set<String> errors = new LinkedHashSet<>();
for (ClassInfo clazz : topLevelClasses) {
if (clazz.getPackageName().startsWith("com.google.template.soy")) {
Class<?> cls = clazz.load();
if (Node.class.isAssignableFrom(cls)) {
if (cls.isInterface()) {
continue;
}
if (Modifier.isAbstract(cls.getModifiers())) {
checkAbstractNode(cls, errors);
} else {
checkConcreteNode(cls, errors);
}
}
}
}
if (!errors.isEmpty()) {
fail("Copy policy failure:\n" + Joiner.on('\n').join(errors));
}
}