[256339]: Migrate XSL Syntax Highlighting to Semantic Highlighting
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256339
diff --git a/bundles/org.eclipse.wst.xsl.ui/plugin.xml b/bundles/org.eclipse.wst.xsl.ui/plugin.xml
index 234f132..af6abd6 100644
--- a/bundles/org.eclipse.wst.xsl.ui/plugin.xml
+++ b/bundles/org.eclipse.wst.xsl.ui/plugin.xml
@@ -283,5 +283,37 @@
<contentType id="org.eclipse.wst.xml.core.xslsource" />
</adapterFactoryDescription>
</extension>
+ <extension
+ point="org.eclipse.wst.sse.ui.semanticHighlighting">
+ <highlighting
+ class="org.eclipse.wst.xsl.ui.internal.style.XSLTagNameSemanticHighlighting"
+ target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xslsource"
+ styleStringKey="xsltagName">
+ </highlighting>
+ </extension>
+ <extension
+ point="org.eclipse.wst.sse.ui.semanticHighlighting">
+ <highlighting
+ class="org.eclipse.wst.xsl.ui.internal.style.XSLAttrNameSemanticHighlighting"
+ target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xslsource"
+ styleStringKey="xsltagAttributeName">
+ </highlighting>
+ </extension>
+<extension
+ point="org.eclipse.wst.sse.ui.semanticHighlighting">
+ <highlighting
+ class="org.eclipse.wst.xsl.ui.internal.style.XSLAttrValueSemanticHighlighting"
+ target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xslsource"
+ styleStringKey="xsltagAttributeValue">
+ </highlighting>
+ </extension>
+ <extension
+ point="org.eclipse.wst.sse.ui.semanticHighlighting">
+ <highlighting
+ class="org.eclipse.wst.xsl.ui.internal.style.XSLTagDelimsSemanticHighlighting"
+ target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xslsource"
+ styleStringKey="xsltagBorder">
+ </highlighting>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/StructuredTextViewerConfigurationXSL.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/StructuredTextViewerConfigurationXSL.java
index ccbd41b..5ba9168 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/StructuredTextViewerConfigurationXSL.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/StructuredTextViewerConfigurationXSL.java
@@ -107,15 +107,15 @@
return fConfiguredContentTypes;
}
- @Override
- public LineStyleProvider[] getLineStyleProviders(
- ISourceViewer sourceViewer, String partitionType) {
- LineStyleProvider[] providers = null;
- if (isXMLPartition(partitionType)) {
- providers = new LineStyleProvider[] {getLineStyleProviderForXSL()};
- }
- return providers;
- }
+// @Override
+// public LineStyleProvider[] getLineStyleProviders(
+// ISourceViewer sourceViewer, String partitionType) {
+// LineStyleProvider[] providers = null;
+// if (isXMLPartition(partitionType)) {
+// providers = new LineStyleProvider[] {getLineStyleProviderForXSL()};
+// }
+// return providers;
+// }
private boolean isXMLPartition(String partitionType) {
return partitionType.equals(IXMLPartitions.XML_DEFAULT)
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/preferences/XSLUIPreferenceInitializer.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/preferences/XSLUIPreferenceInitializer.java
index 63694ce..cf76b08 100755
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/preferences/XSLUIPreferenceInitializer.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/preferences/XSLUIPreferenceInitializer.java
@@ -22,7 +22,7 @@
import org.eclipse.wst.xsl.ui.internal.style.IStyleConstantsXSL;
/**
- * Sets default values for XML UI preferences
+ * Sets default values for XSL UI preferences
*/
public class XSLUIPreferenceInitializer extends AbstractPreferenceInitializer {
@@ -52,5 +52,18 @@
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXSL.TAG_NAME, 63, 127, 127) + BOLD;
store.setDefault(IStyleConstantsXSL.TAG_NAME, styleValue);
+ store.setDefault("xsl.ui.highlighting.tag.bold", true); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.tag.italic", false); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.tag.strikethrough", false); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.tag.underline", false); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.tag.enabled", true); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.tag.color", "#FF00FF"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ store.setDefault("xsl.ui.highlighting.attr.bold", true); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.attr.italic", false); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.attr.strikethrough", false); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.attr.underline", false); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.attr.enabled", true); //$NON-NLS-1$
+ store.setDefault("xsl.ui.highlighting.attr.color", "#FF00FF"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/AbstractXSLSemanticHighlighting.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/AbstractXSLSemanticHighlighting.java
new file mode 100644
index 0000000..7430e0f
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/AbstractXSLSemanticHighlighting.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intalio, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Carver (Intalio) - bug 256339 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.ui.internal.style;
+
+import java.util.ArrayList;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.Position;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.sse.ui.ISemanticHighlighting;
+import org.eclipse.wst.sse.ui.ISemanticHighlightingExtension;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.eclipse.wst.xsl.core.XSLCore;
+import org.eclipse.wst.xsl.ui.internal.XSLUIPlugin;
+
+public abstract class AbstractXSLSemanticHighlighting implements
+ ISemanticHighlightingExtension, ISemanticHighlighting {
+
+ public abstract String getStylePreferenceKey();
+
+ public String getBoldPreferenceKey() {
+ return null;
+ }
+
+ public String getUnderlinePreferenceKey() {
+ return null;
+ }
+
+ public String getStrikethroughPreferenceKey() {
+ return null;
+ }
+
+ public String getItalicPreferenceKey() {
+ return null;
+ }
+
+ public String getColorPreferenceKey() {
+ return null;
+ }
+
+ public IPreferenceStore getPreferenceStore() {
+ return XSLUIPlugin.getDefault().getPreferenceStore();
+ }
+
+ public String getEnabledPreferenceKey() {
+ return null;
+ }
+
+ public String getDisplayName() {
+ return null;
+ }
+
+ public abstract Position[] consumes(IStructuredDocumentRegion region);
+
+ protected Position[] createSemanticPositions(IStructuredDocumentRegion region, String regionType) {
+ if (region == null) {
+ return null;
+ }
+
+ if (!region.getType().equals(DOMRegionContext.XML_TAG_NAME)) {
+ return null;
+ }
+
+ Position p[] = null;
+ ITextRegionList regionList = region.getRegions();
+ ITextRegion tagRegion = regionList.get(1);
+
+ ArrayList arrpos = new ArrayList();
+ for (int i = 0; i < regionList.size(); i++) {
+ ITextRegion textRegion = regionList.get(i);
+ if (textRegion.getType().equals(regionType)) {
+ Position pos = new Position(region
+ .getStartOffset(textRegion), textRegion.getLength());
+ arrpos.add(pos);
+ }
+ }
+ p = new Position[arrpos.size()];
+ arrpos.toArray(p);
+ return p;
+ }
+
+ public Position[] consumes(IStructuredDocumentRegion documentRegion, IndexedRegion indexedRegion) {
+ if (indexedRegion != null && indexedRegion instanceof IDOMNode) {
+ IDOMNode node = (IDOMNode)indexedRegion;
+ if (XSLCore.isXSLNamespace(node)) {
+ return consumes(documentRegion);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/LineStyleProviderForXSL.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/LineStyleProviderForXSL.java
index ca234c8..3099d46 100755
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/LineStyleProviderForXSL.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/LineStyleProviderForXSL.java
@@ -45,8 +45,9 @@
*
* @author David Carver
* @since 1.0
- *
+ * @deprecated Use AbstractXSLSemanticHighlighting and the SemanticHighlighting extension point
*/
+@Deprecated
public class LineStyleProviderForXSL extends AbstractLineStyleProvider implements LineStyleProvider {
protected IStructuredDocument structuredDocument;
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLAttrNameSemanticHighlighting.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLAttrNameSemanticHighlighting.java
new file mode 100644
index 0000000..cc39c52
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLAttrNameSemanticHighlighting.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intalio, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Carver (Intalio) - bug 256339 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.ui.internal.style;
+
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.ui.ISemanticHighlighting;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+
+public class XSLAttrNameSemanticHighlighting extends
+ AbstractXSLSemanticHighlighting implements ISemanticHighlighting {
+
+ public XSLAttrNameSemanticHighlighting() {
+ }
+
+ public String getStylePreferenceKey() {
+ return IStyleConstantsXSL.TAG_ATTRIBUTE_VALUE;
+ }
+
+ @Override
+ public String getEnabledPreferenceKey() {
+ return "xsl.ui.highlighting.tag.enabled"; //$NON-NLS-1$
+ }
+
+ public Position[] consumes(IStructuredDocumentRegion region) {
+ return createSemanticPositions(region,
+ DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE);
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLAttrValueSemanticHighlighting.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLAttrValueSemanticHighlighting.java
new file mode 100644
index 0000000..a577a8b
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLAttrValueSemanticHighlighting.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intalio, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Carver (Intalio) - bug 256339 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.ui.internal.style;
+
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.ui.ISemanticHighlighting;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+
+public class XSLAttrValueSemanticHighlighting extends
+ AbstractXSLSemanticHighlighting implements ISemanticHighlighting {
+
+ public XSLAttrValueSemanticHighlighting() {
+ }
+
+ public String getStylePreferenceKey() {
+ return IStyleConstantsXSL.TAG_ATTRIBUTE_VALUE;
+ }
+
+ @Override
+ public String getEnabledPreferenceKey() {
+ return "xsl.ui.highlighting.tag.enabled"; //$NON-NLS-1$
+ }
+
+ public Position[] consumes(IStructuredDocumentRegion region) {
+ return createSemanticPositions(region,
+ DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE);
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLTagDelimsSemanticHighlighting.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLTagDelimsSemanticHighlighting.java
new file mode 100644
index 0000000..bbdc681
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLTagDelimsSemanticHighlighting.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intalio, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Carver (Intalio) - bug 256339 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.ui.internal.style;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.sse.ui.ISemanticHighlighting;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+
+public class XSLTagDelimsSemanticHighlighting extends
+ AbstractXSLSemanticHighlighting implements ISemanticHighlighting {
+
+ public XSLTagDelimsSemanticHighlighting() {
+ }
+
+ public String getStylePreferenceKey() {
+ return IStyleConstantsXSL.TAG_BORDER;
+ }
+
+ @Override
+ public String getEnabledPreferenceKey() {
+ return "xsl.ui.highlighting.tag.enabled"; //$NON-NLS-1$
+ }
+
+ public Position[] consumes(IStructuredDocumentRegion region) {
+
+ Position[] openPos = createSemanticPositions(region.getFirstRegion(), region, DOMRegionContext.XML_TAG_OPEN);
+ Position[] endOpenPos = createSemanticPositions(region.getFirstRegion(), region, DOMRegionContext.XML_END_TAG_OPEN);
+ Position[] emptyTagClose = createSemanticPositions(region, DOMRegionContext.XML_EMPTY_TAG_CLOSE);
+ Position[] closePos = createSemanticPositions(region, DOMRegionContext.XML_TAG_CLOSE);
+ ArrayList arrpos = new ArrayList();
+ arrpos.addAll(Arrays.asList(openPos));
+ arrpos.addAll(Arrays.asList(closePos));
+ arrpos.addAll(Arrays.asList(endOpenPos));
+ arrpos.addAll(Arrays.asList(emptyTagClose));
+ Position[] allPos = new Position[arrpos.size()];
+ arrpos.toArray(allPos);
+ return allPos;
+ }
+
+ protected Position[] createSemanticPositions(ITextRegion textRegion, IStructuredDocumentRegion region, String regionType) {
+ if (textRegion == null) {
+ return null;
+ }
+
+ Position p[] = null;
+
+ ArrayList arrpos = new ArrayList();
+ if (textRegion.getType().equals(regionType)) {
+ Position pos = new Position(region
+ .getStartOffset(textRegion), textRegion.getLength());
+ arrpos.add(pos);
+ }
+ p = new Position[arrpos.size()];
+ arrpos.toArray(p);
+ return p;
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLTagNameSemanticHighlighting.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLTagNameSemanticHighlighting.java
new file mode 100644
index 0000000..fc029b5
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/style/XSLTagNameSemanticHighlighting.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intalio, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Carver (Intalio) - bug 256339 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.ui.internal.style;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.ui.ISemanticHighlighting;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+
+public class XSLTagNameSemanticHighlighting extends AbstractXSLSemanticHighlighting implements ISemanticHighlighting {
+
+ public XSLTagNameSemanticHighlighting() {
+ }
+
+ public String getStylePreferenceKey() {
+ return IStyleConstantsXSL.TAG_NAME;
+ }
+
+ @Override
+ public String getEnabledPreferenceKey() {
+ return "xsl.ui.highlighting.tag.enabled"; //$NON-NLS-1$
+ }
+
+ public Position[] consumes(IStructuredDocumentRegion region) {
+ return createSemanticPositions(region, DOMRegionContext.XML_TAG_NAME);
+ }
+}