Search in sources :

Example 16 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project jqa-java-plugin by buschmais.

the class ClassVisitor method visitMethod.

@Override
public org.objectweb.asm.MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
    MethodDescriptor methodDescriptor = visitorHelper.getMethodDescriptor(cachedType, SignatureHelper.getMethodSignature(name, desc));
    visitorHelper.getTypeVariableResolver().push();
    methodDescriptor.setName(name);
    setModifiers(access, methodDescriptor);
    if (hasFlag(access, Opcodes.ACC_ABSTRACT)) {
        methodDescriptor.setAbstract(Boolean.TRUE);
    }
    if (hasFlag(access, Opcodes.ACC_NATIVE)) {
        methodDescriptor.setNative(Boolean.TRUE);
    }
    if (signature == null) {
        String returnType = SignatureHelper.getType(org.objectweb.asm.Type.getReturnType(desc));
        methodDescriptor.setReturns(visitorHelper.resolveType(returnType, cachedType).getTypeDescriptor());
        org.objectweb.asm.Type[] types = org.objectweb.asm.Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            String parameterType = SignatureHelper.getType(types[i]);
            TypeDescriptor typeDescriptor = visitorHelper.resolveType(parameterType, cachedType).getTypeDescriptor();
            ParameterDescriptor parameterDescriptor = visitorHelper.addParameterDescriptor(methodDescriptor, i);
            parameterDescriptor.setType(typeDescriptor);
        }
    } else {
        new SignatureReader(signature).accept(new MethodSignatureVisitor(cachedType, methodDescriptor, visitorHelper));
    }
    for (int i = 0; exceptions != null && i < exceptions.length; i++) {
        TypeDescriptor exceptionType = visitorHelper.resolveType(SignatureHelper.getObjectType(exceptions[i]), cachedType).getTypeDescriptor();
        methodDescriptor.getThrows().add(exceptionType);
    }
    return new DelegatingMethodVisitor(asList(new MethodVisitor(cachedType, methodDescriptor, visitorHelper), new MethodLoCVisitor(methodDescriptor), new MethodComplexityVisitor(methodDescriptor)));
}
Also used : DelegatingMethodVisitor(com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.delegate.DelegatingMethodVisitor) SignatureReader(org.objectweb.asm.signature.SignatureReader) DelegatingMethodVisitor(com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.delegate.DelegatingMethodVisitor) MethodSignatureVisitor(com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.generics.MethodSignatureVisitor)

Example 17 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project jqa-java-plugin by buschmais.

the class ClassVisitor method visit.

@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
    Class<? extends ClassFileDescriptor> javaType = getJavaType(access);
    String fullQualifiedName = SignatureHelper.getObjectType(name);
    cachedType = visitorHelper.createType(fullQualifiedName, fileDescriptor, javaType);
    visitorHelper.getTypeVariableResolver().push();
    ClassFileDescriptor classFileDescriptor = cachedType.getTypeDescriptor();
    classFileDescriptor.setByteCodeVersion(version);
    if (hasFlag(access, Opcodes.ACC_ABSTRACT) && !hasFlag(access, Opcodes.ACC_INTERFACE)) {
        classFileDescriptor.setAbstract(Boolean.TRUE);
    }
    setModifiers(access, classFileDescriptor);
    if (signature == null) {
        if (superName != null) {
            TypeDescriptor superClassType = visitorHelper.resolveType(SignatureHelper.getObjectType(superName), cachedType).getTypeDescriptor();
            classFileDescriptor.setSuperClass(superClassType);
        }
        for (int i = 0; interfaces != null && i < interfaces.length; i++) {
            TypeDescriptor interfaceType = visitorHelper.resolveType(SignatureHelper.getObjectType(interfaces[i]), cachedType).getTypeDescriptor();
            classFileDescriptor.getInterfaces().add(interfaceType);
        }
    } else {
        new SignatureReader(signature).accept(new ClassSignatureVisitor(cachedType, visitorHelper));
    }
}
Also used : SignatureReader(org.objectweb.asm.signature.SignatureReader) ClassSignatureVisitor(com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.generics.ClassSignatureVisitor)

Example 18 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project jqa-java-plugin by buschmais.

the class MethodVisitor method visitLocalVariable.

