@Override public void actionPerformed(AnActionEvent e) { final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(myProject); final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper(); InspectionProfile inspectionProfile = myInspectionProfile; final boolean profileIsDefined = isProfileDefined(); if (!profileIsDefined) { inspectionProfile = guessProfileToSelect(profileManager); } if (toolWrapper != null) { final HighlightDisplayKey key = HighlightDisplayKey.find( toolWrapper.getShortName()); // do not search for dead code entry point tool if (key != null) { if (new EditInspectionToolsSettingsAction(key) .editToolSettings( myProject, (InspectionProfileImpl) inspectionProfile, profileIsDefined) && profileIsDefined) { updateCurrentProfile(); } return; } } if (EditInspectionToolsSettingsAction.editToolSettings( myProject, inspectionProfile, profileIsDefined, null) && profileIsDefined) { updateCurrentProfile(); } }
private void popupInvoked(Component component, int x, int y) { final TreePath path = myTree.getLeadSelectionPath(); if (path == null) return; final DefaultActionGroup actions = new DefaultActionGroup(); final ActionManager actionManager = ActionManager.getInstance(); actions.add(actionManager.getAction(IdeActions.ACTION_EDIT_SOURCE)); actions.add(actionManager.getAction(IdeActions.ACTION_FIND_USAGES)); actions.add(myIncludeAction); actions.add(myExcludeAction); actions.addSeparator(); final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper(); if (toolWrapper != null) { final QuickFixAction[] quickFixes = myProvider.getQuickFixes(toolWrapper, myTree); if (quickFixes != null) { for (QuickFixAction quickFixe : quickFixes) { actions.add(quickFixe); } } final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName()); if (key == null) return; // e.g. DummyEntryPointsTool // options actions.addSeparator(); actions.add(new EditSettingsAction()); final List<AnAction> options = new InspectionsOptionsToolbarAction(this).createActions(); for (AnAction action : options) { actions.add(action); } } actions.addSeparator(); actions.add(actionManager.getAction(IdeActions.GROUP_VERSION_CONTROLS)); final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.CODE_INSPECTION, actions); menu.getComponent().show(component, x, y); }
public ToolsImpl( @NotNull InspectionToolWrapper toolWrapper, @NotNull HighlightDisplayLevel level, boolean enabled, boolean enabledByDefault) { myShortName = toolWrapper.getShortName(); myDefaultState = new ScopeToolState( CustomScopesProviderEx.getAllScope(), toolWrapper, enabledByDefault, level); myTools = null; myEnabled = enabled; }
private boolean buildTree() { InspectionProfile profile = myInspectionProfile; boolean isGroupedBySeverity = myGlobalInspectionContext.getUIOptions().GROUP_BY_SEVERITY; myGroups.clear(); final Map<String, Tools> tools = myGlobalInspectionContext.getTools(); boolean resultsFound = false; for (Tools currentTools : tools.values()) { InspectionToolWrapper defaultToolWrapper = currentTools.getDefaultState().getTool(); final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName()); for (ScopeToolState state : myProvider.getTools(currentTools)) { InspectionToolWrapper toolWrapper = state.getTool(); if (myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper)) { addTool( toolWrapper, ((InspectionProfileImpl) profile) .getErrorLevel(key, state.getScope(myProject), myProject), isGroupedBySeverity); resultsFound = true; } } } return resultsFound; }
@NotNull public InspectionNode addTool( @NotNull final InspectionToolWrapper toolWrapper, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { String groupName = toolWrapper.getGroupDisplayName().isEmpty() ? InspectionProfileEntry.GENERAL_GROUP_NAME : toolWrapper.getGroupDisplayName(); InspectionTreeNode parentNode = getToolParentNode(groupName, errorLevel, groupedBySeverity); InspectionNode toolNode = new InspectionNode(toolWrapper); boolean showStructure = myGlobalInspectionContext.getUIOptions().SHOW_STRUCTURE; myProvider.appendToolNodeContent( myGlobalInspectionContext, toolNode, parentNode, showStructure); InspectionToolPresentation presentation = myGlobalInspectionContext.getPresentation(toolWrapper); toolNode = presentation.createToolNode( myGlobalInspectionContext, toolNode, myProvider, parentNode, showStructure); ((DefaultInspectionToolPresentation) presentation).setToolNode(toolNode); registerActionShortcuts(presentation); return toolNode; }
private synchronized void writeOutput( @NotNull final CommonProblemDescriptor[] descriptions, @NotNull RefEntity refElement) { final Element parentNode = new Element(InspectionsBundle.message("inspection.problems")); exportResults(descriptions, refElement, parentNode); final List list = parentNode.getChildren(); @NonNls final String ext = ".xml"; final String fileName = ourOutputPath + File.separator + myToolWrapper.getShortName() + ext; final PathMacroManager pathMacroManager = PathMacroManager.getInstance(getContext().getProject()); PrintWriter printWriter = null; try { new File(ourOutputPath).mkdirs(); final File file = new File(fileName); final CharArrayWriter writer = new CharArrayWriter(); if (!file.exists()) { writer .append("<") .append(InspectionsBundle.message("inspection.problems")) .append(" " + GlobalInspectionContextBase.LOCAL_TOOL_ATTRIBUTE + "=\"") .append(Boolean.toString(myToolWrapper instanceof LocalInspectionToolWrapper)) .append("\">\n"); } for (Object o : list) { final Element element = (Element) o; pathMacroManager.collapsePaths(element); JDOMUtil.writeElement(element, writer, "\n"); } printWriter = new PrintWriter( new BufferedWriter( new OutputStreamWriter( new FileOutputStream(fileName, true), CharsetToolkit.UTF8_CHARSET))); printWriter.append("\n"); printWriter.append(writer.toString()); } catch (IOException e) { LOG.error(e); } finally { if (printWriter != null) { printWriter.close(); } } }
public void writeExternal(@NotNull Element inspectionElement) throws WriteExternalException { if (myTools != null) { for (ScopeToolState state : myTools) { final Element scopeElement = new Element("scope"); scopeElement.setAttribute("name", state.getScopeName()); scopeElement.setAttribute(LEVEL_ATTRIBUTE, state.getLevel().getName()); scopeElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(state.isEnabled())); InspectionToolWrapper toolWrapper = state.getTool(); if (toolWrapper.isInitialized()) { toolWrapper.getTool().writeSettings(scopeElement); } inspectionElement.addContent(scopeElement); } } inspectionElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(isEnabled())); inspectionElement.setAttribute(LEVEL_ATTRIBUTE, getLevel().getName()); inspectionElement.setAttribute( ENABLED_BY_DEFAULT_ATTRIBUTE, Boolean.toString(myDefaultState.isEnabled())); InspectionToolWrapper toolWrapper = myDefaultState.getTool(); if (toolWrapper.isInitialized()) { toolWrapper.getTool().writeSettings(inspectionElement); } }
void readExternal( @NotNull Element toolElement, @NotNull InspectionProfile profile, Map<String, List<String>> dependencies) throws InvalidDataException { final String levelName = toolElement.getAttributeValue(LEVEL_ATTRIBUTE); final ProfileManager profileManager = profile.getProfileManager(); final SeverityRegistrar registrar = ((SeverityProvider) profileManager).getOwnSeverityRegistrar(); HighlightDisplayLevel level = levelName != null ? HighlightDisplayLevel.find(registrar.getSeverity(levelName)) : null; if (level == null) { level = HighlightDisplayLevel.WARNING; } myDefaultState.setLevel(level); final String enabled = toolElement.getAttributeValue(ENABLED_ATTRIBUTE); final boolean isEnabled = enabled != null && Boolean.parseBoolean(enabled); final String enabledTool = toolElement.getAttributeValue(ENABLED_BY_DEFAULT_ATTRIBUTE); myDefaultState.setEnabled(enabledTool != null ? Boolean.parseBoolean(enabledTool) : isEnabled); final InspectionToolWrapper toolWrapper = myDefaultState.getTool(); final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE); final List<String> scopeNames = new ArrayList<String>(); for (Object sO : scopeElements) { final Element scopeElement = (Element) sO; final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME); if (scopeName == null) { continue; } final NamedScopesHolder scopesHolder = profileManager.getScopesManager(); NamedScope namedScope = null; if (scopesHolder != null) { namedScope = scopesHolder.getScope(scopeName); } final String errorLevel = scopeElement.getAttributeValue(LEVEL_ATTRIBUTE); final String enabledInScope = scopeElement.getAttributeValue(ENABLED_ATTRIBUTE); final InspectionToolWrapper copyToolWrapper = toolWrapper.createCopy(); // check if unknown children exists if (scopeElement.getAttributes().size() > 3 || !scopeElement.getChildren().isEmpty()) { copyToolWrapper.getTool().readSettings(scopeElement); } HighlightDisplayLevel scopeLevel = errorLevel != null ? HighlightDisplayLevel.find(registrar.getSeverity(errorLevel)) : null; if (scopeLevel == null) { scopeLevel = level; } if (namedScope != null) { addTool( namedScope, copyToolWrapper, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel); } else { addTool( scopeName, copyToolWrapper, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel); } scopeNames.add(scopeName); } for (int i = 0; i < scopeNames.size(); i++) { String scopeName = scopeNames.get(i); List<String> order = dependencies.get(scopeName); if (order == null) { order = new ArrayList<String>(); dependencies.put(scopeName, order); } for (int j = i + 1; j < scopeNames.size(); j++) { order.add(scopeNames.get(j)); } } // check if unknown children exists if (toolElement.getAttributes().size() > 4 || toolElement.getChildren().size() > scopeElements.size()) { toolWrapper.getTool().readSettings(toolElement); } myEnabled = isEnabled; }
private void exportResults( @NotNull final CommonProblemDescriptor[] descriptors, @NotNull RefEntity refEntity, @NotNull Element parentNode) { for (CommonProblemDescriptor descriptor : descriptors) { @NonNls final String template = descriptor.getDescriptionTemplate(); int line = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getLineNumber() : -1; final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : null; @NonNls String problemText = StringUtil.replace( StringUtil.replace( template, "#ref", psiElement != null ? ProblemDescriptorUtil.extractHighlightedText(descriptor, psiElement) : ""), " #loc ", " "); Element element = refEntity.getRefManager().export(refEntity, parentNode, line); if (element == null) return; @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag")); problemClassElement.addContent(myToolWrapper.getDisplayName()); final HighlightSeverity severity; if (refEntity instanceof RefElement) { final RefElement refElement = (RefElement) refEntity; severity = getSeverity(refElement); } else { final InspectionProfile profile = InspectionProjectProfileManager.getInstance(getContext().getProject()) .getInspectionProfile(); final HighlightDisplayLevel level = profile.getErrorLevel( HighlightDisplayKey.find(myToolWrapper.getShortName()), psiElement); severity = level.getSeverity(); } if (severity != null) { ProblemHighlightType problemHighlightType = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getHighlightType() : ProblemHighlightType.GENERIC_ERROR_OR_WARNING; final String attributeKey = getTextAttributeKey(getRefManager().getProject(), severity, problemHighlightType); problemClassElement.setAttribute("severity", severity.myName); problemClassElement.setAttribute("attribute_key", attributeKey); } element.addContent(problemClassElement); if (myToolWrapper instanceof GlobalInspectionToolWrapper) { final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper) myToolWrapper).getTool(); final QuickFix[] fixes = descriptor.getFixes(); if (fixes != null) { @NonNls Element hintsElement = new Element("hints"); for (QuickFix fix : fixes) { final String hint = globalInspectionTool.getHint(fix); if (hint != null) { @NonNls Element hintElement = new Element("hint"); hintElement.setAttribute("value", hint); hintsElement.addContent(hintElement); } } element.addContent(hintsElement); } } try { Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag")); descriptionElement.addContent(problemText); element.addContent(descriptionElement); } catch (IllegalDataException e) { //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr System.out.println( "Cannot save results for " + refEntity.getName() + ", inspection which caused problem: " + myToolWrapper.getShortName()); } } }