Search in sources :

Example 11 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project pmd by pmd.

the class MethodNode method getMember.

@Override
public Method getMember() {
    Method method = methodReference == null ? null : methodReference.get();
    if (method == null) {
        SignatureReader signatureReader = new SignatureReader(desc);
        TypeSignatureVisitor visitor = new TypeSignatureVisitor();
        signatureReader.accept(visitor);
        method = ClassLoaderUtil.getMethod(super.getClassNode().getType(), name, visitor.getMethodParameterTypes());
        methodReference = new WeakReference<>(method);
    }
    return method;
}
Also used : SignatureReader(org.objectweb.asm.signature.SignatureReader) TypeSignatureVisitor(net.sourceforge.pmd.dcd.asm.TypeSignatureVisitor) Method(java.lang.reflect.Method)

Example 12 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project meghanada-server by mopemope.

the class FieldAnalyzeVisitor method parseSignature.

FieldAnalyzeVisitor parseSignature() {
    final EntryMessage m = log.traceEntry("fieldSignature={}", fieldSignature);
    boolean isStatic = (Opcodes.ACC_STATIC & this.access) > 0;
    SignatureReader signatureReader = new SignatureReader(this.fieldSignature);
    FieldSignatureVisitor visitor;
    if (isStatic) {
        visitor = new FieldSignatureVisitor(this.name, new ArrayList<>(4));
    } else {
        visitor = new FieldSignatureVisitor(this.name, this.classAnalyzeVisitor.classTypeParameters);
    }
    if (this.typeMap != null) {
        visitor.setTypeMap(this.typeMap);
    }
    this.fieldSignatureVisitor = visitor;
    signatureReader.acceptType(fieldSignatureVisitor);
    return log.traceExit(m, this);
}
Also used : SignatureReader(org.objectweb.asm.signature.SignatureReader) ArrayList(java.util.ArrayList) EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 13 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project meghanada-server by mopemope.

the class MethodAnalyzeVisitor method parseSignature.

MethodAnalyzeVisitor parseSignature() {
    final EntryMessage entryMessage = log.traceEntry("name={} methodSignature={}", this.name, this.methodSignature);
    final boolean isStatic = (Opcodes.ACC_STATIC & this.access) > 0;
    final SignatureReader signatureReader = new SignatureReader(this.methodSignature);
    MethodSignatureVisitor visitor;
    if (isStatic) {
        visitor = new MethodSignatureVisitor(this.name, new ArrayList<>(4));
    } else {
        visitor = new MethodSignatureVisitor(this.name, this.classAnalyzeVisitor.classTypeParameters);
    }
    if (this.typeMap != null) {
        visitor.setTypeMap(this.typeMap);
    }
    signatureReader.accept(visitor);
    this.formalType = visitor.getFormalType();
    this.parameterTypes = visitor.getParameterTypes();
    this.typeParameters = visitor.getTypeParameters();
    this.returnType = visitor.getReturnType();
    log.traceExit(entryMessage);
    return this;
}
Also used : SignatureReader(org.objectweb.asm.signature.SignatureReader) ArrayList(java.util.ArrayList) EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 14 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project groovy-core by groovy.

the class ClassSignatureParser method parseClassSignature.

