utility methods moved out of psi hierarchy
This commit is contained in:
committed by
Andrey Breslav
parent
689dbdf6b6
commit
9e17069546
@@ -773,7 +773,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
public StackValue visitNamedFunction(JetNamedFunction function, StackValue data) {
|
public StackValue visitNamedFunction(JetNamedFunction function, StackValue data) {
|
||||||
assert data == StackValue.none();
|
assert data == StackValue.none();
|
||||||
|
|
||||||
if (function.isScriptDeclaration()) {
|
if (JetPsiUtil.isScriptDeclaration(function)) {
|
||||||
return StackValue.none();
|
return StackValue.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -889,7 +889,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
for (JetElement statement : statements) {
|
for (JetElement statement : statements) {
|
||||||
if (statement instanceof JetNamedDeclaration) {
|
if (statement instanceof JetNamedDeclaration) {
|
||||||
JetNamedDeclaration declaration = (JetNamedDeclaration) statement;
|
JetNamedDeclaration declaration = (JetNamedDeclaration) statement;
|
||||||
if (declaration.isScriptDeclaration()) {
|
if (JetPsiUtil.isScriptDeclaration(declaration)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -928,7 +928,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
for (JetElement statement : Lists.reverse(statements)) {
|
for (JetElement statement : Lists.reverse(statements)) {
|
||||||
if (statement instanceof JetNamedDeclaration) {
|
if (statement instanceof JetNamedDeclaration) {
|
||||||
JetNamedDeclaration declaration = (JetNamedDeclaration) statement;
|
JetNamedDeclaration declaration = (JetNamedDeclaration) statement;
|
||||||
if (declaration.isScriptDeclaration()) {
|
if (JetPsiUtil.isScriptDeclaration(declaration)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1538,7 +1538,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
if (fd.getContainingDeclaration() instanceof ScriptDescriptor) {
|
if (fd.getContainingDeclaration() instanceof ScriptDescriptor) {
|
||||||
JetNamedFunction psi = (JetNamedFunction) BindingContextUtils.descriptorToDeclaration(bindingContext, fd);
|
JetNamedFunction psi = (JetNamedFunction) BindingContextUtils.descriptorToDeclaration(bindingContext, fd);
|
||||||
assert psi != null;
|
assert psi != null;
|
||||||
return !psi.isScriptDeclaration();
|
return !JetPsiUtil.isScriptDeclaration(psi);
|
||||||
}
|
}
|
||||||
else if (fd instanceof ExpressionAsFunctionDescriptor) {
|
else if (fd instanceof ExpressionAsFunctionDescriptor) {
|
||||||
return true;
|
return true;
|
||||||
@@ -2562,7 +2562,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
Type sharedVarType;
|
Type sharedVarType;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
if (property.isScriptDeclaration()) {
|
if (JetPsiUtil.isScriptDeclaration(property)) {
|
||||||
return StackValue.none();
|
return StackValue.none();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -2586,9 +2586,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
|
|
||||||
JetExpression initializer = property.getInitializer();
|
JetExpression initializer = property.getInitializer();
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
if (property.isScriptDeclaration()) {
|
if (JetPsiUtil.isScriptDeclaration(property)) {
|
||||||
gen(initializer, varType);
|
gen(initializer, varType);
|
||||||
JetScript scriptPsi = property.getScript();
|
JetScript scriptPsi = JetPsiUtil.getScript(property);
|
||||||
assert scriptPsi != null;
|
assert scriptPsi != null;
|
||||||
JvmClassName scriptClassName = state.getInjector().getClosureAnnotator().classNameForScriptPsi(scriptPsi);
|
JvmClassName scriptClassName = state.getInjector().getClosureAnnotator().classNameForScriptPsi(scriptPsi);
|
||||||
v.putfield(scriptClassName.getInternalName(), property.getName(), varType.getDescriptor());
|
v.putfield(scriptClassName.getInternalName(), property.getName(), varType.getDescriptor());
|
||||||
|
|||||||
@@ -11,9 +11,4 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
|||||||
public interface JetNamedDeclaration extends JetDeclaration, PsiNameIdentifierOwner, JetStatementExpression, JetNamed {
|
public interface JetNamedDeclaration extends JetDeclaration, PsiNameIdentifierOwner, JetStatementExpression, JetNamed {
|
||||||
@NotNull
|
@NotNull
|
||||||
Name getNameAsSafeName();
|
Name getNameAsSafeName();
|
||||||
|
|
||||||
boolean isScriptDeclaration();
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
JetScript getScript();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,20 +74,4 @@ abstract class JetNamedDeclarationNotStubbed extends JetDeclarationImpl implemen
|
|||||||
PsiElement identifier = getNameIdentifier();
|
PsiElement identifier = getNameIdentifier();
|
||||||
return identifier != null ? identifier.getTextRange().getStartOffset() : getTextRange().getStartOffset();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,20 +83,4 @@ abstract class JetNamedDeclarationStub<T extends NamedStub> extends JetDeclarati
|
|||||||
PsiElement identifier = getNameIdentifier();
|
PsiElement identifier = getNameIdentifier();
|
||||||
return identifier != null ? identifier.getTextRange().getStartOffset() : getTextRange().getStartOffset();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,4 +321,19 @@ public class JetPsiUtil {
|
|||||||
}
|
}
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -602,7 +602,7 @@ public class DescriptorResolver {
|
|||||||
DataFlowInfo dataFlowInfo,
|
DataFlowInfo dataFlowInfo,
|
||||||
BindingTrace trace
|
BindingTrace trace
|
||||||
) {
|
) {
|
||||||
if (property.isScriptDeclaration()) {
|
if (JetPsiUtil.isScriptDeclaration(property)) {
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotationResolver.createAnnotationStubs(property.getModifierList(), trace),
|
annotationResolver.createAnnotationStubs(property.getModifierList(), trace),
|
||||||
|
|||||||
Reference in New Issue
Block a user