Add else entry for when quick fix

This commit is contained in:
Nikolay Krasko
2012-10-25 15:52:33 +04:00
parent 6f60d08c3a
commit 33240f167d
9 changed files with 127 additions and 0 deletions
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.LocalTimeCounter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -82,6 +83,10 @@ public class JetPsiFactory {
return property.findElementAt(3);
}
public static PsiElement createNewLineWhiteSpace(Project project) {
return createWhiteSpace(project, "\n");
}
public static JetClass createClass(Project project, String text) {
return createDeclaration(project, text, JetClass.class);
}
@@ -147,6 +152,11 @@ public class JetPsiFactory {
return function.getValueParameters().get(0);
}
public static JetWhenEntry createElseWhenEntry(Project project) {
JetNamedFunction function = createFunction(project, "fun foo() { when(12) { else -> { } } }");
return PsiTreeUtil.findChildOfType(function, JetWhenEntry.class);
}
@NotNull
public static JetImportDirective createImportDirective(Project project, @NotNull String path) {
return createImportDirective(project, new ImportPath(path));
@@ -57,4 +57,10 @@ public class JetWhenExpression extends JetExpressionImpl {
public PsiElement getWhenKeywordElement() {
return findChildByType(JetTokens.WHEN_KEYWORD);
}
@Nullable
public PsiElement getCloseBraceNode() {
ASTNode openBraceNode = getNode().findChildByType(JetTokens.RBRACE);
return openBraceNode != null ? openBraceNode.getPsi() : null;
}
}