property/accessors
This commit is contained in:
@@ -54,7 +54,7 @@ public interface JetNodeTypes {
|
||||
JetNodeType DECOMPOSER_PROPERTY_LIST = new JetNodeType("DECOMPOSER_PROPERTY_LIST", JetDecomposerPropertyList.class);
|
||||
// TODO: review
|
||||
JetNodeType RECEIVER_TYPE_ATTRIBUTES = new JetNodeType("RECEIVER_TYPE_ATTRIBUTES");
|
||||
JetNodeType PROPERTY_ACCESSOR = new JetNodeType("PROPERTY_ACCESSOR");
|
||||
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");
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
@@ -21,7 +23,24 @@ public class JetProperty extends JetNamedDeclaration {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetTypeReference getTypeReference() {
|
||||
public JetTypeReference getReceiverTypeRef() {
|
||||
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 getPropertyTypeRef() {
|
||||
ASTNode node = getNode().getFirstChildNode();
|
||||
boolean passedColon = false;
|
||||
while (node != null) {
|
||||
@@ -37,4 +56,26 @@ public class JetProperty extends JetNamedDeclaration {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetPropertyAccessor> getAccessors() {
|
||||
return findChildrenByType(JetNodeTypes.PROPERTY_ACCESSOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetPropertyAccessor getGetter() {
|
||||
for (JetPropertyAccessor accessor : getAccessors()) {
|
||||
if (accessor.isGetter()) return accessor;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public JetPropertyAccessor getSetter() {
|
||||
for (JetPropertyAccessor accessor : getAccessors()) {
|
||||
if (accessor.isSetter()) return accessor;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
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 org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetPropertyAccessor extends JetDeclaration {
|
||||
public JetPropertyAccessor(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitPropertyAccessor(this);
|
||||
}
|
||||
|
||||
public boolean isSetter() {
|
||||
return findChildByType(JetTokens.SET_KEYWORD) != null;
|
||||
}
|
||||
|
||||
public boolean isGetter() {
|
||||
return findChildByType(JetTokens.GET_KEYWORD) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetParameter getParameter() {
|
||||
return (JetParameter) findChildByType(JetNodeTypes.VALUE_PARAMETER);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetExpression getBody() {
|
||||
return findChildByClass(JetExpression.class);
|
||||
}
|
||||
}
|
||||
@@ -281,4 +281,8 @@ public class JetVisitor extends PsiElementVisitor {
|
||||
public void visitAnonymousInitializer(JetClassInitializer initializer) {
|
||||
visitDeclaration(initializer);
|
||||
}
|
||||
|
||||
public void visitPropertyAccessor(JetPropertyAccessor accessor) {
|
||||
visitDeclaration(accessor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user