private static void parseClassSignature(final ClassNode classNode, String signature, final AsmReferenceResolver resolver) {
    final List<ClassNode> interfaces = new ArrayList<ClassNode>();
    FormalParameterParser v = new FormalParameterParser(resolver) {

        @Override
        public SignatureVisitor visitSuperclass() {
            flushTypeParameter();
            return new TypeSignatureParser(resolver) {

                @Override
                void finished(ClassNode result) {
                    classNode.setSuperClass(result);
                }
            };
        }

        @Override
        public SignatureVisitor visitInterface() {
            flushTypeParameter();
            return new TypeSignatureParser(resolver) {

                @Override
                void finished(ClassNode result) {
                    interfaces.add(result);
                }
            };
        }
    };
    new SignatureReader(signature).accept(v);
    GenericsType[] typeParameters = v.getTypeParameters();
    if (typeParameters.length > 0) {
        classNode.setGenericsTypes(typeParameters);
    }
    classNode.setInterfaces(interfaces.toArray(new ClassNode[interfaces.size()]));
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ArrayList(java.util.ArrayList) SignatureReader(org.objectweb.asm.signature.SignatureReader) GenericsType(org.codehaus.groovy.ast.GenericsType)

Example 15 with SignatureReader

use of org.objectweb.asm.signature.SignatureReader in project groovy-core by groovy.

the class MemberSignatureParser method createMethodNode.

static MethodNode createMethodNode(final AsmReferenceResolver resolver, MethodStub method) {
    GenericsType[] typeParameters = null;
    Type[] argumentTypes = Type.getArgumentTypes(method.desc);
    final ClassNode[] parameterTypes = new ClassNode[argumentTypes.length];
    for (int i = 0; i < argumentTypes.length; i++) {
        parameterTypes[i] = resolver.resolveType(argumentTypes[i]);
    }
    final ClassNode[] exceptions = new ClassNode[method.exceptions.length];
    for (int i = 0; i < method.exceptions.length; i++) {
        exceptions[i] = resolver.resolveClass(AsmDecompiler.fromInternalName(method.exceptions[i]));
    }
    final ClassNode[] returnType = { resolver.resolveType(Type.getReturnType(method.desc)) };
    if (method.signature != null) {
        FormalParameterParser v = new FormalParameterParser(resolver) {

            int paramIndex = 0;

            @Override
            public SignatureVisitor visitParameterType() {
                return new TypeSignatureParser(resolver) {

                    @Override
                    void finished(ClassNode result) {
                        parameterTypes[paramIndex] = applyErasure(result, parameterTypes[paramIndex]);
                        paramIndex++;
                    }
                };
            }

            @Override
            public SignatureVisitor visitReturnType() {
                return new TypeSignatureParser(resolver) {

                    @Override
                    void finished(ClassNode result) {
                        returnType[0] = applyErasure(result, returnType[0]);
                    }
                };
            }

            int exceptionIndex = 0;

            @Override
            public SignatureVisitor visitExceptionType() {
                return new TypeSignatureParser(resolver) {

                    @Override
                    void finished(ClassNode result) {
                        exceptions[exceptionIndex] = applyErasure(result, exceptions[exceptionIndex]);
                        exceptionIndex++;
                    }
                };
            }
        };
        new SignatureReader(method.signature).accept(v);
        typeParameters = v.getTypeParameters();
    }
    Parameter[] parameters = new Parameter[parameterTypes.length];
    for (int i = 0; i < parameterTypes.length; i++) {
        parameters[i] = new Parameter(parameterTypes[i], "param" + i);
    }
    if (method.parameterAnnotations != null) {
        for (Map.Entry<Integer, List<AnnotationStub>> entry : method.parameterAnnotations.entrySet()) {
            for (AnnotationStub stub : entry.getValue()) {
                AnnotationNode annotationNode = Annotations.createAnnotationNode(stub, resolver);
                if (annotationNode != null) {
                    parameters[entry.getKey()].addAnnotation(annotationNode);
                }
            }
        }
    }
    MethodNode result;
    if ("<init>".equals(method.methodName)) {
        result = new ConstructorNode(method.accessModifiers, parameters, exceptions, null);
    } else {
        result = new MethodNode(method.methodName, method.accessModifiers, returnType[0], parameters, exceptions, null);
        if (method.annotationDefault != null) {
            result.setCode(new ReturnStatement(new ConstantExpression(method.annotationDefault)));
            result.setAnnotationDefault(true);
        } else {
            // Seems wrong but otherwise some tests fail (e.g. TestingASTTransformsTest)
            result.setCode(new ReturnStatement(ConstantExpression.NULL));
        }
    }
    if (typeParameters != null && typeParameters.length > 0) {
        result.setGenericsTypes(typeParameters);
    }
    return result;
}
Also used : ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Type(org.objectweb.asm.Type) SignatureReader(org.objectweb.asm.signature.SignatureReader) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) List(java.util.List) Map(java.util.Map)

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