Set<PsiVariable> (@NotNull VariableData data, @NotNull List<? extends PsiVariable> inputVariables, @NotNull PsiExpression expression) { final Set<PsiVariable> found = new HashSet<>(); expression.accept(new JavaRecursiveElementVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression referenceExpression) { super.visitReferenceExpression(referenceExpression); PsiElement resolved = referenceExpression.resolve(); if (resolved instanceof PsiVariable && inputVariables.contains(resolved)) { found.add((PsiVariable)resolved); } } }); found.remove(data.variable); return found; }