PsiClass () { PsiElement parent = getParent().getParent(); if (parent instanceof GrTypeDefinitionBody) { final PsiElement pparent = parent.getParent(); if (pparent instanceof PsiClass) { return (PsiClass)pparent; } } final PsiFile file = getContainingFile(); if (file instanceof GroovyFileBase) { return ((GroovyFileBase)file).getScriptClass(); } return null; }