boolean (PsiJavaCodeReferenceElement ref, @NotNull PsiElement target) { if (PsiTreeUtil.getParentOfType(ref, PsiPackageStatement.class) != null) return false; PsiAnnotation anno = PsiTreeUtil.getParentOfType(ref, PsiAnnotation.class); if (!ref.isQualified() && target instanceof PsiPackage) return false; if (target instanceof PsiClass) { if (anno != null && !((PsiClass)target).isAnnotationType()) { if (PsiTreeUtil.isAncestor(anno.getNameReferenceElement(), ref, true)) { return false; // inner annotation } } } if (target instanceof PsiField) { if (SyntaxTraverser.psiApi().parents(ref).find(e -> e instanceof PsiMethod && ((PsiMethod)e).isConstructor()) != null) { // https://youtrack.jetbrains.com/issue/IDEA-174744 on red code return false; } if (!((PsiField)target).hasModifierProperty(PsiModifier.STATIC) && anno != null) { return false; } } if (isStaticWithInstanceQualifier(ref, target)) { return false; } if (target instanceof PsiVariable && PsiTreeUtil.isAncestor(target, ref, false)) { return false; } if (anno != null && ref.getParent() instanceof PsiNameValuePair && !JavaCompletionContributor.mayCompleteValueExpression(ref, anno.resolveAnnotationType())) { return false; } return true; }