use of org.jetbrains.org.objectweb.asm.tree.MethodNode 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.MethodNode in project kotlin by JetBrains.
the class InlineCodegen method generateLambdaBody.
@NotNull
private SMAPAndMethodNode generateLambdaBody(@NotNull LambdaInfo info) {
KtExpression declaration = info.getFunctionWithBodyOrCallableReference();
FunctionDescriptor descriptor = info.getFunctionDescriptor();
ClassContext closureContext = info.isPropertyReference() ? codegen.getContext().intoAnonymousClass(info.getClassDescriptor(), codegen, OwnerKind.IMPLEMENTATION) : codegen.getContext().intoClosure(descriptor, codegen, typeMapper);
MethodContext context = closureContext.intoInlinedLambda(descriptor, info.isCrossInline, info.isPropertyReference());
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignatureSkipGeneric(descriptor);
Method asmMethod = jvmMethodSignature.getAsmMethod();
MethodNode methodNode = new MethodNode(InlineCodegenUtil.API, getMethodAsmFlags(descriptor, context.getContextKind(), state), asmMethod.getName(), asmMethod.getDescriptor(), null, null);
MethodVisitor adapter = InlineCodegenUtil.wrapWithMaxLocalCalc(methodNode);
SMAP smap = generateMethodBody(adapter, descriptor, context, declaration, jvmMethodSignature, codegen, info);
adapter.visitMaxs(-1, -1);
return new SMAPAndMethodNode(methodNode, smap);
}
use of org.jetbrains.org.objectweb.asm.tree.MethodNode in project kotlin by JetBrains.
the class InlineCodegen method createMethodNode.
@NotNull
static SMAPAndMethodNode createMethodNode(@NotNull final FunctionDescriptor functionDescriptor, @NotNull JvmMethodSignature jvmSignature, @NotNull ExpressionCodegen codegen, @NotNull CodegenContext context, boolean callDefault, @Nullable ResolvedCall<?> resolvedCall) {
if (InlineCodegenUtil.isSpecialEnumMethod(functionDescriptor)) {
assert resolvedCall != null : "Resolved call for " + functionDescriptor + " should be not null";
Map<TypeParameterDescriptor, KotlinType> arguments = resolvedCall.getTypeArguments();
assert arguments.size() == 1 : "Resolved call for " + functionDescriptor + " should have 1 type argument";
MethodNode node = InlineCodegenUtil.createSpecialEnumMethodBody(codegen, functionDescriptor.getName().asString(), arguments.keySet().iterator().next().getDefaultType(), codegen.getState().getTypeMapper());
return new SMAPAndMethodNode(node, SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
} else if (CoroutineCodegenUtilKt.isBuiltInSuspendCoroutineOrReturnInJvm(functionDescriptor)) {
return new SMAPAndMethodNode(CoroutineCodegenUtilKt.createMethodNodeForSuspendCoroutineOrReturn(functionDescriptor, codegen.getState().getTypeMapper()), SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
}
final GenerationState state = codegen.getState();
final Method asmMethod = callDefault ? state.getTypeMapper().mapDefaultMethod(functionDescriptor, context.getContextKind()) : jvmSignature.getAsmMethod();
MethodId methodId = new MethodId(DescriptorUtils.getFqNameSafe(functionDescriptor.getContainingDeclaration()), asmMethod);
final CallableMemberDescriptor directMember = getDirectMemberAndCallableFromObject(functionDescriptor);
if (!isBuiltInArrayIntrinsic(functionDescriptor) && !(directMember instanceof DeserializedCallableMemberDescriptor)) {
return doCreateMethodNodeFromSource(functionDescriptor, jvmSignature, codegen, context, callDefault, state, asmMethod);
}
SMAPAndMethodNode resultInCache = InlineCacheKt.getOrPut(state.getInlineCache().getMethodNodeById(), methodId, new Function0<SMAPAndMethodNode>() {
@Override
public SMAPAndMethodNode invoke() {
SMAPAndMethodNode result = doCreateMethodNodeFromCompiled(directMember, state, asmMethod);
if (result == null) {
throw new IllegalStateException("Couldn't obtain compiled function body for " + functionDescriptor);
}
return result;
}
});
return resultInCache.copyWithNewNode(cloneMethodNode(resultInCache.getNode()));
}
use of org.jetbrains.org.objectweb.asm.tree.MethodNode in project kotlin by JetBrains.
the class InlineCodegen method cloneMethodNode.
@NotNull
private static MethodNode cloneMethodNode(@NotNull MethodNode methodNode) {
methodNode.instructions.resetLabels();
MethodNode result = new MethodNode(API, methodNode.access, methodNode.name, methodNode.desc, methodNode.signature, ArrayUtil.toStringArray(methodNode.exceptions));
methodNode.accept(result);
return result;
}
use of org.jetbrains.org.objectweb.asm.tree.MethodNode in project kotlin by JetBrains.
the class InlineCodegen method throwCompilationException.
@NotNull
private CompilationException throwCompilationException(@Nullable SMAPAndMethodNode nodeAndSmap, @NotNull Exception e, boolean generateNodeText) {
CallableMemberDescriptor contextDescriptor = codegen.getContext().getContextDescriptor();
PsiElement element = DescriptorToSourceUtils.descriptorToDeclaration(contextDescriptor);
MethodNode node = nodeAndSmap != null ? nodeAndSmap.getNode() : null;
throw new CompilationException("Couldn't inline method call '" + functionDescriptor.getName() + "' into\n" + DescriptorRenderer.DEBUG_TEXT.render(contextDescriptor) + "\n" + (element != null ? element.getText() : "<no source>") + (generateNodeText ? ("\nCause: " + InlineCodegenUtil.getNodeText(node)) : ""), e, callElement);
}
Aggregations