diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDotQualifiedExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDotQualifiedExpression.java index 2b0a879177e..a96b1e538da 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDotQualifiedExpression.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDotQualifiedExpression.java @@ -17,14 +17,20 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; +import com.intellij.openapi.diagnostic.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.psi.stubs.PsiJetPlaceHolderStub; import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; import org.jetbrains.jet.lexer.JetToken; +import static org.jetbrains.jet.lang.psi.JetImportDirective.IMPORT_DIRECTIVE_EXPRESSIONS; + public class JetDotQualifiedExpression extends JetExpressionImplStub> implements JetQualifiedExpression { + + private static final Logger LOG = Logger.getInstance(JetDotQualifiedExpression.class); + public JetDotQualifiedExpression(@NotNull ASTNode node) { super(node); } @@ -41,16 +47,49 @@ public class JetDotQualifiedExpression extends JetExpressionImplStub stub = getStub(); + if (stub != null) { + JetExpression[] childExpressionsByStub = getChildExpressionsByStub(stub); + if (childExpressionsByStub != null) { + return childExpressionsByStub[0]; + } + } return JetQualifiedExpressionImpl.instance$.getReceiverExpression(this); } - @Nullable @Override public JetExpression getSelectorExpression() { + PsiJetPlaceHolderStub stub = getStub(); + if (stub != null) { + JetExpression[] childExpressionsByStub = getChildExpressionsByStub(stub); + if (childExpressionsByStub != null && childExpressionsByStub.length == 2) { + return childExpressionsByStub[1]; + } + } return JetQualifiedExpressionImpl.instance$.getSelectorExpression(this); } + + @Nullable + private JetExpression[] getChildExpressionsByStub(@NotNull PsiJetPlaceHolderStub stub) { + if (stub.getParentStubOfType(JetImportDirective.class) == null) { + LOG.error("JetDotQualifiedExpression should only have stubs inside import directives.\n " + + "Stubs were created for:\n " + getText() + + "\nFile text:\n" + getContainingFile().getText()); + return null; + } + else { + JetExpression[] expressions = stub.getChildrenByType(IMPORT_DIRECTIVE_EXPRESSIONS, new JetExpression[] {}); + if (expressions.length < 1 || expressions.length > 2) { + LOG.error("Invalid stub structure. DOT_QUALIFIED_EXPRESSION must have one or two children. Was: " + expressions.length + + "\nFile text:\n" + getContainingFile().getText()); + return null; + } + return expressions; + } + } + @NotNull @Override public ASTNode getOperationTokenNode() {