本文整理匯總了Java中com.google.common.reflect.ClassPath.ClassInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassPath.ClassInfo方法的具體用法?Java ClassPath.ClassInfo怎麽用?Java ClassPath.ClassInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.reflect.ClassPath
的用法示例。
在下文中一共展示了ClassPath.ClassInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadClassesInPackage
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
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;
}
示例2: hasAccessibleConstructor
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
boolean hasAccessibleConstructor(ClassPath.ClassInfo info, String fromPackage) {
Class<?> load = info.load();
boolean isPublicClass = Modifier.isPublic(load.getModifiers()),
isSamePackage = fromPackage.equals(info.getPackageName());
for (Constructor<?> candidate : load.getDeclaredConstructors()) {
int modifiers = candidate.getModifiers();
if (isPublicClass && Modifier.isPublic(modifiers)) return true;
else if (isSamePackage
&& !Modifier.isPrivate(modifiers)
&& !Modifier.isProtected(modifiers)) return true;
}
return false;
}
示例3: getAllModels
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public Collection<Class> getAllModels() throws IOException {
Class<Charge> chargeClass = Charge.class;
ClassPath classPath = ClassPath.from(chargeClass.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> topLevelClasses = classPath.getTopLevelClasses(chargeClass.getPackage().getName());
List<Class> classList = Lists.newArrayListWithExpectedSize(topLevelClasses.size());
for (ClassPath.ClassInfo classInfo : topLevelClasses) {
Class c = classInfo.load();
// Skip things that aren't APIResources
if (!APIResource.class.isAssignableFrom(c)) {
continue;
}
// Skip the APIResource itself
if (APIResource.class == c) {
continue;
}
classList.add(classInfo.load());
}
return classList;
}
示例4: loadClassesInPackage
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
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;
}
示例5: registerHandlers
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public void registerHandlers(String packageName) {
try {
Set<ClassPath.ClassInfo> classes = ClassPath.from(MinecraftProtocol.class.getClassLoader()).getTopLevelClasses(packageName);
for (ClassPath.ClassInfo classInfo : classes) {
Class<?> clazz = classInfo.load();
if (!Handler.class.isAssignableFrom(clazz))
continue;
this.registerHandler(((Class<? extends Handler>) clazz));
}
} catch (IOException e) {
throw new RuntimeException("Failed to register the handlers for package: \'" + packageName + "\'");
}
}
示例6: scanPack
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
protected void scanPack(String pack, ClassPath classPath)
throws MojoExecutionException, IOException {
this.getLog().info("Scanning package " + pack);
if (Strings.isNullOrEmpty(pack)) {
ClassLoaderUtils.restoreOriginalClassLoader();
throw new MojoExecutionException("Invalid target package: " + pack);
}
for (ClassPath.ClassInfo classInfo : classPath.getTopLevelClasses(pack)) {
try {
Class<?> c = classInfo.load();
if (!ignoredList.contains(c.getPackage().getName()) && !ignoredList.contains(c.getName())) {
scanClass(c);
}
} catch (Throwable ex) {
this.getLog().warn("Skipping Class: Unable to load" + classInfo.getName(), ex);
}
}
}
示例7: collectSteps
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private static Map<CukesComponent, Multimap<StepType, StepDefinition>> collectSteps() throws IOException, ClassNotFoundException {
Map<CukesComponent, Multimap<StepType, StepDefinition>> steps = createStepsStubs();
ClassPath classPath = ClassPath.from(DocumentationGenerator.class.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> classes = classPath.getTopLevelClassesRecursive("lv.ctco.cukes");
for (ClassPath.ClassInfo classInfo : classes) {
String className = classInfo.getName();
Class<?> aClass = Class.forName(className);
Method[] methods = aClass.getMethods();
for (Method method : methods) {
StepType type = StepType.getTypeForMethod(method);
if (type != null) {
CukesComponent component = CukesComponent.findByClassName(className);
steps.get(component).put(type, new StepDefinition(type.getPattern(method), type.getDescription(method)));
}
}
}
return steps;
}
示例8: loadClassesInPackage
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
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;
}
示例9: tesstByteBuf
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public void tesstByteBuf() throws InterruptedException, IOException {
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
ClassPath from = ClassPath.from(systemClassLoader);
StdInstantiatorStrategy instantiator = new StdInstantiatorStrategy();
Class<Request> requestClazz = Request.class;
for (ClassPath.ClassInfo clazz : from.getAllClasses()) {
Class<?> load;
try {
load = clazz.load();
} catch (NoClassDefFoundError e) {
continue;
}
for (Class<?> aClass : load.getInterfaces()) {
if (aClass.equals(requestClazz)) {
Object o = instantiator.newInstantiatorOf(aClass).newInstance();
testByteBuf((Request) o);
}
}
}
}
示例10: getRecognizedClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private Set<ClassPath.ClassInfo> getRecognizedClasses(ClassLoader classLoader, List<String> packages) {
Set<ClassPath.ClassInfo> result = new HashSet<>();
try {
ClassPath classPath = ClassPath.from(classLoader);
for (ClassPath.ClassInfo classInfo : classPath.getAllClasses()) {
String packageName = classInfo.getPackageName();
for (String aPackage : packages) {
if (packageName.startsWith(aPackage)) {
result.add(classInfo);
}
}
}
} catch (IOException e) {
logger.severe("Cannot create ClassPath: " + e);
}
return result;
}
示例11: resolve
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@Override
public ImmutableSet<String> resolve(ProjectFilesystem filesystem, Path relativeClassPath) {
ImmutableSet.Builder<String> topLevelSymbolsBuilder = ImmutableSet.builder();
try {
Path classPath = filesystem.getFileForRelativePath(relativeClassPath).toPath();
ClassLoader loader = URLClassLoader.newInstance(
new URL[]{classPath.toUri().toURL()},
/* parent */ null);
// For every class contained in that jar, check to see if the package name
// (e.g. com.facebook.foo), the simple name (e.g. ImmutableSet) or the name
// (e.g com.google.common.collect.ImmutableSet) is one of the missing symbols.
for (ClassPath.ClassInfo classInfo : ClassPath.from(loader).getTopLevelClasses()) {
topLevelSymbolsBuilder.add(classInfo.getPackageName(),
classInfo.getSimpleName(),
classInfo.getName());
}
} catch (IOException e) {
// Since this simply is a heuristic, return an empty set if we fail to load a jar.
return topLevelSymbolsBuilder.build();
}
return topLevelSymbolsBuilder.build();
}
示例12: AutomaticPacketDeserializer
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public AutomaticPacketDeserializer() {
constructors = new Constructor<?>[0xFFFF];
try {
ClassPath cp = ClassPath.from(AutomaticPacketDeserializer.class.getClassLoader());
for (ClassPath.ClassInfo info : cp.getAllClasses()) {
Class<?> c = info.load();
if (Packet.class.isAssignableFrom(c)) {
for (Constructor<?> constructor : c.getConstructors()) {
if (constructor.isAnnotationPresent(Opcode.class)) {
constructors[constructor.getAnnotation(Opcode.class).value()] = constructor;
}
}
}
}
} catch (IOException e) {
throw new Error("OpenMaple was unable to access classpath resources.", e);
}
}
示例13: loadByScanPath
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected Collection<Class<T>> loadByScanPath() throws IOException
{
ClassPath classPath;
Set<Class<T>> classes = Sets.newHashSet();
classPath = ClassPath.from(pluginType.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> infos;
infos = classPath.getTopLevelClassesRecursive(packageName);
for (ClassPath.ClassInfo info : infos)
{
Class<?> clazz = info.load();
if (pluginType.isAssignableFrom(clazz))
classes.add((Class<T>) clazz);
}
return classes;
}
示例14: getModuleClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* Finds all the fully qualified (ie: full package names) module classnames
* by recursively searching the rootDirectories
*
* @return
*/
//only load attempt to add .class files
private Collection<Class<? extends GuiModule>> getModuleClasses() {
Collection<Class<? extends GuiModule>> results = new ArrayList<>();
try {
ClassPath classPath = ClassPath.from(this.getClass().getClassLoader());
ImmutableSet<ClassPath.ClassInfo> set = classPath.getTopLevelClasses(PIPE_GUI_PLUGIN_CONCRETE_PACKAGE);
for (ClassPath.ClassInfo classInfo : set) {
Class<?> clazz = classInfo.load();
if (GuiModule.class.isAssignableFrom(clazz)) {
results.add((Class<? extends GuiModule>) clazz);
}
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage());
}
return results;
}
示例15: listEnumerations
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* Utility method to get a map of all enumerations within a package.
* The map will use the enumeration class simple name as key and the enum itself as value.
*
* @return a map of all enumeration within the package or an empty map in all other cases.
*/
public static Map<String, Enum<?>[]> listEnumerations(String packageName) {
try {
ClassPath cp = ClassPath.from(VocabularyUtils.class.getClassLoader());
ImmutableMap.Builder<String, Enum<?>[]> builder = ImmutableMap.builder();
List<ClassPath.ClassInfo> infos = cp.getTopLevelClasses(packageName).asList();
for (ClassPath.ClassInfo info : infos) {
Class<? extends Enum<?>> vocab = lookupVocabulary(info.getName());
// verify that it is an Enumeration
if (vocab != null && vocab.getEnumConstants() != null) {
builder.put(info.getSimpleName(), vocab.getEnumConstants());
}
}
return builder.build();
} catch (Exception e) {
LOG.error("Unable to read the classpath for enumerations", e);
return ImmutableMap.<String, Enum<?>[]>of(); // empty
}
}