Jet api refactoring: remove JetBodyDeclarationWithBody interface from JetFunctionLiteralExpression

This commit is contained in:
Mikhael Bogdanov
2013-03-20 11:32:55 +04:00
parent 93b860e4ad
commit 8e5f0abb84
14 changed files with 60 additions and 58 deletions
@@ -33,9 +33,7 @@ import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode; import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.java.JvmAbi;
@@ -63,7 +61,7 @@ public class ClosureCodegen extends GenerationStateAware {
this.closure = closure; 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); SimpleFunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, fun);
assert descriptor != null; assert descriptor != null;
@@ -97,7 +95,7 @@ public class ClosureCodegen extends GenerationStateAware {
generateBridge(name.getInternalName(), funDescriptor, fun, cv); 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); constructor = generateConstructor(funClass, fun, cv, closure);
@@ -1246,18 +1246,18 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return gen(expression.getFunctionLiteral().getBodyExpression()); return gen(expression.getFunctionLiteral().getBodyExpression());
} }
else { else {
return genClosure(expression); return genClosure(expression.getFunctionLiteral());
} }
} }
private StackValue genClosure(JetExpression expression) { private StackValue genClosure(JetDeclarationWithBody declaration) {
FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, expression); FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
ClassDescriptor classDescriptor = ClassDescriptor classDescriptor =
bindingContext.get(CLASS_FOR_FUNCTION, descriptor); bindingContext.get(CLASS_FOR_FUNCTION, descriptor);
//noinspection SuspiciousMethodCalls //noinspection SuspiciousMethodCalls
CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor); 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; JvmClassName className = closureCodegen.name;
Type asmType = className.getAsmType(); Type asmType = className.getAsmType();
@@ -81,7 +81,7 @@ public class FunctionCodegen extends GenerationStateAware {
public void generateMethod( public void generateMethod(
@NotNull PsiElement declaration, @NotNull JetDeclaration declaration,
@NotNull JvmMethodSignature jvmSignature, @NotNull JvmMethodSignature jvmSignature,
boolean needJetAnnotations, boolean needJetAnnotations,
@Nullable String propertyTypeSignature, @Nullable String propertyTypeSignature,
@@ -112,7 +112,7 @@ public class FunctionCodegen extends GenerationStateAware {
} }
private void generateMethodHeaderAndBody( private void generateMethodHeaderAndBody(
@NotNull PsiElement declaration, @NotNull JetDeclaration declaration,
@NotNull JvmMethodSignature jvmSignature, @NotNull JvmMethodSignature jvmSignature,
boolean needJetAnnotations, boolean needJetAnnotations,
@Nullable String propertyTypeSignature, @Nullable String propertyTypeSignature,
@@ -152,7 +152,7 @@ public class FunctionCodegen extends GenerationStateAware {
if (expectedThisObject != null) { if (expectedThisObject != null) {
thisType = typeMapper.mapType(expectedThisObject.getType()); 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()); thisType = typeMapper.mapType(context.getThisDescriptor());
} }
else { else {
@@ -167,7 +167,7 @@ public class FunctionCodegen extends GenerationStateAware {
@NotNull @NotNull
private MethodBounds generateMethodBody( private MethodBounds generateMethodBody(
@NotNull MethodVisitor mv, @NotNull MethodVisitor mv,
@NotNull PsiElement funOrProperty, @NotNull JetDeclaration funOrProperty,
@NotNull FunctionDescriptor functionDescriptor, @NotNull FunctionDescriptor functionDescriptor,
@NotNull MethodContext context, @NotNull MethodContext context,
@NotNull Method asmMethod, @NotNull Method asmMethod,
@@ -206,7 +206,7 @@ public class FunctionCodegen extends GenerationStateAware {
boolean hasBodyExpression = hasBodyExpression(funOrProperty); boolean hasBodyExpression = hasBodyExpression(funOrProperty);
if (hasBodyExpression) { if (hasBodyExpression) {
JetDeclarationWithBody fun = (JetDeclarationWithBody)funOrProperty; JetDeclarationWithBody fun = (JetDeclarationWithBody) funOrProperty;
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, asmMethod.getReturnType(), context, state); ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, asmMethod.getReturnType(), context, state);
codegen.returnExpression(fun.getBodyExpression()); codegen.returnExpression(fun.getBodyExpression());
@@ -229,9 +229,9 @@ public class FunctionCodegen extends GenerationStateAware {
return new MethodBounds(methodBegin, methodEnd); return new MethodBounds(methodBegin, methodEnd);
} }
private static boolean hasBodyExpression(PsiElement funOrProperty) { private static boolean hasBodyExpression(JetDeclaration funOrProperty) {
return (funOrProperty instanceof JetDeclarationWithBody return (funOrProperty instanceof JetDeclarationWithBody
&& ((JetDeclarationWithBody)funOrProperty).getBodyExpression() != null); && ((JetDeclarationWithBody) funOrProperty).getBodyExpression() != null);
} }
@@ -224,14 +224,15 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
@Override @Override
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
FunctionDescriptor functionDescriptor = FunctionDescriptor functionDescriptor =
(FunctionDescriptor) bindingContext.get(DECLARATION_TO_DESCRIPTOR, expression); (FunctionDescriptor) bindingContext.get(DECLARATION_TO_DESCRIPTOR, functionLiteral);
// working around a problem with shallow analysis // working around a problem with shallow analysis
if (functionDescriptor == null) return; if (functionDescriptor == null) return;
String name = inventAnonymousClassName(expression); String name = inventAnonymousClassName(expression);
ClassDescriptor classDescriptor = recordClassForFunction(functionDescriptor); 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); classStack.push(classDescriptor);
nameStack.push(name); nameStack.push(name);
@@ -602,10 +602,7 @@ public class JetControlFlowProcessor {
subroutine = builder.getReturnSubroutine(); subroutine = builder.getReturnSubroutine();
// TODO : a context check // TODO : a context check
} }
//todo cache JetFunctionLiteral instead
if (subroutine instanceof JetFunctionLiteralExpression) {
subroutine = ((JetFunctionLiteralExpression) subroutine).getFunctionLiteral();
}
if (subroutine instanceof JetFunction || subroutine instanceof JetPropertyAccessor) { if (subroutine instanceof JetFunction || subroutine instanceof JetPropertyAccessor) {
if (returnedExpression == null) { if (returnedExpression == null) {
builder.returnNoValue(expression, subroutine); builder.returnNoValue(expression, subroutine);
@@ -16,13 +16,12 @@
package org.jetbrains.jet.lang.psi; package org.jetbrains.jet.lang.psi;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
public interface JetDeclarationWithBody extends PsiElement { public interface JetDeclarationWithBody extends JetDeclaration {
@Nullable @Nullable
JetExpression getBodyExpression(); JetExpression getBodyExpression();
@@ -18,11 +18,13 @@ package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lexer.JetToken;
import java.util.List; import java.util.List;
public class JetFunctionLiteralExpression extends JetExpressionImpl implements JetDeclarationWithBody { public class JetFunctionLiteralExpression extends JetExpressionImpl {
public JetFunctionLiteralExpression(@NotNull ASTNode node) { public JetFunctionLiteralExpression(@NotNull ASTNode node) {
super(node); super(node);
} }
@@ -43,30 +45,24 @@ public class JetFunctionLiteralExpression extends JetExpressionImpl implements J
} }
@NotNull @NotNull
@Override
public List<JetParameter> getValueParameters() { public List<JetParameter> getValueParameters() {
return getFunctionLiteral().getValueParameters(); return getFunctionLiteral().getValueParameters();
} }
@Override
public JetBlockExpression getBodyExpression() { public JetBlockExpression getBodyExpression() {
return getFunctionLiteral().getBodyExpression(); return getFunctionLiteral().getBodyExpression();
} }
@Override
public boolean hasBlockBody() { public boolean hasBlockBody() {
return getFunctionLiteral().hasBlockBody(); return getFunctionLiteral().hasBlockBody();
} }
@Override
public boolean hasDeclaredReturnType() { public boolean hasDeclaredReturnType() {
return getFunctionLiteral().getReturnTypeRef() != null; return getFunctionLiteral().getReturnTypeRef() != null;
} }
@NotNull @NotNull
@Override
public JetElement asElement() { public JetElement asElement() {
return this; return this;
} }
} }
@@ -147,8 +147,8 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
Visibilities.LOCAL, Visibilities.LOCAL,
/*isInline = */ false /*isInline = */ false
); );
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor); context.trace.record(BindingContext.FUNCTION, functionLiteral, functionDescriptor);
BindingContextUtils.recordFunctionDeclarationToDescriptor(context.trace, expression, functionDescriptor); BindingContextUtils.recordFunctionDeclarationToDescriptor(context.trace, functionLiteral, functionDescriptor);
return functionDescriptor; return functionDescriptor;
} }
@@ -275,7 +275,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef(); JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef();
if (returnTypeRef != null) { if (returnTypeRef != null) {
JetType returnType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true); JetType returnType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true);
context.expressionTypingServices.checkFunctionReturnType(expression, context.replaceScope(functionInnerScope). context.expressionTypingServices.checkFunctionReturnType(expression.getFunctionLiteral(), context.replaceScope(functionInnerScope).
replaceExpectedType(returnType).replaceBindingTrace(temporaryTrace), temporaryTrace); replaceExpectedType(returnType).replaceBindingTrace(temporaryTrace), temporaryTrace);
if (expectedReturnType != null) { if (expectedReturnType != null) {
if (!JetTypeChecker.INSTANCE.isSubtypeOf(expectedReturnType, returnType)) { if (!JetTypeChecker.INSTANCE.isSubtypeOf(expectedReturnType, returnType)) {
@@ -227,10 +227,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetScope conditionScope = context.scope; JetScope conditionScope = context.scope;
if (body instanceof JetFunctionLiteralExpression) { if (body instanceof JetFunctionLiteralExpression) {
JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body; JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body;
if (!function.getFunctionLiteral().hasParameterSpecification()) { JetFunctionLiteral functionLiteral = function.getFunctionLiteral();
if (!functionLiteral.hasParameterSpecification()) {
WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope"); WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope");
conditionScope = writableScope; conditionScope = writableScope;
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, function.getFunctionLiteral().getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context, context.trace); context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, functionLiteral.getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context, context.trace);
context.trace.record(BindingContext.BLOCK, function); context.trace.record(BindingContext.BLOCK, function);
} }
else { else {
@@ -479,10 +480,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetExpression returnedExpression = expression.getReturnedExpression(); JetExpression returnedExpression = expression.getReturnedExpression();
JetType expectedType = TypeUtils.NO_EXPECTED_TYPE; JetType expectedType = TypeUtils.NO_EXPECTED_TYPE;
JetExpression parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class); JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class);
if (parentDeclaration instanceof JetFunctionLiteral) {
parentDeclaration = (JetFunctionLiteralExpression) parentDeclaration.getParent();
}
if (parentDeclaration instanceof JetParameter) { if (parentDeclaration instanceof JetParameter) {
context.trace.report(RETURN_NOT_ALLOWED.on(expression)); context.trace.report(RETURN_NOT_ALLOWED.on(expression));
} }
@@ -494,11 +493,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (containingFunctionDescriptor != null) { if (containingFunctionDescriptor != null) {
PsiElement containingFunction = BindingContextUtils.callableDescriptorToDeclaration(context.trace.getBindingContext(), containingFunctionDescriptor); PsiElement containingFunction = BindingContextUtils.callableDescriptorToDeclaration(context.trace.getBindingContext(), containingFunctionDescriptor);
assert containingFunction != null; assert containingFunction != null;
if (containingFunction instanceof JetFunctionLiteralExpression) { if (containingFunction instanceof JetFunctionLiteral) {
do { do {
containingFunctionDescriptor = DescriptorUtils.getParentOfType(containingFunctionDescriptor, FunctionDescriptor.class); containingFunctionDescriptor = DescriptorUtils.getParentOfType(containingFunctionDescriptor, FunctionDescriptor.class);
containingFunction = containingFunctionDescriptor != null ? BindingContextUtils.callableDescriptorToDeclaration(context.trace.getBindingContext(), containingFunctionDescriptor) : null; containingFunction = containingFunctionDescriptor != null ? BindingContextUtils.callableDescriptorToDeclaration(context.trace.getBindingContext(), containingFunctionDescriptor) : null;
} while (containingFunction instanceof JetFunctionLiteralExpression); } while (containingFunction instanceof JetFunctionLiteral);
context.trace.report(RETURN_NOT_ALLOWED.on(expression)); context.trace.report(RETURN_NOT_ALLOWED.on(expression));
} }
if (containingFunctionDescriptor != null) { if (containingFunctionDescriptor != null) {
@@ -180,9 +180,9 @@ public class ExpressionTypingServices {
? context.replaceExpectedType(NO_EXPECTED_TYPE) ? context.replaceExpectedType(NO_EXPECTED_TYPE)
: context; : context;
if (function instanceof JetFunctionLiteralExpression) { if (function instanceof JetFunctionLiteral) {
JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) function; JetFunctionLiteral functionLiteral = (JetFunctionLiteral) function;
JetBlockExpression blockExpression = functionLiteralExpression.getBodyExpression(); JetBlockExpression blockExpression = functionLiteral.getBodyExpression();
assert blockExpression != null; assert blockExpression != null;
getBlockReturnedType(newContext.scope, blockExpression, CoercionStrategy.COERCION_TO_UNIT, context, trace); getBlockReturnedType(newContext.scope, blockExpression, CoercionStrategy.COERCION_TO_UNIT, context, trace);
} }
@@ -44,26 +44,27 @@ public class LabelResolver {
public LabelResolver() {} public LabelResolver() {}
public void enterLabeledElement(@NotNull LabelName labelName, @NotNull JetExpression labeledExpression) { public void enterLabeledElement(@NotNull LabelName labelName, @NotNull JetExpression labeledExpression) {
JetExpression deparenthesized = JetPsiUtil.deparenthesizeWithNoTypeResolution(labeledExpression); JetExpression cacheExpression = getCachingExpression(labeledExpression);
if (deparenthesized != null) { if (cacheExpression != null) {
Stack<JetElement> stack = labeledElements.get(labelName); Stack<JetElement> stack = labeledElements.get(labelName);
if (stack == null) { if (stack == null) {
stack = new Stack<JetElement>(); stack = new Stack<JetElement>();
labeledElements.put(labelName, stack); labeledElements.put(labelName, stack);
} }
stack.push(deparenthesized); stack.push(cacheExpression);
} }
} }
public void exitLabeledElement(@NotNull JetExpression expression) { public void exitLabeledElement(@NotNull JetExpression expression) {
JetExpression deparenthesized = JetPsiUtil.deparenthesizeWithNoTypeResolution(expression); JetExpression cacheExpression = getCachingExpression(expression);
// TODO : really suboptimal // TODO : really suboptimal
for (Iterator<Map.Entry<LabelName,Stack<JetElement>>> mapIter = labeledElements.entrySet().iterator(); mapIter.hasNext(); ) { for (Iterator<Map.Entry<LabelName,Stack<JetElement>>> mapIter = labeledElements.entrySet().iterator(); mapIter.hasNext(); ) {
Map.Entry<LabelName, Stack<JetElement>> entry = mapIter.next(); Map.Entry<LabelName, Stack<JetElement>> entry = mapIter.next();
Stack<JetElement> stack = entry.getValue(); Stack<JetElement> stack = entry.getValue();
for (Iterator<JetElement> stackIter = stack.iterator(); stackIter.hasNext(); ) { for (Iterator<JetElement> stackIter = stack.iterator(); stackIter.hasNext(); ) {
JetElement recorded = stackIter.next(); JetElement recorded = stackIter.next();
if (recorded == deparenthesized) { if (recorded == cacheExpression) {
stackIter.remove(); stackIter.remove();
} }
} }
@@ -73,6 +74,15 @@ public class LabelResolver {
} }
} }
@NotNull
private JetExpression getCachingExpression(@NotNull JetExpression labeledExpression) {
JetExpression expression = JetPsiUtil.deparenthesizeWithNoTypeResolution(labeledExpression);
if (expression instanceof JetFunctionLiteralExpression) {
expression = ((JetFunctionLiteralExpression) expression).getFunctionLiteral();
}
return expression;
}
@Nullable @Nullable
private JetElement resolveControlLabel(@NotNull LabelName labelName, @NotNull JetSimpleNameExpression labelExpression, boolean reportUnresolved, ExpressionTypingContext context) { private JetElement resolveControlLabel(@NotNull LabelName labelName, @NotNull JetSimpleNameExpression labelExpression, boolean reportUnresolved, ExpressionTypingContext context) {
Collection<DeclarationDescriptor> declarationsByLabel = context.scope.getDeclarationsByLabel(labelName); Collection<DeclarationDescriptor> declarationsByLabel = context.scope.getDeclarationsByLabel(labelName);
@@ -163,8 +173,9 @@ public class LabelResolver {
} }
else if (size == 0) { else if (size == 0) {
JetElement element = resolveNamedLabel(labelName, targetLabel, false, context); JetElement element = resolveNamedLabel(labelName, targetLabel, false, context);
if (element instanceof JetFunctionLiteralExpression) { if (element instanceof JetFunctionLiteral) {
DeclarationDescriptor declarationDescriptor = context.trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); DeclarationDescriptor declarationDescriptor =
context.trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
if (declarationDescriptor instanceof FunctionDescriptor) { if (declarationDescriptor instanceof FunctionDescriptor) {
ReceiverParameterDescriptor thisReceiver = ((FunctionDescriptor) declarationDescriptor).getReceiverParameter(); ReceiverParameterDescriptor thisReceiver = ((FunctionDescriptor) declarationDescriptor).getReceiverParameter();
if (thisReceiver != null) { if (thisReceiver != null) {
@@ -134,13 +134,13 @@ public class JetPositionManager implements PositionManager {
JetFile namespace = (JetFile) sourcePosition.getFile(); JetFile namespace = (JetFile) sourcePosition.getFile();
JetTypeMapper typeMapper = prepareTypeMapper(namespace); JetTypeMapper typeMapper = prepareTypeMapper(namespace);
PsiElement element = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class); PsiElement element = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetClassOrObject.class, JetFunctionLiteral.class, JetNamedFunction.class);
if (element instanceof JetClassOrObject) { if (element instanceof JetClassOrObject) {
result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) element)); result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) element));
} }
else if (element instanceof JetFunctionLiteralExpression) { else if (element instanceof JetFunctionLiteral) {
result.set(classNameForAnonymousClass(typeMapper.getBindingContext(), result.set(classNameForAnonymousClass(typeMapper.getBindingContext(),
(JetFunctionLiteralExpression) element).getInternalName()); ((JetFunctionLiteral) element)).getInternalName());
} }
else if (element instanceof JetNamedFunction) { else if (element instanceof JetNamedFunction) {
PsiElement parent = PsiTreeUtil.getParentOfType(element, JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class); PsiElement parent = PsiTreeUtil.getParentOfType(element, JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class);
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.descriptors.Modality;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody; import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFunctionLiteral;
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression; import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression;
import org.jetbrains.k2js.translate.context.Namer; import org.jetbrains.k2js.translate.context.Namer;
import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.context.TranslationContext;
@@ -154,6 +155,6 @@ public final class FunctionTranslator extends AbstractTranslator {
} }
private boolean isExtensionFunction() { private boolean isExtensionFunction() {
return JsDescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof JetFunctionLiteralExpression); return JsDescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof JetFunctionLiteral);
} }
} }
@@ -57,7 +57,7 @@ public class LiteralFunctionTranslator {
} }
public JsExpression translate(@NotNull JetFunctionLiteralExpression declaration) { public JsExpression translate(@NotNull JetFunctionLiteralExpression declaration) {
FunctionDescriptor descriptor = getFunctionDescriptor(rootContext.bindingContext(), declaration); FunctionDescriptor descriptor = getFunctionDescriptor(rootContext.bindingContext(), declaration.getFunctionLiteral());
JsFunction fun = createFunction(); JsFunction fun = createFunction();
TranslationContext funContext; TranslationContext funContext;
@@ -75,7 +75,7 @@ public class LiteralFunctionTranslator {
funContext = rootContext.contextWithScope(fun); funContext = rootContext.contextWithScope(fun);
} }
fun.getBody().getStatements().addAll(translateFunctionBody(descriptor, declaration, funContext).getStatements()); fun.getBody().getStatements().addAll(translateFunctionBody(descriptor, declaration.getFunctionLiteral(), funContext).getStatements());
InnerFunctionTranslator translator = null; InnerFunctionTranslator translator = null;
if (!asInner) { if (!asInner) {