use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class ExportHTMLAction method getWorkedTools.
@NotNull
private Set<InspectionToolWrapper> getWorkedTools(@NotNull InspectionNode node) {
final Set<InspectionToolWrapper> result = new HashSet<>();
final InspectionToolWrapper wrapper = node.getToolWrapper();
if (myView.getCurrentProfileName() == null) {
result.add(wrapper);
return result;
}
final String shortName = wrapper.getShortName();
final GlobalInspectionContextImpl context = myView.getGlobalInspectionContext();
final Tools tools = context.getTools().get(shortName);
if (tools != null) {
//dummy entry points tool
for (ScopeToolState state : tools.getTools()) {
InspectionToolWrapper toolWrapper = state.getTool();
result.add(toolWrapper);
}
}
return result;
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class QuickFixesViewActionGroup method getChildren.
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
final InspectionResultsView view = getView(e);
if (view == null || InvokeQuickFixAction.cantApplyFixes(view)) {
return AnAction.EMPTY_ARRAY;
}
InspectionToolWrapper toolWrapper = view.getTree().getSelectedToolWrapper(true);
if (toolWrapper == null)
return AnAction.EMPTY_ARRAY;
final QuickFixAction[] quickFixes = view.getProvider().getQuickFixes(toolWrapper, view.getTree());
if (quickFixes == null || quickFixes.length == 0) {
return AnAction.EMPTY_ARRAY;
}
return quickFixes;
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class ShowIntentionsPass method collectIntentionsFromDoNotShowLeveledInspections.
/**
* Can be invoked in EDT, each inspection should be fast
*/
private static void collectIntentionsFromDoNotShowLeveledInspections(@NotNull final Project project, @NotNull final PsiFile hostFile, PsiElement psiElement, final int offset, @NotNull final IntentionsInfo intentions) {
if (psiElement != null) {
if (!psiElement.isPhysical()) {
VirtualFile virtualFile = hostFile.getVirtualFile();
String text = hostFile.getText();
LOG.error("not physical: '" + psiElement.getText() + "' @" + offset + psiElement.getTextRange() + " elem:" + psiElement + " (" + psiElement.getClass().getName() + ")" + " in:" + psiElement.getContainingFile() + " host:" + hostFile + "(" + hostFile.getClass().getName() + ")", new Attachment(virtualFile != null ? virtualFile.getPresentableUrl() : "null", text != null ? text : "null"));
}
if (DumbService.isDumb(project)) {
return;
}
final List<LocalInspectionToolWrapper> intentionTools = new ArrayList<>();
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
final InspectionToolWrapper[] tools = profile.getInspectionTools(hostFile);
for (InspectionToolWrapper toolWrapper : tools) {
if (toolWrapper instanceof LocalInspectionToolWrapper && !((LocalInspectionToolWrapper) toolWrapper).isUnfair()) {
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
if (profile.isToolEnabled(key, hostFile) && HighlightDisplayLevel.DO_NOT_SHOW.equals(profile.getErrorLevel(key, hostFile))) {
intentionTools.add((LocalInspectionToolWrapper) toolWrapper);
}
}
}
if (!intentionTools.isEmpty()) {
final List<PsiElement> elements = new ArrayList<>();
PsiElement el = psiElement;
while (el != null) {
elements.add(el);
if (el instanceof PsiFile)
break;
el = el.getParent();
}
final Set<String> dialectIds = InspectionEngine.calcElementDialectIds(elements);
final LocalInspectionToolSession session = new LocalInspectionToolSession(hostFile, 0, hostFile.getTextLength());
final Processor<LocalInspectionToolWrapper> processor = toolWrapper -> {
final LocalInspectionTool localInspectionTool = toolWrapper.getTool();
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
final String displayName = toolWrapper.getDisplayName();
final ProblemsHolder holder = new ProblemsHolder(InspectionManager.getInstance(project), hostFile, true) {
@Override
public void registerProblem(@NotNull ProblemDescriptor problemDescriptor) {
super.registerProblem(problemDescriptor);
if (problemDescriptor instanceof ProblemDescriptorBase) {
final TextRange range = ((ProblemDescriptorBase) problemDescriptor).getTextRange();
if (range != null && range.contains(offset)) {
final QuickFix[] fixes = problemDescriptor.getFixes();
if (fixes != null) {
for (int k = 0; k < fixes.length; k++) {
final IntentionAction intentionAction = QuickFixWrapper.wrap(problemDescriptor, k);
final HighlightInfo.IntentionActionDescriptor actionDescriptor = new HighlightInfo.IntentionActionDescriptor(intentionAction, null, displayName, null, key, null, HighlightSeverity.INFORMATION);
intentions.intentionsToShow.add(actionDescriptor);
}
}
}
}
}
};
InspectionEngine.createVisitorAndAcceptElements(localInspectionTool, holder, true, session, elements, dialectIds, InspectionEngine.getDialectIdsSpecifiedForTool(toolWrapper));
localInspectionTool.inspectionFinished(session, holder);
return true;
};
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(intentionTools, new DaemonProgressIndicator(), false, processor);
}
}
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionDescriptionLinkHandler method getDescription.
@Override
public String getDescription(@NotNull final String refSuffix, @NotNull final Editor editor) {
final Project project = editor.getProject();
if (project == null) {
LOG.error(editor);
return null;
}
if (project.isDisposed())
return null;
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) {
return null;
}
final InspectionProfile profile = InspectionProfileManager.getInstance().getCurrentProfile();
final InspectionToolWrapper toolWrapper = profile.getInspectionTool(refSuffix, file);
if (toolWrapper == null)
return null;
String description = toolWrapper.loadDescription();
if (description == null) {
LOG.warn("No description for inspection '" + refSuffix + "'");
description = InspectionsBundle.message("inspection.tool.description.under.construction.text");
}
return description;
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionDump method main.
@Override
public void main(String[] args) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
Element inspections = document.createElement("Inspections");
document.appendChild(inspections);
List<InspectionToolWrapper> tools = InspectionToolRegistrar.getInstance().createTools();
for (InspectionToolWrapper tool : tools) {
Element inspection = document.createElement("Inspection");
inspection.setAttribute("groupPath", StringUtil.join(tool.getGroupPath(), ";"));
inspection.setAttribute("group", tool.getGroupDisplayName());
inspection.setAttribute("name", tool.getDisplayName());
inspection.setAttribute("level", tool.getDefaultLevel().getName());
if (tool.getLanguage() != null) {
inspection.setAttribute("language", tool.getLanguage());
}
Element description = document.createElement("description");
CDATASection descriptionSection = document.createCDATASection(escapeCDATA(tool.loadDescription()));
description.appendChild(descriptionSection);
inspection.appendChild(description);
inspections.appendChild(inspection);
}
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource source = new DOMSource(document);
final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllInspections.xml";
StreamResult console = new StreamResult(new File(path));
transformer.transform(source, console);
System.exit(0);
} catch (ParserConfigurationException | TransformerException e) {
// noinspection CallToPrintStackTrace
e.printStackTrace();
System.exit(1);
}
}
Aggregations