void (@NotNull PsiMethodCallExpression call) { if (!CLEANER_REGISTER.test(call)) return; PsiExpression[] expressions = call.getArgumentList().getExpressions(); PsiExpression trackedObject = ExpressionUtils.resolveExpression(expressions[0]); PsiExpression runnableExpression = ExpressionUtils.resolveExpression(expressions[1]); if (trackedObject == null || runnableExpression == null) return; final PsiElement highlightingElement; final String referenceName; if (trackedObject instanceof PsiThisExpression) { PsiClassType classType = tryCast(trackedObject.getType(), PsiClassType.class); if (classType == null) return; PsiClass trackedClass = classType.resolve(); if (trackedClass == null) return; PsiElement elementCapturingThis = getElementCapturingThis(runnableExpression, trackedClass); if (elementCapturingThis == null) return; highlightingElement = elementCapturingThis; referenceName = "this"; } else if (trackedObject instanceof PsiReferenceExpression) { PsiVariable variable = tryCast(((PsiReferenceExpression)trackedObject).resolve(), PsiVariable.class); if (variable == null) return; if (variable instanceof PsiField) return; if (!VariableAccessUtils.variableIsUsed(variable, runnableExpression)) return; Optional<PsiElement> referenceExpression = StreamEx.ofTree(((PsiElement)runnableExpression), el -> StreamEx.of(el.getChildren())) .findAny(el -> el instanceof PsiReferenceExpression && ((PsiReferenceExpression)el).isReferenceTo(variable)); if (referenceExpression.isEmpty()) return; String variableName = variable.getName(); if (variableName == null) return; highlightingElement = referenceExpression.get(); referenceName = variableName; } else { return; } holder.registerProblem(highlightingElement, JavaBundle.message("inspection.capturing.cleaner", referenceName)); }