Jet api refactoring: remove JetBodyDeclarationWithBody interface from JetFunctionLiteralExpression
This commit is contained in:
@@ -33,9 +33,7 @@ import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
@@ -63,7 +61,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
this.closure = closure;
|
||||
}
|
||||
|
||||
public ClosureCodegen gen(JetExpression fun, CodegenContext context, ExpressionCodegen expressionCodegen) {
|
||||
public ClosureCodegen gen(JetDeclarationWithBody fun, CodegenContext context, ExpressionCodegen expressionCodegen) {
|
||||
SimpleFunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, fun);
|
||||
assert descriptor != null;
|
||||
|
||||
@@ -97,7 +95,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
|
||||
|
||||
generateBridge(name.getInternalName(), funDescriptor, fun, cv);
|
||||
generateBody(funDescriptor, cv, (JetDeclarationWithBody) fun, context, expressionCodegen);
|
||||
generateBody(funDescriptor, cv, fun, context, expressionCodegen);
|
||||
|
||||
constructor = generateConstructor(funClass, fun, cv, closure);
|
||||
|
||||
|
||||
@@ -1246,18 +1246,18 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return gen(expression.getFunctionLiteral().getBodyExpression());
|
||||
}
|
||||
else {
|
||||
return genClosure(expression);
|
||||
return genClosure(expression.getFunctionLiteral());
|
||||
}
|
||||
}
|
||||
|
||||
private StackValue genClosure(JetExpression expression) {
|
||||
FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, expression);
|
||||
private StackValue genClosure(JetDeclarationWithBody declaration) {
|
||||
FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
|
||||
ClassDescriptor classDescriptor =
|
||||
bindingContext.get(CLASS_FOR_FUNCTION, descriptor);
|
||||
//noinspection SuspiciousMethodCalls
|
||||
CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||
|
||||
ClosureCodegen closureCodegen = new ClosureCodegen(state, (MutableClosure) closure).gen(expression, context, this);
|
||||
ClosureCodegen closureCodegen = new ClosureCodegen(state, (MutableClosure) closure).gen(declaration, context, this);
|
||||
|
||||
JvmClassName className = closureCodegen.name;
|
||||
Type asmType = className.getAsmType();
|
||||
|
||||
@@ -81,7 +81,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
|
||||
|
||||
public void generateMethod(
|
||||
@NotNull PsiElement declaration,
|
||||
@NotNull JetDeclaration declaration,
|
||||
@NotNull JvmMethodSignature jvmSignature,
|
||||
boolean needJetAnnotations,
|
||||
@Nullable String propertyTypeSignature,
|
||||
@@ -112,7 +112,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
}
|
||||
|
||||
private void generateMethodHeaderAndBody(
|
||||
@NotNull PsiElement declaration,
|
||||
@NotNull JetDeclaration declaration,
|
||||
@NotNull JvmMethodSignature jvmSignature,
|
||||
boolean needJetAnnotations,
|
||||
@Nullable String propertyTypeSignature,
|
||||
@@ -152,7 +152,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
if (expectedThisObject != null) {
|
||||
thisType = typeMapper.mapType(expectedThisObject.getType());
|
||||
}
|
||||
else if (declaration instanceof JetFunctionLiteralExpression || isLocalFun(bindingContext, functionDescriptor)) {
|
||||
else if (declaration instanceof JetFunctionLiteral || isLocalFun(bindingContext, functionDescriptor)) {
|
||||
thisType = typeMapper.mapType(context.getThisDescriptor());
|
||||
}
|
||||
else {
|
||||
@@ -167,7 +167,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
@NotNull
|
||||
private MethodBounds generateMethodBody(
|
||||
@NotNull MethodVisitor mv,
|
||||
@NotNull PsiElement funOrProperty,
|
||||
@NotNull JetDeclaration funOrProperty,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull MethodContext context,
|
||||
@NotNull Method asmMethod,
|
||||
@@ -206,7 +206,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
|
||||
boolean hasBodyExpression = hasBodyExpression(funOrProperty);
|
||||
if (hasBodyExpression) {
|
||||
JetDeclarationWithBody fun = (JetDeclarationWithBody)funOrProperty;
|
||||
JetDeclarationWithBody fun = (JetDeclarationWithBody) funOrProperty;
|
||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, asmMethod.getReturnType(), context, state);
|
||||
codegen.returnExpression(fun.getBodyExpression());
|
||||
|
||||
@@ -229,9 +229,9 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
return new MethodBounds(methodBegin, methodEnd);
|
||||
}
|
||||
|
||||
private static boolean hasBodyExpression(PsiElement funOrProperty) {
|
||||
private static boolean hasBodyExpression(JetDeclaration funOrProperty) {
|
||||
return (funOrProperty instanceof JetDeclarationWithBody
|
||||
&& ((JetDeclarationWithBody)funOrProperty).getBodyExpression() != null);
|
||||
&& ((JetDeclarationWithBody) funOrProperty).getBodyExpression() != null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -224,14 +224,15 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
|
||||
@Override
|
||||
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||
FunctionDescriptor functionDescriptor =
|
||||
(FunctionDescriptor) bindingContext.get(DECLARATION_TO_DESCRIPTOR, expression);
|
||||
(FunctionDescriptor) bindingContext.get(DECLARATION_TO_DESCRIPTOR, functionLiteral);
|
||||
// working around a problem with shallow analysis
|
||||
if (functionDescriptor == null) return;
|
||||
|
||||
String name = inventAnonymousClassName(expression);
|
||||
ClassDescriptor classDescriptor = recordClassForFunction(functionDescriptor);
|
||||
recordClosure(bindingTrace, expression, classDescriptor, peekFromStack(classStack), JvmClassName.byInternalName(name), true);
|
||||
recordClosure(bindingTrace, functionLiteral, classDescriptor, peekFromStack(classStack), JvmClassName.byInternalName(name), true);
|
||||
|
||||
classStack.push(classDescriptor);
|
||||
nameStack.push(name);
|
||||
|
||||
Reference in New Issue
Block a user