Search in sources :

Example 11 with ReflectionsException

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

the class MemberUsageScanner method scanMember.

private void scanMember(CtBehavior member, List<Map.Entry<String, String>> entries) throws CannotCompileException {
    // key contains this$/val$ means local field/parameter closure
    final String key = member.getDeclaringClass().getName() + "." + member.getMethodInfo().getName() + "(" + parameterNames(member.getMethodInfo()) + // + " #" + member.getMethodInfo().getLineNumber(0)
    ")";
    member.instrument(new ExprEditor() {

        @Override
        public void edit(NewExpr e) {
            try {
                add(entries, e.getConstructor().getDeclaringClass().getName() + "." + "<init>" + "(" + parameterNames(e.getConstructor().getMethodInfo()) + ")", key + " #" + e.getLineNumber());
            } catch (NotFoundException e1) {
                throw new ReflectionsException("Could not find new instance usage in " + key, e1);
            }
        }

        @Override
        public void edit(MethodCall m) {
            try {
                add(entries, m.getMethod().getDeclaringClass().getName() + "." + m.getMethodName() + "(" + parameterNames(m.getMethod().getMethodInfo()) + ")", key + " #" + m.getLineNumber());
            } catch (NotFoundException e) {
                throw new ReflectionsException("Could not find member " + m.getClassName() + " in " + key, e);
            }
        }

        @Override
        public void edit(ConstructorCall c) {
            try {
                add(entries, c.getConstructor().getDeclaringClass().getName() + "." + "<init>" + "(" + parameterNames(c.getConstructor().getMethodInfo()) + ")", key + " #" + c.getLineNumber());
            } catch (NotFoundException e) {
                throw new ReflectionsException("Could not find member " + c.getClassName() + " in " + key, e);
            }
        }

        @Override
        public void edit(FieldAccess f) {
            try {
                add(entries, f.getField().getDeclaringClass().getName() + "." + f.getFieldName(), key + " #" + f.getLineNumber());
            } catch (NotFoundException e) {
                throw new ReflectionsException("Could not find member " + f.getFieldName() + " in " + key, e);
            }
        }
    });
}
Also used : ReflectionsException(org.reflections.ReflectionsException) ExprEditor(javassist.expr.ExprEditor) NewExpr(javassist.expr.NewExpr) NotFoundException(javassist.NotFoundException) ConstructorCall(javassist.expr.ConstructorCall) FieldAccess(javassist.expr.FieldAccess) MethodCall(javassist.expr.MethodCall)

Example 12 with ReflectionsException

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

the class JarInputDir method getFiles.

public Iterable<Vfs.File> getFiles() {
    return () -> new Iterator<Vfs.File>() {

        {
            try {
                jarInputStream = new JarInputStream(url.openConnection().getInputStream());
            } catch (Exception e) {
                throw new ReflectionsException("Could not open url connection", e);
            }
        }

        Vfs.File entry = null;

        @Override
        public boolean hasNext() {
            return entry != null || (entry = computeNext()) != null;
        }

        @Override
        public Vfs.File next() {
            Vfs.File next = entry;
            entry = null;
            return next;
        }

        private Vfs.File computeNext() {
            while (true) {
                try {
                    ZipEntry entry = jarInputStream.getNextJarEntry();
                    if (entry == null) {
                        return null;
                    }
                    long size = entry.getSize();
                    // JDK-6916399
                    if (size < 0)
                        size = 0xffffffffl + size;
                    nextCursor += size;
                    if (!entry.isDirectory()) {
                        return new JarInputFile(entry, JarInputDir.this, cursor, nextCursor);
                    }
                } catch (IOException e) {
                    throw new ReflectionsException("could not get next zip entry", e);
                }
            }
        }
    };
}
Also used : ReflectionsException(org.reflections.ReflectionsException) JarInputStream(java.util.jar.JarInputStream) ZipEntry(java.util.zip.ZipEntry) Iterator(java.util.Iterator) IOException(java.io.IOException) ReflectionsException(org.reflections.ReflectionsException) IOException(java.io.IOException)

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