@Nullable private static HighlightInfo createAnnotationForRef( @NotNull GrReferenceExpression ref, boolean compileStatic, @NotNull String message) { PsiElement refNameElement = ref.getReferenceNameElement(); assert refNameElement != null; HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(ref.getProject(), ref); if (compileStatic || displayLevel == HighlightDisplayLevel.ERROR) { return HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF) .range(refNameElement) .descriptionAndTooltip(message) .create(); } if (displayLevel == HighlightDisplayLevel.WARNING) { boolean isTestMode = ApplicationManager.getApplication().isUnitTestMode(); HighlightInfoType infotype = isTestMode ? HighlightInfoType.WARNING : HighlightInfoType.INFORMATION; HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(infotype).range(refNameElement); builder.descriptionAndTooltip(message); return builder.needsUpdateOnTyping(false).textAttributes(UNRESOLVED_ACCESS).create(); } HighlightInfoType highlightInfoType = HighlightInfo.convertSeverity(displayLevel.getSeverity()); return HighlightInfo.newHighlightInfo(highlightInfoType) .range(refNameElement) .descriptionAndTooltip(message) .create(); }
@Nullable private static HighlightInfo checkRefInner(GrReferenceExpression ref) { PsiElement refNameElement = ref.getReferenceNameElement(); if (refNameElement == null) return null; boolean cannotBeDynamic = PsiUtil.isCompileStatic(ref) || isPropertyAccessInStaticMethod(ref); GroovyResolveResult resolveResult = getBestResolveResult(ref); if (resolveResult.getElement() != null) { if (!isInspectionEnabled(ref.getContainingFile(), ref.getProject())) return null; if (isStaticOk(resolveResult)) return null; String message = GroovyBundle.message("cannot.reference.non.static", ref.getReferenceName()); return createAnnotationForRef(ref, cannotBeDynamic, message); } if (ResolveUtil.isKeyOfMap(ref) || isClassReference(ref)) { return null; } if (!cannotBeDynamic) { if (!isInspectionEnabled(ref.getContainingFile(), ref.getProject())) return null; GrUnresolvedAccessInspection inspection = getInstance(ref.getContainingFile(), ref.getProject()); if (!inspection.myHighlightIfGroovyObjectOverridden && areGroovyObjectMethodsOverridden(ref)) return null; if (!inspection.myHighlightIfMissingMethodsDeclared && areMissingMethodsDeclared(ref)) return null; if (GroovySuppressableInspectionTool.isElementToolSuppressedIn(ref, SHORT_NAME)) return null; } if (cannotBeDynamic || shouldHighlightAsUnresolved(ref)) { HighlightInfo info = createAnnotationForRef( ref, cannotBeDynamic, GroovyBundle.message("cannot.resolve", ref.getReferenceName())); LOG.assertTrue(info != null); HighlightDisplayKey displayKey = HighlightDisplayKey.find(SHORT_NAME); if (ref.getParent() instanceof GrMethodCall) { registerStaticImportFix(ref, info, displayKey); } else { registerCreateClassByTypeFix(ref, info, displayKey); registerAddImportFixes(ref, info, displayKey); } registerReferenceFixes(ref, info, cannotBeDynamic, displayKey); UnresolvedReferenceQuickFixProvider.registerReferenceFixes( ref, new QuickFixActionRegistrarAdapter(info, displayKey)); OrderEntryFix.registerFixes(new QuickFixActionRegistrarAdapter(info, displayKey), ref); return info; } return null; }