diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 243449a93c7..d9f04806a7e 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -98,7 +98,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { OwnerKind kind = owner.getContextKind(); JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, kind); - if (kind != OwnerKind.TRAIT_IMPL || function.getBodyExpression() != null) { + if (kind != OwnerKind.TRAIT_IMPL || function.hasBody()) { generateMethod(function, method, functionDescriptor, new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function)); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index d274c0cdead..da081a8eea6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -202,8 +202,7 @@ public class JetFlowInformationProvider { assert subroutine instanceof JetDeclarationWithBody; JetDeclarationWithBody function = (JetDeclarationWithBody) subroutine; - JetExpression bodyExpression = function.getBodyExpression(); - if (bodyExpression == null) return; + if (!function.hasBody()) return; List returnedExpressions = Lists.newArrayList(); collectReturnExpressions(returnedExpressions); 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 1abfd0a98c9..328031b022b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationWithBody.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationWithBody.java @@ -31,6 +31,8 @@ public interface JetDeclarationWithBody extends JetDeclaration { boolean hasBlockBody(); + boolean hasBody(); + boolean hasDeclaredReturnType(); @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteral.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteral.java index f8d876860fc..b05cde87fb6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteral.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunctionLiteral.java @@ -73,4 +73,9 @@ public class JetFunctionLiteral extends JetFunctionNotStubbed { public FqName getFqName() { return null; } + + @Override + public boolean hasBody() { + return getBodyExpression() != null; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java index d6617ca7864..b7a7dff8db2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java @@ -101,6 +101,11 @@ public class JetNamedFunction extends JetTypeParameterListOwnerStub { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return super.isAvailable(project, editor, file) && - element.getBodyExpression() == null; + return super.isAvailable(project, editor, file) && !element.hasBody(); } @Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { JetFunction newElement = (JetFunction) element.copy(); - JetExpression bodyExpression = newElement.getBodyExpression(); if (!(newElement.getLastChild() instanceof PsiWhiteSpace)) { newElement.add(JetPsiFactory.createWhiteSpace(project)); } - if (bodyExpression == null) { + if (!newElement.hasBody()) { newElement.add(JetPsiFactory.createEmptyBody(project)); } element.replace(newElement); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java index 634c4321300..a1d0dc29c2a 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java @@ -52,8 +52,7 @@ public class RemoveFunctionBodyFix extends JetIntentionAction { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return super.isAvailable(project, editor, file) && - element.getBodyExpression() != null; + return super.isAvailable(project, editor, file) && element.hasBody(); } @Override diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/declaration/PropertyTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/declaration/PropertyTranslator.java index bd82b66919c..98a6bd924c1 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/declaration/PropertyTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/declaration/PropertyTranslator.java @@ -102,11 +102,11 @@ public final class PropertyTranslator extends AbstractTranslator { } private boolean hasCustomGetter() { - return declaration != null && declaration.getGetter() != null && getCustomGetterDeclaration().getBodyExpression() != null; + return declaration != null && declaration.getGetter() != null && getCustomGetterDeclaration().hasBody(); } private boolean hasCustomSetter() { - return declaration != null && declaration.getSetter() != null && getCustomSetterDeclaration().getBodyExpression() != null; + return declaration != null && declaration.getSetter() != null && getCustomSetterDeclaration().hasBody(); } @NotNull 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 04b5c8d26d6..baad30ccffd 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 @@ -110,8 +110,7 @@ public final class FunctionTranslator extends AbstractTranslator { } private void translateBody() { - JetExpression jetBodyExpression = functionDeclaration.getBodyExpression(); - if (jetBodyExpression == null) { + if (!functionDeclaration.hasBody()) { assert descriptor.getModality().equals(Modality.ABSTRACT); return; }