Search in sources :

Example 1 with ReflectionsException

use of org.reflections.ReflectionsException in project reflections by ronmamo.

the class Utils method getFieldFromString.

public static Field getFieldFromString(String field, ClassLoader... classLoaders) {
    String className = field.substring(0, field.lastIndexOf('.'));
    String fieldName = field.substring(field.lastIndexOf('.') + 1);
    try {
        return forName(className, classLoaders).getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        throw new ReflectionsException("Can't resolve field named " + fieldName, e);
    }
}
Also used : ReflectionsException(org.reflections.ReflectionsException)

Example 2 with ReflectionsException

use of org.reflections.ReflectionsException in project reflections by ronmamo.

the class JavassistAdapter method getOfCreateClassObject.

public ClassFile getOfCreateClassObject(final Vfs.File file) {
    InputStream inputStream = null;
    try {
        inputStream = file.openInputStream();
        DataInputStream dis = new DataInputStream(new BufferedInputStream(inputStream));
        return new ClassFile(dis);
    } catch (IOException e) {
        throw new ReflectionsException("could not create class file from " + file.getName(), e);
    } finally {
        Utils.close(inputStream);
    }
}
Also used : ReflectionsException(org.reflections.ReflectionsException) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 3 with ReflectionsException

use of org.reflections.ReflectionsException in project reflections by ronmamo.

the class MemberUsageScanner method scan.

@Override
public void scan(Object cls) {
    try {
        CtClass ctClass = getClassPool().get(getMetadataAdapter().getClassName(cls));
        for (CtBehavior member : ctClass.getDeclaredConstructors()) {
            scanMember(member);
        }
        for (CtBehavior member : ctClass.getDeclaredMethods()) {
            scanMember(member);
        }
        ctClass.detach();
    } catch (Exception e) {
        throw new ReflectionsException("Could not scan method usage for " + getMetadataAdapter().getClassName(cls), e);
    }
}
Also used : ReflectionsException(org.reflections.ReflectionsException) ReflectionsException(org.reflections.ReflectionsException)

Example 4 with ReflectionsException

use of org.reflections.ReflectionsException in project reflections by ronmamo.

the class JavaCodeSerializer method resolveField.

public static Field resolveField(final Class aField) {
    try {
        String name = aField.getSimpleName();
        Class<?> declaringClass = aField.getDeclaringClass().getDeclaringClass();
        return resolveClassOf(declaringClass).getDeclaredField(name);
    } catch (Exception e) {
        throw new ReflectionsException("could not resolve to field " + aField.getName(), e);
    }
}
Also used : ReflectionsException(org.reflections.ReflectionsException) ReflectionsException(org.reflections.ReflectionsException) IOException(java.io.IOException)

Example 5 with ReflectionsException

use of org.reflections.ReflectionsException in project reflections by ronmamo.

the class MemberUsageScanner method scan.

@Override
public List<Map.Entry<String, String>> scan(ClassFile classFile) {
    List<Map.Entry<String, String>> entries = new ArrayList<>();
    CtClass ctClass = null;
    try {
        ctClass = getClassPool().get(classFile.getName());
        for (CtBehavior member : ctClass.getDeclaredConstructors()) {
            scanMember(member, entries);
        }
        for (CtBehavior member : ctClass.getDeclaredMethods()) {
            scanMember(member, entries);
        }
    } catch (Exception e) {
        throw new ReflectionsException("Could not scan method usage for " + classFile.getName(), e);
    } finally {
        if (ctClass != null) {
            ctClass.detach();
        }
    }
    return entries;
}
Also used : CtBehavior(javassist.CtBehavior) ReflectionsException(org.reflections.ReflectionsException) CtClass(javassist.CtClass) ArrayList(java.util.ArrayList) CannotCompileException(javassist.CannotCompileException) ReflectionsException(org.reflections.ReflectionsException) NotFoundException(javassist.NotFoundException)

Aggregations

ReflectionsException (org.reflections.ReflectionsException)12 IOException (java.io.IOException)5 InputStream (java.io.InputStream)2 NotFoundException (javassist.NotFoundException)2 Document (org.dom4j.Document)2 XMLWriter (org.dom4j.io.XMLWriter)2 Predicate (com.google.common.base.Predicate)1 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Annotation (java.lang.annotation.Annotation)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 JarInputStream (java.util.jar.JarInputStream)1 Collectors (java.util.stream.Collectors)1