use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class Java8ExpressionsCheckTest method testCachingOfResultsDuringCandidatesIteration.
public void testCachingOfResultsDuringCandidatesIteration() throws Exception {
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
final Collection<PsiMethodCallExpression> methodCallExpressions = PsiTreeUtil.findChildrenOfType(getFile(), PsiMethodCallExpression.class);
final PsiResolveHelper helper = JavaPsiFacade.getInstance(getProject()).getResolveHelper();
for (PsiMethodCallExpression expression : methodCallExpressions) {
CandidateInfo[] candidates = helper.getReferencedMethodCandidates(expression, false, true);
PsiExpressionList argumentList = expression.getArgumentList();
PsiExpression[] args = argumentList.getExpressions();
for (JavaResolveResult result : candidates) {
if (result instanceof MethodCandidateInfo) {
final MethodCandidateInfo info = (MethodCandidateInfo) result;
MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(argumentList, false, () -> info.inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE, args, true));
}
}
PsiMethodCallExpression parentCall = PsiTreeUtil.getParentOfType(expression, PsiMethodCallExpression.class, true);
if (parentCall != null) {
JavaResolveResult result = parentCall.getMethodExpression().advancedResolve(false);
if (result instanceof MethodCandidateInfo) {
assertNull(((MethodCandidateInfo) result).getInferenceErrorMessage());
}
}
}
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class ChangeStringLiteralToCharInMethodCallFix method registerFixes.
public static void registerFixes(@NotNull final CandidateInfo[] candidates, @NotNull final PsiMethodCallExpression methodCall, @Nullable final HighlightInfo info) {
if (info == null)
return;
final Set<PsiLiteralExpression> literals = new HashSet<>();
boolean exactMatch = false;
for (CandidateInfo candidate : candidates) {
if (candidate instanceof MethodCandidateInfo) {
final PsiMethod method = ((MethodCandidateInfo) candidate).getElement();
exactMatch |= findMatchingExpressions(methodCall.getArgumentList().getExpressions(), method, literals);
}
}
if (!exactMatch) {
processLiterals(literals, methodCall, info);
}
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class JavaOverrideImplementMemberChooser method create.
@Nullable
public static JavaOverrideImplementMemberChooser create(final PsiElement aClass, final boolean toImplement, final Collection<CandidateInfo> candidates, final Collection<CandidateInfo> secondary) {
final Project project = aClass.getProject();
if (candidates.isEmpty() && secondary.isEmpty())
return null;
final PsiMethodMember[] onlyPrimary = convertToMethodMembers(candidates);
final LinkedHashSet<CandidateInfo> allCandidates = new LinkedHashSet<>(candidates);
allCandidates.addAll(secondary);
final PsiMethodMember[] all = convertToMethodMembers(allCandidates);
final NotNullLazyValue<PsiMethodWithOverridingPercentMember[]> lazyElementsWithPercent = new NotNullLazyValue<PsiMethodWithOverridingPercentMember[]>() {
@NotNull
@Override
protected PsiMethodWithOverridingPercentMember[] compute() {
final PsiMethodWithOverridingPercentMember[] elements = PsiMethodWithOverridingPercentMember.calculateOverridingPercents(candidates);
Arrays.sort(elements, PsiMethodWithOverridingPercentMember.COMPARATOR);
return elements;
}
};
final boolean merge = PropertiesComponent.getInstance(project).getBoolean(PROP_COMBINED_OVERRIDE_IMPLEMENT, true);
final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(aClass);
//hide option if implement interface for 1.5 language level
final boolean overrideVisible = languageLevel.isAtLeast(LanguageLevel.JDK_1_6) || languageLevel.equals(LanguageLevel.JDK_1_5) && !toImplement;
final JavaOverrideImplementMemberChooser javaOverrideImplementMemberChooser = new JavaOverrideImplementMemberChooser(all, onlyPrimary, lazyElementsWithPercent, project, overrideVisible, merge, toImplement, PropertiesComponent.getInstance(project).getBoolean(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT));
javaOverrideImplementMemberChooser.setTitle(getChooserTitle(toImplement, merge));
javaOverrideImplementMemberChooser.setCopyJavadocVisible(true);
if (toImplement) {
if (onlyPrimary.length == 0) {
javaOverrideImplementMemberChooser.selectElements(new ClassMember[] { all[0] });
} else {
javaOverrideImplementMemberChooser.selectElements(onlyPrimary);
}
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (!toImplement || onlyPrimary.length == 0) {
javaOverrideImplementMemberChooser.selectElements(all);
}
javaOverrideImplementMemberChooser.close(DialogWrapper.OK_EXIT_CODE);
return javaOverrideImplementMemberChooser;
}
return javaOverrideImplementMemberChooser;
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class OverrideImplementUtil method overrideOrImplementMethods.
@NotNull
public static List<PsiGenerationInfo<PsiMethod>> overrideOrImplementMethods(PsiClass aClass, Collection<PsiMethodMember> candidates, boolean toCopyJavaDoc, boolean toInsertAtOverride) throws IncorrectOperationException {
List<CandidateInfo> candidateInfos = ContainerUtil.map2List(candidates, s -> new CandidateInfo(s.getElement(), s.getSubstitutor()));
final List<PsiMethod> methods = overrideOrImplementMethodCandidates(aClass, candidateInfos, toCopyJavaDoc, toInsertAtOverride);
return convert2GenerationInfos(methods);
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class OverrideImplementUtil method showOverrideImplementChooser.
/**
* @param candidates, secondary should allow modifications
*/
@Nullable
public static MemberChooser<PsiMethodMember> showOverrideImplementChooser(Editor editor, final PsiElement aClass, final boolean toImplement, final Collection<CandidateInfo> candidates, Collection<CandidateInfo> secondary) {
if (toImplement) {
for (Iterator<CandidateInfo> iterator = candidates.iterator(); iterator.hasNext(); ) {
CandidateInfo candidate = iterator.next();
PsiElement element = candidate.getElement();
if (element instanceof PsiMethod && ((PsiMethod) element).hasModifierProperty(PsiModifier.DEFAULT)) {
iterator.remove();
secondary.add(candidate);
}
}
}
final JavaOverrideImplementMemberChooser chooser = JavaOverrideImplementMemberChooser.create(aClass, toImplement, candidates, secondary);
if (chooser == null) {
return null;
}
Project project = aClass.getProject();
registerHandlerForComplementaryAction(project, editor, aClass, toImplement, chooser);
if (ApplicationManager.getApplication().isUnitTestMode()) {
return chooser;
}
chooser.show();
if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE)
return null;
return chooser;
}
Aggregations