Code Smell and Inspections
I am running the CodeSmellDetector before allowing the user to perform a specific action in my plugin. I was hoping that this would include any errors or warnings from Inspections, but that does not seem to be the case.
Is there any way to have CodeSmellDetector recongize the inspections?
Should it already, but I am just doing it wrong?
Is there a way at this time to run the Inspections on-demand? (I have seen previous posts where the answer is no)
Code:
final DataContext dataContext = event.getDataContext();
final List<VirtualFile> userSelectedVirtualFiles = Arrays.asList(DataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext));
final List<VirtualFile> configVirtualFiles = new ArrayList<VirtualFile>();
for (final VirtualFile virtualFile : userSelectedVirtualFiles) {
if (virtualFile.isDirectory()) {
configVirtualFiles.addAll(Arrays.asList(virtualFile.getChildren()));
} else {
configVirtualFiles.add(virtualFile);
}
}
final List<CodeSmellInfo> codeSmells = CodeSmellDetector.getInstance(IDEAUtils.getProject()).findCodeSmells(configVirtualFiles);
if (!codeSmells.isEmpty()) {
// error
} else {
// continue
}
Thanks
Please sign in to leave a comment.
Hello Nicholas,
This should include all the messages from inspections that have severity
Warning or higher. Your code looks correct; I don't know why it doesn't work.
Probably the best thing to do is to step through the implementation in the
CE source code and see what's going on there.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"