"enum class" and "annotation class" are completed as single keywords

This commit is contained in:
Valentin Kipyatkov
2015-10-19 16:11:57 +03:00
parent fa14b18f7f
commit 0cfccdefe4
18 changed files with 52 additions and 33 deletions
@@ -53,6 +53,12 @@ object KeywordCompletion {
private val KEYWORDS_TO_IGNORE_PREFIX = TokenSet.create(OVERRIDE_KEYWORD /* it's needed to complete overrides that should be work by member name too */)
private val COMPOUND_KEYWORDS = mapOf<JetKeywordToken, JetKeywordToken>(
COMPANION_KEYWORD to OBJECT_KEYWORD,
ENUM_KEYWORD to CLASS_KEYWORD,
ANNOTATION_KEYWORD to CLASS_KEYWORD
)
public fun complete(position: PsiElement, prefix: String, isJvmModule: Boolean, consumer: (LookupElement) -> Unit) {
if (!GENERAL_FILTER.isAcceptable(position, position)) return
@@ -60,15 +66,16 @@ object KeywordCompletion {
for (keywordToken in ALL_KEYWORDS) {
var keyword = keywordToken.getValue()
if (keywordToken == COMPANION_KEYWORD) { // complete "companion object" instead of simply "companion" unless we are before "object" already
val nextKeyword = COMPOUND_KEYWORDS[keywordToken]
if (nextKeyword != null) {
fun PsiElement.isSpace() = this is PsiWhiteSpace && '\n' !in getText()
var next = position.nextLeaf { !(it.isSpace() || it.getText() == "$") }?.getText()
if (next != null && next.startsWith("$")) {
next = next.substring(1)
}
if (next != OBJECT_KEYWORD.getValue()) {
keyword += " " + OBJECT_KEYWORD.getValue()
if (next != nextKeyword.value) {
keyword += " " + nextKeyword.value
}
}
@@ -7,7 +7,7 @@ class MouseMovedEventArgs
// EXIST: abstract
// EXIST: as
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: get
@@ -34,6 +34,6 @@ class MouseMovedEventArgs
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -14,7 +14,7 @@ class B {
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: internal
@@ -32,6 +32,6 @@ class B {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -12,7 +12,7 @@ class A {
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: inner
@@ -37,6 +37,6 @@ class A {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+6
View File
@@ -0,0 +1,6 @@
e<caret>class A {
}
// EXIST: enum
// EXIST: external
// NOTHING_ELSE
@@ -12,7 +12,7 @@ var a : Int
// EXIST: abstract
// EXIST: by
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: get
@@ -32,6 +32,6 @@ var a : Int
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
@@ -4,7 +4,7 @@ annotation class Test {
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: object
@@ -23,6 +23,6 @@ annotation class Test {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -10,7 +10,7 @@ public class Test {
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: inner
@@ -35,6 +35,6 @@ public class Test {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -4,7 +4,7 @@ class TestClass {
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: inner
@@ -29,6 +29,6 @@ class TestClass {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -5,7 +5,7 @@ enum class Test {
}
// EXIST: abstract
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: inner
// EXIST: internal
@@ -23,7 +23,7 @@ enum class Test {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// EXIST: fun
+2 -2
View File
@@ -4,7 +4,7 @@ interface Test {
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: fun
// EXIST: object
// EXIST: open
@@ -25,6 +25,6 @@ interface Test {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -4,7 +4,7 @@ object Test {
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: internal
@@ -26,6 +26,6 @@ object Test {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
@@ -4,7 +4,7 @@ package Test
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: import
@@ -23,6 +23,6 @@ package Test
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
@@ -6,7 +6,7 @@ class Some {
// EXIST: abstract
// EXIST: by
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: get
@@ -33,6 +33,6 @@ class Some {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
@@ -6,7 +6,7 @@ class Some {
// EXIST: abstract
// EXIST: as
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: get
@@ -33,6 +33,6 @@ class Some {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -7,7 +7,7 @@ class Some {
// EXIST: abstract
// EXIST: as
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: get
@@ -35,6 +35,6 @@ class Some {
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
+2 -2
View File
@@ -2,7 +2,7 @@
// EXIST: abstract
// EXIST: class
// EXIST: enum
// EXIST: enum class
// EXIST: final
// EXIST: fun
// EXIST: import
@@ -22,6 +22,6 @@
// EXIST: inline
// EXIST: tailrec
// EXIST: external
// EXIST: annotation
// EXIST: annotation class
// EXIST: const
// NOTHING_ELSE
@@ -71,6 +71,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/keywords"), Pattern.compile("^(.+)\\.kt$"), false);
}
@TestMetadata("BeforeClass.kt")
public void testBeforeClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/BeforeClass.kt");
doTest(fileName);
}
@TestMetadata("BeforeDelegationCall.kt")
public void testBeforeDelegationCall() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/BeforeDelegationCall.kt");