GrVariable (final PsiFile file, final Editor editor, final int offset) { final int correctOffset = correctOffset(editor, offset); final PsiElement elementAtCaret = file.findElementAt(correctOffset); final GrVariable variable = PsiTreeUtil.getParentOfType(elementAtCaret, GrVariable.class); if (variable != null && variable.getNameIdentifierGroovy().getTextRange().contains(correctOffset)) return variable; return null; }