本文整理汇总了Java中com.intellij.psi.infos.MethodCandidateInfo.getElement方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCandidateInfo.getElement方法的具体用法?Java MethodCandidateInfo.getElement怎么用?Java MethodCandidateInfo.getElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.infos.MethodCandidateInfo
的用法示例。
在下文中一共展示了MethodCandidateInfo.getElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
}
示例2: 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;
}
示例3: 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;
}
示例4: registerSwapFixes
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
private static void registerSwapFixes(final PsiExpression[] expressions, final PsiCall callExpression, final List<PsiCall> permutations,
MethodCandidateInfo candidate, final int incompatibilitiesCount, final int minIncompatibleIndex,
final int maxIncompatibleIndex) throws IncorrectOperationException {
PsiMethod method = candidate.getElement();
PsiSubstitutor substitutor = candidate.getSubstitutor();
if (incompatibilitiesCount >= 3) return; // no way we can fix it by swapping
for (int i = minIncompatibleIndex; i < maxIncompatibleIndex; i++) {
for (int j = i+1; j <= maxIncompatibleIndex; j++) {
ArrayUtil.swap(expressions, i, j);
if (PsiUtil.isApplicable(method, substitutor, expressions)) {
PsiCall copy = (PsiCall)callExpression.copy();
PsiExpression[] copyExpressions = copy.getArgumentList().getExpressions();
copyExpressions[i].replace(expressions[i]);
copyExpressions[j].replace(expressions[j]);
JavaResolveResult result = copy.resolveMethodGenerics();
if (result.getElement() != null && result.isValidResult()) {
permutations.add(copy);
if (permutations.size() > 1) return;
}
}
ArrayUtil.swap(expressions, i, j);
}
}
}
示例5: 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);
if(methodCallTypeByArgs != null)
{
QuickFixAction.registerQuickFixAction(highlightInfo, getFixRange(methodCall), QUICK_FIX_FACTORY.createMethodReturnFix(containerMethod, methodCallTypeByArgs, true));
}
}
}
}
示例6: 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;
}
示例7: 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;
}
示例8: buildOneLineMismatchDescription
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
private static String buildOneLineMismatchDescription(@NotNull PsiExpressionList list,
@NotNull MethodCandidateInfo candidateInfo,
@NotNull Ref<PsiElement> elementToHighlight) {
final PsiExpression[] expressions = list.getExpressions();
final PsiMethod resolvedMethod = candidateInfo.getElement();
final PsiSubstitutor substitutor = candidateInfo.getSubstitutor();
final PsiParameter[] parameters = resolvedMethod.getParameterList().getParameters();
if (expressions.length == parameters.length && parameters.length > 1) {
int idx = -1;
for (int i = 0; i < expressions.length; i++) {
PsiExpression expression = expressions[i];
if (!TypeConversionUtil.areTypesAssignmentCompatible(substitutor.substitute(parameters[i].getType()), expression)) {
if (idx != -1) {
idx = -1;
break;
}
else {
idx = i;
}
}
}
if (idx > -1) {
final PsiExpression wrongArg = expressions[idx];
final PsiType argType = wrongArg.getType();
if (argType != null) {
elementToHighlight.set(wrongArg);
final String message = JavaErrorMessages
.message("incompatible.call.types", idx + 1, substitutor.substitute(parameters[idx].getType()).getCanonicalText(), argType.getCanonicalText());
return XmlStringUtil.wrapInHtml("<body>" + XmlStringUtil.escapeString(message) +
" <a href=\"#assignment/" + XmlStringUtil.escapeString(createMismatchedArgumentsHtmlTooltip(candidateInfo, list)) + "\"" +
(UIUtil.isUnderDarcula() ? " color=\"7AB4C9\" " : "") +
">" + DaemonBundle.message("inspection.extended.description") + "</a></body>");
}
}
}
return null;
}
示例9: createMismatchedArgumentsHtmlTooltip
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
private static String createMismatchedArgumentsHtmlTooltip(MethodCandidateInfo info, PsiExpressionList list) {
PsiMethod method = info.getElement();
PsiSubstitutor substitutor = info.getSubstitutor();
PsiClass aClass = method.getContainingClass();
PsiParameter[] parameters = method.getParameterList().getParameters();
String methodName = method.getName();
return createMismatchedArgumentsHtmlTooltip(list, parameters, methodName, substitutor, aClass);
}
示例10: registerFix
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
public static void registerFix(HighlightInfo info, PsiCall callExpression, final CandidateInfo[] candidates, final TextRange fixRange) {
PsiExpression[] expressions = callExpression.getArgumentList().getExpressions();
if (expressions.length < 2) return;
List<PsiCall> permutations = new ArrayList<PsiCall>();
for (CandidateInfo candidate : candidates) {
if (candidate instanceof MethodCandidateInfo) {
MethodCandidateInfo methodCandidate = (MethodCandidateInfo)candidate;
PsiMethod method = methodCandidate.getElement();
PsiSubstitutor substitutor = methodCandidate.getSubstitutor();
PsiParameter[] parameters = method.getParameterList().getParameters();
if (expressions.length != parameters.length || parameters.length ==0) continue;
int minIncompatibleIndex = parameters.length;
int maxIncompatibleIndex = 0;
int incompatibilitiesCount = 0;
for (int i = 0; i < parameters.length; i++) {
PsiParameter parameter = parameters[i];
PsiType type = substitutor.substitute(parameter.getType());
if (TypeConversionUtil.areTypesAssignmentCompatible(type, expressions[i])) continue;
if (minIncompatibleIndex == parameters.length) minIncompatibleIndex = i;
maxIncompatibleIndex = i;
incompatibilitiesCount++;
}
try {
registerSwapFixes(expressions, callExpression, permutations, methodCandidate, incompatibilitiesCount, minIncompatibleIndex, maxIncompatibleIndex);
registerShiftFixes(expressions, callExpression, permutations, methodCandidate, minIncompatibleIndex, maxIncompatibleIndex);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
if (permutations.size() == 1) {
PermuteArgumentsFix fix = new PermuteArgumentsFix(callExpression, permutations.get(0));
QuickFixAction.registerQuickFixAction(info, fixRange, fix);
}
}
示例11: createMismatchedArgumentsHtmlTooltip
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
private static String createMismatchedArgumentsHtmlTooltip(MethodCandidateInfo info, PsiExpressionList list)
{
PsiMethod method = info.getElement();
PsiSubstitutor substitutor = info.getSubstitutor();
PsiClass aClass = method.getContainingClass();
PsiParameter[] parameters = method.getParameterList().getParameters();
String methodName = method.getName();
return createMismatchedArgumentsHtmlTooltip(list, info, parameters, methodName, substitutor, aClass);
}
示例12: resolveInferredTypesNoCheck
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
public static DiamondInferenceResult resolveInferredTypesNoCheck(final PsiNewExpression newExpression, final PsiElement context) {
final Ref<MethodCandidateInfo> staticFactoryRef = new Ref<MethodCandidateInfo>();
final PsiSubstitutor inferredSubstitutor = ourDiamondGuard.doPreventingRecursion(context, false, new Computable<PsiSubstitutor>() {
@Override
public PsiSubstitutor compute() {
final MethodCandidateInfo staticFactoryCandidateInfo = context == newExpression ?
CachedValuesManager.getCachedValue(context,
new CachedValueProvider<MethodCandidateInfo>() {
@Nullable
@Override
public Result<MethodCandidateInfo> compute() {
return new Result<MethodCandidateInfo>(getStaticFactoryCandidateInfo(newExpression, newExpression),
PsiModificationTracker.MODIFICATION_COUNT);
}
})
: getStaticFactoryCandidateInfo(newExpression, context);
staticFactoryRef.set(staticFactoryCandidateInfo);
return staticFactoryCandidateInfo != null ? staticFactoryCandidateInfo.getSubstitutor() : null;
}
});
if (inferredSubstitutor == null) {
return DiamondInferenceResult.NULL_RESULT;
}
final MethodCandidateInfo staticFactoryInfo = staticFactoryRef.get();
if (staticFactoryInfo == null) {
LOG.error(inferredSubstitutor);
return DiamondInferenceResult.NULL_RESULT;
}
final PsiMethod staticFactory = staticFactoryInfo.getElement();
final PsiTypeParameter[] parameters = staticFactory.getTypeParameters();
final PsiElement staticFactoryContext = staticFactory.getContext();
final PsiClass psiClass = PsiTreeUtil.getContextOfType(staticFactoryContext, PsiClass.class, false);
if (psiClass == null) {
LOG.error("failed for expression:" + newExpression);
return DiamondInferenceResult.NULL_RESULT;
}
final PsiTypeParameter[] classParameters = psiClass.getTypeParameters();
final PsiJavaCodeReferenceElement classOrAnonymousClassReference = newExpression.getClassOrAnonymousClassReference();
LOG.assertTrue(classOrAnonymousClassReference != null);
final DiamondInferenceResult result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>");
if (PsiUtil.isRawSubstitutor(staticFactory, inferredSubstitutor)) {
if (!JavaVersionService.getInstance().isAtLeast(newExpression, JavaSdkVersion.JDK_1_8) &&
PsiUtil.skipParenthesizedExprUp(newExpression.getParent()) instanceof PsiExpressionList) {
for (PsiTypeParameter ignored : parameters) {
result.addInferredType(PsiType.getJavaLangObject(newExpression.getManager(), GlobalSearchScope.allScope(newExpression.getProject())));
}
}
return result;
}
for (PsiTypeParameter parameter : parameters) {
for (PsiTypeParameter classParameter : classParameters) {
if (Comparing.strEqual(classParameter.getName(), parameter.getName())) {
result.addInferredType(inferredSubstitutor.substitute(parameter));
break;
}
}
}
return result;
}
示例13: getContainingClassName
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
private static String getContainingClassName(final MethodCandidateInfo methodCandidate) {
PsiMethod method = methodCandidate.getElement();
PsiClass containingClass = method.getContainingClass();
return containingClass == null ? method.getContainingFile().getName() : HighlightUtil.formatClass(containingClass, false);
}
示例14: checkParametersNumber
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
public boolean checkParametersNumber(@NotNull List<CandidateInfo> conflicts, final int argumentsCount, FactoryMap<MethodCandidateInfo, PsiSubstitutor> map, boolean ignoreIfStaticsProblem)
{
boolean atLeastOneMatch = false;
TIntArrayList unmatchedIndices = null;
for(int i = 0; i < conflicts.size(); i++)
{
ProgressManager.checkCanceled();
CandidateInfo info = conflicts.get(i);
if(ignoreIfStaticsProblem && !info.isStaticsScopeCorrect())
{
return true;
}
if(!(info instanceof MethodCandidateInfo))
{
continue;
}
PsiMethod method = ((MethodCandidateInfo) info).getElement();
final int parametersCount = method.getParameterList().getParametersCount();
boolean isVarargs = (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) ? ((MethodCandidateInfo) info).isVarargs() : method.isVarArgs()) && parametersCount - 1 <= argumentsCount;
if(isVarargs || parametersCount == argumentsCount)
{
// remove all unmatched before
if(unmatchedIndices != null)
{
for(int u = unmatchedIndices.size() - 1; u >= 0; u--)
{
int index = unmatchedIndices.get(u);
//ensure super method with varargs won't win over non-vararg override
if(ignoreIfStaticsProblem && isVarargs)
{
MethodCandidateInfo candidateInfo = (MethodCandidateInfo) conflicts.get(index);
PsiMethod candidateToRemove = candidateInfo.getElement();
if(candidateToRemove != method)
{
PsiSubstitutor candidateToRemoveSubst = map.get(candidateInfo);
PsiSubstitutor substitutor = map.get(info);
if(MethodSignatureUtil.isSubsignature(candidateToRemove.getSignature(candidateToRemoveSubst), method.getSignature(substitutor)))
{
continue;
}
}
}
conflicts.remove(index);
i--;
}
unmatchedIndices = null;
}
atLeastOneMatch = true;
}
else if(atLeastOneMatch)
{
conflicts.remove(i);
i--;
}
else
{
if(unmatchedIndices == null)
{
unmatchedIndices = new TIntArrayList(conflicts.size() - i);
}
unmatchedIndices.add(i);
}
}
return atLeastOneMatch;
}
示例15: buildOneLineMismatchDescription
import com.intellij.psi.infos.MethodCandidateInfo; //导入方法依赖的package包/类
private static String buildOneLineMismatchDescription(@NotNull PsiExpressionList list, @NotNull MethodCandidateInfo candidateInfo, @NotNull Ref<PsiElement> elementToHighlight)
{
final PsiExpression[] expressions = list.getExpressions();
final PsiMethod resolvedMethod = candidateInfo.getElement();
final PsiSubstitutor substitutor = candidateInfo.getSubstitutor();
final PsiParameter[] parameters = resolvedMethod.getParameterList().getParameters();
if(expressions.length == parameters.length && parameters.length > 1)
{
int idx = -1;
for(int i = 0; i < expressions.length; i++)
{
PsiExpression expression = expressions[i];
if(expression instanceof PsiMethodCallExpression)
{
final JavaResolveResult result = ((PsiCallExpression) expression).resolveMethodGenerics();
if(result instanceof MethodCandidateInfo && PsiUtil.isLanguageLevel8OrHigher(list) && ((MethodCandidateInfo) result).isToInferApplicability() && ((MethodCandidateInfo) result)
.getInferenceErrorMessage() == null)
{
continue;
}
}
if(!TypeConversionUtil.areTypesAssignmentCompatible(substitutor.substitute(parameters[i].getType()), expression))
{
if(idx != -1)
{
idx = -1;
break;
}
else
{
idx = i;
}
}
}
if(idx > -1)
{
final PsiExpression wrongArg = expressions[idx];
final PsiType argType = wrongArg.getType();
if(argType != null)
{
elementToHighlight.set(wrongArg);
final String message = JavaErrorMessages.message("incompatible.call.types", idx + 1, substitutor.substitute(parameters[idx].getType()).getCanonicalText(), argType
.getCanonicalText());
return XmlStringUtil.wrapInHtml("<body>" + XmlStringUtil.escapeString(message) + " <a href=\"#assignment/" + XmlStringUtil.escapeString(createMismatchedArgumentsHtmlTooltip
(candidateInfo, list)) + "\"" + (UIUtil.isUnderDarcula() ? " color=\"7AB4C9\" " : "") + ">" + DaemonBundle.message("inspection.extended.description") + "</a></body>");
}
}
}
return null;
}