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;
}
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);
}
}
}
}
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();
}
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);
}
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);
}
Aggregations