Type nodes
This commit is contained in:
@@ -42,15 +42,17 @@ public interface JetNodeTypes {
|
|||||||
JetNodeType MODIFIER_LIST = new JetNodeType("MODIFIER_LIST", JetModifierList.class);
|
JetNodeType MODIFIER_LIST = new JetNodeType("MODIFIER_LIST", JetModifierList.class);
|
||||||
JetNodeType ATTRIBUTE_ANNOTATION = new JetNodeType("ATTRIBUTE_ANNOTATION", JetAttributeAnnotation.class);
|
JetNodeType ATTRIBUTE_ANNOTATION = new JetNodeType("ATTRIBUTE_ANNOTATION", JetAttributeAnnotation.class);
|
||||||
JetNodeType ATTRIBUTE = new JetNodeType("ATTRIBUTE", JetAttribute.class);
|
JetNodeType ATTRIBUTE = new JetNodeType("ATTRIBUTE", JetAttribute.class);
|
||||||
JetNodeType USER_TYPE = new JetNodeType("USER_TYPE");
|
|
||||||
JetNodeType TYPE_ARGUMENT_LIST = new JetNodeType("TYPE_ARGUMENT_LIST", JetTypeArgumentList.class);
|
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_LIST = new JetNodeType("VALUE_ARGUMENT_LIST", JetArgumentList.class);
|
||||||
JetNodeType VALUE_ARGUMENT = new JetNodeType("VALUE_ARGUMENT", JetArgument.class);
|
JetNodeType VALUE_ARGUMENT = new JetNodeType("VALUE_ARGUMENT", JetArgument.class);
|
||||||
JetNodeType TYPE_REFERENCE = new JetNodeType("TYPE_REFERENCE", JetTypeReference.class);
|
JetNodeType TYPE_REFERENCE = new JetNodeType("TYPE_REFERENCE", JetTypeReference.class);
|
||||||
JetNodeType LABELED_TUPLE_ENTRY = new JetNodeType("LABELED_TUPLE_ENTRY");
|
JetNodeType LABELED_TUPLE_ENTRY = new JetNodeType("LABELED_TUPLE_ENTRY");
|
||||||
JetNodeType TUPLE_TYPE = new JetNodeType("TUPLE_TYPE");
|
|
||||||
JetNodeType FUNCTION_TYPE = new JetNodeType("FUNCTION_TYPE");
|
JetNodeType USER_TYPE = new JetNodeType("USER_TYPE", JetUserType.class);
|
||||||
JetNodeType SELF_TYPE = new JetNodeType("SELF_TYPE");
|
JetNodeType TUPLE_TYPE = new JetNodeType("TUPLE_TYPE", JetTupleType.class);
|
||||||
|
JetNodeType FUNCTION_TYPE = new JetNodeType("FUNCTION_TYPE", JetFunctionType.class);
|
||||||
|
JetNodeType SELF_TYPE = new JetNodeType("SELF_TYPE", JetSelfType.class);
|
||||||
|
|
||||||
JetNodeType DECOMPOSER_PROPERTY_LIST = new JetNodeType("DECOMPOSER_PROPERTY_LIST", JetDecomposerPropertyList.class);
|
JetNodeType DECOMPOSER_PROPERTY_LIST = new JetNodeType("DECOMPOSER_PROPERTY_LIST", JetDecomposerPropertyList.class);
|
||||||
// TODO: review
|
// TODO: review
|
||||||
JetNodeType RECEIVER_TYPE_ATTRIBUTES = new JetNodeType("RECEIVER_TYPE_ATTRIBUTES");
|
JetNodeType RECEIVER_TYPE_ATTRIBUTES = new JetNodeType("RECEIVER_TYPE_ATTRIBUTES");
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author max
|
||||||
|
*/
|
||||||
|
public class JetFunctionType extends JetTypeElement {
|
||||||
|
public JetFunctionType(@NotNull ASTNode node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(JetVisitor visitor) {
|
||||||
|
visitor.visitFunctionType(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public JetParameterList getParameterList() {
|
||||||
|
return (JetParameterList) findChildByType(JetNodeTypes.VALUE_PARAMETER_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<JetParameter> getParameters() {
|
||||||
|
JetParameterList list = getParameterList();
|
||||||
|
return list != null ? list.getParameters() : Collections.<JetParameter>emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public JetTypeReference getReceiverTypeRef() {
|
||||||
|
PsiElement child = getFirstChild();
|
||||||
|
while (child != null) {
|
||||||
|
IElementType tt = child.getNode().getElementType();
|
||||||
|
if (tt == JetTokens.LPAR || tt == JetTokens.COLON) break;
|
||||||
|
if (child instanceof JetTypeReference) {
|
||||||
|
return (JetTypeReference) child;
|
||||||
|
}
|
||||||
|
child = child.getNextSibling();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public JetTypeReference getReturnTypeRef() {
|
||||||
|
boolean colonPassed = false;
|
||||||
|
PsiElement child = getFirstChild();
|
||||||
|
while (child != null) {
|
||||||
|
IElementType tt = child.getNode().getElementType();
|
||||||
|
if (tt == JetTokens.COLON) {
|
||||||
|
colonPassed = true;
|
||||||
|
}
|
||||||
|
if (colonPassed && child instanceof JetTypeReference) {
|
||||||
|
return (JetTypeReference) child;
|
||||||
|
}
|
||||||
|
child = child.getNextSibling();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ public class JetModifierList extends JetElement {
|
|||||||
visitor.visitModifierList(this);
|
visitor.visitModifierList(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public List<JetAttributeAnnotation> getAttributeAnnotations() {
|
public List<JetAttributeAnnotation> getAttributeAnnotations() {
|
||||||
return findChildrenByType(JetNodeTypes.ATTRIBUTE_ANNOTATION);
|
return findChildrenByType(JetNodeTypes.ATTRIBUTE_ANNOTATION);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author max
|
||||||
|
*/
|
||||||
|
public class JetSelfType extends JetTypeElement {
|
||||||
|
public JetSelfType(@NotNull ASTNode node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(JetVisitor visitor) {
|
||||||
|
visitor.visitSelfType(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
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 JetTupleType extends JetTypeElement {
|
||||||
|
public JetTupleType(@NotNull ASTNode node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(JetVisitor visitor) {
|
||||||
|
visitor.visitTupleType(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<JetTypeReference> getComponentTypeRefs() {
|
||||||
|
return findChildrenByType(JetNodeTypes.TYPE_REFERENCE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author max
|
||||||
|
*/
|
||||||
|
public abstract class JetTypeElement extends JetElement {
|
||||||
|
public JetTypeElement(@NotNull ASTNode node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,11 @@ package org.jetbrains.jet.lang.psi;
|
|||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author max
|
* @author max
|
||||||
@@ -15,4 +20,17 @@ public class JetTypeReference extends JetElement {
|
|||||||
public void accept(JetVisitor visitor) {
|
public void accept(JetVisitor visitor) {
|
||||||
visitor.visitTypeReference(this);
|
visitor.visitTypeReference(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<JetAttributeAnnotation> getAttributeAnnotations() {
|
||||||
|
return findChildrenByType(JetNodeTypes.ATTRIBUTE_ANNOTATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<JetAttribute> getAttributes() {
|
||||||
|
List<JetAttribute> answer = null;
|
||||||
|
for (JetAttributeAnnotation annotation : getAttributeAnnotations()) {
|
||||||
|
if (answer == null) answer = new ArrayList<JetAttribute>();
|
||||||
|
answer.addAll(annotation.getAttributes());
|
||||||
|
}
|
||||||
|
return answer != null ? answer : Collections.<JetAttribute>emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author max
|
||||||
|
*/
|
||||||
|
public class JetUserType extends JetTypeElement {
|
||||||
|
public JetUserType(@NotNull ASTNode node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(JetVisitor visitor) {
|
||||||
|
visitor.visitUserType(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getReferencedName() {
|
||||||
|
StringBuilder answer = new StringBuilder();
|
||||||
|
ASTNode childNode = getNode().getFirstChildNode();
|
||||||
|
while (childNode != null) {
|
||||||
|
IElementType tt = childNode.getElementType();
|
||||||
|
if (tt == JetTokens.IDENTIFIER || tt == JetTokens.DOT || tt == JetTokens.NAMESPACE_KEYWORD) {
|
||||||
|
answer.append(childNode.getText());
|
||||||
|
}
|
||||||
|
childNode = childNode.getTreeNext();
|
||||||
|
}
|
||||||
|
return answer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public JetTypeArgumentList getTypeArgumentList() {
|
||||||
|
return (JetTypeArgumentList) findChildByType(JetNodeTypes.TYPE_ARGUMENT_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<JetTypeReference> getTypeArguments() {
|
||||||
|
JetTypeArgumentList list = getTypeArgumentList();
|
||||||
|
return list != null ? list.getArguments() : Collections.<JetTypeReference>emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -293,4 +293,24 @@ public class JetVisitor extends PsiElementVisitor {
|
|||||||
public void visitTypeConstraint(JetTypeConstraint constraint) {
|
public void visitTypeConstraint(JetTypeConstraint constraint) {
|
||||||
visitJetElement(constraint);
|
visitJetElement(constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void visitTypeElement(JetTypeElement type) {
|
||||||
|
visitJetElement(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visitUserType(JetUserType type) {
|
||||||
|
visitTypeElement(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visitTupleType(JetTupleType type) {
|
||||||
|
visitTypeElement(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visitFunctionType(JetFunctionType type) {
|
||||||
|
visitTypeElement(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visitSelfType(JetSelfType type) {
|
||||||
|
visitTypeElement(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user