From 8e5f0abb8413a8c325201663b50fcd8a0c68f63b Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 20 Mar 2013 11:32:55 +0400 Subject: [PATCH] Jet api refactoring: remove JetBodyDeclarationWithBody interface from JetFunctionLiteralExpression --- .../jetbrains/jet/codegen/ClosureCodegen.java | 8 +++--- .../jet/codegen/ExpressionCodegen.java | 8 +++--- .../jet/codegen/FunctionCodegen.java | 14 +++++------ .../binding/CodegenAnnotatingVisitor.java | 5 ++-- .../jet/lang/cfg/JetControlFlowProcessor.java | 5 +--- .../jet/lang/psi/JetDeclarationWithBody.java | 3 +-- .../psi/JetFunctionLiteralExpression.java | 10 +++----- .../ClosureExpressionsTypingVisitor.java | 6 ++--- .../ControlStructureTypingVisitor.java | 15 ++++++----- .../expressions/ExpressionTypingServices.java | 6 ++--- .../lang/types/expressions/LabelResolver.java | 25 +++++++++++++------ .../plugin/debugger/JetPositionManager.java | 6 ++--- .../expression/FunctionTranslator.java | 3 ++- .../expression/LiteralFunctionTranslator.java | 4 +-- 14 files changed, 60 insertions(+), 58 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java index e90fa53de7c..6c6d0f99f32 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java @@ -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); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index da107a6af9e..a787de7323a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1246,18 +1246,18 @@ public class ExpressionCodegen extends JetVisitor 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(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 2d4fea7fa85..c69fbb86d56 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -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); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java index ccd7267c780..92138c85e42 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java @@ -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); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 9abd6161422..8595d62cf24 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -602,10 +602,7 @@ public class JetControlFlowProcessor { subroutine = builder.getReturnSubroutine(); // TODO : a context check } - //todo cache JetFunctionLiteral instead - if (subroutine instanceof JetFunctionLiteralExpression) { - subroutine = ((JetFunctionLiteralExpression) subroutine).getFunctionLiteral(); - } + if (subroutine instanceof JetFunction || subroutine instanceof JetPropertyAccessor) { if (returnedExpression == null) { builder.returnNoValue(expression, subroutine); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationWithBody.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationWithBody.java index 744ff21539a..1abfd0a98c9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationWithBody.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationWithBody.java @@ -16,13 +16,12 @@ package org.jetbrains.jet.lang.psi; -import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public interface JetDeclarationWithBody extends PsiElement { +public interface JetDeclarationWithBody extends JetDeclaration { @Nullable JetExpression getBodyExpression(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteralExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteralExpression.java index 6d88222a899..a87277dc210 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteralExpression.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteralExpression.java @@ -18,11 +18,13 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; +import org.jetbrains.jet.lexer.JetToken; import java.util.List; -public class JetFunctionLiteralExpression extends JetExpressionImpl implements JetDeclarationWithBody { +public class JetFunctionLiteralExpression extends JetExpressionImpl { public JetFunctionLiteralExpression(@NotNull ASTNode node) { super(node); } @@ -43,30 +45,24 @@ public class JetFunctionLiteralExpression extends JetExpressionImpl implements J } @NotNull - @Override public List getValueParameters() { return getFunctionLiteral().getValueParameters(); } - @Override public JetBlockExpression getBodyExpression() { return getFunctionLiteral().getBodyExpression(); } - @Override public boolean hasBlockBody() { return getFunctionLiteral().hasBlockBody(); } - @Override public boolean hasDeclaredReturnType() { return getFunctionLiteral().getReturnTypeRef() != null; } @NotNull - @Override public JetElement asElement() { return this; } - } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java index 8b60f473f9b..33f211d3187 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java @@ -147,8 +147,8 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { Visibilities.LOCAL, /*isInline = */ false ); - context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor); - BindingContextUtils.recordFunctionDeclarationToDescriptor(context.trace, expression, functionDescriptor); + context.trace.record(BindingContext.FUNCTION, functionLiteral, functionDescriptor); + BindingContextUtils.recordFunctionDeclarationToDescriptor(context.trace, functionLiteral, functionDescriptor); return functionDescriptor; } @@ -275,7 +275,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef(); if (returnTypeRef != null) { 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); if (expectedReturnType != null) { if (!JetTypeChecker.INSTANCE.isSubtypeOf(expectedReturnType, returnType)) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java index 4e729257b91..8460ae12c8a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java @@ -227,10 +227,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { JetScope conditionScope = context.scope; if (body instanceof JetFunctionLiteralExpression) { JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body; - if (!function.getFunctionLiteral().hasParameterSpecification()) { + JetFunctionLiteral functionLiteral = function.getFunctionLiteral(); + if (!functionLiteral.hasParameterSpecification()) { WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope"); 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); } else { @@ -479,10 +480,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { JetExpression returnedExpression = expression.getReturnedExpression(); JetType expectedType = TypeUtils.NO_EXPECTED_TYPE; - JetExpression parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class); - if (parentDeclaration instanceof JetFunctionLiteral) { - parentDeclaration = (JetFunctionLiteralExpression) parentDeclaration.getParent(); - } + JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class); + if (parentDeclaration instanceof JetParameter) { context.trace.report(RETURN_NOT_ALLOWED.on(expression)); } @@ -494,11 +493,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { if (containingFunctionDescriptor != null) { PsiElement containingFunction = BindingContextUtils.callableDescriptorToDeclaration(context.trace.getBindingContext(), containingFunctionDescriptor); assert containingFunction != null; - if (containingFunction instanceof JetFunctionLiteralExpression) { + if (containingFunction instanceof JetFunctionLiteral) { do { containingFunctionDescriptor = DescriptorUtils.getParentOfType(containingFunctionDescriptor, FunctionDescriptor.class); 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)); } if (containingFunctionDescriptor != null) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java index c84ca3f9332..803579e026a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java @@ -180,9 +180,9 @@ public class ExpressionTypingServices { ? context.replaceExpectedType(NO_EXPECTED_TYPE) : context; - if (function instanceof JetFunctionLiteralExpression) { - JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) function; - JetBlockExpression blockExpression = functionLiteralExpression.getBodyExpression(); + if (function instanceof JetFunctionLiteral) { + JetFunctionLiteral functionLiteral = (JetFunctionLiteral) function; + JetBlockExpression blockExpression = functionLiteral.getBodyExpression(); assert blockExpression != null; getBlockReturnedType(newContext.scope, blockExpression, CoercionStrategy.COERCION_TO_UNIT, context, trace); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java index 1dd91a4fffc..5bac2a1c714 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java @@ -44,26 +44,27 @@ public class LabelResolver { public LabelResolver() {} public void enterLabeledElement(@NotNull LabelName labelName, @NotNull JetExpression labeledExpression) { - JetExpression deparenthesized = JetPsiUtil.deparenthesizeWithNoTypeResolution(labeledExpression); - if (deparenthesized != null) { + JetExpression cacheExpression = getCachingExpression(labeledExpression); + if (cacheExpression != null) { Stack stack = labeledElements.get(labelName); if (stack == null) { stack = new Stack(); labeledElements.put(labelName, stack); } - stack.push(deparenthesized); + stack.push(cacheExpression); } } public void exitLabeledElement(@NotNull JetExpression expression) { - JetExpression deparenthesized = JetPsiUtil.deparenthesizeWithNoTypeResolution(expression); + JetExpression cacheExpression = getCachingExpression(expression); + // TODO : really suboptimal for (Iterator>> mapIter = labeledElements.entrySet().iterator(); mapIter.hasNext(); ) { Map.Entry> entry = mapIter.next(); Stack stack = entry.getValue(); for (Iterator stackIter = stack.iterator(); stackIter.hasNext(); ) { JetElement recorded = stackIter.next(); - if (recorded == deparenthesized) { + if (recorded == cacheExpression) { 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 private JetElement resolveControlLabel(@NotNull LabelName labelName, @NotNull JetSimpleNameExpression labelExpression, boolean reportUnresolved, ExpressionTypingContext context) { Collection declarationsByLabel = context.scope.getDeclarationsByLabel(labelName); @@ -163,8 +173,9 @@ public class LabelResolver { } else if (size == 0) { JetElement element = resolveNamedLabel(labelName, targetLabel, false, context); - if (element instanceof JetFunctionLiteralExpression) { - DeclarationDescriptor declarationDescriptor = context.trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); + if (element instanceof JetFunctionLiteral) { + DeclarationDescriptor declarationDescriptor = + context.trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); if (declarationDescriptor instanceof FunctionDescriptor) { ReceiverParameterDescriptor thisReceiver = ((FunctionDescriptor) declarationDescriptor).getReceiverParameter(); if (thisReceiver != null) { diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java index 0076c22be4f..a05e49e08b7 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java +++ b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java @@ -134,13 +134,13 @@ public class JetPositionManager implements PositionManager { JetFile namespace = (JetFile) sourcePosition.getFile(); 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) { result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) element)); } - else if (element instanceof JetFunctionLiteralExpression) { + else if (element instanceof JetFunctionLiteral) { result.set(classNameForAnonymousClass(typeMapper.getBindingContext(), - (JetFunctionLiteralExpression) element).getInternalName()); + ((JetFunctionLiteral) element)).getInternalName()); } else if (element instanceof JetNamedFunction) { PsiElement parent = PsiTreeUtil.getParentOfType(element, JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class); diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/expression/FunctionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/expression/FunctionTranslator.java index c380e33d076..5a07b32652e 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/expression/FunctionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/expression/FunctionTranslator.java @@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.descriptors.Modality; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.psi.JetDeclarationWithBody; import org.jetbrains.jet.lang.psi.JetExpression; +import org.jetbrains.jet.lang.psi.JetFunctionLiteral; import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression; import org.jetbrains.k2js.translate.context.Namer; import org.jetbrains.k2js.translate.context.TranslationContext; @@ -154,6 +155,6 @@ public final class FunctionTranslator extends AbstractTranslator { } private boolean isExtensionFunction() { - return JsDescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof JetFunctionLiteralExpression); + return JsDescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof JetFunctionLiteral); } } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/expression/LiteralFunctionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/expression/LiteralFunctionTranslator.java index 6f5cbe50ce5..08f5001224b 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/expression/LiteralFunctionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/expression/LiteralFunctionTranslator.java @@ -57,7 +57,7 @@ public class LiteralFunctionTranslator { } public JsExpression translate(@NotNull JetFunctionLiteralExpression declaration) { - FunctionDescriptor descriptor = getFunctionDescriptor(rootContext.bindingContext(), declaration); + FunctionDescriptor descriptor = getFunctionDescriptor(rootContext.bindingContext(), declaration.getFunctionLiteral()); JsFunction fun = createFunction(); TranslationContext funContext; @@ -75,7 +75,7 @@ public class LiteralFunctionTranslator { 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; if (!asInner) {