Search in sources :

Example 36 with CandidateInfo

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

the class ElementExtractorFilter method isAcceptable.

@Override
public boolean isAcceptable(Object element, PsiElement context) {
    if (element instanceof CandidateInfo) {
        final CandidateInfo candidateInfo = (CandidateInfo) element;
        final PsiElement psiElement = candidateInfo.getElement();
        return myFilter.isAcceptable(psiElement, context);
    } else if (element instanceof PsiElement)
        return myFilter.isAcceptable(element, context);
    return false;
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) PsiElement(com.intellij.psi.PsiElement)

Example 37 with CandidateInfo

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

the class OverrideImplementExploreUtil method collectMethodsToImplement.

public static void collectMethodsToImplement(PsiClass aClass, Map<MethodSignature, PsiMethod> abstracts, Map<MethodSignature, PsiMethod> finals, Map<MethodSignature, PsiMethod> concretes, Map<MethodSignature, CandidateInfo> result) {
    for (Map.Entry<MethodSignature, PsiMethod> entry : abstracts.entrySet()) {
        MethodSignature signature = entry.getKey();
        PsiMethod abstractOne = entry.getValue();
        PsiMethod concrete = concretes.get(signature);
        if (concrete == null || PsiUtil.getAccessLevel(concrete.getModifierList()) < PsiUtil.getAccessLevel(abstractOne.getModifierList()) || !abstractOne.getContainingClass().isInterface() && abstractOne.getContainingClass().isInheritor(concrete.getContainingClass(), true) || isDefaultMethod(aClass, abstractOne)) {
            if (finals.get(signature) == null) {
                PsiSubstitutor subst = correctSubstitutor(abstractOne, signature.getSubstitutor());
                CandidateInfo info = new CandidateInfo(abstractOne, subst);
                result.put(signature, info);
            }
        }
    }
    MemberImplementorExplorersProvider explorersProvider = ourExplorersProvider.getValue();
    if (explorersProvider != null) {
        for (final MemberImplementorExplorer implementor : explorersProvider.getExplorers()) {
            for (final PsiMethod method : implementor.getMethodsToImplement(aClass)) {
                MethodSignature signature = MethodSignatureUtil.createMethodSignature(method.getName(), method.getParameterList(), method.getTypeParameterList(), PsiSubstitutor.EMPTY, method.isConstructor());
                CandidateInfo info = new CandidateInfo(method, PsiSubstitutor.EMPTY);
                result.put(signature, info);
            }
        }
    }
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) MemberImplementorExplorer(com.intellij.codeInsight.MemberImplementorExplorer)

Example 38 with CandidateInfo

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

the class PsiDiamondTypeImpl method collectStaticFactories.

@Nullable
public static JavaResolveResult[] collectStaticFactories(PsiNewExpression newExpression, final PsiConflictResolver... conflictResolvers) {
    PsiExpressionList argumentList = newExpression.getArgumentList();
    if (argumentList == null) {
        return null;
    }
    final PsiClass psiClass = findClass(newExpression);
    if (psiClass == null) {
        //should not happens: unresolved class reference would be first and inference won't start
        return null;
    }
    final List<CandidateInfo> candidates = new ArrayList<>();
    PsiMethod[] constructors = psiClass.getConstructors();
    if (constructors.length == 0) {
        //default constructor
        constructors = new PsiMethod[] { null };
    }
    final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(argumentList, argumentList.getContainingFile(), conflictResolvers, candidates) {

        @Override
        protected boolean isAccepted(PsiMethod candidate) {
            return true;
        }

        @Override
        protected PsiClass getContainingClass(PsiMethod method) {
            return psiClass;
        }

        @Override
        protected boolean acceptVarargs() {
            return true;
        }
    };
    processor.setArgumentList(argumentList);
    for (PsiMethod constructor : constructors) {
        final PsiTypeParameter[] params = getAllTypeParams(constructor, psiClass);
        final PsiMethod staticFactory = generateStaticFactory(constructor, psiClass, params, newExpression.getClassReference());
        if (staticFactory != null) {
            processor.add(staticFactory, PsiSubstitutor.EMPTY);
        }
    }
    return processor.getResult();
}
Also used : MethodCandidatesProcessor(com.intellij.psi.scope.processor.MethodCandidatesProcessor) CandidateInfo(com.intellij.psi.infos.CandidateInfo) MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with CandidateInfo

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

the class JavaMethodsOverridingStatisticsTest method doTest.

private void doTest(final int resultSize, final Pair<String, Integer>... expectedValues) {
    myFixture.configureByFile(getTestName(false) + ".java");
    final PsiClass contextClass = OverrideImplementUtil.getContextClass(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile(), true);
    assert contextClass != null;
    if (OverrideImplementExploreUtil.getMethodSignaturesToOverride(contextClass).isEmpty() && expectedValues.length != 0) {
        fail();
    }
    final Collection<CandidateInfo> candidateInfos = OverrideImplementExploreUtil.getMethodsToOverrideImplement(contextClass, false);
    final PsiMethodWithOverridingPercentMember[] searchResults = PsiMethodWithOverridingPercentMember.calculateOverridingPercents(candidateInfos);
    assertSize(resultSize, searchResults);
    final Set<Pair<String, Integer>> actualValues = new HashSet<>();
    for (PsiMethodWithOverridingPercentMember searchResult : searchResults) {
        actualValues.add(Pair.<String, Integer>create(searchResult.getElement().getName(), searchResult.getOverridingPercent()));
    }
    final Set<Pair<String, Integer>> expectedValuesSet = ContainerUtil.newHashSet(expectedValues);
    assertEquals(expectedValuesSet, actualValues);
}
Also used : PsiMethodWithOverridingPercentMember(com.intellij.codeInsight.generation.PsiMethodWithOverridingPercentMember) CandidateInfo(com.intellij.psi.infos.CandidateInfo) PsiClass(com.intellij.psi.PsiClass) HashSet(java.util.HashSet) Pair(com.intellij.openapi.util.Pair)

Example 40 with CandidateInfo

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

the class Java8ExpressionsCheckTest method testRejectCachedTopLevelSessionIfItCorrespondsToTheWrongOverload.

public void testRejectCachedTopLevelSessionIfItCorrespondsToTheWrongOverload() throws Exception {
    final String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
    configureByFile(filePath);
    PsiMethodCallExpression methodCall = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiMethodCallExpression.class);
    assertNotNull(methodCall);
    final PsiResolveHelper helper = JavaPsiFacade.getInstance(methodCall.getProject()).getResolveHelper();
    CandidateInfo[] candidates = helper.getReferencedMethodCandidates(methodCall, false, true);
    for (CandidateInfo candidate : candidates) {
        if (candidate instanceof MethodCandidateInfo) {
            //try to cache top level session
            candidate.getSubstitutor();
        }
    }
    doTestConfiguredFile(false, false, filePath);
}
Also used : MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) CandidateInfo(com.intellij.psi.infos.CandidateInfo) MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo)

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