PsiElement () { final GrTypeDefinitionStub stub = getStub(); if (stub != null) { return stub.getParentStub().getPsi(); } ASTNode treeElement = getNode(); ASTNode parent = treeElement.getTreeParent(); while (parent != null) { if (parent.getElementType() instanceof IStubElementType && !(parent.getElementType() == GroovyEmptyStubElementTypes.CLASS_BODY)) { return parent.getPsi(); } parent = parent.getTreeParent(); } return getContainingFile(); }