boolean (@NotNull PsiJavaCodeReferenceElement referenceElement, boolean ignoreStaticAccessFromStaticContext, boolean ignoreStaticFieldAccesses, boolean ignoreStaticMethodCalls) { if (referenceElement instanceof PsiMethodReferenceExpression) { return false; } final PsiElement parent = referenceElement.getParent(); if (parent instanceof PsiImportStatementBase) { return false; } final PsiElement qualifierElement = referenceElement.getQualifier(); if (!(qualifierElement instanceof PsiJavaCodeReferenceElement qualifier)) { return false; } if (GenericsUtil.isGenericReference(referenceElement, qualifier)) { return false; } final PsiElement target = referenceElement.resolve(); if ((!(target instanceof PsiField) || ignoreStaticFieldAccesses) && (!(target instanceof PsiMethod) || ignoreStaticMethodCalls)) { return false; } if (ignoreStaticAccessFromStaticContext) { final PsiMember containingMember = PsiTreeUtil.getParentOfType(referenceElement, PsiMember.class); if (containingMember != null && !containingMember.hasModifierProperty(PsiModifier.STATIC)) { return false; } } final String referenceName = referenceElement.getReferenceName(); if (referenceName == null) { return false; } final PsiElement resolvedQualifier = qualifier.resolve(); if (!(resolvedQualifier instanceof PsiClass qualifyingClass)) { return false; } final PsiClass containingClass = PsiTreeUtil.getParentOfType(referenceElement, PsiClass.class); if (containingClass == null || !PsiTreeUtil.isAncestor(qualifyingClass, containingClass, false)) { return false; } final Project project = referenceElement.getProject(); final JavaPsiFacade manager = JavaPsiFacade.getInstance(project); final PsiResolveHelper resolveHelper = manager.getResolveHelper(); final PsiMember member = (PsiMember)target; final PsiClass memberClass; if (target instanceof PsiField) { final PsiVariable variable = resolveHelper.resolveReferencedVariable(referenceName, referenceElement); if (variable == null || !variable.equals(member)) { return false; } final TextRange referenceElementTextRange = referenceElement.getTextRange(); if (referenceElementTextRange == null) { return false; } final TextRange variableTextRange = variable.getTextRange(); if (variableTextRange == null) { return false; } //illegal forward ref if (referenceElementTextRange.getStartOffset() < variableTextRange.getEndOffset()) { return false; } final PsiMember memberVariable = (PsiMember)variable; memberClass = memberVariable.getContainingClass(); } else if (target instanceof PsiClass) { final PsiClass aClass = resolveHelper.resolveReferencedClass(referenceName, referenceElement); if (aClass == null || !aClass.equals(member)) { return false; } memberClass = aClass.getContainingClass(); } else { return isMethodAccessibleWithoutQualifier(referenceElement, qualifyingClass); } return resolvedQualifier.equals(memberClass); }