use of org.jetbrains.org.objectweb.asm.tree.MethodInsnNode in project kotlin by JetBrains.
the class ClassContext method getLocation.
/**
* Returns a location for the given {@link AbstractInsnNode}.
*
* @param instruction the instruction to look up the location for
* @return a location pointing to the instruction, or as close to it
* as possible
*/
@NonNull
public Location getLocation(@NonNull AbstractInsnNode instruction) {
SearchHints hints = SearchHints.create(FORWARD).matchJavaSymbol();
String pattern = null;
if (instruction instanceof MethodInsnNode) {
MethodInsnNode call = (MethodInsnNode) instruction;
if (call.name.equals(CONSTRUCTOR_NAME)) {
pattern = call.owner;
hints = hints.matchConstructor();
} else {
pattern = call.name;
}
int index = pattern.lastIndexOf('$');
if (index != -1) {
pattern = pattern.substring(index + 1);
}
index = pattern.lastIndexOf('/');
if (index != -1) {
pattern = pattern.substring(index + 1);
}
}
int line = findLineNumber(instruction);
return getLocationForLine(line, pattern, null, hints);
}
use of org.jetbrains.org.objectweb.asm.tree.MethodInsnNode 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.MethodInsnNode in project intellij-community by JetBrains.
the class NullableInterpreter method naryOperation.
@Override
public BasicValue naryOperation(AbstractInsnNode insn, List<? extends BasicValue> values) throws AnalyzerException {
int opcode = insn.getOpcode();
boolean isStaticInvoke = opcode == INVOKESTATIC;
int shift = isStaticInvoke ? 0 : 1;
if ((opcode == INVOKESPECIAL || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL) && values.get(0) instanceof ParamValue) {
subResult = NPE;
}
switch(opcode) {
case INVOKEINTERFACE:
if (nullableAnalysis) {
for (int i = shift; i < values.size(); i++) {
if (values.get(i) instanceof ParamValue) {
top = true;
return super.naryOperation(insn, values);
}
}
}
break;
case INVOKESTATIC:
case INVOKESPECIAL:
case INVOKEVIRTUAL:
boolean stable = opcode == INVOKESTATIC || opcode == INVOKESPECIAL;
MethodInsnNode methodNode = (MethodInsnNode) insn;
Method method = new Method(methodNode.owner, methodNode.name, methodNode.desc);
for (int i = shift; i < values.size(); i++) {
BasicValue value = values.get(i);
if (value instanceof ParamValue || (NullValue == value && nullityMask == In.NULLABLE_MASK && "<init>".equals(methodNode.name))) {
subResult = combine(subResult, new ConditionalNPE(new Key(method, new In(i - shift, nullityMask), stable)));
}
}
break;
default:
}
return super.naryOperation(insn, values);
}
use of org.jetbrains.org.objectweb.asm.tree.MethodInsnNode in project kotlin by JetBrains.
the class ControlFlowGraph method dotDescribe.
private static String dotDescribe(Node node) {
AbstractInsnNode instruction = node.instruction;
if (instruction instanceof LabelNode) {
return "Label";
} else if (instruction instanceof LineNumberNode) {
LineNumberNode lineNode = (LineNumberNode) instruction;
return "Line " + lineNode.line;
} else if (instruction instanceof FrameNode) {
return "Stack Frame";
} else if (instruction instanceof MethodInsnNode) {
MethodInsnNode method = (MethodInsnNode) instruction;
String cls = method.owner.substring(method.owner.lastIndexOf('/') + 1);
cls = cls.replace('$', '.');
return "Call " + cls + "#" + method.name;
} else if (instruction instanceof FieldInsnNode) {
FieldInsnNode field = (FieldInsnNode) instruction;
String cls = field.owner.substring(field.owner.lastIndexOf('/') + 1);
cls = cls.replace('$', '.');
return "Field " + cls + "#" + field.name;
} else if (instruction instanceof TypeInsnNode && instruction.getOpcode() == Opcodes.NEW) {
return "New " + ((TypeInsnNode) instruction).desc;
}
StringBuilder sb = new StringBuilder();
String opcodeName = getOpcodeName(instruction.getOpcode());
sb.append(opcodeName);
if (instruction instanceof IntInsnNode) {
IntInsnNode in = (IntInsnNode) instruction;
sb.append(" ").append(Integer.toString(in.operand));
} else if (instruction instanceof LdcInsnNode) {
LdcInsnNode ldc = (LdcInsnNode) instruction;
sb.append(" ");
if (ldc.cst instanceof String) {
sb.append("\\\"");
}
sb.append(ldc.cst);
if (ldc.cst instanceof String) {
sb.append("\\\"");
}
}
return sb.toString();
}
use of org.jetbrains.org.objectweb.asm.tree.MethodInsnNode in project kotlin by JetBrains.
the class AsmVisitor method runClassDetectors.
// ASM API uses raw types
@SuppressWarnings("rawtypes")
void runClassDetectors(ClassContext context) {
ClassNode classNode = context.getClassNode();
for (Detector detector : mAllDetectors) {
detector.beforeCheckFile(context);
}
for (Detector detector : mFullClassChecks) {
Detector.ClassScanner scanner = (Detector.ClassScanner) detector;
scanner.checkClass(context, classNode);
detector.afterCheckFile(context);
}
if (!mMethodNameToChecks.isEmpty() || !mMethodOwnerToChecks.isEmpty() || mNodeTypeDetectors != null && mNodeTypeDetectors.length > 0) {
List methodList = classNode.methods;
for (Object m : methodList) {
MethodNode method = (MethodNode) m;
InsnList nodes = method.instructions;
for (int i = 0, n = nodes.size(); i < n; i++) {
AbstractInsnNode instruction = nodes.get(i);
int type = instruction.getType();
if (type == AbstractInsnNode.METHOD_INSN) {
MethodInsnNode call = (MethodInsnNode) instruction;
String owner = call.owner;
List<ClassScanner> scanners = mMethodOwnerToChecks.get(owner);
if (scanners != null) {
for (ClassScanner scanner : scanners) {
scanner.checkCall(context, classNode, method, call);
}
}
String name = call.name;
scanners = mMethodNameToChecks.get(name);
if (scanners != null) {
for (ClassScanner scanner : scanners) {
scanner.checkCall(context, classNode, method, call);
}
}
}
if (mNodeTypeDetectors != null && type < mNodeTypeDetectors.length) {
List<ClassScanner> scanners = mNodeTypeDetectors[type];
if (scanners != null) {
for (ClassScanner scanner : scanners) {
scanner.checkInstruction(context, classNode, method, instruction);
}
}
}
}
}
}
for (Detector detector : mAllDetectors) {
detector.afterCheckFile(context);
}
}
Aggregations