More consistent API in psi

This commit is contained in:
Valentin Kipyatkov
2014-10-21 18:23:52 +04:00
parent 4fd417d419
commit 762dc31e98
8 changed files with 14 additions and 15 deletions
@@ -492,7 +492,7 @@ public class PositioningStrategies {
if (valueParameterList != null) {
return markElement(valueParameterList);
}
return markNode(functionLiteral.getOpenBraceNode());
return markNode(functionLiteral.getLBrace().getNode());
}
};
@@ -53,14 +53,14 @@ public class JetFunctionLiteral extends JetFunctionNotStubbed {
}
@NotNull
public ASTNode getOpenBraceNode() {
return getNode().findChildByType(JetTokens.LBRACE);
public PsiElement getLBrace() {
return findChildByType(JetTokens.LBRACE);
}
@Nullable
@IfNotParsed
public ASTNode getClosingBraceNode() {
return getNode().findChildByType(JetTokens.RBRACE);
public PsiElement getRBrace() {
return findChildByType(JetTokens.RBRACE);
}
@Nullable
@@ -54,10 +54,10 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor {
public void visitFunctionLiteralExpression(@NotNull JetFunctionLiteralExpression expression) {
if (ApplicationManager.getApplication().isUnitTestMode()) return;
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW);
ASTNode closingBraceNode = functionLiteral.getClosingBraceNode();
if (closingBraceNode != null) {
holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW);
holder.createInfoAnnotation(functionLiteral.getLBrace(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW);
PsiElement closingBrace = functionLiteral.getRBrace();
if (closingBrace != null) {
holder.createInfoAnnotation(closingBrace, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW);
}
ASTNode arrowNode = functionLiteral.getArrowNode();
if (arrowNode != null) {
@@ -252,7 +252,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
}
if (prev?.getNode()?.getElementType() != JetTokens.LBRACE) return false
val functionLiteral = prev!!.getParent() as? JetFunctionLiteral ?: return false
return functionLiteral.getOpenBraceNode().getPsi() == prev
return functionLiteral.getLBrace() == prev
}
private fun isAtEndOfLine(offset: Int, document: Document): Boolean {
@@ -70,7 +70,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
oldParameterList.replace(newParameterList)
}
else {
val openBraceElement = functionLiteral.getOpenBraceNode().getPsi()
val openBraceElement = functionLiteral.getLBrace()
val nextSibling = openBraceElement?.getNextSibling()
val addNewline = nextSibling is PsiWhiteSpace && nextSibling.getText()?.contains("\n") ?: false
val (whitespace, arrow) = psiFactory.createWhitespaceAndArrow()
@@ -53,7 +53,7 @@ public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
}
if (hasExplicitReceiverType(element)) {
val childAfterBrace = functionLiteral.getOpenBraceNode().getPsi()?.getNextSibling()
val childAfterBrace = functionLiteral.getLBrace()?.getNextSibling()
val childBeforeParamList = oldParameterList?.getPrevSibling()
functionLiteral.deleteChildRange(childAfterBrace, childBeforeParamList)
}
@@ -46,7 +46,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBa
val newExpr = JetPsiFactory(simpleNameExpression).createExpression("{ it -> 42 }") as JetFunctionLiteralExpression
funcExpr.addRangeAfter(newExpr.getFunctionLiteral().getValueParameterList(),
newExpr.getFunctionLiteral().getArrowNode()!!.getPsi(),
funcExpr.getOpenBraceNode().getPsi())
funcExpr.getLBrace())
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument())
val paramToRename = funcExpr.getValueParameters().first()
@@ -64,7 +64,6 @@ import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.List;
import java.util.Map;
@@ -282,7 +281,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
currentParameterList.replace(newParameterList);
}
else {
PsiElement openBraceElement = functionLiteral.getOpenBraceNode().getPsi();
PsiElement openBraceElement = functionLiteral.getLBrace();
PsiElement nextSibling = openBraceElement.getNextSibling();
PsiElement whitespaceToAdd = nextSibling instanceof PsiWhiteSpace && nextSibling.getText().contains("\n")