Search in sources :

Example 1 with VisitorHelper

use of com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.VisitorHelper in project jqa-java-plugin by buschmais.

the class ClassFileScannerPlugin method scan.

@Override
public ClassFileDescriptor scan(FileResource file, String path, Scope scope, final Scanner scanner) throws IOException {
    final FileDescriptor fileDescriptor = scanner.getContext().getCurrentDescriptor();
    VisitorHelper visitorHelper = new VisitorHelper(scanner.getContext(), classModelConfiguration);
    final ClassVisitor visitor = new ClassVisitor(fileDescriptor, visitorHelper);
    ClassFileDescriptor classFileDescriptor;
    try (InputStream stream = file.createStream()) {
        classFileDescriptor = MD5DigestDelegate.getInstance().digest(stream, new MD5DigestDelegate.DigestOperation<ClassFileDescriptor>() {

            @Override
            public ClassFileDescriptor execute(InputStream inputStream) throws IOException {
                new ClassReader(inputStream).accept(visitor, 0);
                return visitor.getTypeDescriptor();
            }
        });
        classFileDescriptor.setValid(true);
    } catch (RuntimeException e) {
        LOGGER.warn("Cannot scan class '" + path + "'.", e);
        classFileDescriptor = visitor.getTypeDescriptor();
        if (classFileDescriptor == null) {
            classFileDescriptor = scanner.getContext().getStore().addDescriptorType(fileDescriptor, ClassFileDescriptor.class);
        }
        classFileDescriptor.setValid(false);
    }
    return classFileDescriptor;
}
Also used : InputStream(java.io.InputStream) ClassReader(org.objectweb.asm.ClassReader) VisitorHelper(com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.VisitorHelper) ClassVisitor(com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.ClassVisitor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor)

Aggregations

FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)1 ClassFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor)1 ClassVisitor (com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.ClassVisitor)1 VisitorHelper (com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.VisitorHelper)1 InputStream (java.io.InputStream)1 ClassReader (org.objectweb.asm.ClassReader)1