From 14660aff4164e5eb4a700acaf1827c7b58846ca4 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 6 Sep 2016 13:06:37 +0200 Subject: [PATCH] java completion: show only accessible constructors, make array braces non-grayed (IDEA-CR-13383) --- .../codeInsight/completion/JavaCompletionUtil.java | 2 +- .../completion/JavaConstructorCallElement.java | 3 ++- .../intellij/codeInsight/lookup/PsiTypeLookupItem.java | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java index b69f87c23522..c78cbde20d9e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java @@ -565,7 +565,7 @@ public class JavaCompletionUtil { return methods.length == 0 || Arrays.stream(methods).anyMatch(JavaCompletionUtil::isConstructorCompletable); } - static boolean isConstructorCompletable(@NotNull PsiMethod constructor) { + private static boolean isConstructorCompletable(@NotNull PsiMethod constructor) { return !(constructor instanceof PsiCompiledElement) || !constructor.hasModifierProperty(PsiModifier.PRIVATE); } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaConstructorCallElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaConstructorCallElement.java index 29bbd8b9b80a..ea9b4f7178d8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaConstructorCallElement.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaConstructorCallElement.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; +import com.intellij.psi.impl.source.resolve.JavaResolveUtil; import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiTreeUtil; @@ -94,7 +95,7 @@ public class JavaConstructorCallElement extends JavaMethodCallElement { PsiMethod[] constructors = psiClass.getConstructors(); if (constructors.length > 0) { return JBIterable.of(constructors). - filter(JavaCompletionUtil::isConstructorCompletable). + filter(c -> JavaResolveUtil.isAccessible(c, psiClass, c.getModifierList(), position, null, null)). map(c -> new JavaConstructorCallElement(classItem, c, type)). toList(); } diff --git a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java index 14dd940b5547..bc10f7eab150 100644 --- a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java +++ b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java @@ -34,7 +34,9 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; /** @@ -284,7 +286,12 @@ public class PsiTypeLookupItem extends LookupItem implements TypedLookupItem { } if (myBracketsCount > 0) { - presentation.setTailText(StringUtil.repeat("[]", myBracketsCount) + StringUtil.notNullize(presentation.getTailText()), true); + List tail = new ArrayList<>(presentation.getTailFragments()); + presentation.clearTail(); + presentation.appendTailText(StringUtil.repeat("[]", myBracketsCount), false); + for (LookupElementPresentation.TextFragment fragment : tail) { + presentation.appendTailText(fragment.text, fragment.isGrayed()); + } } }