public static InspectionToolWrapper findTool2RunInBatch( @NotNull Project project, @Nullable PsiElement element, @NotNull String name) { final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); final InspectionToolWrapper toolWrapper = element == null ? inspectionProfile.getInspectionTool(name, project) : inspectionProfile.getInspectionTool(name, element); if (toolWrapper instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper) toolWrapper).isUnfair()) { final LocalInspectionTool inspectionTool = ((LocalInspectionToolWrapper) toolWrapper).getTool(); if (inspectionTool instanceof PairedUnfairLocalInspectionTool) { final String oppositeShortName = ((PairedUnfairLocalInspectionTool) inspectionTool).getInspectionForBatchShortName(); if (oppositeShortName != null) { return element == null ? inspectionProfile.getInspectionTool(oppositeShortName, project) : inspectionProfile.getInspectionTool(oppositeShortName, element); } } return null; } return toolWrapper; }
@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; }
protected void disableInspectionTool(@NotNull String shortName) { InspectionProfile profile = InspectionProjectProfileManager.getInstance(getProject()).getInspectionProfile(); if (profile.getInspectionTool(shortName, getProject()) != null) { ((InspectionProfileImpl) profile).disableTool(shortName, getProject()); } }
public boolean canCleanup(@NotNull PsiElement element) { if (myCanCleanup == null) { InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()) .getInspectionProfile(); final HighlightDisplayKey key = myKey; if (key == null) { myCanCleanup = false; } else { InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element); myCanCleanup = toolWrapper != null && toolWrapper.isCleanupTool(); } } return myCanCleanup; }
private static boolean isAvailable(PyCallExpression node) { final InspectionProfile profile = InspectionProjectProfileManager.getInstance(node.getProject()).getInspectionProfile(); final InspectionToolWrapper inspectionTool = profile.getInspectionTool("PyCompatibilityInspection", node.getProject()); if (inspectionTool != null) { final InspectionProfileEntry inspection = inspectionTool.getTool(); if (inspection instanceof PyCompatibilityInspection) { final JDOMExternalizableStringList versions = ((PyCompatibilityInspection) inspection).ourVersions; for (String s : versions) { if (!LanguageLevel.fromPythonVersion(s).supportsSetLiterals()) return false; } } } return LanguageLevel.forElement(node).supportsSetLiterals(); }
private void checkRequiredAttributes( XmlTag tag, String name, XmlElementDescriptor elementDescriptor) { XmlAttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributesDescriptors(tag); Set<String> requiredAttributes = null; for (XmlAttributeDescriptor attribute : attributeDescriptors) { if (attribute != null && attribute.isRequired()) { if (requiredAttributes == null) { requiredAttributes = new HashSet<String>(); } requiredAttributes.add(attribute.getName(tag)); } } if (requiredAttributes != null) { for (final String attrName : requiredAttributes) { if (tag.getAttribute(attrName, "") == null && !XmlExtension.getExtension(tag.getContainingFile()) .isRequiredAttributeImplicitlyPresent(tag, attrName)) { final InsertRequiredAttributeFix insertRequiredAttributeIntention = new InsertRequiredAttributeFix(tag, attrName, null); final String localizedMessage = XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName); final InspectionProfile profile = InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile(); final LocalInspectionToolWrapper toolWrapper = (LocalInspectionToolWrapper) profile.getInspectionTool(RequiredAttributesInspection.SHORT_NAME, tag); if (toolWrapper != null) { RequiredAttributesInspection inspection = (RequiredAttributesInspection) toolWrapper.getTool(); reportOneTagProblem( tag, attrName, localizedMessage, insertRequiredAttributeIntention, HighlightDisplayKey.find(RequiredAttributesInspection.SHORT_NAME), inspection, XmlEntitiesInspection.NOT_REQUIRED_ATTRIBUTE); } } } } }
@Nullable public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) { if (editor != null && Boolean.FALSE.equals( editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) { return null; } List<IntentionAction> options = myOptions; HighlightDisplayKey key = myKey; if (myProblemGroup != null) { String problemName = myProblemGroup.getProblemName(); HighlightDisplayKey problemGroupKey = problemName != null ? HighlightDisplayKey.findById(problemName) : null; if (problemGroupKey != null) { key = problemGroupKey; } } if (options != null || key == null) { return options; } IntentionManager intentionManager = IntentionManager.getInstance(); List<IntentionAction> newOptions = intentionManager.getStandardIntentionOptions(key, element); InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile(); InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element); if (!(toolWrapper instanceof LocalInspectionToolWrapper)) { HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString()); if (idkey != null) { toolWrapper = profile.getInspectionTool(idkey.toString(), element); } } if (toolWrapper != null) { myCanCleanup = toolWrapper.isCleanupTool(); ContainerUtil.addIfNotNull( newOptions, intentionManager.createFixAllIntention(toolWrapper, myAction)); InspectionProfileEntry wrappedTool = toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper) toolWrapper).getTool() : ((GlobalInspectionToolWrapper) toolWrapper).getTool(); if (wrappedTool instanceof CustomSuppressableInspectionTool) { final IntentionAction[] suppressActions = ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element); if (suppressActions != null) { ContainerUtil.addAll(newOptions, suppressActions); } } else { SuppressQuickFix[] suppressFixes = wrappedTool.getBatchSuppressActions(element); if (suppressFixes.length > 0) { ContainerUtil.addAll( newOptions, ContainerUtil.map( suppressFixes, new Function<SuppressQuickFix, IntentionAction>() { @Override public IntentionAction fun(SuppressQuickFix fix) { return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction( fix); } })); } } } if (myProblemGroup instanceof SuppressableProblemGroup) { final IntentionAction[] suppressActions = ((SuppressableProblemGroup) myProblemGroup).getSuppressActions(element); ContainerUtil.addAll(newOptions, suppressActions); } synchronized (this) { options = myOptions; if (options == null) { myOptions = options = newOptions; } myKey = null; } return options; }
@Nullable public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) { if (editor != null && Boolean.FALSE.equals( editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) { return null; } List<IntentionAction> options = myOptions; HighlightDisplayKey key = myKey; if (options != null || key == null) { return options; } List<IntentionAction> newOptions = IntentionManager.getInstance().getStandardIntentionOptions(key, element); InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile(); InspectionProfileEntry tool = profile.getInspectionTool(key.toString(), element); if (!(tool instanceof LocalInspectionToolWrapper)) { HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString()); if (idkey != null) { tool = profile.getInspectionTool(idkey.toString(), element); } } InspectionProfileEntry wrappedTool = tool; if (tool instanceof LocalInspectionToolWrapper) { wrappedTool = ((LocalInspectionToolWrapper) tool).getTool(); Class aClass = myAction.getClass(); if (myAction instanceof QuickFixWrapper) { aClass = ((QuickFixWrapper) myAction).getFix().getClass(); } newOptions.add(new CleanupInspectionIntention((LocalInspectionToolWrapper) tool, aClass)); } else if (tool instanceof GlobalInspectionToolWrapper) { wrappedTool = ((GlobalInspectionToolWrapper) tool).getTool(); if (wrappedTool instanceof GlobalSimpleInspectionTool && (myAction instanceof LocalQuickFix || myAction instanceof QuickFixWrapper)) { Class aClass = myAction.getClass(); if (myAction instanceof QuickFixWrapper) { aClass = ((QuickFixWrapper) myAction).getFix().getClass(); } newOptions.add( new CleanupInspectionIntention((GlobalInspectionToolWrapper) tool, aClass)); } } if (wrappedTool instanceof CustomSuppressableInspectionTool) { final IntentionAction[] suppressActions = ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element); if (suppressActions != null) { ContainerUtil.addAll(newOptions, suppressActions); } } if (wrappedTool instanceof BatchSuppressableTool) { final SuppressQuickFix[] suppressActions = ((BatchSuppressableTool) wrappedTool).getBatchSuppressActions(element); ContainerUtil.addAll( newOptions, ContainerUtil.map( suppressActions, new Function<SuppressQuickFix, IntentionAction>() { @Override public IntentionAction fun(SuppressQuickFix fix) { return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix); } })); } synchronized (this) { options = myOptions; if (options == null) { myOptions = options = newOptions; } myKey = null; } return options; }