PsiClass (@Nullable PsiElement element) { if (element == null) return null; if (DumbService.isDumb(element.getProject())) return null; final PsiFile file = element.getContainingFile(); if (!(file instanceof GroovyFile)) return null; for (PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class); clazz != null; clazz = PsiTreeUtil.getParentOfType(clazz, PsiClass.class)) { if (canBeRunByGroovy(clazz)) return clazz; } if (((GroovyFile)file).isScript()) return ((GroovyFile)file).getScriptClass(); final PsiClass[] classes = ((GroovyFile)file).getClasses(); if (classes.length > 0) { return classes[0]; } return null; }