mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -158,9 +158,11 @@ public class AllClassesGetter {
|
||||
}).forEach(new Processor<PsiClass>() {
|
||||
public boolean process(PsiClass psiClass) {
|
||||
assert psiClass != null;
|
||||
if (isSuitable(context, packagePrefix, qnames, psiClass, filterByScope, pkgContext)) {
|
||||
qnames.add(psiClass.getQualifiedName());
|
||||
consumer.consume(psiClass);
|
||||
if (isAcceptableInContext(context, psiClass, filterByScope, pkgContext)) {
|
||||
String qName = psiClass.getQualifiedName();
|
||||
if (qName != null && qName.startsWith(packagePrefix) && qnames.add(qName)) {
|
||||
consumer.consume(psiClass);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -181,9 +183,9 @@ public class AllClassesGetter {
|
||||
return j > 0 ? prefix.substring(0, j) : "";
|
||||
}
|
||||
|
||||
private static boolean isSuitable(@NotNull final PsiElement context, final String packagePrefix, final Set<String> qnames,
|
||||
@NotNull final PsiClass psiClass,
|
||||
final boolean filterByScope, final boolean pkgContext) {
|
||||
public static boolean isAcceptableInContext(@NotNull final PsiElement context,
|
||||
@NotNull final PsiClass psiClass,
|
||||
final boolean filterByScope, final boolean pkgContext) {
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
if (!context.isValid() || !psiClass.isValid()) return false;
|
||||
@@ -191,9 +193,7 @@ public class AllClassesGetter {
|
||||
if (JavaCompletionUtil.isInExcludedPackage(psiClass, false)) return false;
|
||||
|
||||
final String qualifiedName = psiClass.getQualifiedName();
|
||||
if (qualifiedName == null || !qualifiedName.startsWith(packagePrefix)) return false;
|
||||
|
||||
if (qnames.contains(qualifiedName)) return false;
|
||||
if (qualifiedName == null) return false;
|
||||
|
||||
if (!filterByScope && !(psiClass instanceof PsiCompiledElement)) return true;
|
||||
|
||||
|
||||
@@ -44,9 +44,7 @@ public class InheritorsHolder implements Consumer<LookupElement> {
|
||||
public void consume(LookupElement lookupElement) {
|
||||
final Object object = lookupElement.getObject();
|
||||
if (object instanceof PsiClass) {
|
||||
final PsiClass psiClass = (PsiClass)object;
|
||||
if (JavaCompletionUtil.hasAccessibleInnerClass(psiClass, myPosition)) return;
|
||||
registerClass(psiClass);
|
||||
registerClass((PsiClass)object);
|
||||
}
|
||||
myResult.addElement(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(lookupElement));
|
||||
}
|
||||
|
||||
+51
-8
@@ -19,12 +19,12 @@ import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.ExpectedTypesProvider;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.lang.LangBundle;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.patterns.PsiJavaElementPattern;
|
||||
import com.intellij.patterns.PsiJavaPatterns;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.ClassFilter;
|
||||
import com.intellij.psi.filters.ElementFilter;
|
||||
@@ -35,15 +35,18 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
private static final PsiJavaElementPattern.Capture<PsiElement> AFTER_NEW = psiElement().afterLeaf(PsiKeyword.NEW);
|
||||
public static final PsiJavaElementPattern.Capture<PsiElement> AFTER_NEW = psiElement().afterLeaf(PsiKeyword.NEW);
|
||||
private static final PsiJavaElementPattern.Capture<PsiElement> IN_TYPE_PARAMETER =
|
||||
psiElement().afterLeaf(PsiKeyword.EXTENDS, PsiKeyword.SUPER, "&").withParent(
|
||||
psiElement(PsiReferenceList.class).withParent(PsiTypeParameter.class));
|
||||
@@ -92,7 +95,8 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
final boolean inJavaContext = parameters.getPosition() instanceof PsiIdentifier;
|
||||
if (AFTER_NEW.accepts(insertedElement)) {
|
||||
final boolean afterNew = AFTER_NEW.accepts(insertedElement);
|
||||
if (afterNew) {
|
||||
final PsiExpression expr = PsiTreeUtil.getContextOfType(insertedElement, PsiExpression.class, true);
|
||||
for (final ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes(expr, true)) {
|
||||
final PsiType type = info.getType();
|
||||
@@ -104,20 +108,34 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
if (!defaultType.equals(type)) {
|
||||
final PsiClass defClass = PsiUtil.resolveClassInType(defaultType);
|
||||
if (defClass != null) {
|
||||
consumer.consume(createClassLookupItem(defClass, inJavaContext));
|
||||
consumer.consume(createClassLookupItem(defClass, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final boolean lookingForAnnotations = PsiJavaPatterns.psiElement().afterLeaf("@").accepts(insertedElement);
|
||||
final boolean lookingForAnnotations = psiElement().afterLeaf("@").accepts(insertedElement);
|
||||
final boolean pkgContext = JavaCompletionUtil.inSomePackage(insertedElement);
|
||||
AllClassesGetter.processJavaClasses(parameters, matcher, filterByScope, new Consumer<PsiClass>() {
|
||||
@Override
|
||||
public void consume(PsiClass psiClass) {
|
||||
if (lookingForAnnotations && !psiClass.isAnnotationType()) return;
|
||||
|
||||
if (filter.isAcceptable(psiClass, insertedElement)) {
|
||||
consumer.consume(createClassLookupItem(psiClass, inJavaContext));
|
||||
if (!inJavaContext) {
|
||||
consumer.consume(AllClassesGetter.createLookupItem(psiClass, AllClassesGetter.TRY_SHORTENING));
|
||||
} else {
|
||||
for (JavaPsiClassReferenceElement element : createClassLookupItems(psiClass, afterNew,
|
||||
JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER, new Condition<PsiClass>() {
|
||||
@Override
|
||||
public boolean value(PsiClass psiClass) {
|
||||
return filter.isAcceptable(psiClass, insertedElement) &&
|
||||
AllClassesGetter.isAcceptableInContext(insertedElement, psiClass, filterByScope, pkgContext);
|
||||
}
|
||||
})) {
|
||||
consumer.consume(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -128,6 +146,31 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
: AllClassesGetter.TRY_SHORTENING);
|
||||
}
|
||||
|
||||
public static List<JavaPsiClassReferenceElement> createClassLookupItems(final PsiClass psiClass,
|
||||
boolean withInners,
|
||||
InsertHandler<JavaPsiClassReferenceElement> insertHandler,
|
||||
Condition<PsiClass> condition) {
|
||||
List<JavaPsiClassReferenceElement> result = new SmartList<JavaPsiClassReferenceElement>();
|
||||
if (condition.value(psiClass)) {
|
||||
result.add(AllClassesGetter.createLookupItem(psiClass, insertHandler));
|
||||
}
|
||||
String name = psiClass.getName();
|
||||
if (withInners && name != null) {
|
||||
for (PsiClass inner : psiClass.getInnerClasses()) {
|
||||
if (inner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
for (JavaPsiClassReferenceElement lookupInner : createClassLookupItems(inner, withInners, insertHandler, condition)) {
|
||||
String forced = lookupInner.getForcedPresentableName();
|
||||
lookupInner.setForcedPresentableName(name + "." + (forced != null ? forced : inner.getName()));
|
||||
result.add(lookupInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String handleEmptyLookup(@NotNull final CompletionParameters parameters, final Editor editor) {
|
||||
if (!(parameters.getOriginalFile() instanceof PsiJavaFile)) return null;
|
||||
@@ -145,6 +188,6 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
private static boolean shouldShowSecondSmartCompletionHint(final CompletionParameters parameters) {
|
||||
return parameters.getCompletionType() == CompletionType.CLASS_NAME &&
|
||||
parameters.getInvocationCount() == 1 &&
|
||||
parameters.getOriginalFile().getLanguage() == StdLanguages.JAVA;
|
||||
parameters.getOriginalFile().getLanguage().isKindOf(JavaLanguage.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-9
@@ -32,9 +32,6 @@ import com.intellij.psi.filters.FilterPositionUtil;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -91,8 +88,9 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
}
|
||||
|
||||
PsiTypeLookupItem.addImportForItem(context, psiClass);
|
||||
context.setTailOffset(context.getOffset(refEnd));
|
||||
|
||||
if (shouldInsertParentheses(psiClass, file.findElementAt(context.getTailOffset() - 1))) {
|
||||
if (shouldInsertParentheses(file.findElementAt(context.getTailOffset() - 1))) {
|
||||
if (ConstructorInsertHandler.insertParentheses(context, item, psiClass, false)) {
|
||||
fillTypeArgs |= psiClass.hasTypeParameters() && PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
@@ -122,7 +120,7 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldInsertParentheses(PsiClass psiClass, PsiElement position) {
|
||||
private static boolean shouldInsertParentheses(PsiElement position) {
|
||||
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
|
||||
if (ref == null) {
|
||||
return false;
|
||||
@@ -135,13 +133,13 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
|
||||
final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
|
||||
if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
|
||||
|
||||
Set<PsiType> expectedTypes = new HashSet<PsiType>();
|
||||
for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes((PsiExpression)prevElement.getParent(), true)) {
|
||||
expectedTypes.add(info.getType());
|
||||
if (info.getType() instanceof PsiArrayType) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return JavaCompletionUtil.isDefinitelyExpected(psiClass, expectedTypes, position);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
+12
-3
@@ -31,6 +31,7 @@ import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
@@ -282,12 +283,14 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
final Set<String> usedWords = new HashSet<String>();
|
||||
final PsiElement position = parameters.getPosition();
|
||||
final boolean checkAccess = parameters.getInvocationCount() <= 1;
|
||||
final boolean isSwitchLabel = SWITCH_LABEL.accepts(position);
|
||||
final boolean isAfterNew = JavaClassNameCompletionContributor.AFTER_NEW.accepts(position);
|
||||
final boolean pkgContext = JavaCompletionUtil.inSomePackage(position);
|
||||
LegacyCompletionContributor.processReferences(parameters, result, new PairConsumer<PsiReference, CompletionResultSet>() {
|
||||
public void consume(final PsiReference reference, final CompletionResultSet result) {
|
||||
if (reference instanceof PsiJavaReference) {
|
||||
final ElementFilter filter = getReferenceFilter(position);
|
||||
if (filter != null) {
|
||||
final boolean isSwitchLabel = SWITCH_LABEL.accepts(position);
|
||||
final PsiFile originalFile = parameters.getOriginalFile();
|
||||
for (LookupElement element : JavaCompletionUtil.processJavaReference(position,
|
||||
(PsiJavaReference)reference,
|
||||
@@ -332,11 +335,17 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
result.addElement((LookupElement)completion);
|
||||
}
|
||||
else if (completion instanceof PsiClass) {
|
||||
if (!inheritors.alreadyProcessed((PsiClass)completion)) {
|
||||
JavaPsiClassReferenceElement item = JavaClassNameCompletionContributor.createClassLookupItem((PsiClass)completion, true);
|
||||
for (JavaPsiClassReferenceElement item : JavaClassNameCompletionContributor.createClassLookupItems((PsiClass)completion, isAfterNew,
|
||||
JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER, new Condition<PsiClass>() {
|
||||
@Override
|
||||
public boolean value(PsiClass psiClass) {
|
||||
return !inheritors.alreadyProcessed(psiClass) && JavaCompletionUtil.isSourceLevelAccessible(position, psiClass, pkgContext);
|
||||
}
|
||||
})) {
|
||||
usedWords.add(item.getLookupString());
|
||||
result.addElement(item);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
LookupElement element = LookupItemUtil.objectToLookupItem(completion);
|
||||
|
||||
@@ -69,10 +69,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
|
||||
@@ -419,9 +416,9 @@ public class JavaCompletionUtil {
|
||||
}
|
||||
|
||||
public static Set<LookupElement> processJavaReference(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter,
|
||||
final boolean checkAccess, boolean filterStaticAfterInstance, @Nullable final PrefixMatcher matcher, CompletionParameters parameters) {
|
||||
final boolean checkAccess, boolean filterStaticAfterInstance, final PrefixMatcher matcher, CompletionParameters parameters) {
|
||||
final THashSet<LookupElement> set = new THashSet<LookupElement>();
|
||||
final Condition<String> nameCondition = matcher == null ? null : new Condition<String>() {
|
||||
final Condition<String> nameCondition = new Condition<String>() {
|
||||
public boolean value(String s) {
|
||||
return matcher.prefixMatches(s);
|
||||
}
|
||||
@@ -450,8 +447,7 @@ public class JavaCompletionUtil {
|
||||
|
||||
final Set<PsiMember> mentioned = new THashSet<PsiMember>();
|
||||
for (CompletionElement completionElement : processor.getResults()) {
|
||||
LookupElement item = createLookupElement(completionElement, javaReference);
|
||||
if (item != null) {
|
||||
for (LookupElement item : createLookupElements(completionElement, javaReference)) {
|
||||
item.putUserData(QUALIFIER_TYPE_ATTR, qualifierType);
|
||||
final Object o = item.getObject();
|
||||
if (o instanceof PsiClass && !isSourceLevelAccessible(element, (PsiClass)o, pkgContext)) {
|
||||
@@ -604,25 +600,33 @@ public class JavaCompletionUtil {
|
||||
}), 1);
|
||||
}
|
||||
|
||||
private static LookupElement createLookupElement(CompletionElement completionElement, PsiJavaReference reference) {
|
||||
private static List<? extends LookupElement> createLookupElements(CompletionElement completionElement, PsiJavaReference reference) {
|
||||
Object completion = completionElement.getElement();
|
||||
assert !(completion instanceof LookupElement);
|
||||
|
||||
if (completion instanceof PsiMethod &&
|
||||
reference instanceof PsiJavaCodeReferenceElement &&
|
||||
((PsiJavaCodeReferenceElement)reference).getParent() instanceof PsiImportStaticStatement) {
|
||||
return JavaLookupElementBuilder.forMethod((PsiMethod)completion, PsiSubstitutor.EMPTY);
|
||||
if (reference instanceof PsiJavaCodeReferenceElement) {
|
||||
if (completion instanceof PsiMethod &&
|
||||
((PsiJavaCodeReferenceElement)reference).getParent() instanceof PsiImportStaticStatement) {
|
||||
return Arrays.asList(JavaLookupElementBuilder.forMethod((PsiMethod)completion, PsiSubstitutor.EMPTY));
|
||||
}
|
||||
|
||||
if (completion instanceof PsiClass) {
|
||||
return JavaClassNameCompletionContributor.createClassLookupItems((PsiClass)completion,
|
||||
JavaClassNameCompletionContributor.AFTER_NEW.accepts(reference),
|
||||
JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER,
|
||||
Condition.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
LookupElement _ret = LookupItemUtil.objectToLookupItem(completion);
|
||||
if (_ret == null || !(_ret instanceof LookupItem)) return null;
|
||||
if (_ret == null || !(_ret instanceof LookupItem)) return Collections.emptyList();
|
||||
|
||||
final PsiSubstitutor substitutor = completionElement.getSubstitutor();
|
||||
if (substitutor != null) {
|
||||
((LookupItem<?>)_ret).setAttribute(LookupItem.SUBSTITUTOR, substitutor);
|
||||
}
|
||||
|
||||
return _ret;
|
||||
return Arrays.asList(_ret);
|
||||
}
|
||||
|
||||
public static boolean hasAccessibleConstructor(PsiType type) {
|
||||
@@ -878,19 +882,6 @@ public class JavaCompletionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasAccessibleInnerClass(@NotNull PsiClass psiClass, @NotNull PsiElement position) {
|
||||
final PsiClass[] inners = psiClass.getInnerClasses();
|
||||
if (inners.length > 0) {
|
||||
PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(position.getProject()).getResolveHelper();
|
||||
for (PsiClass inner : inners) {
|
||||
if (inner.hasModifierProperty(PsiModifier.STATIC) && resolveHelper.isAccessible(inner, position, null)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean inSomePackage(PsiElement context) {
|
||||
PsiFile contextFile = context.getContainingFile();
|
||||
return contextFile instanceof PsiClassOwner && StringUtil.isNotEmpty(((PsiClassOwner)contextFile).getPackageName());
|
||||
@@ -914,19 +905,6 @@ public class JavaCompletionUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isDefinitelyExpected(PsiClass psiClass, Set<PsiType> expectedTypes, PsiElement position) {
|
||||
final PsiClassType classType = JavaPsiFacade.getElementFactory(psiClass.getProject()).createType(psiClass);
|
||||
for (PsiType expectedType : expectedTypes) {
|
||||
if (expectedType instanceof PsiArrayType) return false;
|
||||
}
|
||||
for (PsiType type : expectedTypes) {
|
||||
if (type instanceof PsiClassType && ((PsiClassType)type).rawType().isAssignableFrom(classType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !hasAccessibleInnerClass(psiClass, position);
|
||||
}
|
||||
|
||||
public static boolean promptTypeArgs(InsertionContext context, int offset) {
|
||||
if (offset < 0) {
|
||||
return false;
|
||||
|
||||
+37
@@ -31,6 +31,9 @@ import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -38,6 +41,7 @@ public class JavaPsiClassReferenceElement extends LookupItem<Object> {
|
||||
public static final ClassConditionKey<JavaPsiClassReferenceElement> CLASS_CONDITION_KEY = ClassConditionKey.create(JavaPsiClassReferenceElement.class);
|
||||
private final Object myClass;
|
||||
private final String myQualifiedName;
|
||||
private String myForcedPresentableName;
|
||||
|
||||
public JavaPsiClassReferenceElement(PsiClass psiClass) {
|
||||
super(psiClass.getName(), psiClass.getName());
|
||||
@@ -48,6 +52,32 @@ public class JavaPsiClassReferenceElement extends LookupItem<Object> {
|
||||
setTailType(TailType.NONE);
|
||||
}
|
||||
|
||||
public String getForcedPresentableName() {
|
||||
return myForcedPresentableName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLookupString() {
|
||||
if (myForcedPresentableName != null) {
|
||||
return myForcedPresentableName;
|
||||
}
|
||||
return super.getLookupString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAllLookupStrings() {
|
||||
if (myForcedPresentableName != null) {
|
||||
return Collections.singleton(myForcedPresentableName);
|
||||
}
|
||||
|
||||
return super.getAllLookupStrings();
|
||||
}
|
||||
|
||||
public void setForcedPresentableName(String forcedPresentableName) {
|
||||
myForcedPresentableName = forcedPresentableName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass getObject() {
|
||||
@@ -126,6 +156,13 @@ public class JavaPsiClassReferenceElement extends LookupItem<Object> {
|
||||
}
|
||||
|
||||
private static String getName(final PsiClass psiClass, final LookupItem<?> item, boolean diamond) {
|
||||
if (item instanceof JavaPsiClassReferenceElement) {
|
||||
String forced = ((JavaPsiClassReferenceElement)item).getForcedPresentableName();
|
||||
if (forced != null) {
|
||||
return forced;
|
||||
}
|
||||
}
|
||||
|
||||
String name = PsiUtilCore.getName(psiClass);
|
||||
|
||||
if (item.getAttribute(LookupItem.FORCE_QUALIFY) != null) {
|
||||
|
||||
+1
-1
@@ -388,7 +388,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
final ElementFilter filter,
|
||||
final boolean acceptClasses,
|
||||
final boolean acceptMembers,
|
||||
CompletionParameters parameters, @Nullable final PrefixMatcher matcher) {
|
||||
CompletionParameters parameters, final PrefixMatcher matcher) {
|
||||
if (reference instanceof PsiMultiReference) {
|
||||
reference = ContainerUtil.findInstance(((PsiMultiReference) reference).getReferences(), PsiJavaReference.class);
|
||||
}
|
||||
|
||||
+2
-2
@@ -138,7 +138,7 @@ public class ReferenceExpressionCompletionContributor {
|
||||
final boolean secondTime = parameters.getParameters().getInvocationCount() >= 2;
|
||||
|
||||
final Set<LookupElement> base =
|
||||
JavaSmartCompletionContributor.completeReference(element, reference, filter, false, true, parameters.getParameters(), null);
|
||||
JavaSmartCompletionContributor.completeReference(element, reference, filter, false, true, parameters.getParameters(), PrefixMatcher.ALWAYS_TRUE);
|
||||
for (final LookupElement item : new LinkedHashSet<LookupElement>(base)) {
|
||||
ExpressionLookupItem access = getSingleArrayElementAccess(element, item);
|
||||
if (access != null) {
|
||||
@@ -200,7 +200,7 @@ public class ReferenceExpressionCompletionContributor {
|
||||
public boolean isClassAcceptable(Class hintClass) {
|
||||
return true;
|
||||
}
|
||||
}), false, true, parameters.getParameters(), null);
|
||||
}), false, true, parameters.getParameters(), PrefixMatcher.ALWAYS_TRUE);
|
||||
for (LookupElement lookupElement : elements) {
|
||||
if (lookupElement.getObject() instanceof PsiMethod) {
|
||||
final JavaMethodCallElement item = lookupElement.as(JavaMethodCallElement.CLASS_CONDITION_KEY);
|
||||
|
||||
@@ -122,18 +122,18 @@ public abstract class StaticMemberProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public List<PsiMember> processMembersOfRegisteredClasses(@Nullable final PrefixMatcher matcher, PairConsumer<PsiMember, PsiClass> consumer) {
|
||||
public List<PsiMember> processMembersOfRegisteredClasses(final PrefixMatcher matcher, PairConsumer<PsiMember, PsiClass> consumer) {
|
||||
final ArrayList<PsiMember> result = CollectionFactory.arrayList();
|
||||
for (final PsiClass psiClass : myStaticImportedClasses) {
|
||||
for (final PsiMethod method : psiClass.getAllMethods()) {
|
||||
if (matcher == null || matcher.prefixMatches(method.getName())) {
|
||||
if (matcher.prefixMatches(method.getName())) {
|
||||
if (isStaticallyImportable(method)) {
|
||||
consumer.consume(method, psiClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final PsiField field : psiClass.getAllFields()) {
|
||||
if (matcher == null || matcher.prefixMatches(field. getName())) {
|
||||
if (matcher.prefixMatches(field. getName())) {
|
||||
if (isStaticallyImportable(field)) {
|
||||
consumer.consume(field, psiClass);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.psi.filters.getters;
|
||||
import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInsight.completion.CompletionUtil;
|
||||
import com.intellij.codeInsight.completion.JavaCompletionUtil;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.completion.StaticMemberProcessor;
|
||||
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
@@ -61,7 +62,7 @@ public abstract class MembersGetter {
|
||||
}
|
||||
|
||||
final Set<PsiMember> importedStatically = new HashSet<PsiMember>();
|
||||
processor.processMembersOfRegisteredClasses(null, new PairConsumer<PsiMember, PsiClass>() {
|
||||
processor.processMembersOfRegisteredClasses(PrefixMatcher.ALWAYS_TRUE, new PairConsumer<PsiMember, PsiClass>() {
|
||||
@Override
|
||||
public void consume(PsiMember member, PsiClass psiClass) {
|
||||
importedStatically.add(member);
|
||||
|
||||
+1
-1
@@ -2,6 +2,6 @@ import pack.WithInnerAClass;
|
||||
|
||||
public class Test1 {
|
||||
public void foo() {
|
||||
new WithInnerAClass<caret>
|
||||
new WithInnerAClass()<caret>
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -1,6 +1,11 @@
|
||||
class Foo {
|
||||
{
|
||||
Zzoo l = new Zzoo()<caret>
|
||||
Zzoo l = new Zzoo() {
|
||||
@Override
|
||||
public void run() {
|
||||
<selection>//To change body of implemented methods use File | Settings | File Templates.</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ public class TestClass {
|
||||
|
||||
public TestClass create() {
|
||||
final int value = 1;
|
||||
return new Xxx<caret>(value);
|
||||
return new Xxx(<caret>value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -64,6 +64,7 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
checkResultByFile(path + "/after1.java");
|
||||
|
||||
configureByFile(path + "/before2.java");
|
||||
selectItem(myItems[0]);
|
||||
checkResultByFile(path + "/after2.java");
|
||||
}
|
||||
|
||||
|
||||
+13
-24
@@ -24,7 +24,6 @@ import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
|
||||
@@ -695,21 +694,15 @@ public class ListUtils {
|
||||
public void _testClassBeforeCast() throws Throwable { doTest '\n' }
|
||||
|
||||
public void testNoAllClassesOnQualifiedReference() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
assertEmpty(myItems);
|
||||
checkResultByFile(getTestName(false) + ".java");
|
||||
doAntiTest()
|
||||
}
|
||||
|
||||
public void testFinishClassNameWithDot() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
type('.');
|
||||
checkResult()
|
||||
doTest('.')
|
||||
}
|
||||
|
||||
public void testFinishClassNameWithLParen() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
type('(');
|
||||
checkResult()
|
||||
doTest('(')
|
||||
}
|
||||
|
||||
public void testSelectNoParameterSignature() throws Throwable {
|
||||
@@ -722,12 +715,7 @@ public class ListUtils {
|
||||
|
||||
public void testCompletionInsideClassLiteral() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
new WriteCommandAction.Simple(getProject(), new PsiFile[0]) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
}
|
||||
}.execute().throwException();
|
||||
type('\n')
|
||||
checkResult()
|
||||
}
|
||||
|
||||
@@ -797,18 +785,19 @@ public class ListUtils {
|
||||
}
|
||||
|
||||
public void testClassNameGenerics() throws Throwable {
|
||||
configure()
|
||||
type '\n'
|
||||
checkResult();
|
||||
doTest('\n')
|
||||
}
|
||||
|
||||
public void testClassNameAnonymous() throws Throwable {
|
||||
configure()
|
||||
type '\n'
|
||||
checkResult();
|
||||
doTest('\n')
|
||||
}
|
||||
|
||||
public void testClassNameWithInner() throws Throwable { doTest() }
|
||||
public void testClassNameWithInner() throws Throwable {
|
||||
configure()
|
||||
assertStringItems 'Zzoo', 'Zzoo.Impl'
|
||||
type '\n'
|
||||
checkResult()
|
||||
}
|
||||
public void testClassNameWithInner2() throws Throwable { doTest() }
|
||||
|
||||
public void testClassNameWithInstanceInner() throws Throwable { doTest('\n') }
|
||||
@@ -987,7 +976,7 @@ public class ListUtils {
|
||||
|
||||
public void testPrimitiveMethodParameter() throws Throwable { doTest(); }
|
||||
|
||||
public void testNewExpectedClassParens() throws Throwable { doTest(); }
|
||||
public void testNewExpectedClassParens() throws Throwable { doTest('\n'); }
|
||||
|
||||
public void testQualifyInnerMembers() throws Throwable { doTest('\n') }
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class PrefixMatcher {
|
||||
public static final PrefixMatcher ALWAYS_TRUE = new PlainPrefixMatcher("");
|
||||
protected final String myPrefix;
|
||||
|
||||
protected PrefixMatcher(String prefix) {
|
||||
|
||||
@@ -41,9 +41,9 @@ public final class LookupElementBuilder extends LookupElement {
|
||||
@Nullable private final LookupElementPresentation myHardcodedPresentation;
|
||||
@NotNull private final Set<String> myAllLookupStrings;
|
||||
|
||||
private LookupElementBuilder(String lookupString, Object object, InsertHandler<LookupElement> insertHandler,
|
||||
LookupElementRenderer<LookupElement> renderer,
|
||||
LookupElementPresentation hardcodedPresentation,
|
||||
private LookupElementBuilder(String lookupString, Object object, @Nullable InsertHandler<LookupElement> insertHandler,
|
||||
@Nullable LookupElementRenderer<LookupElement> renderer,
|
||||
@Nullable LookupElementPresentation hardcodedPresentation,
|
||||
Set<String> allLookupStrings,
|
||||
boolean caseSensitive) {
|
||||
myLookupString = lookupString;
|
||||
@@ -55,10 +55,6 @@ public final class LookupElementBuilder extends LookupElement {
|
||||
myCaseSensitive = caseSensitive;
|
||||
}
|
||||
|
||||
private LookupElementBuilder(LookupElementBuilder other) {
|
||||
this(other.myLookupString, other.myObject, other.myInsertHandler, other.myRenderer, other.myHardcodedPresentation, other.myAllLookupStrings, other.myCaseSensitive);
|
||||
}
|
||||
|
||||
private LookupElementBuilder(@NotNull String lookupString, @NotNull Object object) {
|
||||
this(lookupString, object, null, null, null, Collections.singleton(lookupString), true);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class AutoPopupController implements Disposable {
|
||||
myAlarm.cancelAllRequests();
|
||||
}
|
||||
|
||||
public void autoPopupParameterInfo(final Editor editor, final PsiElement highlightedMethod){
|
||||
public void autoPopupParameterInfo(final Editor editor, @Nullable final PsiElement highlightedMethod){
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
if (DumbService.isDumb(myProject)) return;
|
||||
|
||||
@@ -168,7 +168,7 @@ public class AutoPopupController implements Disposable {
|
||||
documentManager.commitAllDocuments();
|
||||
int lbraceOffset = editor.getCaretModel().getOffset() - 1;
|
||||
try {
|
||||
new ShowParameterInfoHandler().invoke(myProject, editor, file1, lbraceOffset, highlightedMethod);
|
||||
ShowParameterInfoHandler.invoke(myProject, editor, file1, lbraceOffset, highlightedMethod);
|
||||
}
|
||||
catch (IndexNotReadyException ignored) { //anything can happen on alarm
|
||||
}
|
||||
|
||||
+11
-4
@@ -45,8 +45,10 @@ import java.util.Map;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class LookupCellRenderer implements ListCellRenderer {
|
||||
//TODO[kb]: move all these awesome constants to Editor's Fonts & Colors settings
|
||||
private static final int AFTER_TAIL = 10;
|
||||
private static final int AFTER_TYPE = 6;
|
||||
public static final Color BACKGROUND_COLOR_DARK_VARIANT = new Color(47, 67, 96);
|
||||
private Icon myEmptyIcon = EmptyIcon.create(5);
|
||||
private final Font myNormalFont;
|
||||
private final Font myBoldFont;
|
||||
@@ -120,8 +122,9 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
}
|
||||
|
||||
final LookupElement item = (LookupElement)value;
|
||||
final Color foreground = isSelected ? SELECTED_FOREGROUND_COLOR : FOREGROUND_COLOR;
|
||||
final Color background = isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;
|
||||
final boolean dark = UIUtil.isUnderDarcula();
|
||||
final Color foreground = getForegroundColor(isSelected);
|
||||
final Color background = isSelected ? SELECTED_BACKGROUND_COLOR : dark ? BACKGROUND_COLOR_DARK_VARIANT : BACKGROUND_COLOR;
|
||||
|
||||
int allowedWidth = list.getWidth() - AFTER_TAIL - AFTER_TYPE - getIconIndent();
|
||||
final LookupElementPresentation presentation = new RealLookupElementPresentation(isSelected ? getMaxWidth() : allowedWidth, myNormalMetrics, myBoldMetrics, myLookup);
|
||||
@@ -175,6 +178,10 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
private static Color getForegroundColor(boolean isSelected) {
|
||||
return UIUtil.isUnderDarcula() ? Gray._230 : isSelected ? SELECTED_FOREGROUND_COLOR : FOREGROUND_COLOR;
|
||||
}
|
||||
|
||||
private int getMaxWidth() {
|
||||
if (myMaxWidth < 0) {
|
||||
final Point p = myLookup.getComponent().getLocationOnScreen();
|
||||
@@ -246,7 +253,7 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
}
|
||||
|
||||
public static Color getGrayedForeground(boolean isSelected) {
|
||||
return isSelected ? SELECTED_GRAYED_FOREGROUND_COLOR : GRAYED_FOREGROUND_COLOR;
|
||||
return UIUtil.isUnderDarcula() ? Gray._230 : isSelected ? SELECTED_GRAYED_FOREGROUND_COLOR : GRAYED_FOREGROUND_COLOR;
|
||||
}
|
||||
|
||||
private int setItemTextLabel(LookupElement item, final Color foreground, final boolean selected, LookupElementPresentation presentation, int allowedWidth) {
|
||||
@@ -323,7 +330,7 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
}
|
||||
|
||||
myTypeLabel.setBackground(sampleBackground);
|
||||
myTypeLabel.setForeground(presentation.isTypeGrayed() ? getGrayedForeground(selected) : item instanceof EmptyLookupItem ? EMPTY_ITEM_FOREGROUND_COLOR : foreground);
|
||||
myTypeLabel.setForeground(presentation.isTypeGrayed() ? getGrayedForeground(selected) : item instanceof EmptyLookupItem ? UIUtil.isUnderDarcula() ? Gray._230 : EMPTY_ITEM_FOREGROUND_COLOR : foreground);
|
||||
return used;
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
myList.setFixedCellWidth(50);
|
||||
|
||||
myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
myList.setBackground(LookupCellRenderer.BACKGROUND_COLOR);
|
||||
myList.setBackground(UIUtil.isUnderDarcula() ? LookupCellRenderer.BACKGROUND_COLOR_DARK_VARIANT : LookupCellRenderer.BACKGROUND_COLOR);
|
||||
|
||||
myList.getExpandableItemsHandler();
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ public interface StatusBarWidget extends Disposable {
|
||||
private static final Color SEPARATOR_COLOR = UIUtil.getPanelBackground().darker();
|
||||
|
||||
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
|
||||
if (UIUtil.isUnderDarcula()) return;
|
||||
final Graphics2D g2 = (Graphics2D)g.create();
|
||||
if (SystemInfo.isMac) {
|
||||
final Window window = SwingUtilities.getWindowAncestor(c);
|
||||
|
||||
+11
-4
@@ -166,10 +166,17 @@ public class ShowFeatureUsageStatisticsDialog extends DialogWrapper {
|
||||
Date completionDate = FeatureUsageTracker.getInstance().getCompletionStatisticsStartDate();
|
||||
if (completionDate != null) {
|
||||
int spared = FeatureUsageTracker.getInstance().getCharactersSparedByCompletion();
|
||||
long dayCount = Math.min(1, DateFormatUtil.getDifferenceInDays(completionDate, new Date()));
|
||||
labelText += "<br>Code completion has saved you from typing at least " +
|
||||
spared + " characters since " + DateFormatUtil.formatDate(completionDate) +
|
||||
"; that's approximately " + (spared / dayCount) + " per day";
|
||||
String total = spared > 1024 * 1024 ? (spared / 1024 / 1024) + "MB code" :
|
||||
spared > 1024 ? (spared / 1024) + "KB code" :
|
||||
spared + " characters";
|
||||
|
||||
long perDayCount = spared / Math.max(1, DateFormatUtil.getDifferenceInDays(completionDate, new Date()) + 1);
|
||||
String perDay = perDayCount > 1024 * 1024 ? (perDayCount / 1024 / 1024) + "MB" :
|
||||
perDayCount > 1024 ? (perDayCount / 1024) + "KB" :
|
||||
perDayCount + " characters";
|
||||
|
||||
labelText += "<br>Code completion has saved you from typing at least " + total + " since " + DateFormatUtil.formatDate(completionDate) +
|
||||
" (\u2245 " + perDay + " per day)";
|
||||
}
|
||||
controlsPanel.add(new JLabel("<html><body>" + labelText + "</body></html>"), BorderLayout.NORTH);
|
||||
|
||||
|
||||
@@ -16,9 +16,14 @@
|
||||
package com.intellij.ide.ui;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.ui.laf.IdeaDarkLookAndFeelInfo;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.options.BaseConfigurable;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.wm.ex.WindowManagerEx;
|
||||
import com.intellij.ui.ListCellRendererWrapper;
|
||||
@@ -154,10 +159,27 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab
|
||||
settings.SHOW_ICONS_IN_QUICK_NAVIGATION = myComponent.myHideIconsInQuickNavigation.isSelected();
|
||||
|
||||
if (!Comparing.equal(myComponent.myLafComboBox.getSelectedItem(), lafManager.getCurrentLookAndFeel())) {
|
||||
UIManager.LookAndFeelInfo lafInfo = (UIManager.LookAndFeelInfo)myComponent.myLafComboBox.getSelectedItem();
|
||||
final UIManager.LookAndFeelInfo lafInfo = (UIManager.LookAndFeelInfo)myComponent.myLafComboBox.getSelectedItem();
|
||||
if (lafManager.checkLookAndFeel(lafInfo)) {
|
||||
update = shouldUpdateUI = true;
|
||||
lafManager.setCurrentLookAndFeel(lafInfo);
|
||||
if (lafInfo instanceof IdeaDarkLookAndFeelInfo && !lafInfo.getName().equals(
|
||||
EditorColorsManager.getInstance().getGlobalScheme().getName())) {
|
||||
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getScheme(lafInfo.getName());
|
||||
|
||||
if (scheme != null) {
|
||||
final int answer = Messages.showOkCancelDialog("Set " + lafInfo.getName() + " editor scheme as well?",
|
||||
"Setup Editor Color Scheme",
|
||||
Messages.getQuestionIcon());
|
||||
if (answer == Messages.OK) {
|
||||
EditorColorsManager.getInstance().setGlobalScheme(scheme);
|
||||
if (Messages.showOkCancelDialog("Restart now?", "Restart", Messages.getQuestionIcon()) == Messages.OK) {
|
||||
ApplicationManagerEx.getApplicationEx().restart();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,6 @@ final class IdeaDarkLaf extends BasicLookAndFeel {
|
||||
static void initIdeaDefaults(UIDefaults defaults) {
|
||||
loadDefaults(defaults, null); //load defaults
|
||||
loadDefaults(defaults, SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux"); // load OS customization
|
||||
|
||||
defaults.put("Table.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] {
|
||||
"ctrl C", "copy",
|
||||
"ctrl V", "paste",
|
||||
|
||||
+1
-1
@@ -507,7 +507,7 @@ public class IdeStatusBarImpl extends JComponent implements StatusBarEx {
|
||||
setUI((StatusBarUI)UIManager.getUI(this));
|
||||
}
|
||||
else {
|
||||
setUI(SystemInfo.isMac ? new MacStatusBarUI() : new StatusBarUI());
|
||||
setUI(SystemInfo.isMac && !UIUtil.isUnderDarcula() ? new MacStatusBarUI() : new StatusBarUI());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,13 +85,15 @@ public class StatusBarUI extends ComponentUI {
|
||||
g2d.setColor(background);
|
||||
g2d.fillRect(0, 0, width, height);
|
||||
|
||||
g2d.setColor(BORDER_TOP_COLOR);
|
||||
g2d.setColor(UIUtil.isUnderDarcula() ? BORDER_TOP_COLOR.darker().darker() : BORDER_TOP_COLOR);
|
||||
g2d.drawLine(0, 0, width, 0);
|
||||
|
||||
g2d.setColor(BORDER2_TOP_COLOR);
|
||||
g2d.drawLine(0, 1, width, 1);
|
||||
if (!UIUtil.isUnderDarcula()) {
|
||||
g2d.setColor(BORDER2_TOP_COLOR);
|
||||
g2d.drawLine(0, 1, width, 1);
|
||||
}
|
||||
|
||||
g2d.setColor(BORDER_BOTTOM_COLOR);
|
||||
g2d.setColor(UIUtil.isUnderDarcula() ? BORDER_BOTTOM_COLOR.darker().darker() : BORDER_BOTTOM_COLOR);
|
||||
g2d.drawLine(0, height, width, height);
|
||||
|
||||
g2d.dispose();
|
||||
|
||||
@@ -61,8 +61,12 @@ public class TextPanel extends JComponent {
|
||||
@Override
|
||||
protected void paintComponent(final Graphics g) {
|
||||
String s = getText();
|
||||
if (s == null) return;
|
||||
final Rectangle bounds = getBounds();
|
||||
if (UIUtil.isUnderDarcula()) {
|
||||
g.setColor(UIUtil.getPanelBackground());
|
||||
g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
}
|
||||
if (s == null) return;
|
||||
final Insets insets = getInsets();
|
||||
|
||||
final Graphics2D g2 = (Graphics2D)g;
|
||||
@@ -92,7 +96,7 @@ public class TextPanel extends JComponent {
|
||||
}
|
||||
|
||||
final int y = UIUtil.getStringY(s, bounds, g2);
|
||||
if (SystemInfo.isMac && myDecorate) {
|
||||
if (SystemInfo.isMac && !UIUtil.isUnderDarcula() && myDecorate) {
|
||||
g2.setColor(Gray._215);
|
||||
g2.drawString(s, x, y + 1);
|
||||
}
|
||||
|
||||
+2
-4
@@ -20,12 +20,11 @@ import org.junit.rules.TestName;
|
||||
import org.junit.runner.Description;
|
||||
|
||||
public abstract class AbstractJunitVcsTestCase extends AbstractVcsTestCase {
|
||||
private boolean succeeded = true;
|
||||
@Rule
|
||||
public TestName name= new TestName(){
|
||||
@Override
|
||||
protected void failed(Throwable e, Description description) {
|
||||
succeeded = false;
|
||||
AbstractJunitVcsTestCase.this.failed(e, description);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,7 +32,6 @@ public abstract class AbstractJunitVcsTestCase extends AbstractVcsTestCase {
|
||||
return name.getMethodName();
|
||||
}
|
||||
|
||||
public boolean isSucceeded() {
|
||||
return succeeded;
|
||||
protected void failed(Throwable e, Description description) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ public class MacTreeUI extends BasicTreeUI {
|
||||
Color background = tree.getBackground();
|
||||
|
||||
if ((row % 2) == 0 && Boolean.TRUE.equals(tree.getClientProperty(STRIPED_CLIENT_PROPERTY))) {
|
||||
background = DECORATED_ROW_BG_COLOR;
|
||||
background = UIUtil.getDecoratedRowColor();
|
||||
}
|
||||
|
||||
if (sourceList != null && (Boolean)sourceList) {
|
||||
|
||||
@@ -1442,9 +1442,10 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
|
||||
@TestOnly
|
||||
public static void printLog() {
|
||||
System.out.println(log);
|
||||
System.out.flush();
|
||||
}
|
||||
@TestOnly
|
||||
public static void log(Object o) {
|
||||
log.append(o+"\n");
|
||||
log.append(o).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -18,11 +18,9 @@ package org.jetbrains.plugins.groovy.lang.completion;
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
@@ -62,7 +60,7 @@ public class GroovyClassNameInsertHandler implements InsertHandler<JavaPsiClassR
|
||||
}
|
||||
PsiElement position = file.findElementAt(endOffset - 1);
|
||||
|
||||
boolean parens = shouldInsertParentheses(position, item.getObject());
|
||||
boolean parens = shouldInsertParentheses(position);
|
||||
|
||||
final PsiClass psiClass = item.getObject();
|
||||
if (isInVariable(position) || GroovyCompletionContributor.isInPossibleClosureParameter(position)) {
|
||||
@@ -96,10 +94,10 @@ public class GroovyClassNameInsertHandler implements InsertHandler<JavaPsiClassR
|
||||
|
||||
}
|
||||
|
||||
private static boolean shouldInsertParentheses(PsiElement position, PsiClass psiClass) {
|
||||
private static boolean shouldInsertParentheses(PsiElement position) {
|
||||
final GrNewExpression newExpression = findNewExpression(position);
|
||||
return newExpression != null && JavaCompletionUtil
|
||||
.isDefinitelyExpected(psiClass, GroovyExpectedTypesProvider.getDefaultExpectedTypes(newExpression), position);
|
||||
return newExpression != null && ContainerUtil.findInstance(GroovyExpectedTypesProvider.getDefaultExpectedTypes(newExpression),
|
||||
PsiArrayType.class) == null;
|
||||
}
|
||||
|
||||
private static boolean isInVariable(PsiElement position) {
|
||||
|
||||
+24
-27
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
@@ -191,15 +192,21 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
final InheritorsHolder inheritors, final PrefixMatcher matcher) {
|
||||
final PsiElement position = parameters.getPosition();
|
||||
final ElementFilter filter = getClassFilter(position);
|
||||
AllClassesGetter.processJavaClasses(parameters, matcher, parameters.getInvocationCount() <= 1,
|
||||
new Consumer<PsiClass>() {
|
||||
@Override
|
||||
public void consume(PsiClass psiClass) {
|
||||
if (!inheritors.alreadyProcessed(psiClass) && filter.isAcceptable(psiClass, position)) {
|
||||
consumer.consume(GroovyCompletionUtil.createClassLookupItem(psiClass));
|
||||
}
|
||||
}
|
||||
});
|
||||
final boolean afterNew = JavaClassNameCompletionContributor.AFTER_NEW.accepts(position);
|
||||
AllClassesGetter.processJavaClasses(parameters, matcher, parameters.getInvocationCount() <= 1, new Consumer<PsiClass>() {
|
||||
@Override
|
||||
public void consume(PsiClass psiClass) {
|
||||
for (JavaPsiClassReferenceElement element : JavaClassNameCompletionContributor
|
||||
.createClassLookupItems(psiClass, afterNew, new GroovyClassNameInsertHandler(), new Condition<PsiClass>() {
|
||||
@Override
|
||||
public boolean value(PsiClass psiClass) {
|
||||
return !inheritors.alreadyProcessed(psiClass) && filter.isAcceptable(psiClass, position);
|
||||
}
|
||||
})) {
|
||||
consumer.consume(element);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ElementFilter getClassFilter(PsiElement position) {
|
||||
@@ -435,7 +442,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
if (reference instanceof GrReferenceExpression && (qualifier instanceof GrExpression || qualifier == null)) {
|
||||
unresolvedProps = CompleteReferenceExpression.getVariantsWithSameQualifier(matcher, (GrExpression)qualifier, (GrReferenceExpression)reference);
|
||||
for (String string : unresolvedProps) {
|
||||
result.add(GroovyCompletionUtil.getLookupElement(string));
|
||||
result.add(LookupElementBuilder.create(string).withItemTextUnderlined(true));
|
||||
}
|
||||
if (parameters.getInvocationCount() < 2 && qualifier != null && qualifierType == null &&
|
||||
!(qualifier instanceof GrReferenceExpression && ((GrReferenceExpression)qualifier).resolve() instanceof PsiPackage)) {
|
||||
@@ -452,27 +459,17 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
final ElementFilter classFilter = getClassFilter(position);
|
||||
|
||||
final List<LookupElement> items = arrayList();
|
||||
reference.processVariants(matcher, parameters, new Consumer<Object>() {
|
||||
public void consume(Object element) {
|
||||
if (element instanceof PsiClass && inheritorsHolder.alreadyProcessed((PsiClass)element)) {
|
||||
return;
|
||||
}
|
||||
if (element instanceof LookupElement && inheritorsHolder.alreadyProcessed((LookupElement)element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (element instanceof LookupElement && ((LookupElement)element).getObject() instanceof PsiClass) {
|
||||
element = ((LookupElement)element).getObject();
|
||||
}
|
||||
|
||||
LookupElement lookupElement = element instanceof PsiClass
|
||||
? GroovyCompletionUtil.createClassLookupItem(CompletionUtil.getOriginalOrSelf((PsiClass)element))
|
||||
: GroovyCompletionUtil.getLookupElement(element);
|
||||
reference.processVariants(matcher, parameters, new Consumer<LookupElement>() {
|
||||
public void consume(LookupElement lookupElement) {
|
||||
Object object = lookupElement.getObject();
|
||||
if (object instanceof GroovyResolveResult) {
|
||||
object = ((GroovyResolveResult)object).getElement();
|
||||
}
|
||||
|
||||
if (!(lookupElement instanceof LookupElementBuilder) && inheritorsHolder.alreadyProcessed(lookupElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (object instanceof GrReferenceExpression && unresolvedProps.contains(((GrReferenceExpression)object).getName())) {
|
||||
return;
|
||||
}
|
||||
@@ -501,7 +498,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
});
|
||||
|
||||
if (qualifier == null) {
|
||||
completeStaticMembers(parameters).processMembersOfRegisteredClasses(null, new PairConsumer<PsiMember, PsiClass>() {
|
||||
completeStaticMembers(parameters).processMembersOfRegisteredClasses(PrefixMatcher.ALWAYS_TRUE, new PairConsumer<PsiMember, PsiClass>() {
|
||||
@Override
|
||||
public void consume(PsiMember member, PsiClass psiClass) {
|
||||
if (member instanceof GrAccessorMethod) {
|
||||
|
||||
+36
-37
@@ -19,7 +19,9 @@ package org.jetbrains.plugins.groovy.lang.completion;
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.completion.AllClassesGetter;
|
||||
import com.intellij.codeInsight.completion.JavaClassNameCompletionContributor;
|
||||
import com.intellij.codeInsight.completion.JavaCompletionUtil;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
@@ -30,6 +32,7 @@ import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
@@ -40,7 +43,6 @@ import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
@@ -74,8 +76,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GdkMethodUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.WHITE_SPACES_OR_COMMENTS;
|
||||
@@ -213,28 +214,36 @@ public class GroovyCompletionUtil {
|
||||
}
|
||||
|
||||
|
||||
public static List<Object> getCompletionVariants(GroovyResolveResult[] candidates) {
|
||||
List<Object> result = CollectionFactory.arrayList();
|
||||
public static List<LookupElement> getCompletionVariants(GroovyResolveResult[] candidates, boolean afterNew, PrefixMatcher matcher) {
|
||||
List<LookupElement> result = CollectionFactory.arrayList();
|
||||
for (GroovyResolveResult candidate : candidates) {
|
||||
result.add(createCompletionVariant(candidate));
|
||||
result.addAll(createLookupElements(candidate, afterNew, matcher));
|
||||
ProgressManager.checkCanceled();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Object createCompletionVariant(GroovyResolveResult candidate) {
|
||||
public static List<? extends LookupElement> createLookupElements(GroovyResolveResult candidate, boolean afterNew, PrefixMatcher matcher) {
|
||||
final PsiElement element = candidate.getElement();
|
||||
final PsiElement context = candidate.getCurrentFileResolveContext();
|
||||
if (context instanceof GrImportStatement && element != null) {
|
||||
if (element instanceof PsiPackage) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final String importedName = ((GrImportStatement)context).getImportedName();
|
||||
if (importedName != null) {
|
||||
if (!matcher.prefixMatches(importedName)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final GrCodeReferenceElement importReference = ((GrImportStatement)context).getImportReference();
|
||||
if (importReference != null) {
|
||||
boolean alias = ((GrImportStatement)context).isAliasedImport();
|
||||
for (GroovyResolveResult r : importReference.multiResolve(false)) {
|
||||
final PsiElement resolved = r.getElement();
|
||||
if (context.getManager().areElementsEquivalent(resolved, element)) {
|
||||
if (context.getManager().areElementsEquivalent(resolved, element) && (alias || !(element instanceof PsiClass))) {
|
||||
return generateLookupForImportedElement(candidate, importedName, alias);
|
||||
}
|
||||
else {
|
||||
@@ -246,18 +255,19 @@ public class GroovyCompletionUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
return setupLookupBuilder(element, candidate.getSubstitutor(), LookupElementBuilder.create(candidate, ((PsiMethod)element).getName()));
|
||||
}
|
||||
if (element instanceof PsiClass) {
|
||||
return createClassLookupItem((PsiClass)element);
|
||||
|
||||
String name = element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName() : element.getText();
|
||||
if (name == null || !matcher.prefixMatches(name)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (element instanceof PsiNamedElement) {
|
||||
return setupLookupBuilder(element, candidate.getSubstitutor(),
|
||||
LookupElementBuilder.create(candidate, ((PsiNamedElement)element).getName()));
|
||||
if (element instanceof PsiClass) {
|
||||
return JavaClassNameCompletionContributor
|
||||
.createClassLookupItems((PsiClass)element, afterNew, new GroovyClassNameInsertHandler(), Condition.TRUE);
|
||||
}
|
||||
return candidate;
|
||||
|
||||
LookupElementBuilder builder = LookupElementBuilder.create(element instanceof PsiPackage ? element : candidate, name);
|
||||
return Arrays.asList(setupLookupBuilder(element, candidate.getSubstitutor(), builder));
|
||||
}
|
||||
|
||||
public static LookupElement createClassLookupItem(PsiClass psiClass) {
|
||||
@@ -265,26 +275,16 @@ public class GroovyCompletionUtil {
|
||||
return AllClassesGetter.createLookupItem(psiClass, new GroovyClassNameInsertHandler());
|
||||
}
|
||||
|
||||
private static LookupElement generateLookupForImportedElement(GroovyResolveResult resolveResult, String importedName, boolean alias) {
|
||||
private static List<? extends LookupElement> generateLookupForImportedElement(GroovyResolveResult resolveResult, String importedName, boolean alias) {
|
||||
final PsiElement element = resolveResult.getElement();
|
||||
assert element != null;
|
||||
if (!alias && element instanceof PsiClass) {
|
||||
return createClassLookupItem((PsiClass)element);
|
||||
}
|
||||
|
||||
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
|
||||
LookupElementBuilder builder = LookupElementBuilder.create(resolveResult, importedName).withPresentableText(importedName);
|
||||
return setupLookupBuilder(element, substitutor, builder);
|
||||
return Arrays.asList(setupLookupBuilder(element, substitutor, builder));
|
||||
}
|
||||
|
||||
public static LookupElement getLookupElement(Object o) {
|
||||
if (o instanceof LookupElement) return (LookupElement)o;
|
||||
if (o instanceof PsiNamedElement) return generateLookupElement((PsiNamedElement)o);
|
||||
if (o instanceof PsiElement) return setupLookupBuilder((PsiElement)o, PsiSubstitutor.EMPTY, LookupElementBuilder.create(o, ((PsiElement)o).getText()));
|
||||
return LookupElementBuilder.create(o, o.toString()).withItemTextUnderlined(true);
|
||||
}
|
||||
private static LookupElementBuilder generateLookupElement(PsiNamedElement element) {
|
||||
return setupLookupBuilder(element, PsiSubstitutor.EMPTY, LookupElementBuilder.create(element));
|
||||
public static LookupElement createLookupElement(PsiNamedElement o) {
|
||||
return setupLookupBuilder(o, PsiSubstitutor.EMPTY, LookupElementBuilder.create(o, o.getName()));
|
||||
}
|
||||
|
||||
private static LookupElementBuilder setupLookupBuilder(PsiElement element, PsiSubstitutor substitutor, LookupElementBuilder builder) {
|
||||
@@ -498,20 +498,19 @@ public class GroovyCompletionUtil {
|
||||
return t == mLT || t == mCOMMA;
|
||||
}
|
||||
|
||||
public static Object[] getAnnotationCompletionResults(GrAnnotation anno) {
|
||||
public static List<LookupElement> getAnnotationCompletionResults(GrAnnotation anno, PrefixMatcher matcher) {
|
||||
if (anno != null) {
|
||||
GrCodeReferenceElement ref = anno.getClassReference();
|
||||
PsiElement resolved = ref.resolve();
|
||||
if (resolved instanceof PsiClass && ((PsiClass)resolved).isAnnotationType()) {
|
||||
PsiMethod[] methods = ((PsiClass)resolved).getMethods();
|
||||
Object[] result = new Object[methods.length];
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
result[i] = createCompletionVariant(new GroovyResolveResultImpl(methods[i], true));
|
||||
List<LookupElement> result = new ArrayList<LookupElement>();
|
||||
for (PsiMethod method : ((PsiClass)resolved).getMethods()) {
|
||||
result.addAll(createLookupElements(new GroovyResolveResultImpl(method, true), false, matcher));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -19,10 +19,7 @@ import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.patterns.PsiJavaPatterns;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.ResolveState;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
@@ -76,7 +73,7 @@ public class GroovyDocCompletionProvider extends CompletionProvider<CompletionPa
|
||||
PsiElement[] elements = ArrayUtil.mergeArrays(propertyCandidates, methodCandidates);
|
||||
|
||||
for (PsiElement psiElement : elements) {
|
||||
LookupElement element = GroovyCompletionUtil.getLookupElement(psiElement);
|
||||
LookupElement element = GroovyCompletionUtil.createLookupElement((PsiNamedElement)psiElement);
|
||||
if (psiElement instanceof PsiMethod) {
|
||||
element = ((LookupElementBuilder)element).withInsertHandler(new GroovyMethodSignatureInsertHandler());
|
||||
}
|
||||
|
||||
+4
-12
@@ -92,17 +92,11 @@ public class GroovySmartCompletionContributor extends CompletionContributor {
|
||||
final PsiElement reference = position.getParent();
|
||||
if (reference == null) return;
|
||||
if (reference instanceof GrReferenceElement) {
|
||||
((GrReferenceElement)reference).processVariants(result.getPrefixMatcher(), params, new Consumer<Object>() {
|
||||
public void consume(Object variant) {
|
||||
((GrReferenceElement)reference).processVariants(result.getPrefixMatcher(), params, new Consumer<LookupElement>() {
|
||||
public void consume(LookupElement variant) {
|
||||
PsiType type = null;
|
||||
|
||||
Object o;
|
||||
if (variant instanceof LookupElement) {
|
||||
o = ((LookupElement)variant).getObject();
|
||||
}
|
||||
else {
|
||||
o = variant;
|
||||
}
|
||||
Object o = variant.getObject();
|
||||
if (o instanceof GroovyResolveResult) {
|
||||
if (!((GroovyResolveResult)o).isAccessible()) return;
|
||||
o = ((GroovyResolveResult)o).getElement();
|
||||
@@ -122,9 +116,7 @@ public class GroovySmartCompletionContributor extends CompletionContributor {
|
||||
if (type == null) return;
|
||||
for (TypeConstraint info : infos) {
|
||||
if (info.satisfied(type, position.getManager(), GlobalSearchScope.allScope(position.getProject()))) {
|
||||
final LookupElement lookupElement =
|
||||
variant instanceof LookupElement ? (LookupElement)variant : GroovyCompletionUtil.getLookupElement(o);
|
||||
result.addElement(lookupElement);
|
||||
result.addElement(variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.lang.psi;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPolyVariantReference;
|
||||
import com.intellij.psi.PsiType;
|
||||
@@ -47,7 +48,7 @@ public interface GrReferenceElement<Q extends PsiElement> extends GroovyPsiEleme
|
||||
@Nullable
|
||||
GrTypeArgumentList getTypeArgumentList();
|
||||
|
||||
void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<Object> consumer);
|
||||
void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<LookupElement> consumer);
|
||||
|
||||
@Nullable
|
||||
String getClassNameText();
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.annotation;
|
||||
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
@@ -150,7 +151,7 @@ public class GrAnnotationNameValuePairImpl extends GroovyPsiElementImpl implemen
|
||||
|
||||
@NotNull
|
||||
public Object[] getVariants() {
|
||||
return GroovyCompletionUtil.getAnnotationCompletionResults(getAnnotation());
|
||||
return GroovyCompletionUtil.getAnnotationCompletionResults(getAnnotation(), PrefixMatcher.ALWAYS_TRUE).toArray();
|
||||
}
|
||||
|
||||
public boolean isSoft() {
|
||||
|
||||
+17
-9
@@ -17,8 +17,11 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions;
|
||||
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.JavaClassNameCompletionContributor;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -67,25 +70,25 @@ public class CompleteReferenceExpression {
|
||||
private CompleteReferenceExpression() {
|
||||
}
|
||||
|
||||
public static void processVariants(PrefixMatcher matcher, Consumer<Object> consumer, GrReferenceExpressionImpl refExpr, CompletionParameters parameters) {
|
||||
processRefInAnnotation(consumer, refExpr);
|
||||
public static void processVariants(PrefixMatcher matcher, Consumer<LookupElement> consumer, GrReferenceExpressionImpl refExpr, CompletionParameters parameters) {
|
||||
processRefInAnnotation(consumer, refExpr, matcher);
|
||||
|
||||
final CompleteReferenceProcessor processor = new CompleteReferenceProcessor(refExpr, consumer, matcher, parameters);
|
||||
getVariantsImpl(refExpr, processor);
|
||||
final GroovyResolveResult[] candidates = processor.getCandidates();
|
||||
for (Object o : GroovyCompletionUtil.getCompletionVariants(candidates)) {
|
||||
for (LookupElement o : GroovyCompletionUtil.getCompletionVariants(candidates, JavaClassNameCompletionContributor.AFTER_NEW.accepts(refExpr), matcher)) {
|
||||
consumer.consume(o);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processRefInAnnotation(Consumer<Object> consumer, GrReferenceExpressionImpl refExpr) {
|
||||
private static void processRefInAnnotation(Consumer<LookupElement> consumer, GrReferenceExpressionImpl refExpr, PrefixMatcher matcher) {
|
||||
if (refExpr.getParent() instanceof GrAnnotationNameValuePair) {
|
||||
PsiElement parent = refExpr.getParent().getParent();
|
||||
if (!(parent instanceof GrAnnotation)) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (parent instanceof GrAnnotation) {
|
||||
for (Object result : GroovyCompletionUtil.getAnnotationCompletionResults((GrAnnotation)parent)) {
|
||||
for (LookupElement result : GroovyCompletionUtil.getAnnotationCompletionResults((GrAnnotation)parent, matcher)) {
|
||||
consumer.consume(result);
|
||||
}
|
||||
}
|
||||
@@ -357,7 +360,9 @@ public class CompleteReferenceExpression {
|
||||
}
|
||||
|
||||
private static class CompleteReferenceProcessor extends ResolverProcessor implements Consumer<Object> {
|
||||
private final Consumer<Object> myConsumer;
|
||||
private static final Logger LOG = Logger.getInstance(
|
||||
"#org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.CompleteReferenceExpression.CompleteReferenceProcessor");
|
||||
private final Consumer<LookupElement> myConsumer;
|
||||
private final PrefixMatcher myMatcher;
|
||||
private final CompletionParameters myParameters;
|
||||
private Collection<String> myPreferredFieldNames;
|
||||
@@ -371,7 +376,7 @@ public class CompleteReferenceExpression {
|
||||
private final boolean myIsMap;
|
||||
private Set<String> myNonDeclaredVars = new com.intellij.util.containers.HashSet<String>();
|
||||
|
||||
protected CompleteReferenceProcessor(GrReferenceExpression place, Consumer<Object> consumer, @NotNull PrefixMatcher matcher, CompletionParameters parameters) {
|
||||
protected CompleteReferenceProcessor(GrReferenceExpression place, Consumer<LookupElement> consumer, @NotNull PrefixMatcher matcher, CompletionParameters parameters) {
|
||||
super(null, EnumSet.allOf(ResolveKind.class), place, PsiType.EMPTY_ARRAY);
|
||||
myConsumer = consumer;
|
||||
myMatcher = matcher;
|
||||
@@ -416,7 +421,7 @@ public class CompleteReferenceExpression {
|
||||
|
||||
public void consume(Object o) {
|
||||
if (!(o instanceof GroovyResolveResult)) {
|
||||
myConsumer.consume(o);
|
||||
LOG.error(o);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -469,7 +474,10 @@ public class CompleteReferenceExpression {
|
||||
private void processPropertyFromField(GrField field, GroovyResolveResult resolveResult) {
|
||||
if (field.getGetters().length != 0 || field.getSetter() != null || !myPropertyNames.add(field.getName()) || myIsMap) return;
|
||||
|
||||
myConsumer.consume(((LookupElementBuilder)GroovyCompletionUtil.createCompletionVariant(resolveResult)).withIcon(GroovyIcons.PROPERTY));
|
||||
for (LookupElement element : GroovyCompletionUtil.createLookupElements(resolveResult, false, myMatcher)) {
|
||||
myConsumer.consume(((LookupElementBuilder)element).withIcon(GroovyIcons.PROPERTY));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processProperty(PsiMethod method, GroovyResolveResult resolveResult) {
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
@@ -776,7 +777,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<Object> consumer) {
|
||||
public void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<LookupElement> consumer) {
|
||||
CompleteReferenceExpression.processVariants(matcher, consumer, this, parameters);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -95,7 +96,7 @@ public class GrLightClassReferenceElement extends LightElement implements GrCode
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<Object> consumer) {
|
||||
public void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<LookupElement> consumer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+44
-38
@@ -17,9 +17,12 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.types;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.JavaClassNameCompletionContributor;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.ResolveCache;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -251,7 +254,14 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
return parent instanceof GrNewExpression;
|
||||
}
|
||||
|
||||
private void processVariantsImpl(ReferenceKind kind, Consumer<Object> consumer) {
|
||||
private static void feedLookupElements(PsiNamedElement psi, boolean afterNew, Consumer<LookupElement> consumer, PrefixMatcher matcher) {
|
||||
for (LookupElement element : GroovyCompletionUtil.createLookupElements(new GroovyResolveResultImpl(psi, true), afterNew, matcher)) {
|
||||
consumer.consume(element);
|
||||
}
|
||||
}
|
||||
|
||||
private void processVariantsImpl(ReferenceKind kind, Consumer<LookupElement> consumer, PrefixMatcher matcher) {
|
||||
boolean afterNew = JavaClassNameCompletionContributor.AFTER_NEW.accepts(this);
|
||||
switch (kind) {
|
||||
case STATIC_MEMBER_FQ: {
|
||||
final GrCodeReferenceElement qualifier = getQualifier();
|
||||
@@ -262,26 +272,26 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
|
||||
for (PsiField field : clazz.getFields()) {
|
||||
if (field.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
consumer.consume(field);
|
||||
feedLookupElements(field, afterNew, consumer, matcher);
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiMethod method : clazz.getMethods()) {
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
consumer.consume(method);
|
||||
feedLookupElements(method, afterNew, consumer, matcher);
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiClass inner : clazz.getInnerClasses()) {
|
||||
if (inner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
consumer.consume(inner);
|
||||
feedLookupElements(inner, afterNew, consumer, matcher);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//fallthrough
|
||||
// fall through
|
||||
|
||||
case PACKAGE_FQ:
|
||||
case CLASS_FQ:
|
||||
@@ -290,33 +300,31 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
LOG.assertTrue(refText != null, this.getText());
|
||||
|
||||
final int lastDot = refText.lastIndexOf(".");
|
||||
String parentPackageFQName = lastDot > 0 ? refText.substring(0, lastDot) : "";
|
||||
String parentPackageFQName = StringUtil.getPackageName(refText);
|
||||
final PsiPackage parentPackage = JavaPsiFacade.getInstance(getProject()).findPackage(parentPackageFQName);
|
||||
if (parentPackage != null) {
|
||||
final GlobalSearchScope scope = getResolveScope();
|
||||
if (kind == PACKAGE_FQ) {
|
||||
for (PsiPackage aPackage : parentPackage.getSubPackages(scope)) {
|
||||
consumer.consume(aPackage);
|
||||
feedLookupElements(aPackage, afterNew, consumer, matcher);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (kind == CLASS_FQ) {
|
||||
for (PsiClass aClass : parentPackage.getClasses(scope)) {
|
||||
consumer.consume(aClass);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
final PsiPackage[] subpackages = parentPackage.getSubPackages(scope);
|
||||
final PsiClass[] classes = parentPackage.getClasses(scope);
|
||||
for (PsiPackage aPackage : subpackages) {
|
||||
consumer.consume(aPackage);
|
||||
}
|
||||
for (PsiClass aClass : classes) {
|
||||
consumer.consume(aClass);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (kind == CLASS_FQ) {
|
||||
for (PsiClass aClass : parentPackage.getClasses(scope)) {
|
||||
feedLookupElements(aClass, afterNew, consumer, matcher);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (PsiPackage aPackage : parentPackage.getSubPackages(scope)) {
|
||||
feedLookupElements(aPackage, afterNew, consumer, matcher);
|
||||
}
|
||||
for (PsiClass aClass : parentPackage.getClasses(scope)) {
|
||||
feedLookupElements(aClass, afterNew, consumer, matcher);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,27 +336,25 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
PsiElement qualifierResolved = qualifier.resolve();
|
||||
if (qualifierResolved instanceof PsiPackage) {
|
||||
PsiPackage aPackage = (PsiPackage) qualifierResolved;
|
||||
PsiClass[] classes = aPackage.getClasses(getResolveScope());
|
||||
|
||||
for (PsiClass aClass : classes) {
|
||||
consumer.consume(aClass);
|
||||
for (PsiClass aClass : aPackage.getClasses(getResolveScope())) {
|
||||
feedLookupElements(aClass, afterNew, consumer, matcher);
|
||||
}
|
||||
if (kind == CLASS) return;
|
||||
|
||||
PsiPackage[] subpackages = aPackage.getSubPackages(getResolveScope());
|
||||
for (PsiPackage subpackage : subpackages) {
|
||||
consumer.consume(subpackage);
|
||||
for (PsiPackage subpackage : aPackage.getSubPackages(getResolveScope())) {
|
||||
feedLookupElements(subpackage, afterNew, consumer, matcher);
|
||||
}
|
||||
} else if (qualifierResolved instanceof PsiClass) {
|
||||
for (PsiClass aClass : ((PsiClass)qualifierResolved).getInnerClasses()) {
|
||||
consumer.consume(aClass);
|
||||
feedLookupElements(aClass, afterNew, consumer, matcher);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ResolverProcessor classProcessor = CompletionProcessor.createClassCompletionProcessor(this);
|
||||
ResolveUtil.treeWalkUp(this, classProcessor, false);
|
||||
|
||||
for (Object o : GroovyCompletionUtil.getCompletionVariants(classProcessor.getCandidates())) {
|
||||
for (LookupElement o : GroovyCompletionUtil.getCompletionVariants(classProcessor.getCandidates(),
|
||||
afterNew, matcher)) {
|
||||
consumer.consume(o);
|
||||
}
|
||||
}
|
||||
@@ -554,8 +560,8 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<Object> consumer) {
|
||||
processVariantsImpl(getKind(true), consumer);
|
||||
public void processVariants(PrefixMatcher matcher, CompletionParameters parameters, Consumer<LookupElement> consumer) {
|
||||
processVariantsImpl(getKind(true), consumer, matcher);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -574,10 +580,10 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
PsiElement parent = getParent();
|
||||
if (!(parent instanceof GrNewExpression)) return PsiType.EMPTY_ARRAY;
|
||||
|
||||
PsiType ltype = PsiImplUtil.inferExpectedTypeForDiamond((GrNewExpression)parent);
|
||||
PsiType lType = PsiImplUtil.inferExpectedTypeForDiamond((GrNewExpression)parent);
|
||||
|
||||
if (ltype instanceof PsiClassType) {
|
||||
return ((PsiClassType)ltype).getParameters();
|
||||
if (lType instanceof PsiClassType) {
|
||||
return ((PsiClassType)lType).getParameters();
|
||||
}
|
||||
|
||||
return PsiType.EMPTY_ARRAY;
|
||||
|
||||
+6
-1
@@ -628,6 +628,7 @@ class A {
|
||||
}"""
|
||||
configure "Zzoo l = new Zz<caret>"
|
||||
myFixture.completeBasic()
|
||||
myFixture.type '\n'
|
||||
myFixture.checkResult "Zzoo l = new Zzoo()<caret>"
|
||||
}
|
||||
|
||||
@@ -738,6 +739,8 @@ format(<caret>)"""
|
||||
myFixture.addClass "class Fooooo { interface Bar {} }"
|
||||
myFixture.configureByText "a.groovy", "Fooooo f = new Foo<caret>"
|
||||
myFixture.completeBasic()
|
||||
assert myFixture.lookupElementStrings == ['Fooooo', 'Fooooo.Bar']
|
||||
myFixture.type '\n'
|
||||
myFixture.checkResult "Fooooo f = new Fooooo()<caret>"
|
||||
}
|
||||
|
||||
@@ -745,7 +748,9 @@ format(<caret>)"""
|
||||
myFixture.addClass "class Fooooo { interface Bar {} }"
|
||||
myFixture.configureByText "a.groovy", "Fooooo.Bar f = new Foo<caret>"
|
||||
myFixture.completeBasic()
|
||||
myFixture.checkResult "Fooooo.Bar f = new Fooooo<caret>"
|
||||
assert myFixture.lookupElementStrings == ['Fooooo', 'Fooooo.Bar']
|
||||
myFixture.type '\n'
|
||||
myFixture.checkResult "Fooooo.Bar f = new Fooooo()<caret>"
|
||||
}
|
||||
|
||||
public void testOnlyExceptionsInCatch() {
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ abstract public class GroovyCompletionTestBase extends LightCodeInsightFixtureTe
|
||||
|
||||
public void checkSingleItemCompletion(String before, String after) {
|
||||
myFixture.configureByText("a.groovy", before);
|
||||
myFixture.completeBasic();
|
||||
assert !myFixture.completeBasic();
|
||||
myFixture.checkResult(after);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class A {
|
||||
<caret>
|
||||
}
|
||||
-----
|
||||
META-INF
|
||||
abstract
|
||||
boolean
|
||||
byte
|
||||
@@ -23,8 +24,11 @@ final
|
||||
float
|
||||
int
|
||||
interface
|
||||
java
|
||||
javax
|
||||
long
|
||||
native
|
||||
org
|
||||
private
|
||||
protected
|
||||
public
|
||||
|
||||
@@ -10,6 +10,7 @@ class A { <caret>
|
||||
}
|
||||
}
|
||||
-----
|
||||
META-INF
|
||||
abstract
|
||||
boolean
|
||||
byte
|
||||
@@ -22,8 +23,11 @@ final
|
||||
float
|
||||
int
|
||||
interface
|
||||
java
|
||||
javax
|
||||
long
|
||||
native
|
||||
org
|
||||
private
|
||||
protected
|
||||
public
|
||||
|
||||
Reference in New Issue
Block a user