mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-26763 Auto-complete Generics on the RHS (now in basic completion as well)
This commit is contained in:
@@ -210,6 +210,10 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (JavaSmartCompletionContributor.IN_TYPE_ARGS.accepts(position)) {
|
||||
new TypeArgumentCompletionProvider(false).addCompletions(parameters, new ProcessingContext(), result);
|
||||
}
|
||||
|
||||
final InheritorsHolder inheritors = new InheritorsHolder(position, result);
|
||||
if (JavaSmartCompletionContributor.AFTER_NEW.accepts(position)) {
|
||||
new JavaInheritorsGetter(ConstructorInsertHandler.BASIC_INSTANCE).generateVariants(parameters, result.getPrefixMatcher(), inheritors);
|
||||
|
||||
+4
-1
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.*;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PsiElementPattern;
|
||||
import com.intellij.patterns.PsiJavaPatterns;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.ElementExtractorFilter;
|
||||
@@ -86,6 +87,8 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
static final ElementPattern<PsiElement> INSIDE_TYPECAST_EXPRESSION = psiElement().withParent(
|
||||
psiElement(PsiReferenceExpression.class).afterLeaf(
|
||||
psiElement().withText(")").withParent(PsiTypeCastExpression.class)));
|
||||
static final PsiElementPattern.Capture<PsiElement> IN_TYPE_ARGS =
|
||||
psiElement().inside(psiElement(PsiReferenceParameterList.class));
|
||||
|
||||
@Nullable
|
||||
private static ElementFilter getReferenceFilter(PsiElement element) {
|
||||
@@ -283,7 +286,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
|
||||
extend(CompletionType.SMART, psiElement().inside(psiElement(PsiReferenceParameterList.class)), new TypeArgumentCompletionProvider());
|
||||
extend(CompletionType.SMART, IN_TYPE_ARGS, new TypeArgumentCompletionProvider(true));
|
||||
|
||||
|
||||
extend(CompletionType.SMART, AFTER_NEW, new JavaInheritorsGetter(ConstructorInsertHandler.SMART_INSTANCE));
|
||||
|
||||
+7
-2
@@ -46,6 +46,11 @@ import static com.intellij.patterns.PsiJavaPatterns.psiElement;
|
||||
* @author peter
|
||||
*/
|
||||
class TypeArgumentCompletionProvider extends CompletionProvider<CompletionParameters> {
|
||||
private final boolean mySmart;
|
||||
|
||||
TypeArgumentCompletionProvider(boolean smart) {
|
||||
mySmart = smart;
|
||||
}
|
||||
|
||||
protected void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext processingContext, @NotNull final CompletionResultSet resultSet) {
|
||||
final PsiElement context = parameters.getPosition();
|
||||
@@ -58,10 +63,10 @@ class TypeArgumentCompletionProvider extends CompletionProvider<CompletionParame
|
||||
for (ExpectedTypeInfo info : types) {
|
||||
PsiType type = info.getType();
|
||||
if (type instanceof PsiClassType) {
|
||||
fillExpectedTypeArgs(resultSet, context, pair.first, pair.second, ((PsiClassType)type).resolveGenerics(), info.getTailType());
|
||||
fillExpectedTypeArgs(resultSet, context, pair.first, pair.second, ((PsiClassType)type).resolveGenerics(), mySmart ? info.getTailType() : TailType.NONE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (mySmart) {
|
||||
addInheritors(parameters, resultSet, pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import java.util.HashMap;
|
||||
|
||||
public class A {
|
||||
private HashMap<String, String> m = new HashMap<St<caret>>()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import java.util.HashMap;
|
||||
|
||||
public class A {
|
||||
private HashMap<String, String> m = new HashMap<String, String>(<caret>)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
class HashMap<T,V> {}
|
||||
|
||||
public class A {
|
||||
private HashMap<String, String> m = new HashMap<String, String><caret>();
|
||||
private HashMap<String, String> m = new HashMap<String, String>();<caret>
|
||||
}
|
||||
|
||||
+9
@@ -1315,4 +1315,13 @@ public class ListUtils {
|
||||
checkResult()
|
||||
}
|
||||
|
||||
public void testSuggestAllTypeArguments() {
|
||||
configure()
|
||||
assert 'String, String' == lookup.items[1].lookupString
|
||||
lookup.currentItem = lookup.items[1]
|
||||
type '\n'
|
||||
checkResult()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user