Collection<PsiPolyVariantReference> (@NotNull GrReferenceExpressionImpl expression) { final GrExpression qualifier = expression.getQualifier(); if (qualifier == null) return null; final List<PsiPolyVariantReference> result = new SmartList<>(); qualifier.accept(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof GrReferenceExpression) { super.visitElement(element); } else if (element instanceof GrMethodCall) { super.visitElement(((GrMethodCall)element).getInvokedExpression()); } else if (element instanceof GrParenthesizedExpression) { GrExpression operand = ((GrParenthesizedExpression)element).getOperand(); if (operand != null) super.visitElement(operand); } } @Override protected void elementFinished(PsiElement element) { if (element instanceof GrReferenceExpression) { result.add(((GrReferenceExpression)element)); } } }); return result; }