use of org.jetbrains.org.objectweb.asm.tree.ClassNode in project kotlin by JetBrains.
the class LintDriver method isSuppressed.
/**
* Returns whether the given issue is suppressed in the given class.
*
* @param issue the issue to be checked, or null to just check for "all"
* @param classNode the class containing the issue
* @return true if there is a suppress annotation covering the specific
* issue in this class
*/
public boolean isSuppressed(@Nullable Issue issue, @NonNull ClassNode classNode) {
if (classNode.invisibleAnnotations != null) {
@SuppressWarnings("unchecked") List<AnnotationNode> annotations = classNode.invisibleAnnotations;
return isSuppressed(issue, annotations);
}
if (classNode.outerClass != null && classNode.outerMethod == null && isAnonymousClass(classNode)) {
ClassNode outer = getOuterClassNode(classNode);
if (outer != null) {
MethodNode m = findMethod(outer, CONSTRUCTOR_NAME, false);
if (m != null) {
MethodInsnNode call = findConstructorInvocation(m, classNode.name);
if (call != null) {
if (isSuppressed(issue, outer, m, call)) {
return true;
}
}
}
m = findMethod(outer, CLASS_CONSTRUCTOR, false);
if (m != null) {
MethodInsnNode call = findConstructorInvocation(m, classNode.name);
if (call != null) {
if (isSuppressed(issue, outer, m, call)) {
return true;
}
}
}
}
}
return false;
}
use of org.jetbrains.org.objectweb.asm.tree.ClassNode in project kotlin by JetBrains.
the class LintDriver method getOuterClassNode.
/** Returns the outer class node of the given class node
* @param classNode the inner class node
* @return the outer class node */
public ClassNode getOuterClassNode(@NonNull ClassNode classNode) {
String outerName = classNode.outerClass;
Iterator<ClassNode> iterator = mOuterClasses.iterator();
while (iterator.hasNext()) {
ClassNode node = iterator.next();
if (outerName != null) {
if (node.name.equals(outerName)) {
return node;
}
} else if (node == classNode) {
return iterator.hasNext() ? iterator.next() : null;
}
}
return null;
}
use of org.jetbrains.org.objectweb.asm.tree.ClassNode in project android by JetBrains.
the class ClassConverterTest method testMethodWrapping.
public void testMethodWrapping() throws Exception {
byte[] data = ClassConverterTest.dumpTestViewClass();
assertTrue(isValidClassFile(data));
byte[] modified = rewriteClass(data, Integer.MAX_VALUE);
assertTrue(isValidClassFile(data));
// Parse both classes and compare
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(modified);
classReader.accept(classNode, 0);
assertEquals(3, classNode.methods.size());
final Set<String> methods = new HashSet<>();
classNode.accept(new ClassVisitor(ASM5) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
methods.add(name + desc);
return super.visitMethod(access, name, desc, signature, exceptions);
}
});
assertTrue(methods.contains("onMeasure(II)V"));
assertTrue(methods.contains("onMeasure_Original(II)V"));
}
use of org.jetbrains.org.objectweb.asm.tree.ClassNode in project kotlin by JetBrains.
the class CodegenTestCase method verifyWithAsm.
private static boolean verifyWithAsm(@NotNull OutputFile file, ClassLoader loader) {
ClassNode classNode = new ClassNode();
new ClassReader(file.asByteArray()).accept(classNode, 0);
SimpleVerifier verifier = new SimpleVerifier();
verifier.setClassLoader(loader);
Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(verifier);
boolean noErrors = true;
for (MethodNode method : classNode.methods) {
try {
analyzer.analyze(classNode.name, method);
} catch (Throwable e) {
System.err.println(file.asText());
System.err.println(classNode.name + "::" + method.name + method.desc);
//noinspection InstanceofCatchParameter
if (e instanceof AnalyzerException) {
// Print the erroneous instruction
TraceMethodVisitor tmv = new TraceMethodVisitor(new Textifier());
((AnalyzerException) e).node.accept(tmv);
PrintWriter pw = new PrintWriter(System.err);
tmv.p.print(pw);
pw.flush();
}
e.printStackTrace();
noErrors = false;
}
}
return noErrors;
}
use of org.jetbrains.org.objectweb.asm.tree.ClassNode in project kotlin by JetBrains.
the class ClassContext method report.
/**
* Reports an issue.
* <p>
* Detectors should only call this method if an error applies to the whole class
* scope and there is no specific method or field that applies to the error.
* If so, use
* {@link #report(Issue, MethodNode, AbstractInsnNode, Location, String)} or
* {@link #report(Issue, FieldNode, Location, String)}, such that
* suppress annotations are checked.
*
* @param issue the issue to report
* @param location the location of the issue, or null if not known
* @param message the message for this warning
*/
@Override
public void report(@NonNull Issue issue, @NonNull Location location, @NonNull String message) {
if (mDriver.isSuppressed(issue, mClassNode)) {
return;
}
ClassNode curr = mClassNode;
while (curr != null) {
ClassNode prev = curr;
curr = mDriver.getOuterClassNode(curr);
if (curr != null) {
if (prev.outerMethod != null) {
// ASM API
@SuppressWarnings("rawtypes") List methods = curr.methods;
for (Object m : methods) {
MethodNode method = (MethodNode) m;
if (method.name.equals(prev.outerMethod) && method.desc.equals(prev.outerMethodDesc)) {
// class hierarchy)
if (method != null && mDriver.isSuppressed(issue, mClassNode, method, null)) {
return;
}
break;
}
}
}
if (mDriver.isSuppressed(issue, curr)) {
return;
}
}
}
super.report(issue, location, message);
}
Aggregations