diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java b/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java index 82193f5950d..fdd3432712c 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java +++ b/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java @@ -36,6 +36,7 @@ import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lexer.JetToken; +import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.plugin.completion.handlers.JetFunctionInsertHandler; import org.jetbrains.jet.plugin.completion.handlers.JetKeywordInsertHandler; import org.jetbrains.jet.plugin.completion.handlers.JetTemplateInsertHandler; @@ -61,7 +62,9 @@ public class JetKeywordCompletionContributor extends CompletionContributor { new CommentFilter(), // or new ParentFilter(new ClassFilter(JetLiteralStringTemplateEntry.class)), // or new ParentFilter(new ClassFilter(JetConstantExpression.class)), // or - new LeftNeighbour(new TextFilter(".")) + new LeftNeighbour(new TextFilter(".")), // or + new AndFilter(new LeafElementFilter(JetTokens.IDENTIFIER), + new NotFilter(new ParentFilter(new ClassFilter(JetReferenceExpression.class)))) )); private final static List FUNCTION_KEYWORDS = Lists.newArrayList(GET_KEYWORD.toString(), SET_KEYWORD.toString()); @@ -309,4 +312,5 @@ public class JetKeywordCompletionContributor extends CompletionContributor { new FilterPattern(new AndFilter(GENERAL_FILTER, placeFilter))); } + } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/LeafElementFilter.java b/idea/src/org/jetbrains/jet/plugin/completion/LeafElementFilter.java new file mode 100644 index 00000000000..d4d48783b7d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/completion/LeafElementFilter.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.completion; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.filters.ClassFilter; +import com.intellij.psi.filters.ElementFilter; +import com.intellij.psi.impl.source.tree.LeafPsiElement; +import com.intellij.psi.tree.IElementType; + +/** +* @author Evgeny Gerashchenko +* @since 2/23/12 +*/ +public class LeafElementFilter implements ElementFilter { + private static final ClassFilter LEAF_CLASS_FILTER = new ClassFilter(LeafPsiElement.class); + + private IElementType myElementType; + + LeafElementFilter(IElementType elementType) { + myElementType = elementType; + } + + @Override + public boolean isAcceptable(Object element, PsiElement context) { + return element instanceof LeafPsiElement && ((LeafPsiElement) element).getElementType() == myElementType; + } + + @Override + public boolean isClassAcceptable(Class hintClass) { + return LEAF_CLASS_FILTER.isClassAcceptable(hintClass); + } +} diff --git a/idea/testData/completion/keywords/InFunctionName.kt b/idea/testData/completion/keywords/InFunctionName.kt new file mode 100644 index 00000000000..360c1ff4af9 --- /dev/null +++ b/idea/testData/completion/keywords/InFunctionName.kt @@ -0,0 +1,52 @@ +fun () { + +} + +// ABSENT: abstract +// ABSENT: annotation +// ABSENT: as +// ABSENT: break +// ABSENT: by +// ABSENT: catch +// ABSENT: class +// ABSENT: continue +// ABSENT: do +// ABSENT: else +// ABSENT: enum +// ABSENT: false +// ABSENT: final +// ABSENT: finally +// ABSENT: for +// ABSENT: fun +// ABSENT: get +// ABSENT: if +// ABSENT: import +// ABSENT: in +// ABSENT: inline +// ABSENT: internal +// ABSENT: is +// ABSENT: null +// ABSENT: object +// ABSENT: open +// ABSENT: out +// ABSENT: override +// ABSENT: package +// ABSENT: private +// ABSENT: protected +// ABSENT: public +// ABSENT: return +// ABSENT: set +// ABSENT: super +// ABSENT: This +// ABSENT: this +// ABSENT: throw +// ABSENT: trait +// ABSENT: true +// ABSENT: try +// ABSENT: type +// ABSENT: val +// ABSENT: var +// ABSENT: vararg +// ABSENT: when +// ABSENT: where +// ABSENT: while \ No newline at end of file diff --git a/idea/testData/completion/keywords/InMethodParametersList.kt b/idea/testData/completion/keywords/InMethodParametersList.kt index cd762862b7f..45e2d3900dc 100644 --- a/idea/testData/completion/keywords/InMethodParametersList.kt +++ b/idea/testData/completion/keywords/InMethodParametersList.kt @@ -31,7 +31,7 @@ class TestSample() { // ABSENT: null // ABSENT: object // ABSENT: open -// EXIST: out +// ABSENT: out // ABSENT: override // ABSENT: package // ABSENT: private diff --git a/idea/testData/completion/keywords/InParametersList.kt b/idea/testData/completion/keywords/InParametersList.kt index 936832f8078..3721eb6e546 100644 --- a/idea/testData/completion/keywords/InParametersList.kt +++ b/idea/testData/completion/keywords/InParametersList.kt @@ -28,7 +28,7 @@ fun test() { // ABSENT: null // ABSENT: object // ABSENT: open -// EXIST: out +// ABSENT: out // ABSENT: override // ABSENT: package // ABSENT: private diff --git a/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java b/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java index 5beca227a01..68d3ad8f77f 100644 --- a/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java +++ b/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java @@ -63,6 +63,10 @@ public class KeywordsCompletionTest extends JetCompletionTestBase { doTest(); } + public void testInFunctionName() { + doTest(); + } + public void testInFunctionScope() { doTest(); }