Additional constraints on type parameters
This commit is contained in:
@@ -57,8 +57,8 @@ public interface JetNodeTypes {
|
||||
JetNodeType PROPERTY_ACCESSOR = new JetNodeType("PROPERTY_ACCESSOR", JetPropertyAccessor.class);
|
||||
JetNodeType INITIALIZER_LIST = new JetNodeType("INITIALIZER_LIST", JetInitializerList.class);
|
||||
JetNodeType THIS_CALL = new JetNodeType("THIS_CALL", JetDelegatorToThisCall.class);
|
||||
JetNodeType TYPE_CONSTRAINT_LIST = new JetNodeType("TYPE_CONSTRAINT_LIST");
|
||||
JetNodeType TYPE_CONSTRAINT = new JetNodeType("TYPE_CONSTRAINT");
|
||||
JetNodeType TYPE_CONSTRAINT_LIST = new JetNodeType("TYPE_CONSTRAINT_LIST", JetTypeConstraintList.class);
|
||||
JetNodeType TYPE_CONSTRAINT = new JetNodeType("TYPE_CONSTRAINT", JetTypeConstraint.class);
|
||||
|
||||
// TODO: Not sure if we need separate NT for each kind of constants
|
||||
JetNodeType NULL = new JetNodeType("NULL", JetConstantExpression.class);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetTypeConstraint extends JetElement {
|
||||
public JetTypeConstraint(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitTypeConstraint(this);
|
||||
}
|
||||
|
||||
public boolean isClassObjectContraint() {
|
||||
return findChildByType(JetTokens.CLASS_KEYWORD) != null &&
|
||||
findChildByType(JetTokens.OBJECT_KEYWORD) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetTypeReference getSubjectTypeReference() {
|
||||
ASTNode node = getNode().getFirstChildNode();
|
||||
while (node != null) {
|
||||
IElementType tt = node.getElementType();
|
||||
if (tt == JetTokens.COLON) break;
|
||||
if (tt == JetNodeTypes.TYPE_REFERENCE) return (JetTypeReference) node.getPsi();
|
||||
node = node.getTreeNext();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetTypeReference getExtendsTypeReference() {
|
||||
boolean passedColon = false;
|
||||
ASTNode node = getNode().getFirstChildNode();
|
||||
while (node != null) {
|
||||
IElementType tt = node.getElementType();
|
||||
if (tt == JetTokens.COLON) passedColon = true;
|
||||
if (passedColon && tt == JetNodeTypes.TYPE_REFERENCE) return (JetTypeReference) node.getPsi();
|
||||
node = node.getTreeNext();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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 JetTypeConstraintList extends JetElement {
|
||||
public JetTypeConstraintList(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitTypeConstraintList(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetTypeConstraint> getConstraints() {
|
||||
return findChildrenByType(JetNodeTypes.TYPE_CONSTRAINT);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -18,6 +20,17 @@ public class JetTypeParameterList extends JetElement {
|
||||
return findChildrenByType(JetNodeTypes.TYPE_PARAMETER);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetTypeConstraintList getTypeConstraintList() {
|
||||
return (JetTypeConstraintList) findChildByType(JetNodeTypes.TYPE_CONSTRAINT_LIST);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetTypeConstraint> getAdditionalConstraints() {
|
||||
JetTypeConstraintList list = getTypeConstraintList();
|
||||
return list != null ? list.getConstraints() : Collections.<JetTypeConstraint>emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitTypeParameterList(this);
|
||||
|
||||
@@ -285,4 +285,12 @@ public class JetVisitor extends PsiElementVisitor {
|
||||
public void visitPropertyAccessor(JetPropertyAccessor accessor) {
|
||||
visitDeclaration(accessor);
|
||||
}
|
||||
|
||||
public void visitTypeConstraintList(JetTypeConstraintList list) {
|
||||
visitJetElement(list);
|
||||
}
|
||||
|
||||
public void visitTypeConstraint(JetTypeConstraint constraint) {
|
||||
visitJetElement(constraint);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user