Improve AddInitKeyword quickfix

- Extract quickfix method
- Delete redundant semicolon
- Do not replace initializer PSI element
This commit is contained in:
Denis Zharkov
2015-03-18 11:56:34 +03:00
parent 13f933693f
commit df23ff3473
11 changed files with 83 additions and 16 deletions
@@ -58,6 +58,11 @@ public class JetClassInitializer extends JetDeclarationStub<KotlinPlaceHolderStu
}
public boolean hasInitKeyword() {
return findChildByType(JetTokens.INIT_KEYWORD) != null;
return getInitKeyword() != null;
}
@Nullable
public PsiElement getInitKeyword() {
return findChildByType(JetTokens.INIT_KEYWORD);
}
}
@@ -230,9 +230,11 @@ public class JetPsiFactory(private val project: Project) {
}
public fun createAnonymousInitializer(): JetClassInitializer {
return createClass("class A { {} }").getAnonymousInitializers().first()
return createClass("class A { init {} }").getAnonymousInitializers().first()
}
public fun createInitKeyword(): PsiElement = createAnonymousInitializer().getInitKeyword()!!
public fun createEmptyClassBody(): JetClassBody {
return createClass("class A(){}").getBody()!!
}
@@ -408,6 +408,14 @@ public fun PsiElement.prevLeafSkipWhitespacesAndComments(): PsiElement? {
return leaf
}
public fun PsiElement.prevLeafSkipWhitespaces(): PsiElement? {
var leaf = prevLeaf()
while (leaf is PsiWhiteSpace) {
leaf = leaf!!.prevLeaf()
}
return leaf
}
public fun PsiElement.nextLeafSkipWhitespacesAndComments(): PsiElement? {
var leaf = nextLeaf()
while (leaf is PsiWhiteSpace || leaf is PsiComment) {