String (@NotNull DataContext dataContext) { //Project project = (Project)dataContext.getData(DataConstants.PROJECT); //if (project == null) { // return null; //} //VirtualFile file = (VirtualFile)dataContext.getData(DataConstantsEx.VIRTUAL_FILE); //if (file == null) { // return null; //} //PsiFile psiFile = PsiManager.getInstance(project).findFile(file); //if (!(psiFile instanceof PsiJavaFile)) { // return null; //} final PsiFile javaFile = CommonDataKeys.PSI_FILE.getData(dataContext); if (!(javaFile instanceof PsiJavaFile)) return null; PsiClass[] classes = ((PsiJavaFile) javaFile).getClasses(); if (classes.length == 1) { return classes[0].getQualifiedName(); } String fileName = javaFile.getVirtualFile().getNameWithoutExtension(); for (PsiClass aClass : classes) { String name = aClass.getName(); if (fileName.equals(name)) { return aClass.getQualifiedName(); } } return null; }