void (@NotNull PsiReferenceExpression expression) { super.visitReferenceExpression(expression); final PsiReferenceParameterList parameterList = expression.getParameterList(); if (parameterList == null) { return; } if (parameterList.getTypeArguments().length > 0) { return; } final PsiExpression qualifierExpression = PsiUtil.skipParenthesizedExprDown(expression.getQualifierExpression()); if (!(qualifierExpression instanceof PsiThisExpression thisExpression)) { return; } final PsiJavaCodeReferenceElement qualifier = thisExpression.getQualifier(); final String referenceName = expression.getReferenceName(); if (referenceName == null) { return; } if (ignoreAssignments && PsiUtil.isAccessedForWriting(expression)) { return; } final PsiElement parent = expression.getParent(); if (qualifier == null) { if (referenceName.equals(PsiKeyword.YIELD) && parent instanceof PsiMethodCallExpression) { // Qualifier might be required since Java 14, so don't warn return; } if (parent instanceof PsiCallExpression) { // method calls are always in error registerError(qualifierExpression); return; } final PsiElement target = expression.resolve(); if (!(target instanceof PsiVariable variable)) { return; } if (!DeclarationSearchUtils.variableNameResolvesToTarget(referenceName, variable, expression)) { return; } if (variable instanceof PsiField && HighlightUtil.isIllegalForwardReferenceToField(expression, (PsiField)variable, true) != null) { return; } registerError(thisExpression); } else { final String qualifierName = qualifier.getReferenceName(); if (qualifierName == null) { return; } if (parent instanceof PsiCallExpression callExpression) { final PsiMethod calledMethod = callExpression.resolveMethod(); if (calledMethod == null) { return; } final String methodName = calledMethod.getName(); PsiClass parentClass = ClassUtils.getContainingClass(expression); final Project project = expression.getProject(); final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); final PsiResolveHelper resolveHelper = psiFacade.getResolveHelper(); while (parentClass != null) { if (qualifierName.equals(parentClass.getName())) { registerError(thisExpression); } final PsiMethod[] methods = parentClass.findMethodsByName(methodName, true); for (PsiMethod method : methods) { final PsiClass containingClass = method.getContainingClass(); if (resolveHelper.isAccessible(method, expression, null)) { if (method.hasModifierProperty(PsiModifier.PRIVATE) && !PsiTreeUtil.isAncestor(containingClass, expression, true)) { continue; } return; } } parentClass = ClassUtils.getContainingClass(parentClass); } } else { final PsiElement target = expression.resolve(); if (!(target instanceof PsiVariable variable)) { return; } if (!DeclarationSearchUtils.variableNameResolvesToTarget(referenceName, variable, expression)) { return; } PsiClass parentClass = ClassUtils.getContainingClass(expression); while (parentClass != null) { if (qualifierName.equals(parentClass.getName())) { registerError(thisExpression); } final PsiField field = parentClass.findFieldByName(referenceName, true); if (field != null) { return; } parentClass = ClassUtils.getContainingClass(parentClass); } } } }