List<String> (GrReferenceExpression ref) { List<String> res = new ArrayList<>(); GrExpression qualifier = ref.getQualifierExpression(); while (qualifier != null) { if (!(qualifier instanceof GrReferenceExpression r)) return null; String name = r.getReferenceName(); if (name == null) return null; res.add(name); qualifier = r.getQualifierExpression(); } PsiElement e = ref.getParent(); if (e instanceof GrAssignmentExpression assignmentExpression) { if (assignmentExpression.getLValue() != ref) return null; e = assignmentExpression.getParent(); } while (!(e instanceof PsiFile)) { if (e instanceof GrClosableBlock) { PsiElement eCall = e.getParent(); if (!(eCall instanceof GrMethodCall call)) return null; if (!isPropertyCall(call)) return null; String name = extractPropertyName(call); if (name == null) return null; res.add(name); e = call.getParent(); } else if (e instanceof GrBlockStatement || e instanceof GrOpenBlock || e instanceof GrIfStatement || e instanceof GrForStatement || e instanceof GrWhileStatement || e instanceof GrTryCatchStatement) { e = e.getParent(); } else { return null; } } Collections.reverse(res); return res; }