Search in sources :

Example 6 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class MethodAnalyzeVisitor method toMemberDescriptor.

private void toMemberDescriptor() {
    String modifier = ASMReflector.toModifier(this.access, this.hasDefault);
    if (this.interfaceMethod) {
        modifier = ClassNameUtils.replace(modifier, "abstract", "").trim();
    }
    final CandidateUnit.MemberType memberType = name.equals("<init>") ? CandidateUnit.MemberType.CONSTRUCTOR : CandidateUnit.MemberType.METHOD;
    final String methodName = memberType == CandidateUnit.MemberType.CONSTRUCTOR ? this.classAnalyzeVisitor.className : this.name;
    final EntryMessage message = log.traceEntry("className={} memberType={} methodName={} returnType={}", this.classAnalyzeVisitor.className, methodName, memberType, this.returnType);
    if (methodName.startsWith("lambda$")) {
        // skip
        log.traceExit(message);
        return;
    }
    if (memberType == CandidateUnit.MemberType.CONSTRUCTOR && methodName.equals(ClassNameUtils.OBJECT_CLASS)) {
        // skip
        log.traceExit(message);
        return;
    }
    final String returnFQCN = memberType == CandidateUnit.MemberType.CONSTRUCTOR ? methodName : this.returnType.getFQCN();
    final List<MethodParameter> methodParameters = this.parameterTypes.stream().map(typeInfo -> new MethodParameter(typeInfo.getFQCN(), typeInfo.paramName)).collect(Collectors.toList());
    final MethodDescriptor descriptor = new MethodDescriptor(this.classAnalyzeVisitor.className, methodName, modifier, methodParameters, this.exceptions, returnFQCN, this.hasDefault, memberType);
    descriptor.setTypeParameters(this.typeParameters);
    log.trace("formalType={}", this.formalType);
    if (this.formalType != null) {
        descriptor.formalType = this.formalType.toString();
    }
    this.classAnalyzeVisitor.members.add(descriptor);
    log.traceExit(message);
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor) Label(org.objectweb.asm.Label) Type(org.objectweb.asm.Type) ParameterName(meghanada.reflect.names.ParameterName) ArrayList(java.util.ArrayList) Serializer(meghanada.store.Serializer) Map(java.util.Map) CandidateUnit(meghanada.reflect.CandidateUnit) Attribute(org.objectweb.asm.Attribute) Opcodes(org.objectweb.asm.Opcodes) MethodDescriptor(meghanada.reflect.MethodDescriptor) MoreObjects(com.google.common.base.MoreObjects) Set(java.util.Set) SignatureReader(org.objectweb.asm.signature.SignatureReader) Collectors(java.util.stream.Collectors) EntryMessage(org.apache.logging.log4j.message.EntryMessage) MethodParameter(meghanada.reflect.MethodParameter) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TypePath(org.objectweb.asm.TypePath) ClassNameUtils(meghanada.utils.ClassNameUtils) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) MethodParameterNames(meghanada.reflect.names.MethodParameterNames) CandidateUnit(meghanada.reflect.CandidateUnit) MethodParameter(meghanada.reflect.MethodParameter) EntryMessage(org.apache.logging.log4j.message.EntryMessage) MethodDescriptor(meghanada.reflect.MethodDescriptor)

Example 7 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class MethodAnalyzeVisitor method visitEnd.

@Override
public void visitEnd() {
    final EntryMessage entryMessage = log.traceEntry("returnType={} parameterTypes={}", this.returnType, this.parameterTypes);
    if (this.returnType == null) {
        // void
        this.returnType = new TypeInfo("void", "void");
    }
    if (this.parameterTypes == null) {
        // void
        this.parameterTypes = new ArrayList<>(4);
    }
    if (((this.parameterTypes.size() != this.parameterNames.length) || (this.parameterNames.length > 0 && this.parameterNames[0] == null)) && !tryGetParameterName(this.classAnalyzeVisitor.className, this.name)) {
        setDefaultParameterNames();
    }
    for (int i = 0; i < this.parameterTypes.size(); i++) {
        TypeInfo typeInfo = this.parameterTypes.get(i);
        typeInfo.paramName = this.parameterNames[i];
    }
    // log.debug("{} ({})", this.name, this.parameterTypes);
    this.toMemberDescriptor();
    log.traceExit(entryMessage);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 8 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage 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 9 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class MethodSignatureVisitor method visitClassType.

@Override
public void visitClassType(final String s) {
    final String className = ClassNameUtils.replaceSlash(s);
    final EntryMessage message = log.traceEntry("current={} s={} className={} isClassBound={}", this.current, s, className, this.isClassBound);
    TypeInfo typeInfo = new TypeInfo(className, className);
    if (this.isInterfaceBound && !this.isFormalType) {
        final String name = this.current.name;
        current.name = '<' + name + " extends " + className + '>';
        log.traceExit(message);
        return;
    }
    if (this.isClassBound && !this.isFormalType) {
        final String name = this.current.name;
        current.name = '<' + name + '>';
        log.traceExit(message);
        return;
    }
    if (this.hasTypes) {
        // override
        if (this.isExtends) {
            typeInfo = new TypeInfo("? extends " + className, "? extends " + className);
        } else if (this.isSuper) {
            typeInfo = new TypeInfo("? super " + className, "? super " + className);
        }
        this.current = typeInfo;
    }
    if (this.current == null) {
        this.current = typeInfo;
    }
    log.traceExit(message);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 10 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class MethodSignatureVisitor method visitEnd.

@Override
public void visitEnd() {
    final EntryMessage message = log.traceEntry("current={} isClassBound={} isInterfaceBound={}", this.current, this.isClassBound, this.isInterfaceBound);
    if (this.isReturn && this.parent != null) {
        if (this.hasTypes) {
            if (this.parent.current.typeParameters == null) {
                this.parent.current.typeParameters = new ArrayList<>(4);
            }
            this.parent.current.typeParameters.add(this.current);
        } else {
            if (this.isArray) {
                this.parent.returnType = this.current;
                this.parent.returnType.isArray = true;
            } else {
                this.parent.returnType = this.current;
            }
        }
        log.traceExit(message);
        return;
    }
    if (this.isParameter && this.parent != null) {
        if (this.isArray) {
            this.current.variableArguments = true;
        }
        if (this.parent.current != null) {
            if (this.parent.current.typeParameters == null) {
                this.parent.current.typeParameters = new ArrayList<>(4);
            }
            this.parent.current.typeParameters.add(this.current);
        } else {
            if (this.parent.parameterTypes == null) {
                this.parent.parameterTypes = new ArrayList<>(4);
            }
            this.parent.parameterTypes.add(this.current);
        }
        log.traceExit(message);
        return;
    }
    if (this.isClassBound || this.isInterfaceBound) {
        assert this.parent != null;
        this.parent.formalType = this.current;
    }
    log.traceExit(message);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Aggregations

EntryMessage (org.apache.logging.log4j.message.EntryMessage)64 ArrayList (java.util.ArrayList)9 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)8 Test (org.junit.jupiter.api.Test)8 ClassScope (meghanada.analyze.ClassScope)5 MethodCall (meghanada.analyze.MethodCall)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 Variable (meghanada.analyze.Variable)3 Project (meghanada.project.Project)3 ClassIndex (meghanada.reflect.ClassIndex)3 ClassNameUtils (meghanada.utils.ClassNameUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 SignatureReader (org.objectweb.asm.signature.SignatureReader)3