本文整理汇总了Java中com.intellij.psi.infos.MethodCandidateInfo类的典型用法代码示例。如果您正苦于以下问题:Java MethodCandidateInfo类的具体用法?Java MethodCandidateInfo怎么用?Java MethodCandidateInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodCandidateInfo类属于com.intellij.psi.infos包,在下文中一共展示了MethodCandidateInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSubstitutor
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
private static PsiSubstitutor getSubstitutor(final JavaResolveResult result, PsiCallExpression methodCall) {
final PsiLambdaExpression expression = PsiTreeUtil.getParentOfType(methodCall, PsiLambdaExpression.class);
final PsiSubstitutor substitutor;
if (expression != null) {
final PsiElement parent = methodCall.getParent();
final boolean callInReturnStatement = parent == expression ||
parent instanceof PsiReturnStatement && PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class, true, PsiMethod.class) == expression;
substitutor = callInReturnStatement ? ourThrowsGuard.doPreventingRecursion(expression, false, new Computable<PsiSubstitutor>() {
@Override
public PsiSubstitutor compute() {
return result.getSubstitutor();
}
}) : result.getSubstitutor();
} else {
substitutor = result.getSubstitutor();
}
return substitutor == null ? ((MethodCandidateInfo)result).getSiteSubstitutor() : substitutor;
}
示例2: createCandidateInfo
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
protected MethodCandidateInfo createCandidateInfo(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor,
final boolean staticProblem, final boolean accessible, final boolean varargs) {
final PsiExpressionList argumentList = getArgumentList();
return new MethodCandidateInfo(method, substitutor, !accessible, staticProblem, argumentList, myCurrentFileContext,
null, getTypeArguments(), getLanguageLevel()) {
private PsiType[] myExpressionTypes;
@Override
public PsiType[] getArgumentTypes() {
if (myExpressionTypes == null && argumentList != null) {
final PsiType[] expressionTypes = getExpressionTypes(argumentList);
if (MethodCandidateInfo.isOverloadCheck()) {
return expressionTypes;
}
myExpressionTypes = expressionTypes;
}
return myExpressionTypes;
}
@Override
public boolean isVarargs() {
return varargs;
}
};
}
示例3: resolveConflict
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
@Override
public CandidateInfo resolveConflict(@NotNull List<CandidateInfo> conflicts){
if (conflicts.size() == 1) return conflicts.get(0);
final Map<Object, CandidateInfo> uniqueItems = new HashMap<Object, CandidateInfo>();
for (CandidateInfo info : conflicts) {
final PsiElement element = info.getElement();
Object key;
if (info instanceof MethodCandidateInfo) {
key = ((PsiMethod)element).getSignature(((MethodCandidateInfo)info).getSubstitutor(false));
}
else {
key = PsiUtilCore.getName(element);
}
if (!uniqueItems.containsKey(key)) {
uniqueItems.put(key, info);
}
}
if(uniqueItems.size() == 1) return uniqueItems.values().iterator().next();
return null;
}
示例4: resolveConflict
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
@Override
public final CandidateInfo resolveConflict(@NotNull final List<CandidateInfo> conflicts){
/*
//non-default policies
final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(myArgumentsList);
if (properties != null) {
final PsiMethod method = properties.getMethod();
LOG.error("Recursive conflict resolution for:" + method + "; " + myArgumentsList.getText() + "; file="
+ (method == null ? "<unknown>" : method.getContainingFile()));
}*/
return MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(myArgumentsList, true, new Computable<CandidateInfo>() {
@Override
public CandidateInfo compute() {
return guardedOverloadResolution(conflicts);
}
});
}
示例5: checkAccessStaticLevels
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
protected static void checkAccessStaticLevels(@NotNull List<CandidateInfo> conflicts, boolean checkAccessible) {
int conflictsCount = conflicts.size();
int maxCheckLevel = -1;
int[] checkLevels = new int[conflictsCount];
int index = 0;
for (final CandidateInfo conflict : conflicts) {
ProgressManager.checkCanceled();
final MethodCandidateInfo method = (MethodCandidateInfo)conflict;
final int level = checkAccessible ? getCheckAccessLevel(method) : getCheckStaticLevel(method);
checkLevels[index++] = level;
maxCheckLevel = Math.max(maxCheckLevel, level);
}
for (int i = conflictsCount - 1; i >= 0; i--) {
// check for level
if (checkLevels[i] < maxCheckLevel) {
conflicts.remove(i);
}
}
}
示例6: checkStaticMethodsOfInterfaces
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
/**
* choose to accept static interface methods during search to get "Static interface methods must be invoked on containing interface class only" error
* instead of non clear javac message that symbol not found
*
* but these methods should be ignored during overload resolution if another methods are present
*/
private void checkStaticMethodsOfInterfaces(@NotNull List<CandidateInfo> conflicts) {
if (!(myArgumentsList instanceof PsiExpressionList)) return;
PsiClass qualifierClass = null;
for (Iterator<CandidateInfo> iterator = conflicts.iterator(); iterator.hasNext(); ) {
CandidateInfo conflict = iterator.next();
if (!(conflict instanceof MethodCandidateInfo)) continue;
final PsiMethod method = ((MethodCandidateInfo)conflict).getElement();
if (method.hasModifierProperty(PsiModifier.STATIC)) {
if (conflict.getCurrentFileResolveScope() instanceof PsiImportStaticStatement) continue;
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null && containingClass.isInterface()) {
if (qualifierClass == null) {
qualifierClass = getQualifiedClass(method);
if (qualifierClass == null) return;
}
if (!containingClass.getManager().areElementsEquivalent(containingClass, qualifierClass)) {
iterator.remove();
}
}
}
}
}
示例7: isApplicableTo
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
private boolean isApplicableTo(@NotNull PsiType[] types2AtSite,
@NotNull PsiMethod method1,
@NotNull LanguageLevel languageLevel,
boolean varargsPosition,
@NotNull PsiSubstitutor methodSubstitutor1,
@NotNull PsiMethod method2,
PsiSubstitutor siteSubstitutor1) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && method1.getTypeParameters().length > 0 && myArgumentsList instanceof PsiExpressionList) {
final PsiElement parent = myArgumentsList.getParent();
if (parent instanceof PsiCallExpression) {
return InferenceSession.isMoreSpecific(method2, method1, siteSubstitutor1, ((PsiExpressionList)myArgumentsList).getExpressions(), myArgumentsList, varargsPosition);
}
}
final PsiUtil.ApplicabilityChecker applicabilityChecker = languageLevel.isAtLeast(LanguageLevel.JDK_1_8)
? new PsiUtil.ApplicabilityChecker() {
@Override
public boolean isApplicable(PsiType left, PsiType right,
boolean allowUncheckedConversion, int argId) {
return isTypeMoreSpecific(left, right, argId);
}
}
: PsiUtil.ApplicabilityChecker.ASSIGNABILITY_CHECKER;
final int applicabilityLevel = PsiUtil.getApplicabilityLevel(method1, methodSubstitutor1, types2AtSite, languageLevel, false, varargsPosition, applicabilityChecker);
return applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
}
示例8: initExpressionConstraints
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
public void initExpressionConstraints(PsiParameter[] parameters,
PsiExpression[] args,
PsiElement parent,
PsiMethod method,
boolean varargs) {
final MethodCandidateInfo.CurrentCandidateProperties currentProperties = getCurrentProperties(parent);
if (method == null) {
if (currentProperties != null) {
method = currentProperties.getMethod();
}
}
if (method != null) {
initThrowsConstraints(method);
}
if (parameters.length > 0) {
for (int i = 0; i < args.length; i++) {
if (args[i] != null && isPertinentToApplicability(args[i], method)) {
PsiType parameterType = getParameterType(parameters, i, mySiteSubstitutor, varargs);
addConstraint(new ExpressionCompatibilityConstraint(args[i], substituteWithInferenceVariables(parameterType)));
}
}
}
}
示例9: getCalledMethod
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
private static PsiMethod getCalledMethod(PsiCall arg) {
final PsiExpressionList argumentList = arg.getArgumentList();
if (argumentList == null) {
return null;
}
MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
if (properties != null) {
return properties.getMethod();
}
final JavaResolveResult resolveResult = getMethodResult(arg);
if (resolveResult instanceof MethodCandidateInfo) {
return (PsiMethod)resolveResult.getElement();
}
else {
return null;
}
}
示例10: collectAdditionalConstraints
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
private void collectAdditionalConstraints(final Set<ConstraintFormula> additionalConstraints,
final PsiCall callExpression) {
PsiExpressionList argumentList = callExpression.getArgumentList();
if (argumentList != null) {
final JavaResolveResult result = getMethodResult(callExpression);
MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
final PsiMethod method = result instanceof MethodCandidateInfo ? ((MethodCandidateInfo)result).getElement() : properties != null ? properties.getMethod() : null;
if (method != null) {
final PsiExpression[] newArgs = argumentList.getExpressions();
final PsiParameter[] newParams = method.getParameterList().getParameters();
if (newParams.length > 0) {
collectAdditionalConstraints(newParams, newArgs, method, chooseSiteSubstitutor(properties, result, method), additionalConstraints, chooseVarargsMode(properties, result));
}
}
}
}
示例11: getMethodResult
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
private static JavaResolveResult getMethodResult(final PsiCall callExpression) {
final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiLambdaExpression expression = PsiTreeUtil.getParentOfType(argumentList, PsiLambdaExpression.class);
final Computable<JavaResolveResult> computableResolve = new Computable<JavaResolveResult>() {
@Override
public JavaResolveResult compute() {
return getResolveResult(callExpression, argumentList);
}
};
MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
return properties != null ? null :
expression == null || !PsiResolveHelper.ourGraphGuard.currentStack().contains(expression)
? computableResolve.compute()
: PsiResolveHelper.ourGraphGuard.doPreventingRecursion(expression, false, computableResolve);
}
示例12: TypeParamsChecker
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
public TypeParamsChecker(PsiElement expression, PsiClass aClass) {
myClass = aClass;
PsiElement parent = expression != null ? expression.getParent() : null;
while (parent instanceof PsiParenthesizedExpression) {
parent = parent.getParent();
}
if (parent instanceof PsiExpressionList) {
final PsiElement gParent = parent.getParent();
if (gParent instanceof PsiCall) {
final MethodCandidateInfo.CurrentCandidateProperties pair = MethodCandidateInfo.getCurrentMethod(parent);
myMethod = pair != null ? pair.getMethod() : null;
if (myMethod == null) {
myMethod = ((PsiCall)gParent).resolveMethod();
}
if (myMethod != null && PsiTreeUtil.isAncestor(myMethod, expression, false)) {
myMethod = null;
}
}
}
}
示例13: registerMethodReturnFixAction
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
private static void registerMethodReturnFixAction(HighlightInfo highlightInfo,
MethodCandidateInfo candidate,
PsiCall methodCall) {
if (methodCall.getParent() instanceof PsiReturnStatement) {
final PsiMethod containerMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class, true, PsiLambdaExpression.class);
if (containerMethod != null) {
final PsiMethod method = candidate.getElement();
final PsiExpression methodCallCopy =
JavaPsiFacade.getElementFactory(method.getProject()).createExpressionFromText(methodCall.getText(), methodCall);
PsiType methodCallTypeByArgs = methodCallCopy.getType();
//ensure type params are not included
methodCallTypeByArgs = JavaPsiFacade.getElementFactory(method.getProject())
.createRawSubstitutor(method).substitute(methodCallTypeByArgs);
QuickFixAction.registerQuickFixAction(highlightInfo,
getFixRange(methodCall),
QUICK_FIX_FACTORY.createMethodReturnFix(containerMethod, methodCallTypeByArgs, true));
}
}
}
示例14: createAmbiguousMethodHtmlTooltipMethodRow
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
@Language("HTML")
private static String createAmbiguousMethodHtmlTooltipMethodRow(final MethodCandidateInfo methodCandidate) {
PsiMethod method = methodCandidate.getElement();
PsiParameter[] parameters = method.getParameterList().getParameters();
PsiSubstitutor substitutor = methodCandidate.getSubstitutor();
@NonNls @Language("HTML") String ms = "<td><b>" + method.getName() + "</b></td>";
for (int j = 0; j < parameters.length; j++) {
PsiParameter parameter = parameters[j];
PsiType type = substitutor.substitute(parameter.getType());
ms += "<td><b>" + (j == 0 ? "(" : "") +
XmlStringUtil.escapeString(type.getPresentableText())
+ (j == parameters.length - 1 ? ")" : ",") + "</b></td>";
}
if (parameters.length == 0) {
ms += "<td><b>()</b></td>";
}
return ms;
}
示例15: checkVarargParameterErasureToBeAccessible
import com.intellij.psi.infos.MethodCandidateInfo; //导入依赖的package包/类
/**
* If the compile-time declaration is applicable by variable arity invocation,
* then where the last formal parameter type of the invocation type of the method is Fn[],
* it is a compile-time error if the type which is the erasure of Fn is not accessible at the point of invocation.
*/
private static HighlightInfo checkVarargParameterErasureToBeAccessible(MethodCandidateInfo info, PsiCall place) {
final PsiMethod method = info.getElement();
if (info.isVarargs() || method.isVarArgs() && !PsiUtil.isLanguageLevel8OrHigher(place)) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
final PsiType componentType = ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
final PsiType substitutedTypeErasure = TypeConversionUtil.erasure(info.getSubstitutor().substitute(componentType));
final PsiClass targetClass = PsiUtil.resolveClassInClassTypeOnly(substitutedTypeErasure);
if (targetClass != null && !PsiUtil.isAccessible(targetClass, place, null)) {
final PsiExpressionList argumentList = place.getArgumentList();
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.descriptionAndTooltip("Formal varargs element type " +
PsiFormatUtil.formatClass(targetClass, PsiFormatUtilBase.SHOW_FQ_NAME) +
" is inaccessible here")
.range(argumentList != null ? argumentList : place)
.create();
}
}
return null;
}