File (@Nullable ExternalSourceDirectorySet sourceDirectorySet) { if (sourceDirectorySet == null) return null; Set<File> srcDirs = sourceDirectorySet.getSrcDirs(); Collection<File> outputDirectories = sourceDirectorySet.getGradleOutputDirs(); String firstExistingLang = srcDirs.stream() .sorted() .filter(File::exists) .findFirst() .map(File::getName) .orElse(null); if (firstExistingLang == null) { return ContainerUtil.getFirstItem(outputDirectories); } return outputDirectories.stream() .filter(f -> f.getPath().contains(firstExistingLang)) .findFirst() .orElse(ContainerUtil.getFirstItem(outputDirectories)); }