mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
'default' completion in extension methods
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.psi.PsiKeyword;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.intellij.psi.filters.AndFilter;
|
||||
import com.intellij.psi.filters.ClassFilter;
|
||||
import com.intellij.psi.filters.ElementFilter;
|
||||
import com.intellij.psi.filters.TextFilter;
|
||||
import com.intellij.psi.filters.classes.InterfaceFilter;
|
||||
import com.intellij.psi.filters.position.LeftNeighbour;
|
||||
import com.intellij.psi.filters.position.ParentElementFilter;
|
||||
|
||||
public class Java18CompletionData extends Java15CompletionData {
|
||||
@Override
|
||||
protected void initVariantsInMethodScope() {
|
||||
super.initVariantsInMethodScope();
|
||||
|
||||
{
|
||||
// in extension method
|
||||
ElementFilter position = new AndFilter(
|
||||
new LeftNeighbour(new AndFilter(
|
||||
new TextFilter(")"),
|
||||
new ParentElementFilter(new ClassFilter(PsiParameterList.class)))),
|
||||
new ParentElementFilter(new InterfaceFilter(), 3));
|
||||
CompletionVariant variant = new CompletionVariant(PsiMethod.class, position);
|
||||
variant.addCompletion(PsiKeyword.DEFAULT);
|
||||
registerVariant(variant);
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -36,6 +36,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PatternCondition;
|
||||
import com.intellij.patterns.PsiNameValuePairPattern;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.*;
|
||||
import com.intellij.psi.filters.classes.AssignableFromContextFilter;
|
||||
@@ -66,8 +67,22 @@ import static com.intellij.patterns.PsiJavaPatterns.*;
|
||||
public class JavaCompletionContributor extends CompletionContributor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.JavaCompletionContributor");
|
||||
|
||||
private static final Java15CompletionData ourJava15CompletionData = new Java15CompletionData();
|
||||
private static final JavaCompletionData ourJavaCompletionData = new JavaCompletionData();
|
||||
private static final Map<LanguageLevel, JavaCompletionData> ourCompletionData;
|
||||
|
||||
static {
|
||||
ourCompletionData = new LinkedHashMap<LanguageLevel, JavaCompletionData>();
|
||||
ourCompletionData.put(LanguageLevel.JDK_1_8, new Java18CompletionData());
|
||||
ourCompletionData.put(LanguageLevel.JDK_1_3, new Java15CompletionData());
|
||||
ourCompletionData.put(LanguageLevel.JDK_1_3, new JavaCompletionData());
|
||||
}
|
||||
|
||||
private static JavaCompletionData getCompletionData(LanguageLevel level) {
|
||||
final Set<Map.Entry<LanguageLevel, JavaCompletionData>> entries = ourCompletionData.entrySet();
|
||||
for (Map.Entry<LanguageLevel, JavaCompletionData> entry : entries) {
|
||||
if (entry.getKey().isAtLeast(level)) return entry.getValue();
|
||||
}
|
||||
return ourCompletionData.get(LanguageLevel.JDK_1_3);
|
||||
}
|
||||
|
||||
private static final PsiNameValuePairPattern NAME_VALUE_PAIR =
|
||||
psiNameValuePair().withSuperParent(2, psiElement(PsiAnnotation.class));
|
||||
@@ -338,7 +353,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
PsiElement position = parameters.getPosition();
|
||||
final Set<LookupElement> lookupSet = new LinkedHashSet<LookupElement>();
|
||||
final Set<CompletionVariant> keywordVariants = new HashSet<CompletionVariant>();
|
||||
final JavaCompletionData completionData = PsiUtil.isLanguageLevel5OrHigher(position) ? ourJava15CompletionData : ourJavaCompletionData;
|
||||
final JavaCompletionData completionData = getCompletionData(PsiUtil.getLanguageLevel(position));
|
||||
completionData.addKeywordVariants(keywordVariants, position, parameters.getOriginalFile());
|
||||
completionData.completeKeywordsBySet(lookupSet, keywordVariants, position, result.getPrefixMatcher(), parameters.getOriginalFile());
|
||||
completionData.fillCompletions(parameters, result);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -311,7 +311,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
}
|
||||
}
|
||||
|
||||
private void initVariantsInMethodScope() {
|
||||
protected void initVariantsInMethodScope() {
|
||||
// Completion for classes in method throws section
|
||||
// position
|
||||
{
|
||||
@@ -363,7 +363,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
registerVariant(variant);
|
||||
}
|
||||
|
||||
// Catch/Finnaly completion
|
||||
// Catch/Finally completion
|
||||
{
|
||||
final ElementFilter position = new LeftNeighbour(new AndFilter(
|
||||
new TextFilter("}"),
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
interface Foo {
|
||||
String foo() def<caret>
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
interface Foo {
|
||||
String foo() default <caret>
|
||||
}
|
||||
@@ -86,6 +86,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testContinue() throws Exception { doTest(false); }
|
||||
public void testThrowsOnSeparateLine() throws Exception { doTest(false); }
|
||||
public void testDefaultInAnno() throws Exception { doTest(false); }
|
||||
public void testDefaultInExtMethod() throws Exception { doTest(false); }
|
||||
public void testNullInMethodCall() throws Exception { doTest(false); }
|
||||
public void testNullInMethodCall2() throws Exception { doTest(false); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user