本文整理匯總了Java中org.reflections.ReflectionUtils.forName方法的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionUtils.forName方法的具體用法?Java ReflectionUtils.forName怎麽用?Java ReflectionUtils.forName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.reflections.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.forName方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveMethod
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public static Method resolveMethod(final Class aMethod) {
String methodOgnl = aMethod.getSimpleName();
try {
String methodName;
Class<?>[] paramTypes;
if (methodOgnl.contains(tokenSeparator)) {
methodName = methodOgnl.substring(0, methodOgnl.indexOf(tokenSeparator));
String[] params = methodOgnl.substring(methodOgnl.indexOf(tokenSeparator) + 1).split(doubleSeparator);
paramTypes = new Class<?>[params.length];
for (int i = 0; i < params.length; i++) {
String typeName = params[i].replace(arrayDescriptor, "[]").replace(pathSeparator, dotSeparator);
paramTypes[i] = ReflectionUtils.forName(typeName);
}
} else {
methodName = methodOgnl;
paramTypes = null;
}
Class<?> declaringClass = aMethod.getDeclaringClass().getDeclaringClass();
return resolveClassOf(declaringClass).getDeclaredMethod(methodName, paramTypes);
} catch (Exception e) {
throw new ReflectionsException("could not resolve to method " + aMethod.getName(), e);
}
}
示例2: scan
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@Override public void scan(Object cls) {
String className = getMetadataAdapter().getClassName(cls);
Class<?> aClass = ReflectionUtils.forName(className, getConfiguration().getClassLoaders());
if (acceptResult(klass.getName()) && klass.isAssignableFrom(aClass) && aClass != klass) {
getStore().put(klass.getName(), className);
}
}
示例3: resolveAnnotation
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public static Annotation resolveAnnotation(Class annotation) {
try {
String name = annotation.getSimpleName().replace(pathSeparator, dotSeparator);
Class<?> declaringClass = annotation.getDeclaringClass().getDeclaringClass();
Class<?> aClass = resolveClassOf(declaringClass);
Class<? extends Annotation> aClass1 = (Class<? extends Annotation>) ReflectionUtils.forName(name);
Annotation annotation1 = aClass.getAnnotation(aClass1);
return annotation1;
} catch (Exception e) {
throw new ReflectionsException("could not resolve to annotation " + annotation.getName(), e);
}
}
示例4: newInstance
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public static Object newInstance(String fullClassName) {
Class<?> clazz = ReflectionUtils.forName(fullClassName);
return newInstance(clazz);
}
示例5: createConfigFile
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private void createConfigFile() throws Exception {
File classesDir = new File(outputDirectory, "classes/");
File libDir = new File(outputDirectory, "lib");
File[] jars = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
if (jars == null) {
throw new MojoExecutionException("No jar files found in " + libDir.getAbsolutePath());
}
List<URL> jarURLs = new ArrayList<URL>();
jarURLs.add(classesDir.toURI().toURL());
for (File jar : jars) {
jarURLs.add(jar.toURI().toURL());
}
// Scan classes and all jars
final List<String> candidates = new ArrayList<String>();
new Reflections(new ConfigurationBuilder().
addUrls(jarURLs).setScanners(new AbstractScanner() {
@Override
public void scan(Object cls) {
if ((cls instanceof ClassFile)) {
ClassFile classFile = (ClassFile) cls;
if (XmlSchemaGeneratingMojo.isInjectable(classFile, getLog()) &&
(classFile.getName().equals(configClassName) || classFile.getName().endsWith(configClassName))) {
candidates.add(classFile.getName());
}
}
}
}));
if (candidates.isEmpty()) {
throw new MojoFailureException("No class found for " + configClassName);
}
if (candidates.size() > 1) {
throw new MojoFailureException("More classes found for " + configClassName + ":" + candidates);
}
String fullClassName = candidates.get(0);
URLClassLoader classLoader = new URLClassLoader(jarURLs.toArray(new URL[jarURLs.size()]),
ConfigProperty.class.getClassLoader());
Class configClass = ReflectionUtils.forName(fullClassName, classLoader);
generateToFile(configClass);
}