GroovyPsiElement (int offset, PsiFile file) { PsiElement element = file.findElementAt(offset); if (element == null) return null; GroovyPsiElement argList = PsiTreeUtil.getParentOfType(element, GrArgumentList.class); if (argList != null) return argList; final GrCall call = PsiTreeUtil.getParentOfType(element, GrCall.class); if (call != null) { argList = call.getArgumentList(); if (argList != null && argList.getTextRange().contains(element.getTextRange().getStartOffset())) return argList; } else { offset = CharArrayUtil.shiftBackward(file.getText(), offset, "\n\t "); if (offset <= 0) return null; element = file.findElementAt(offset); if (element != null && element.getParent() instanceof GrReferenceExpression) return (GroovyPsiElement) element.getParent(); } return null; }