function literal node getters
This commit is contained in:
@@ -24,6 +24,6 @@ public class JetDoWhileExpression extends JetExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JetExpression getBody() {
|
public JetExpression getBody() {
|
||||||
return findExpressionUnder(JetNodeTypes.THEN);
|
return findExpressionUnder(JetNodeTypes.BODY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ public class JetForExpression extends JetExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JetExpression getBody() {
|
public JetExpression getBody() {
|
||||||
return findExpressionUnder(JetNodeTypes.THEN);
|
return findExpressionUnder(JetNodeTypes.BODY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
package org.jetbrains.jet.lang.psi;
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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
|
* @author max
|
||||||
@@ -15,4 +24,61 @@ public class JetFunctionLiteralExpression extends JetExpression {
|
|||||||
public void accept(JetVisitor visitor) {
|
public void accept(JetVisitor visitor) {
|
||||||
visitor.visitFunctionLiteralExpression(this);
|
visitor.visitFunctionLiteralExpression(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Due to the lack of multiple implementation inheritance these getters are copied from JetFunction
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ASTNode getBodyNode() {
|
||||||
|
ASTNode answer = getNode().findChildByType(JetNodeTypes.BODY);
|
||||||
|
assert answer != null;
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<JetExpression> getBody() {
|
||||||
|
return PsiTreeUtil.getChildrenOfTypeAsList(getBodyNode().getPsi(), JetExpression.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@ public class JetWhileExpression extends JetExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JetExpression getBody() {
|
public JetExpression getBody() {
|
||||||
return findExpressionUnder(JetNodeTypes.THEN);
|
return findExpressionUnder(JetNodeTypes.BODY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user