@Override
public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
    if (visitorHelper.getClassModelConfiguration().isMethodDeclaresVariable() && !THIS.equals(name)) {
        final VariableDescriptor variableDescriptor = visitorHelper.getVariableDescriptor(name, SignatureHelper.getFieldSignature(name, desc));
        if (signature == null) {
            TypeDescriptor type = visitorHelper.resolveType(SignatureHelper.getType((desc)), containingType).getTypeDescriptor();
            variableDescriptor.setType(type);
        } else {
            new SignatureReader(signature).accept(new AbstractBoundVisitor(visitorHelper, containingType) {

                @Override
                protected void apply(TypeDescriptor rawTypeBound, BoundDescriptor bound) {
                    variableDescriptor.setType(rawTypeBound);
                    variableDescriptor.setGenericType(bound);
                }
            });
        }
        methodDescriptor.getVariables().add(variableDescriptor);
    }
}
Also used : BoundDescriptor(com.buschmais.jqassistant.plugin.java.api.model.generics.BoundDescriptor) SignatureReader(org.objectweb.asm.signature.SignatureReader) AbstractBoundVisitor(com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.generics.AbstractBoundVisitor)

Example 19 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project maple-ir by LLVM-but-worse.

the class Remapper method mapSignature.

/**
 * @param typeSignature
 *            true if signature is a FieldTypeSignature, such as the
 *            signature parameter of the ClassVisitor.visitField or
 *            MethodVisitor.visitLocalVariable methods
 */
public String mapSignature(String signature, boolean typeSignature) {
    if (signature == null) {
        return null;
    }
    SignatureReader r = new SignatureReader(signature);
    SignatureWriter w = new SignatureWriter();
    SignatureVisitor a = createRemappingSignatureAdapter(w);
    if (typeSignature) {
        r.acceptType(a);
    } else {
        r.accept(a);
    }
    return w.toString();
}
Also used : SignatureReader(org.objectweb.asm.signature.SignatureReader) SignatureVisitor(org.objectweb.asm.signature.SignatureVisitor) SignatureWriter(org.objectweb.asm.signature.SignatureWriter)

Example 20 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project maple-ir by LLVM-but-worse.

the class Textifier method visit.

// ------------------------------------------------------------------------
// Classes
// ------------------------------------------------------------------------
@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
    this.access = access;
    int major = version & 0xFFFF;
    int minor = version >>> 16;
    buf.setLength(0);
    buf.append("// class version ").append(major).append('.').append(minor).append(" (").append(version).append(")\n");
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        buf.append("// DEPRECATED\n");
    }
    buf.append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n');
    appendDescriptor(CLASS_SIGNATURE, signature);
    if (signature != null) {
        TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
        SignatureReader r = new SignatureReader(signature);
        r.accept(sv);
        buf.append("// declaration: ").append(name).append(sv.getDeclaration()).append('\n');
    }
    appendAccess(access & ~Opcodes.ACC_SUPER);
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        buf.append("@interface ");
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        buf.append("interface ");
    } else if ((access & Opcodes.ACC_ENUM) == 0) {
        buf.append("class ");
    }
    appendDescriptor(INTERNAL_NAME, name);
    if (superName != null && !"java/lang/Object".equals(superName)) {
        buf.append(" extends ");
        appendDescriptor(INTERNAL_NAME, superName);
        buf.append(' ');
    }
    if (interfaces != null && interfaces.length > 0) {
        buf.append(" implements ");
        for (int i = 0; i < interfaces.length; ++i) {
            appendDescriptor(INTERNAL_NAME, interfaces[i]);
            buf.append(' ');
        }
    }
    buf.append(" {\n\n");
    text.add(buf.toString());
}
Also used : SignatureReader(org.objectweb.asm.signature.SignatureReader)

Aggregations

SignatureReader (org.objectweb.asm.signature.SignatureReader)41 SignatureWriter (org.objectweb.asm.signature.SignatureWriter)12 ArrayList (java.util.ArrayList)5 ClassNode (org.codehaus.groovy.ast.ClassNode)4 GenericsType (org.codehaus.groovy.ast.GenericsType)3 Type (org.objectweb.asm.Type)3 SignatureVisitor (org.objectweb.asm.signature.SignatureVisitor)3 BoundDescriptor (com.buschmais.jqassistant.plugin.java.api.model.generics.BoundDescriptor)2 AbstractBoundVisitor (com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.generics.AbstractBoundVisitor)2 List (java.util.List)2 Map (java.util.Map)2 TypeSignatureVisitor (net.sourceforge.pmd.dcd.asm.TypeSignatureVisitor)2 EntryMessage (org.apache.logging.log4j.message.EntryMessage)2 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)2 ReturnStatement (org.codehaus.groovy.ast.stmt.ReturnStatement)2 DelegatingMethodVisitor (com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.delegate.DelegatingMethodVisitor)1 ClassSignatureVisitor (com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.generics.ClassSignatureVisitor)1 MethodSignatureVisitor (com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.generics.MethodSignatureVisitor)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1