Java 类com.intellij.psi.JavaResolveResult 实例源码

项目:lombok-intellij-plugin    文件:LombokInspection.java   
/**
 * Check MethodCallExpressions for calls for default (argument less) constructor
 * Produce an error if resolved constructor method is build by lombok and contains some arguments
 */
@Override
public void visitMethodCallExpression(PsiMethodCallExpression methodCall) {
  super.visitMethodCallExpression(methodCall);

  PsiExpressionList list = methodCall.getArgumentList();
  PsiReferenceExpression referenceToMethod = methodCall.getMethodExpression();

  boolean isThisOrSuper = referenceToMethod.getReferenceNameElement() instanceof PsiKeyword;
  final int parameterCount = list.getExpressions().length;
  if (isThisOrSuper && parameterCount == 0) {

    JavaResolveResult[] results = referenceToMethod.multiResolve(true);
    JavaResolveResult resolveResult = results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
    PsiElement resolved = resolveResult.getElement();

    if (resolved instanceof LombokLightMethodBuilder && ((LombokLightMethodBuilder) resolved).getParameterList().getParameters().length != 0) {
      holder.registerProblem(methodCall, "Default constructor doesn't exist", ProblemHighlightType.ERROR);
    }
  }
}
项目:consulo-java    文件:ConflictFilterProcessor.java   
@NotNull
public JavaResolveResult[] getResult()
{
    JavaResolveResult[] cachedResult = myCachedResult;
    if(cachedResult == null)
    {
        List<CandidateInfo> conflicts = getResults();
        if(!conflicts.isEmpty())
        {
            for(PsiConflictResolver resolver : myResolvers)
            {
                CandidateInfo candidate = resolver.resolveConflict(conflicts);
                if(candidate != null)
                {
                    conflicts.clear();
                    conflicts.add(candidate);
                    break;
                }
            }
        }
        myCachedResult = cachedResult = conflicts.toArray(new JavaResolveResult[conflicts.size()]);
    }

    return cachedResult;
}
项目:consulo-java    文件:PermuteArgumentsFix.java   
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);
    }
  }
}
项目:consulo-java    文件:JavaTypeDeclarationProvider.java   
@RequiredReadAction
@Nullable
@Override
public PsiElement[] getSymbolTypeDeclarations(@NotNull PsiElement targetElement, Editor editor, int offset) {
  PsiType type;
  if (targetElement instanceof PsiVariable){
    type = ((PsiVariable)targetElement).getType();
  }
  else if (targetElement instanceof PsiMethod){
    type = ((PsiMethod)targetElement).getReturnType();
  }
  else{
    return null;
  }
  if (type == null) return null;
  if (editor != null) {
    final PsiReference reference = TargetElementUtil.findReference(editor, offset);
    if (reference instanceof PsiJavaReference) {
      final JavaResolveResult resolveResult = ((PsiJavaReference)reference).advancedResolve(true);
      type = resolveResult.getSubstitutor().substitute(type);
    }
  }
  PsiClass psiClass = PsiUtil.resolveClassInType(type);
  return psiClass == null ? null : new PsiElement[] {psiClass};
}
项目:intellij-ce-playground    文件:ResolveVariableUtil.java   
public static PsiVariable resolveVariable(@NotNull PsiJavaCodeReferenceElement ref,
                                          boolean[] problemWithAccess,
                                          boolean[] problemWithStatic
) {

  /*
  long time1 = System.currentTimeMillis();
  */

  final VariableResolverProcessor processor = new VariableResolverProcessor(ref, ref.getContainingFile());
  PsiScopesUtil.resolveAndWalk(processor, ref, null);

  /*
  long time2 = System.currentTimeMillis();
  Statistics.resolveVariableTime += (time2 - time1);
  Statistics.resolveVariableCount++;
  */
  final JavaResolveResult[] result = processor.getResult();
  if (result.length != 1) return null;
  final PsiVariable refVar = (PsiVariable)result[0].getElement();

  if (problemWithAccess != null) {
    problemWithAccess[0] = !result[0].isAccessible();
  }
  if (problemWithStatic != null) {
    problemWithStatic[0] = !result[0].isStaticsScopeCorrect();
  }


  return refVar;
}
项目:intellij-ce-playground    文件:ResolveVariable15Test.java   
public void testDuplicateStaticImport() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:intellij-ce-playground    文件:ResolveVariable15Test.java   
public void testRhombExtending() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:tools-idea    文件:ResolveVariableUtil.java   
public static PsiVariable resolveVariable(@NotNull PsiJavaCodeReferenceElement ref,
                                          boolean[] problemWithAccess,
                                          boolean[] problemWithStatic
) {

  /*
  long time1 = System.currentTimeMillis();
  */

  final VariableResolverProcessor processor = new VariableResolverProcessor(ref, ref.getContainingFile());
  PsiScopesUtil.resolveAndWalk(processor, ref, null);

  /*
  long time2 = System.currentTimeMillis();
  Statistics.resolveVariableTime += (time2 - time1);
  Statistics.resolveVariableCount++;
  */
  final JavaResolveResult[] result = processor.getResult();
  if (result.length != 1) return null;
  final PsiVariable refVar = (PsiVariable)result[0].getElement();

  if (problemWithAccess != null) {
    problemWithAccess[0] = !result[0].isAccessible();
  }
  if (problemWithStatic != null) {
    problemWithStatic[0] = !result[0].isStaticsScopeCorrect();
  }


  return refVar;
}
项目:tools-idea    文件:ResolveVariable15Test.java   
public void testDuplicateStaticImport() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:tools-idea    文件:ResolveVariable15Test.java   
public void testRhombExtending() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:consulo-java    文件:ConflictFilterProcessor.java   
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state)
{
    JavaResolveResult[] cachedResult = myCachedResult;
    if(cachedResult != null && cachedResult.length == 1 && cachedResult[0].isAccessible())
    {
        return false;
    }
    if(myName == null || PsiUtil.checkName(element, myName, myPlace))
    {
        return super.execute(element, state);
    }
    return true;
}
项目:consulo-java    文件:ResolveVariableUtil.java   
public static PsiVariable resolveVariable(@NotNull PsiJavaCodeReferenceElement ref, boolean[] problemWithAccess, boolean[] problemWithStatic)
{

   /*
long time1 = System.currentTimeMillis();
   */

    final VariableResolverProcessor processor = new VariableResolverProcessor(ref, ref.getContainingFile());
    PsiScopesUtil.resolveAndWalk(processor, ref, null);

   /*
   long time2 = System.currentTimeMillis();
   Statistics.resolveVariableTime += (time2 - time1);
   Statistics.resolveVariableCount++;
   */
    final JavaResolveResult[] result = processor.getResult();
    if(result.length != 1)
    {
        return null;
    }
    final PsiVariable refVar = (PsiVariable) result[0].getElement();

    if(problemWithAccess != null)
    {
        problemWithAccess[0] = !result[0].isAccessible();
    }
    if(problemWithStatic != null)
    {
        problemWithStatic[0] = !result[0].isStaticsScopeCorrect();
    }


    return refVar;
}
项目:consulo-java    文件:PsiReferenceExpressionBase.java   
@NotNull
@Override
public JavaResolveResult advancedResolve(boolean incompleteCode)
{
    final JavaResolveResult[] results = multiResolve(incompleteCode);
    return results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
}
项目:consulo-java    文件:DelegationContract.java   
@NotNull
@Override
public List<StandardMethodContract> toContracts(PsiMethod method, Supplier<PsiCodeBlock> body)
{
    PsiMethodCallExpression call = ObjectUtil.tryCast(expression.restoreExpression(body.get()), PsiMethodCallExpression.class);
    if(call == null)
    {
        return Collections.emptyList();
    }

    JavaResolveResult result = call.resolveMethodGenerics();
    PsiMethod targetMethod = ObjectUtil.tryCast(result.getElement(), PsiMethod.class);
    if(targetMethod == null)
    {
        return Collections.emptyList();
    }
    PsiParameter[] parameters = targetMethod.getParameterList().getParameters();
    PsiExpression[] arguments = call.getArgumentList().getExpressions();
    boolean varArgCall = MethodCallInstruction.isVarArgCall(targetMethod, result.getSubstitutor(), arguments, parameters);


    List<StandardMethodContract> fromDelegate = ContainerUtil.mapNotNull(ControlFlowAnalyzer.getMethodContracts(targetMethod), dc -> convertDelegatedMethodContract(method, parameters, arguments,
            varArgCall, dc));

    if(NullableNotNullManager.isNotNull(targetMethod))
    {
        return ContainerUtil.concat(ContainerUtil.map(fromDelegate, DelegationContract::returnNotNull), Collections.singletonList(new StandardMethodContract(emptyConstraints(method),
                MethodContract.ValueConstraint.NOT_NULL_VALUE)));
    }
    return fromDelegate;
}
项目:consulo-java    文件:RemoveRedundantArgumentsFix.java   
public static void registerIntentions(@NotNull JavaResolveResult[] candidates,
                                      @NotNull PsiExpressionList arguments,
                                      @Nullable HighlightInfo highlightInfo,
                                      TextRange fixRange) {
  for (JavaResolveResult candidate : candidates) {
    registerIntention(arguments, highlightInfo, fixRange, candidate, arguments);
  }
}
项目:consulo-java    文件:RemoveRedundantArgumentsFix.java   
private static void registerIntention(@NotNull PsiExpressionList arguments,
                                      @Nullable HighlightInfo highlightInfo,
                                      TextRange fixRange,
                                      @NotNull JavaResolveResult candidate,
                                      @NotNull PsiElement context) {
  if (!candidate.isStaticsScopeCorrect()) return;
  PsiMethod method = (PsiMethod)candidate.getElement();
  PsiSubstitutor substitutor = candidate.getSubstitutor();
  if (method != null && context.getManager().isInProject(method)) {
    QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, new RemoveRedundantArgumentsFix(method, arguments.getExpressions(), substitutor));
  }
}
项目:consulo-java    文件:JavaMethodResolveHelper.java   
public Collection<JavaMethodCandidateInfo> getMethods()
{
    return ContainerUtil.mapNotNull(getCandidates(), new Function<JavaResolveResult, JavaMethodCandidateInfo>()
    {
        @Override
        public JavaMethodCandidateInfo fun(final JavaResolveResult javaResolveResult)
        {
            return new JavaMethodCandidateInfo((PsiMethod) javaResolveResult.getElement(), javaResolveResult.getSubstitutor());
        }
    });
}
项目:consulo-java    文件:ResolveVariable15Test.java   
public void testDuplicateStaticImport() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:consulo-java    文件:ResolveVariable15Test.java   
public void testRhombExtending() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:intellij-ce-playground    文件:AccessStaticViaInstance.java   
@Override
protected AccessStaticViaInstanceFix createAccessStaticViaInstanceFix(PsiReferenceExpression expr,
                                                                      boolean onTheFly,
                                                                      JavaResolveResult result) {
  return new AccessStaticViaInstanceFix(expr, result, onTheFly);
}
项目:tools-idea    文件:AccessStaticViaInstance.java   
@Override
protected AccessStaticViaInstanceFix createAccessStaticViaInstanceFix(PsiReferenceExpression expr,
                                                                      boolean onTheFly,
                                                                      JavaResolveResult result) {
  return new AccessStaticViaInstanceFix(expr, result, onTheFly);
}
项目:intellij-haxe    文件:HaxeClassResolveResult.java   
public JavaResolveResult toJavaResolveResult() {
  return new JavaResult(this);
}
项目:consulo-java    文件:AccessStaticViaInstance.java   
@Override
protected AccessStaticViaInstanceFix createAccessStaticViaInstanceFix(PsiReferenceExpression expr,
                                                                      boolean onTheFly,
                                                                      JavaResolveResult result) {
  return new AccessStaticViaInstanceFix(expr, result, onTheFly);
}