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;
}
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);
}
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;
}
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()]));
}
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;
}
Aggregations