void (@NotNull PsiAnonymousClass aClass) { super.visitAnonymousClass(aClass); final PsiCodeBlock codeBlock = PsiTreeUtil.getParentOfType(aClass, PsiCodeBlock.class); if (codeBlock == null) { return; } final VariableCollector collector = new VariableCollector(); aClass.acceptChildren(collector); final PsiStatement[] statements = codeBlock.getStatements(); final int offset = aClass.getTextOffset(); for (PsiStatement statement : statements) { if (statement.getTextOffset() >= offset) { break; } if (!(statement instanceof PsiDeclarationStatement declarationStatement)) { continue; } final PsiElement[] declaredElements = declarationStatement.getDeclaredElements(); for (PsiElement declaredElement : declaredElements) { if (!(declaredElement instanceof PsiLocalVariable localVariable)) { continue; } final String name = localVariable.getName(); final PsiVariable[] variables = collector.getVariables(name); for (PsiVariable variable : variables) { registerVariableError(variable, variable); } } } final PsiElement containingMethod = PsiTreeUtil.getParentOfType(codeBlock, PsiMethod.class, PsiLambdaExpression.class); if (containingMethod == null) { return; } final PsiParameterList parameterList = containingMethod instanceof PsiMethod ? ((PsiMethod)containingMethod).getParameterList() : ((PsiLambdaExpression)containingMethod).getParameterList(); final PsiParameter[] parameters = parameterList.getParameters(); for (PsiParameter parameter : parameters) { final String name = parameter.getName(); final PsiVariable[] variables = collector.getVariables(name); for (PsiVariable variable : variables) { registerVariableError(variable, variable); } } }