當前位置: 首頁>>代碼示例>>Java>>正文


Java ReflectionUtils.forName方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:ronmamo,項目名稱:reflections,代碼行數:26,代碼來源:JavaCodeSerializer.java

示例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);
    }

}
 
開發者ID:eventsourcing,項目名稱:es4j,代碼行數:10,代碼來源:PackageScanner.java

示例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);
    }
}
 
開發者ID:ronmamo,項目名稱:reflections,代碼行數:13,代碼來源:JavaCodeSerializer.java

示例4: newInstance

import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public static Object newInstance(String fullClassName) {
	Class<?> clazz = ReflectionUtils.forName(fullClassName);
	return newInstance(clazz);
}
 
開發者ID:aureliano,項目名稱:evt-bridge,代碼行數:5,代碼來源:ReflectionHelper.java

示例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);
}
 
開發者ID:avast,項目名稱:syringe-maven-plugin,代碼行數:51,代碼來源:XmlConfigGeneratingMojo.java


注:本文中的org.reflections.ReflectionUtils.forName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。