mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
IDEA-71746 Please, enable completion of non initialized fields
This commit is contained in:
@@ -59,7 +59,7 @@ public class JavaCompletionSorting {
|
||||
|
||||
List<LookupElementWeigher> afterNegativeStats = new ArrayList<LookupElementWeigher>();
|
||||
ContainerUtil.addIfNotNull(afterNegativeStats, smart ? new PreferDefaultTypeWeigher(expectedTypes, parameters) : preferStatics(position));
|
||||
afterNegativeStats.add(new PreferLocalVariablesLiteralsAndAnnoMethodsWeigher(type));
|
||||
afterNegativeStats.add(new PreferLocalVariablesLiteralsAndAnnoMethodsWeigher(type, position));
|
||||
ContainerUtil.addIfNotNull(afterNegativeStats, recursion(parameters, expectedTypes));
|
||||
if (!smart && !afterNew) {
|
||||
afterNegativeStats.add(new PreferExpected(false, expectedTypes));
|
||||
|
||||
@@ -417,7 +417,11 @@ public class JavaCompletionUtil {
|
||||
return matcher.prefixMatches(s);
|
||||
}
|
||||
};
|
||||
final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, checkAccess, parameters.getInvocationCount() <= 1, nameCondition);
|
||||
|
||||
PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
|
||||
boolean checkInitialized = parameters.getInvocationCount() <= 1 && call != null && PsiKeyword.SUPER.equals(call.getMethodExpression().getText());
|
||||
|
||||
final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, checkAccess, checkInitialized, nameCondition);
|
||||
javaReference.processVariants(processor);
|
||||
final Collection<CompletionElement> plainResults = processor.getResults();
|
||||
|
||||
|
||||
+11
-1
@@ -15,20 +15,25 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementWeigher;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends LookupElementWeigher {
|
||||
private final CompletionType myCompletionType;
|
||||
private final Set<PsiField> myNonInitializedFields;
|
||||
|
||||
public PreferLocalVariablesLiteralsAndAnnoMethodsWeigher(CompletionType completionType) {
|
||||
public PreferLocalVariablesLiteralsAndAnnoMethodsWeigher(CompletionType completionType, PsiElement position) {
|
||||
super("local");
|
||||
myCompletionType = completionType;
|
||||
myNonInitializedFields = JavaCompletionProcessor.getNonInitializedFields(position);
|
||||
}
|
||||
|
||||
enum MyResult {
|
||||
@@ -37,6 +42,7 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends LookupEle
|
||||
localOrParameter,
|
||||
superMethodParameters,
|
||||
normal,
|
||||
nonInitialized,
|
||||
classLiteral,
|
||||
className,
|
||||
}
|
||||
@@ -76,6 +82,10 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends LookupEle
|
||||
if (object instanceof PsiClass) {
|
||||
return MyResult.className;
|
||||
}
|
||||
|
||||
if (object instanceof PsiField && myNonInitializedFields.contains(object)) {
|
||||
return MyResult.nonInitialized;
|
||||
}
|
||||
}
|
||||
|
||||
return MyResult.normal;
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Set<PsiField> getNonInitializedFields(PsiElement element) {
|
||||
public static Set<PsiField> getNonInitializedFields(PsiElement element) {
|
||||
final PsiStatement statement = PsiTreeUtil.getParentOfType(element, PsiStatement.class);
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, true, PsiClass.class);
|
||||
if (statement == null || method == null || !method.isConstructor()) {
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
class A {
|
||||
int aaa;
|
||||
int aab;
|
||||
A(int aac) {
|
||||
aaa = aac;<caret>
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -446,7 +446,11 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
public void testNoSecondMethodTypeArguments() throws Throwable { doTest(Lookup.REPLACE_SELECT_CHAR); }
|
||||
|
||||
public void testNoFieldsInSuperConstructorCall() throws Throwable { doTest(); }
|
||||
public void testNoUninitializedFieldsInConstructor() throws Throwable { doTest(); }
|
||||
|
||||
public void testNoUninitializedFieldsInConstructor() throws Throwable {
|
||||
configureByTestName();
|
||||
assertStringItems("aac", "aab");
|
||||
}
|
||||
public void testFieldsSetInAnotherConstructor() throws Throwable { doTest(); }
|
||||
public void testFieldsSetAbove() throws Throwable { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user