IDEA-106103 XML editor: Allow highlighting of different namespace nodes in different colors: XSLT color page

This commit is contained in:
Dmitry Avdeev
2014-10-27 15:02:54 +04:00
parent e3faaf0442
commit f79ce8cc9e
5 changed files with 106 additions and 1 deletions
@@ -116,8 +116,8 @@
<lang.syntaxHighlighterFactory key="XHTML" implementationClass="com.intellij.lang.xhtml.XhtmlSyntaxHighlighterFactory"/>
<lang.syntaxHighlighterFactory key="DTD" implementationClass="com.intellij.lang.dtd.DtdSyntaxHighlighterFactory"/>
<annotator language="XML" implementationClass="com.intellij.codeInsight.daemon.impl.analysis.XmlNamespaceAnnotator"/>
<annotator language="XML" implementationClass="com.intellij.codeInsight.daemon.impl.analysis.XmlNsPrefixAnnotator"/>
<annotator language="XML" implementationClass="com.intellij.codeInsight.daemon.impl.analysis.XmlNamespaceAnnotator"/>
<renameHandler id="xmlTagRenameHandler" implementation="com.intellij.xml.refactoring.XmlTagRenameHandler"/>
<renameHandler implementation="com.intellij.xml.refactoring.SchemaPrefixRenameHandler" order="before xmlTagRenameHandler"/>
@@ -15,6 +15,8 @@
*/
package org.intellij.lang.xpath.xslt;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiElement;
@@ -47,6 +49,8 @@ public class XsltSupport {
public static final String XSLT_NS = "http://www.w3.org/1999/XSL/Transform";
public static final String PLUGIN_EXTENSIONS_NS = "urn:idea:xslt-plugin#extensions";
public static final Key<ParameterizedCachedValue<XsltChecker.LanguageLevel, PsiFile>> FORCE_XSLT_KEY = Key.create("FORCE_XSLT");
public static final TextAttributesKey XSLT_DIRECTIVE =
TextAttributesKey.createTextAttributesKey("XSLT_DIRECTIVE", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR);
private static final Map<String, String> XPATH_ATTR_MAP = new THashMap<String, String>(10);
private static final Map<String, Set<String>> XPATH_AVT_MAP = new THashMap<String, Set<String>>(10);
@@ -0,0 +1,61 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.intellij.lang.xpath.xslt.validation;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.pages.XMLColorsPage;
import org.intellij.lang.xpath.xslt.XsltSupport;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Map;
/**
* @author Dmitry Avdeev
*/
public class XsltColorPage extends XMLColorsPage {
@NotNull
@Override
public String getDisplayName() {
return "XSLT";
}
@NotNull
@Override
public AttributesDescriptor[] getAttributeDescriptors() {
return new AttributesDescriptor[] { new AttributesDescriptor("XSLT directive", XsltSupport.XSLT_DIRECTIVE)};
}
@NotNull
@Override
public String getDemoText() {
return "<xsl><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"></xsl>\n" +
" <xsl><xsl:template match=\"/hello-world\"></xsl>\n" +
" <html>\n" +
" <body>\n" +
" <xsl><xsl:value-of select=\"greeting\"/></xsl>\n" +
" </body>\n" +
" </html>\n" +
" <xsl></xsl:template></xsl>\n" +
"<xsl></xsl:stylesheet></xsl>";
}
@Override
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return Collections.singletonMap("xsl", XsltSupport.XSLT_DIRECTIVE);
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.intellij.lang.xpath.xslt.validation;
import com.intellij.codeInsight.daemon.impl.analysis.XmlNSColorProvider;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import org.intellij.lang.xpath.xslt.XsltSupport;
import org.jetbrains.annotations.Nullable;
/**
* @author Dmitry Avdeev
*/
public class XsltNSColorProvider implements XmlNSColorProvider {
@Nullable
@Override
public TextAttributesKey getKeyForNamespace(String namespace, XmlElement context) {
if (!(context instanceof XmlTag)) return null;
if (XsltSupport.XSLT_NS.equals(((XmlTag)context).getNamespace())) return XsltSupport.XSLT_DIRECTIVE;
return null;
}
}
@@ -145,6 +145,9 @@
<annotator language="XPath" implementationClass="org.intellij.lang.xpath.xslt.validation.XsltAnnotator"/>
<annotator language="XML" implementationClass="org.intellij.lang.xpath.xslt.validation.XsltXmlAnnotator"/>
<xml.nsColorProvider implementation="org.intellij.lang.xpath.xslt.validation.XsltNSColorProvider"/>
<colorSettingsPage implementation="org.intellij.lang.xpath.xslt.validation.XsltColorPage"/>
<lang.documentationProvider language="XML" implementationClass="org.intellij.lang.xpath.xslt.impl.XsltDocumentationProvider"/>
<lang.documentationProvider language="XPath" implementationClass="org.intellij.lang.xpath.xslt.impl.XsltDocumentationProvider"/>