diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index c1896c5397a..1e8a2d560e3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -773,7 +773,7 @@ public class ExpressionCodegen extends JetVisitor { public StackValue visitNamedFunction(JetNamedFunction function, StackValue data) { assert data == StackValue.none(); - if (function.isScriptDeclaration()) { + if (JetPsiUtil.isScriptDeclaration(function)) { return StackValue.none(); } @@ -889,7 +889,7 @@ public class ExpressionCodegen extends JetVisitor { for (JetElement statement : statements) { if (statement instanceof JetNamedDeclaration) { JetNamedDeclaration declaration = (JetNamedDeclaration) statement; - if (declaration.isScriptDeclaration()) { + if (JetPsiUtil.isScriptDeclaration(declaration)) { continue; } } @@ -928,7 +928,7 @@ public class ExpressionCodegen extends JetVisitor { for (JetElement statement : Lists.reverse(statements)) { if (statement instanceof JetNamedDeclaration) { JetNamedDeclaration declaration = (JetNamedDeclaration) statement; - if (declaration.isScriptDeclaration()) { + if (JetPsiUtil.isScriptDeclaration(declaration)) { continue; } } @@ -1538,7 +1538,7 @@ public class ExpressionCodegen extends JetVisitor { if (fd.getContainingDeclaration() instanceof ScriptDescriptor) { JetNamedFunction psi = (JetNamedFunction) BindingContextUtils.descriptorToDeclaration(bindingContext, fd); assert psi != null; - return !psi.isScriptDeclaration(); + return !JetPsiUtil.isScriptDeclaration(psi); } else if (fd instanceof ExpressionAsFunctionDescriptor) { return true; @@ -2562,7 +2562,7 @@ public class ExpressionCodegen extends JetVisitor { Type sharedVarType; int index; - if (property.isScriptDeclaration()) { + if (JetPsiUtil.isScriptDeclaration(property)) { return StackValue.none(); } else { @@ -2586,9 +2586,9 @@ public class ExpressionCodegen extends JetVisitor { JetExpression initializer = property.getInitializer(); if (initializer != null) { - if (property.isScriptDeclaration()) { + if (JetPsiUtil.isScriptDeclaration(property)) { gen(initializer, varType); - JetScript scriptPsi = property.getScript(); + JetScript scriptPsi = JetPsiUtil.getScript(property); assert scriptPsi != null; JvmClassName scriptClassName = state.getInjector().getClosureAnnotator().classNameForScriptPsi(scriptPsi); v.putfield(scriptClassName.getInternalName(), property.getName(), varType.getDescriptor()); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java index f9fd37bd073..a3cca71146b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java @@ -11,9 +11,4 @@ import org.jetbrains.jet.lang.resolve.name.Name; public interface JetNamedDeclaration extends JetDeclaration, PsiNameIdentifierOwner, JetStatementExpression, JetNamed { @NotNull Name getNameAsSafeName(); - - boolean isScriptDeclaration(); - - @Nullable - JetScript getScript(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java index eb808b0275b..47347744c8b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java @@ -74,20 +74,4 @@ abstract class JetNamedDeclarationNotStubbed extends JetDeclarationImpl implemen PsiElement identifier = getNameIdentifier(); return identifier != null ? identifier.getTextRange().getStartOffset() : getTextRange().getStartOffset(); } - - @Override - public boolean isScriptDeclaration() { - return getScript() != null; - } - - @Override - @Nullable - public JetScript getScript() { - if (getParent() != null && getParent().getParent() instanceof JetScript) { - return (JetScript) getParent().getParent(); - } - else { - return null; - } - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java index 81b9a230e88..077f7804e27 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java @@ -83,20 +83,4 @@ abstract class JetNamedDeclarationStub extends JetDeclarati PsiElement identifier = getNameIdentifier(); return identifier != null ? identifier.getTextRange().getStartOffset() : getTextRange().getStartOffset(); } - - @Override - public boolean isScriptDeclaration() { - return getScript() != null; - } - - @Override - @Nullable - public JetScript getScript() { - if (getParent() != null && getParent().getParent() instanceof JetScript) { - return (JetScript) getParent().getParent(); - } - else { - return null; - } - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index 1b6e616137e..1200c788e7e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -321,4 +321,19 @@ public class JetPsiUtil { } return true; } + + public static boolean isScriptDeclaration(@NotNull JetDeclaration namedDeclaration) { + return getScript(namedDeclaration) != null; + } + + @Nullable + public static JetScript getScript(@NotNull JetDeclaration namedDeclaration) { + PsiElement parent = namedDeclaration.getParent(); + if (parent != null && parent.getParent() instanceof JetScript) { + return (JetScript) parent.getParent(); + } + else { + return null; + } + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index e6eed7ad61f..1ab0a22c639 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -602,7 +602,7 @@ public class DescriptorResolver { DataFlowInfo dataFlowInfo, BindingTrace trace ) { - if (property.isScriptDeclaration()) { + if (JetPsiUtil.isScriptDeclaration(property)) { PropertyDescriptor propertyDescriptor = new PropertyDescriptor( containingDeclaration, annotationResolver.createAnnotationStubs(property.getModifierList(), trace),