getReceiverExpression() and getSelectorExpression() in JetDotQualifiedExpression using stubs
This commit is contained in:
@@ -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<PsiJetPlaceHolderStub<JetDotQualifiedExpression>>
|
||||
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<PsiJetPlace
|
||||
@NotNull
|
||||
@Override
|
||||
public JetExpression getReceiverExpression() {
|
||||
PsiJetPlaceHolderStub<JetDotQualifiedExpression> 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<JetDotQualifiedExpression> 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<JetDotQualifiedExpression> 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() {
|
||||
|
||||
Reference in New Issue
Block a user