@Override public void consume(Object o) { if (!(o instanceof GroovyResolveResult)) { LOG.error(o); return; } GroovyResolveResult result = (GroovyResolveResult) o; if (!result.isStaticsOK()) { if (myInapplicable == null) myInapplicable = ContainerUtil.newArrayList(); myInapplicable.add(result); return; } if (!result.isAccessible() && myParameters.getInvocationCount() < 2) return; if (mySkipPackages && result.getElement() instanceof PsiPackage) return; PsiElement element = result.getElement(); if (element instanceof PsiVariable && !myMatcher.prefixMatches(((PsiVariable) element).getName())) { return; } if (element instanceof GrReflectedMethod) { element = ((GrReflectedMethod) element).getBaseMethod(); if (!myProcessedMethodWithOptionalParams.add((GrMethod) element)) return; result = new GroovyResolveResultImpl( element, result.getCurrentFileResolveContext(), result.getSpreadState(), result.getSubstitutor(), result.isAccessible(), result.isStaticsOK(), result.isInvokedOnProperty(), result.isValidResult()); } if (myFieldPointerOperator && !(element instanceof PsiVariable)) { return; } if (myMethodPointerOperator && !(element instanceof PsiMethod)) { return; } addCandidate(result); if (!myFieldPointerOperator && !myMethodPointerOperator) { if (element instanceof PsiMethod) { processProperty((PsiMethod) element, result); } else if (element instanceof GrField) { if (((GrField) element).isProperty()) { processPropertyFromField((GrField) element, result); } } } if (element instanceof GrVariable && !(element instanceof GrField)) { myLocalVars.add(((GrVariable) element).getName()); } }
private static GroovyResolveResult getBestResolveResult(GrReferenceExpression ref) { GroovyResolveResult[] results = ref.multiResolve(false); if (results.length == 0) return GroovyResolveResult.EMPTY_RESULT; if (results.length == 1) return results[0]; for (GroovyResolveResult result : results) { if (result.isAccessible() && result.isStaticsOK()) return result; } for (GroovyResolveResult result : results) { if (result.isStaticsOK()) return result; } return results[0]; }
private static boolean canBeSimplified(PsiElement element) { if (PsiTreeUtil.getParentOfType(element, PsiComment.class) != null) return false; if (element instanceof GrCodeReferenceElement) { if (PsiTreeUtil.getParentOfType(element, GrImportStatement.class, GrPackageDefinition.class) != null) return false; } else if (element instanceof GrReferenceExpression) { if (!PsiImplUtil.seemsToBeQualifiedClassName((GrReferenceExpression) element)) return false; } else { return false; } final GrReferenceElement ref = (GrReferenceElement) element; if (ref.getQualifier() == null) return false; if (!(ref.getContainingFile() instanceof GroovyFileBase)) return false; final PsiElement resolved = ref.resolve(); if (!(resolved instanceof PsiClass)) return false; final String name = ((PsiClass) resolved).getName(); if (name == null) return false; final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(element.getProject()); final GrReferenceExpression shortedRef = factory.createReferenceExpressionFromText(name, element); final GroovyResolveResult resolveResult = shortedRef.advancedResolve(); if (element.getManager().areElementsEquivalent(resolved, resolveResult.getElement())) { return true; } final PsiClass containingClass = ((PsiClass) resolved).getContainingClass(); if (containingClass != null && !GroovyCodeStyleSettingsFacade.getInstance(containingClass.getProject()) .insertInnerClassImports()) { return false; } return resolveResult.getElement() == null || !resolveResult.isAccessible() || !resolveResult.isStaticsOK(); }
@NotNull private static GroovyResolveResult generatePropertyResolveResult( @NotNull String name, @NotNull PsiMethod method, @Nullable PsiType type, @Nullable GroovyResolveResult resolveResult) { PsiType nonNullType = type != null ? type : TypesUtil.getJavaLangObject(method); final GrPropertyForCompletion field = new GrPropertyForCompletion(method, name, nonNullType); if (resolveResult != null) { return new GroovyResolveResultImpl( field, resolveResult.getCurrentFileResolveContext(), resolveResult.getSpreadState(), resolveResult.getSubstitutor(), resolveResult.isAccessible(), resolveResult.isStaticsOK()); } else { return new GroovyResolveResultImpl(field, true); } }