void (@NotNull List<? extends PsiRecordComponent> targets) { assert targets.size() == 1; PsiRecordComponent record = targets.get(0); PsiIdentifier nameIdentifier = record.getNameIdentifier(); if (nameIdentifier != null) { addOccurrence(nameIdentifier); final String name = nameIdentifier.getText(); Consumer<PsiExpression> onOccurence = (expr) -> addOccurrence(expr); JavaRecursiveElementWalkingVisitor visitor = new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { super.visitReferenceExpression(expression); if (isReferenceToRecordComponent(name, expression)) { onOccurence.consume(expression); } } }; myComponent.getContainingFile().accept(visitor); } }