String (GroovyFile file) { final PsiDirectory dir = file.getContainingDirectory(); LOG.assertTrue(dir != null); final PsiFile[] files = dir.getFiles(); Set<String> fileNames = new HashSet<>(); for (PsiFile psiFile : files) { fileNames.add(psiFile.getName()); } String prefix = FileUtilRt.getNameWithoutExtension(file.getName()); String fileName = prefix + ".java"; int index = 1; while (fileNames.contains(fileName)) { fileName = prefix + (index++) + ".java"; } return fileName; }