use of org.objectweb.asm.signature.SignatureReader in project dex2jar by pxb1988.
the class Dex2Asm method isSignatureNotValid.
/**
* @see org.objectweb.asm.commons.Remapper#mapSignature(String, boolean)
*/
private static boolean isSignatureNotValid(String signature, boolean typeSignature) {
if (signature == null) {
return false;
}
try {
SignatureReader r = new SignatureReader(signature);
SignatureWriter a = new SignatureWriter();
if (typeSignature) {
r.acceptType(a);
} else {
r.accept(a);
}
} catch (Exception ignore) {
return true;
}
return false;
}
use of org.objectweb.asm.signature.SignatureReader in project bytecode-viewer by Konloch.
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
*/
@Override
public String mapSignature(String signature, boolean typeSignature) {
if (signature == null) {
return null;
}
SignatureReader r = new SignatureReader(signature);
SignatureWriter w = new SignatureWriter();
SignatureVisitor a = createSignatureRemapper(w);
if (typeSignature) {
r.acceptType(a);
} else {
r.accept(a);
}
return w.toString();
}
use of org.objectweb.asm.signature.SignatureReader in project groovy by apache.
the class MemberSignatureParser method createMethodNode.
static MethodNode createMethodNode(final AsmReferenceResolver resolver, final MethodStub method) {
GenericsType[] typeParameters = null;
ClassNode[] returnType = resolve(resolver, Type.getReturnType(method.desc));
ClassNode[] parameterTypes = resolve(resolver, Type.getArgumentTypes(method.desc));
ClassNode[] exceptionTypes = resolve(resolver, method.exceptions);
if (method.signature != null) {
FormalParameterParser parser = new FormalParameterParser(resolver) {
private int exceptionIndex, parameterIndex;
@Override
public SignatureVisitor visitReturnType() {
return new TypeSignatureParser(resolver) {
@Override
void finished(final ClassNode result) {
returnType[0] = applyErasure(result, returnType[0]);
}
};
}
@Override
public SignatureVisitor visitParameterType() {
return new TypeSignatureParser(resolver) {
@Override
void finished(final ClassNode result) {
parameterTypes[parameterIndex] = applyErasure(result, parameterTypes[parameterIndex]);
parameterIndex += 1;
}
};
}
@Override
public SignatureVisitor visitExceptionType() {
return new TypeSignatureParser(resolver) {
@Override
void finished(final ClassNode result) {
exceptionTypes[exceptionIndex] = applyErasure(result, exceptionTypes[exceptionIndex]);
exceptionIndex += 1;
}
};
}
};
new SignatureReader(method.signature).accept(parser);
typeParameters = parser.getTypeParameters();
} else {
returnType[0] = GenericsUtils.nonGeneric(returnType[0]);
for (int i = 0, n = parameterTypes.length; i < n; i += 1) {
parameterTypes[i] = GenericsUtils.nonGeneric(parameterTypes[i]);
}
}
int nParameters = parameterTypes.length;
Parameter[] parameters = new Parameter[nParameters];
List<String> parameterNames = method.parameterNames;
for (int i = 0; i < nParameters; i += 1) {
String parameterName = "param" + i;
if (parameterNames != null && i < parameterNames.size()) {
String decompiledName = parameterNames.get(i);
if (decompiledName != null) {
parameterName = decompiledName;
}
}
parameters[i] = new Parameter(parameterTypes[i], parameterName);
}
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, exceptionTypes, null);
} else {
result = new MethodNode(method.methodName, method.accessModifiers, returnType[0], parameters, exceptionTypes, null);
Object annDefault = method.annotationDefault;
if (annDefault != null) {
if (annDefault instanceof TypeWrapper) {
annDefault = resolver.resolveType(Type.getType(((TypeWrapper) annDefault).desc));
}
result.setCode(new ReturnStatement(new ConstantExpression(annDefault)));
result.setAnnotationDefault(true);
} else {
// seems wrong but otherwise some tests fail (e.g. TestingASTTransformsTest)
result.setCode(new ReturnStatement(new ConstantExpression(null)));
}
}
if (typeParameters != null && typeParameters.length > 0) {
result.setGenericsTypes(typeParameters);
}
return result;
}
use of org.objectweb.asm.signature.SignatureReader in project groovy by apache.
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(ClassNode.EMPTY_ARRAY));
}
use of org.objectweb.asm.signature.SignatureReader in project groovy by apache.
the class ClassSignatureParser method configureClass.
static void configureClass(ClassNode classNode, ClassStub stub, AsmReferenceResolver resolver) {
if (stub.signature != null) {
parseClassSignature(classNode, stub.signature, resolver);
return;
}
if (stub.superName != null) {
classNode.setSuperClass(resolver.resolveClass(AsmDecompiler.fromInternalName(stub.superName)));
}
ClassNode[] interfaces = new ClassNode[stub.interfaceNames.length];
for (int i = 0; i < stub.interfaceNames.length; i++) {
interfaces[i] = resolver.resolveClass(AsmDecompiler.fromInternalName(stub.interfaceNames[i]));
}
classNode.setInterfaces(interfaces);
if (!stub.permittedSubclasses.isEmpty()) {
List<ClassNode> permittedSubclasses = classNode.getPermittedSubclasses();
for (String name : stub.permittedSubclasses) {
permittedSubclasses.add(resolver.resolveClass(AsmDecompiler.fromInternalName(name)));
}
}
if (!stub.recordComponents.isEmpty()) {
classNode.setRecordComponents(stub.recordComponents.stream().map(r -> {
ClassNode type = resolver.resolveType(Type.getType(r.descriptor));
ObjectHolder<ClassNode> typeHolder = new ObjectHolder<>(type);
if (null != r.signature) {
new SignatureReader(r.signature).accept(new TypeSignatureParser(resolver) {
@Override
void finished(final ClassNode result) {
typeHolder.setObject(applyErasure(result, typeHolder.getObject()));
}
});
}
ClassNode cn = typeHolder.getObject();
Annotations.addTypeAnnotations(r, cn, resolver);
RecordComponentNode recordComponentNode = new RecordComponentNode(classNode, r.name, cn);
Annotations.addAnnotations(r, recordComponentNode, resolver);
return recordComponentNode;
}).collect(Collectors.toList()));
}
}
Aggregations