@SuppressFBWarnings({"SIC_INNER_SHOULD_BE_STATIC_ANON"})
protected final Iterable<String> findClasses(@NotNull final Project project, final AnalysisScope scope) {
final Collection<String> ret = new ArrayList<String>(256);
final PsiManager psiManager = PsiManager.getInstance(project);
psiManager.startBatchFilesProcessingMode();
try {
//noinspection AnonymousInnerClass
scope.accept(new PsiRecursiveElementVisitor() {
FileType fileType;
String path;
VirtualFile virtualFile;
@Override
public void visitFile(final PsiFile file) {
fileType = file.getFileType();
if (StdFileTypes.JAVA.equals(fileType)) {
path = AnalyzeUtil.getOutputClassFilePathForJavaFile(file, project);
if (path != null) {
addPath(path);
} else {
LOGGER.warn("No output class path found for PsiFile: " + file);
}
} else if (StdFileTypes.CLASS.equals(fileType)) {
virtualFile = file.getVirtualFile();
if (virtualFile != null) {
path = virtualFile.getPath();
if (path != null) {
addPath(path);
} else {
LOGGER.warn("No path for VirtualFile: " + virtualFile);
}
} else {
LOGGER.warn("No virtual file for PsiFile: " + file);
}
} // else skip non .java and .class files
}
private void addPath(final String path) {
if (!ret.contains(path)) {
ret.add(path);
} // LATER: check why visitFile is called multiple times for the same PsiFile ?
}
});
} finally {
psiManager.finishBatchFilesProcessingMode();
}
return ret;
}