Search in sources :

Example 26 with CandidateInfo

use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.

the class GrClassImplUtil method getInnerClassesForResolve.

@NotNull
private static List<PsiClass> getInnerClassesForResolve(@NotNull final GrTypeDefinition grType, @Nullable final PsiElement lastParent, @NotNull final PsiElement place) {
    if (lastParent instanceof GrReferenceList || PsiTreeUtil.getParentOfType(place, GrReferenceList.class) != null) {
        return Arrays.asList(grType.getCodeInnerClasses());
    }
    boolean includeSynthetic = !PsiTreeUtil.isContextAncestor(grType, place, true);
    Object key = Trinity.create(grType, lastParent, place);
    List<PsiClass> classes = RecursionManager.doPreventingRecursion(key, false, () -> {
        List<PsiClass> result = new ArrayList<>();
        for (CandidateInfo info : CollectClassMembersUtil.getAllInnerClasses(grType, includeSynthetic).values()) {
            final PsiClass inner = (PsiClass) info.getElement();
            final PsiClass containingClass = inner.getContainingClass();
            assert containingClass != null;
            if (lastParent == null || !containingClass.isInterface() || PsiTreeUtil.isAncestor(containingClass, place, false)) {
                ContainerUtil.addIfNotNull(result, inner);
            }
        }
        return result;
    });
    if (classes == null) {
        return Arrays.asList(grType.getCodeInnerClasses());
    }
    return classes;
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) GrReferenceList(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with CandidateInfo

use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.

the class GrClassImplUtil method findInnerClassByName.

@Nullable
public static PsiClass findInnerClassByName(GrTypeDefinition grType, String name, boolean checkBases) {
    if (!checkBases) {
        for (PsiClass inner : grType.getInnerClasses()) {
            if (name.equals(inner.getName()))
                return inner;
        }
        return null;
    } else {
        Map<String, CandidateInfo> innerClasses = CollectClassMembersUtil.getAllInnerClasses(grType, true);
        final CandidateInfo info = innerClasses.get(name);
        return info == null ? null : (PsiClass) info.getElement();
    }
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with CandidateInfo

use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.

the class CollectClassMembersUtil method addMethod.

private static void addMethod(@NotNull Map<String, List<CandidateInfo>> allMethods, @NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor) {
    String name = method.getName();
    List<CandidateInfo> methods = allMethods.get(name);
    if (methods == null) {
        methods = new ArrayList<>();
        allMethods.put(name, methods);
    }
    methods.add(new CandidateInfo(method, substitutor));
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo)

Example 29 with CandidateInfo

use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.

the class CollectClassMembersUtil method processClass.

private static void processClass(@NotNull PsiClass aClass, @NotNull Map<String, CandidateInfo> allFields, @NotNull Map<String, List<CandidateInfo>> allMethods, @NotNull Map<String, CandidateInfo> allInnerClasses, @NotNull Set<PsiClass> visitedClasses, @NotNull PsiSubstitutor substitutor, boolean includeSynthetic) {
    PsiUtilCore.ensureValid(aClass);
    if (!visitedClasses.add(aClass))
        return;
    if (visitedClasses.size() == 1 || !GrTraitUtil.isTrait(aClass)) {
        for (PsiField field : getFields(aClass, includeSynthetic)) {
            String name = field.getName();
            if (!allFields.containsKey(name)) {
                allFields.put(name, new CandidateInfo(field, substitutor));
            } else if (hasExplicitVisibilityModifiers(field)) {
                final CandidateInfo candidateInfo = allFields.get(name);
                final PsiElement element = candidateInfo.getElement();
                if (element instanceof GrField) {
                    final GrModifierList modifierList = ((GrField) element).getModifierList();
                    if ((modifierList == null || !modifierList.hasExplicitVisibilityModifiers()) && aClass == ((GrField) element).getContainingClass()) {
                        //replace property-field with field with explicit visibilityModifier
                        allFields.put(name, new CandidateInfo(field, substitutor));
                    }
                }
            }
        }
    }
    for (PsiMethod method : getMethods(aClass, includeSynthetic)) {
        addMethod(allMethods, method, substitutor);
    }
    for (final PsiClass inner : getInnerClasses(aClass, includeSynthetic)) {
        final String name = inner.getName();
        if (name != null && !allInnerClasses.containsKey(name)) {
            allInnerClasses.put(name, new CandidateInfo(inner, substitutor));
        }
    }
    for (PsiClass superClass : getSupers(aClass, includeSynthetic)) {
        final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, substitutor);
        processClass(superClass, allFields, allMethods, allInnerClasses, visitedClasses, superSubstitutor, includeSynthetic);
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) CandidateInfo(com.intellij.psi.infos.CandidateInfo)

Example 30 with CandidateInfo

use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.

the class ReferenceExpressionCompletionContributor method completeFinalReference.

static Set<LookupElement> completeFinalReference(final PsiElement element, PsiJavaCodeReferenceElement reference, ElementFilter filter, final JavaSmartCompletionParameters parameters) {
    final Set<PsiField> used = parameters.getParameters().getInvocationCount() < 2 ? findConstantsUsedInSwitch(element) : Collections.<PsiField>emptySet();
    final Set<LookupElement> elements = JavaSmartCompletionContributor.completeReference(element, reference, new AndFilter(filter, new ElementFilter() {

        @Override
        public boolean isAcceptable(Object o, PsiElement context) {
            if (o instanceof CandidateInfo) {
                final CandidateInfo info = (CandidateInfo) o;
                final PsiElement member = info.getElement();
                final PsiType expectedType = parameters.getExpectedType();
                if (expectedType.equals(PsiType.VOID)) {
                    return member instanceof PsiMethod;
                }
                //noinspection SuspiciousMethodCalls
                if (member instanceof PsiEnumConstant && used.contains(CompletionUtil.getOriginalOrSelf(member))) {
                    return false;
                }
                return AssignableFromFilter.isAcceptable(member, element, expectedType, info.getSubstitutor());
            }
            return false;
        }

        @Override
        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    }), 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);
            if (item != null) {
                final PsiMethod method = (PsiMethod) lookupElement.getObject();
                if (SmartCompletionDecorator.hasUnboundTypeParams(method, parameters.getExpectedType())) {
                    item.setInferenceSubstitutor(SmartCompletionDecorator.calculateMethodReturnTypeSubstitutor(method, parameters.getExpectedType()), element);
                }
            }
        }
    }
    return elements;
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

CandidateInfo (com.intellij.psi.infos.CandidateInfo)60 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)19 NotNull (org.jetbrains.annotations.NotNull)13 Nullable (org.jetbrains.annotations.Nullable)6 Pair (com.intellij.openapi.util.Pair)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)4 Project (com.intellij.openapi.project.Project)3 TextRange (com.intellij.openapi.util.TextRange)3 PsiClass (com.intellij.psi.PsiClass)3 PsiElement (com.intellij.psi.PsiElement)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 GrReferenceList (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList)3 PsiMethodMember (com.intellij.codeInsight.generation.PsiMethodMember)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 LanguageLevel (com.intellij.pom.java.LanguageLevel)2 ClassCandidateInfo (com.intellij.psi.infos.ClassCandidateInfo)2 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)2