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