use of org.objectweb.asm.signature.SignatureReader in project bytecode-viewer by Konloch.
the class Textifier method visitLocalVariable.
@Override
public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
buf.setLength(0);
buf.append(tab2).append("LOCALVARIABLE ").append(name).append(' ');
appendDescriptor(FIELD_DESCRIPTOR, desc);
buf.append(' ');
appendLabel(start);
buf.append(' ');
appendLabel(end);
buf.append(' ').append(index).append('\n');
if (signature != null) {
buf.append(tab2);
appendDescriptor(FIELD_SIGNATURE, signature);
TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
SignatureReader r = new SignatureReader(signature);
r.acceptType(sv);
buf.append(tab2).append("// declaration: ").append(sv.getDeclaration()).append('\n');
}
text.add(buf.toString());
}
use of org.objectweb.asm.signature.SignatureReader in project sonar-java by SonarSource.
the class BytecodeVisitor method visitMethod.
@Override
public MethodVisitor visitMethod(int flags, String name, String desc, @Nullable String signature, @Nullable String[] exceptions) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(desc);
if (isNotSynthetic(flags)) {
if ((flags & Opcodes.ACC_BRIDGE) != 0) {
LOG.warn("bridge method {} not marked as synthetic in class {}", name, className);
return null;
}
// TODO(Godin): according to JVMS 4.7.24 - parameter can be marked as synthetic
MethodJavaType type = new MethodJavaType(convertAsmTypes(org.objectweb.asm.Type.getArgumentTypes(desc)), convertAsmType(org.objectweb.asm.Type.getReturnType(desc)), getCompletedClassSymbolsType(exceptions), classSymbol);
int methodFlags = Flags.filterAccessBytecodeFlags(flags);
if (classSymbol.isInterface() && Flags.isNotFlagged(methodFlags, Flags.ABSTRACT | Flags.PRIVATE | Flags.STATIC)) {
// abstract, static nor private method of interface is a default method
methodFlags |= Flags.DEFAULT;
}
final JavaSymbol.MethodJavaSymbol methodSymbol = new JavaSymbol.MethodJavaSymbol(methodFlags, name, type, classSymbol);
methodSymbol.desc = desc;
classSymbol.members.enter(methodSymbol);
if (signature != null) {
SignatureReader signatureReader = new SignatureReader(signature);
signatureReader.accept(new TypeParameterDeclaration(methodSymbol));
signatureReader.accept(new ReadMethodSignature(methodSymbol));
}
methodSymbol.parameters = new Scope(methodSymbol);
for (int i = 0; i < type.argTypes.size(); i += 1) {
methodSymbol.parameters.enter(new JavaSymbol.VariableJavaSymbol(0, "arg" + i, methodSymbol));
}
// checks for annotations on the method and its parameters
return new BytecodeMethodVisitor(methodSymbol, this);
}
return null;
}
use of org.objectweb.asm.signature.SignatureReader in project sonar-java by SonarSource.
the class BytecodeVisitor method visit.
@Override
public void visit(int version, int flags, String name, @Nullable String signature, @Nullable String superName, @Nullable String[] interfaces) {
Preconditions.checkState(name.endsWith(classSymbol.name), "Name : '%s' should ends with %s", name, classSymbol.name);
Preconditions.checkState(name.endsWith("package-info") || isNotSynthetic(flags), "%s is synthetic", name);
className = name;
if (signature != null) {
SignatureReader signatureReader = new SignatureReader(signature);
signatureReader.accept(new TypeParameterDeclaration(classSymbol));
ReadGenericSignature readGenericSignature = new ReadGenericSignature();
signatureReader.accept(readGenericSignature);
((ClassJavaType) classSymbol.type).interfaces = readGenericSignature.interfaces();
} else {
if (superName == null) {
Preconditions.checkState("java/lang/Object".equals(className), "superName must be null only for java/lang/Object, but not for %s", className);
// TODO(Godin): what about interfaces and annotations
} else {
((ClassJavaType) classSymbol.type).supertype = getClassSymbol(superName).type;
}
((ClassJavaType) classSymbol.type).interfaces = getCompletedClassSymbolsType(interfaces);
}
// The important access flags are the one defined in the outer class.
if ((classSymbol.flags & Flags.ACCESS_FLAGS) != 0) {
classSymbol.flags |= Flags.filterAccessBytecodeFlags(flags & ~Flags.ACCESS_FLAGS);
} else {
classSymbol.flags |= Flags.filterAccessBytecodeFlags(flags);
}
classSymbol.members = new Scope(classSymbol);
}
use of org.objectweb.asm.signature.SignatureReader in project evosuite by EvoSuite.
the class CastClassAnalyzer method handleMethodNode.
/**
* Add all possible calls for a given method
*
* @param mn
*/
@SuppressWarnings("unchecked")
public void handleMethodNode(ClassNode cn, MethodNode mn, int depth) {
if (mn.signature != null) {
logger.debug("Visiting signature: " + mn.signature);
CollectParameterTypesVisitor visitor = new CollectParameterTypesVisitor(cn.name);
new SignatureReader(mn.signature).accept(visitor);
for (Type castType : visitor.getClasses()) {
if (!castClassMap.containsKey(castType)) {
logger.debug("Adding new cast class from signature visitor: " + castType);
castClassMap.put(castType, depth + 1);
}
}
}
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> iterator = instructions.iterator();
// TODO: This really shouldn't be here but in its own class
while (iterator.hasNext()) {
AbstractInsnNode insn = iterator.next();
if (insn.getOpcode() == Opcodes.CHECKCAST) {
TypeInsnNode typeNode = (TypeInsnNode) insn;
Type castType = Type.getObjectType(typeNode.desc);
while (castType.getSort() == Type.ARRAY) {
castType = castType.getElementType();
}
logger.debug("Adding new cast class from cast: " + castType);
if (!castClassMap.containsKey(castType))
castClassMap.put(castType, depth + 1);
} else if (insn.getOpcode() == Opcodes.INSTANCEOF) {
TypeInsnNode typeNode = (TypeInsnNode) insn;
Type castType = Type.getObjectType(typeNode.desc);
while (castType.getSort() == Type.ARRAY) {
castType = castType.getElementType();
}
logger.debug("Adding new cast class from instanceof: " + castType);
if (!castClassMap.containsKey(castType))
castClassMap.put(castType, depth + 1);
} else if (insn.getOpcode() == Opcodes.LDC) {
LdcInsnNode ldcNode = (LdcInsnNode) insn;
if (ldcNode.cst instanceof Type) {
Type type = (Type) ldcNode.cst;
while (type.getSort() == Type.ARRAY) {
type = type.getElementType();
}
if (!castClassMap.containsKey(type))
castClassMap.put(type, depth + 1);
}
}
}
}
use of org.objectweb.asm.signature.SignatureReader in project pmd by pmd.
the class ConstructorNode method getMember.
@Override
public Constructor<?> getMember() {
if (ClassLoaderUtil.CLINIT.equals(name)) {
return null;
} else {
Constructor<?> constructor = constructorReference == null ? null : constructorReference.get();
if (constructor == null) {
SignatureReader signatureReader = new SignatureReader(desc);
TypeSignatureVisitor visitor = new TypeSignatureVisitor();
signatureReader.accept(visitor);
constructor = ClassLoaderUtil.getConstructor(super.getClassNode().getType(), name, visitor.getMethodParameterTypes());
constructorReference = new WeakReference<Constructor<?>>(constructor);
}
return constructor;
}
}
Aggregations