Search in sources :

Example 1 with InspectionProfile

use of com.intellij.codeInspection.InspectionProfile in project intellij-community by JetBrains.

the class AddCustomHtmlElementIntentionAction method applyFix.

@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
    profile.modifyToolSettings(myInspectionKey, element, tool -> tool.addEntry(myName));
}
Also used : InspectionProfile(com.intellij.codeInspection.InspectionProfile) PsiElement(com.intellij.psi.PsiElement)

Example 2 with InspectionProfile

use of com.intellij.codeInspection.InspectionProfile in project intellij-community by JetBrains.

the class AddHtmlTagOrAttributeToCustomsIntention method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
    profile.modifyToolSettings(myInspectionKey, descriptor.getPsiElement().getContainingFile(), entry -> {
        XmlEntitiesInspection xmlEntitiesInspection = (XmlEntitiesInspection) entry;
        xmlEntitiesInspection.addEntry(myName);
    });
}
Also used : InspectionProfile(com.intellij.codeInspection.InspectionProfile)

Example 3 with InspectionProfile

use of com.intellij.codeInspection.InspectionProfile in project intellij-community by JetBrains.

the class DomHighlightingLiteTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myInspectionProfile = new MockInspectionProfile();
    myAnnotationsManager = new DomElementAnnotationsManagerImpl(getProject()) {

        @Override
        protected InspectionProfile getInspectionProfile(final DomFileElement fileElement) {
            return myInspectionProfile;
        }
    };
    final XmlFile file = createXmlFile("<a/>");
    final MockDomElement rootElement = new MockDomElement() {

        @Override
        @Nullable
        public XmlElement getXmlElement() {
            return getXmlTag();
        }

        @Override
        public XmlTag getXmlTag() {
            return file.getRootTag();
        }

        @NotNull
        @Override
        public Type getDomElementType() {
            return DomElement.class;
        }
    };
    myElement = new MockDomFileElement() {

        @Override
        @Nullable
        public XmlElement getXmlElement() {
            return file;
        }

        @Override
        @NotNull
        public XmlFile getFile() {
            return file;
        }

        @Override
        public DomElement getParent() {
            return null;
        }

        @Override
        @NotNull
        public DomElement getRootElement() {
            return rootElement;
        }

        @NotNull
        @Override
        public Class getRootElementClass() {
            return DomElement.class;
        }

        @Override
        public boolean isValid() {
            return true;
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) MockInspectionProfile(com.intellij.mock.MockInspectionProfile) InspectionProfile(com.intellij.codeInspection.InspectionProfile) NotNull(org.jetbrains.annotations.NotNull) MockInspectionProfile(com.intellij.mock.MockInspectionProfile) XmlElement(com.intellij.psi.xml.XmlElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with InspectionProfile

use of com.intellij.codeInspection.InspectionProfile in project intellij-community by JetBrains.

the class XmlTagInsertHandler method addRequiredAttributes.

@Nullable
private static StringBuilder addRequiredAttributes(XmlElementDescriptor descriptor, @Nullable XmlTag tag, Template template, PsiFile containingFile) {
    boolean htmlCode = HtmlUtil.hasHtml(containingFile) || HtmlUtil.supportsXmlTypedHandlers(containingFile);
    Set<String> notRequiredAttributes = Collections.emptySet();
    if (tag instanceof HtmlTag) {
        final InspectionProfile profile = InspectionProjectProfileManager.getInstance(tag.getProject()).getCurrentProfile();
        XmlEntitiesInspection inspection = (XmlEntitiesInspection) profile.getUnwrappedTool(XmlEntitiesInspection.REQUIRED_ATTRIBUTES_SHORT_NAME, tag);
        if (inspection != null) {
            StringTokenizer tokenizer = new StringTokenizer(inspection.getAdditionalEntries());
            notRequiredAttributes = new HashSet<>();
            while (tokenizer.hasMoreElements()) notRequiredAttributes.add(tokenizer.nextToken());
        }
    }
    XmlAttributeDescriptor[] attributes = descriptor.getAttributesDescriptors(tag);
    StringBuilder indirectRequiredAttrs = null;
    if (WebEditorOptions.getInstance().isAutomaticallyInsertRequiredAttributes()) {
        final XmlExtension extension = XmlExtension.getExtension(containingFile);
        for (XmlAttributeDescriptor attributeDecl : attributes) {
            String attributeName = attributeDecl.getName(tag);
            boolean shouldBeInserted = extension.shouldBeInserted(attributeDecl);
            if (shouldBeInserted && (tag == null || tag.getAttributeValue(attributeName) == null)) {
                if (!notRequiredAttributes.contains(attributeName)) {
                    if (!extension.isIndirectSyntax(attributeDecl)) {
                        template.addTextSegment(" " + attributeName + "=" + XmlAttributeInsertHandler.getAttributeQuote(htmlCode));
                        template.addVariable(new MacroCallNode(new CompleteMacro()), true);
                        template.addTextSegment(XmlAttributeInsertHandler.getAttributeQuote(htmlCode));
                    } else {
                        if (indirectRequiredAttrs == null)
                            indirectRequiredAttrs = new StringBuilder();
                        indirectRequiredAttrs.append("\n<jsp:attribute name=\"").append(attributeName).append("\"></jsp:attribute>\n");
                    }
                }
            } else if (shouldBeInserted && attributeDecl.isFixed() && attributeDecl.getDefaultValue() != null && !htmlCode) {
                template.addTextSegment(" " + attributeName + "=" + XmlAttributeInsertHandler.getAttributeQuote(false) + attributeDecl.getDefaultValue() + XmlAttributeInsertHandler.getAttributeQuote(false));
            }
        }
    }
    return indirectRequiredAttrs;
}
Also used : InspectionProfile(com.intellij.codeInspection.InspectionProfile) HtmlTag(com.intellij.psi.html.HtmlTag) CompleteMacro(com.intellij.codeInsight.template.macro.CompleteMacro) MacroCallNode(com.intellij.codeInsight.template.impl.MacroCallNode) XmlEntitiesInspection(com.intellij.codeInspection.htmlInspections.XmlEntitiesInspection) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with InspectionProfile

use of com.intellij.codeInspection.InspectionProfile in project intellij-community by JetBrains.

the class PyCompatibilityInspectionAdvertiser method isCompatibilityInspectionEnabled.

private static boolean isCompatibilityInspectionEnabled(@NotNull PsiElement anchor) {
    final InspectionProfile profile = InspectionProfileManager.getInstance(anchor.getProject()).getCurrentProfile();
    final InspectionToolWrapper tool = profile.getInspectionTool(getCompatibilityInspectionShortName(), anchor.getProject());
    return tool != null && profile.isToolEnabled(HighlightDisplayKey.findById(tool.getID()), anchor);
}
Also used : InspectionProfile(com.intellij.codeInspection.InspectionProfile) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Aggregations

InspectionProfile (com.intellij.codeInspection.InspectionProfile)28 Nullable (org.jetbrains.annotations.Nullable)10 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)7 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)6 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 UnusedDeclarationInspectionBase (com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase)2 InspectionManagerEx (com.intellij.codeInspection.ex.InspectionManagerEx)2 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)2 Language (com.intellij.lang.Language)2 Module (com.intellij.openapi.module.Module)2 InspectionProjectProfileManager (com.intellij.profile.codeInspection.InspectionProjectProfileManager)2 ProjectInspectionProfileManager (com.intellij.profile.codeInspection.ProjectInspectionProfileManager)2 PsiElement (com.intellij.psi.PsiElement)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ActionEvent (java.awt.event.ActionEvent)2 AnalysisScope (com.intellij.analysis.AnalysisScope)1