More expression getters
This commit is contained in:
@@ -45,7 +45,7 @@ public interface JetNodeTypes {
|
||||
JetNodeType ATTRIBUTE_ANNOTATION = new JetNodeType("ATTRIBUTE_ANNOTATION", JetAttributeAnnotation.class);
|
||||
JetNodeType ATTRIBUTE = new JetNodeType("ATTRIBUTE", JetAttribute.class);
|
||||
JetNodeType USER_TYPE = new JetNodeType("USER_TYPE");
|
||||
JetNodeType TYPE_ARGUMENT_LIST = new JetNodeType("TYPE_ARGUMENT_LIST");
|
||||
JetNodeType TYPE_ARGUMENT_LIST = new JetNodeType("TYPE_ARGUMENT_LIST", JetTypeArgumentList.class);
|
||||
JetNodeType VALUE_ARGUMENT_LIST = new JetNodeType("VALUE_ARGUMENT_LIST", JetArgumentList.class);
|
||||
JetNodeType VALUE_ARGUMENT = new JetNodeType("VALUE_ARGUMENT", JetArgument.class);
|
||||
JetNodeType TYPE_REFERENCE = new JetNodeType("TYPE_REFERENCE", JetTypeReference.class);
|
||||
@@ -69,7 +69,6 @@ public interface JetNodeTypes {
|
||||
JetNodeType CHARACTER_CONSTANT = new JetNodeType("CHARACTER_CONSTANT", JetConstantExpression.class);
|
||||
JetNodeType STRING_CONSTANT = new JetNodeType("STRING_CONSTANT", JetConstantExpression.class);
|
||||
JetNodeType INTEGER_CONSTANT = new JetNodeType("INTEGER_CONSTANT", JetConstantExpression.class);
|
||||
JetNodeType SUPERTYE_QUALIFIER = new JetNodeType("SUPERTYE_QUALIFIER", JetConstantExpression.class);
|
||||
JetNodeType LONG_CONSTANT = new JetNodeType("LONG_CONSTANT", JetConstantExpression.class);
|
||||
|
||||
JetNodeType TUPLE = new JetNodeType("TUPLE", JetTupleExpression.class);
|
||||
@@ -97,12 +96,13 @@ public interface JetNodeTypes {
|
||||
JetNodeType FUNCTION_LITERAL = new JetNodeType("FUNCTION_LITERAL", JetFunctionLiteralExpression.class);
|
||||
JetNodeType ANNOTATED_EXPRESSION = new JetNodeType("ANNOTATED_EXPRESSION", JetAnnotatedExpression.class);
|
||||
JetNodeType REFERENCE_EXPRESSION = new JetNodeType("REFERENCE_EXPRESSION", JetReferenceExpression.class);
|
||||
JetNodeType THIS_EXPRESSION = new JetNodeType("THIS_EXPRESSION", JetThisExpression.class);
|
||||
JetNodeType BINARY_EXPRESSION = new JetNodeType("BINARY_EXPRESSION", JetBinaryExpression.class);
|
||||
JetNodeType PREFIX_EXPRESSION = new JetNodeType("PREFIX_EXPRESSION", JetPrefixExpression.class);
|
||||
JetNodeType POSTFIX_EXPRESSION = new JetNodeType("POSTFIX_EXPRESSION", JetPostfixExpression.class);
|
||||
JetNodeType CALL_EXPRESSION = new JetNodeType("CALL_EXPRESSION", JetCallExpression.class);
|
||||
JetNodeType ARRAY_ACCESS_EXPRESSION = new JetNodeType("ARRAY_ACCESS_EXPRESSION", JetArrayAccessExpression.class);
|
||||
JetNodeType INDICES = new JetNodeType("INDICES");
|
||||
JetNodeType INDICES = new JetNodeType("INDICES"); //TODO: discuss, this can be omitted
|
||||
JetNodeType DOT_QIALIFIED_EXPRESSION = new JetNodeType("DOT_QIALIFIED_EXPRESSION", JetDotQualifiedExpression.class);
|
||||
JetNodeType HASH_QIALIFIED_EXPRESSION = new JetNodeType("HASH_QIALIFIED_EXPRESSION", JetHashQualifiedExpression.class);
|
||||
JetNodeType SAFE_ACCESS_EXPRESSION = new JetNodeType("SAFE_ACCESS_EXPRESSION", JetSafeQualifiedExpression.class);
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -15,4 +21,18 @@ public class JetArrayAccessExpression extends JetExpression {
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitArrayAccessExpression(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetExpression getArrayExpression() {
|
||||
JetExpression baseExpression = findChildByClass(JetExpression.class);
|
||||
assert baseExpression != null;
|
||||
return baseExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetExpression> getIndexExpressions() {
|
||||
PsiElement container = findChildByType(JetNodeTypes.INDICES);
|
||||
if (container == null) return Collections.emptyList();
|
||||
return PsiTreeUtil.getChildrenOfTypeAsList(container, JetExpression.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -15,4 +20,33 @@ public class JetCallExpression extends JetExpression {
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitCallExpression(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetExpression getCalleeExpression() {
|
||||
JetExpression callee = findChildByClass(JetExpression.class);
|
||||
assert callee != null;
|
||||
return callee;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetArgumentList getArgumentList() {
|
||||
return (JetArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetTypeArgumentList getTypeArgumentList() {
|
||||
return (JetTypeArgumentList) findChildByType(JetNodeTypes.TYPE_ARGUMENT_LIST);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetArgument> getArguments() {
|
||||
JetArgumentList list = getArgumentList();
|
||||
return list != null ? list.getArguments() : Collections.<JetArgument>emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetTypeReference> getTypeArguments() {
|
||||
JetTypeArgumentList list = getTypeArgumentList();
|
||||
return list != null ? list.getArguments() : Collections.<JetTypeReference>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
@@ -36,21 +35,15 @@ public abstract class JetQualifiedExpression extends JetExpression {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ASTNode getOperationTokenNode() {
|
||||
PsiElement child = getReceiverExpression().getNextSibling();
|
||||
ASTNode operationNode = getNode().findChildByType(JetTokens.OPERATIONS);
|
||||
assert operationNode != null;
|
||||
return operationNode;
|
||||
}
|
||||
|
||||
while (child != null) {
|
||||
IElementType tt = child.getNode().getElementType();
|
||||
|
||||
if (JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(tt) || child instanceof PsiErrorElement) {
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
else {
|
||||
return child.getNode();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@Nullable
|
||||
public JetToken getOperationSign() {
|
||||
return (JetToken) getOperationTokenNode().getElementType();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetThisExpression extends JetExpression {
|
||||
public JetThisExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitThisExpression(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetTypeReference getSuperTypeQualifier() {
|
||||
return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
|
||||
}
|
||||
|
||||
public boolean hasSuperTypeQualifier() {
|
||||
return getSuperTypeQualifier() != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetTypeArgumentList extends JetElement {
|
||||
public JetTypeArgumentList(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitTypeArgumentList(this);
|
||||
}
|
||||
|
||||
public List<JetTypeReference> getArguments() {
|
||||
return findChildrenByType(JetNodeTypes.TYPE_REFERENCE);
|
||||
}
|
||||
}
|
||||
@@ -253,4 +253,12 @@ public class JetVisitor extends PsiElementVisitor {
|
||||
public void visitFinallySection(JetFinallySection finallySection) {
|
||||
visitJetElement(finallySection);
|
||||
}
|
||||
|
||||
public void visitTypeArgumentList(JetTypeArgumentList typeArgumentList) {
|
||||
visitJetElement(typeArgumentList);
|
||||
}
|
||||
|
||||
public void visitThisExpression(JetThisExpression expression) {
|
||||
visitExpression(expression);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user