PsiClass (PsiElement element) { while (element != null) { if (element instanceof PsiClass) { final PsiClass aClass = (PsiClass)element; if (PsiMethodUtil.findMainInClass(aClass) != null) { return aClass; } } else if (element instanceof PsiJavaFile) { final PsiClass[] classes = ((PsiJavaFile)element).getClasses(); for (PsiClass aClass : classes) { if (PsiMethodUtil.findMainInClass(aClass) != null) { return aClass; } } } element = element.getParent(); } return null; }