Browse Source

add syntax highlighting for deprecated FeatureType and FeatureParameter

Flow.Antony@googlemail.com 11 years ago
parent
commit
75fd58866e

+ 7 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/SGenUiModule.java

@@ -12,12 +12,14 @@ import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider;
 import org.eclipse.xtext.ui.editor.model.IResourceForEditorInputFactory;
 import org.eclipse.xtext.ui.editor.model.JavaClassPathResourceForIEditorInputFactory;
 import org.eclipse.xtext.ui.editor.model.ResourceForIEditorInputFactory;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
 import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
 import org.eclipse.xtext.ui.resource.IResourceSetProvider;
 import org.eclipse.xtext.ui.resource.SimpleResourceSetProvider;
 import org.eclipse.xtext.ui.resource.XtextResourceSetProvider;
 import org.eclipse.xtext.ui.shared.Access;
 import org.yakindu.sct.generator.genmodel.ui.help.SGenUserHelpDocumentationProvider;
+import org.yakindu.sct.generator.genmodel.ui.highlighting.SGenHighlightingConfiguration;
 import org.yakindu.sct.generator.genmodel.ui.highlighting.SGenSemanticHighlightingCalculator;
 import org.yakindu.sct.generator.genmodel.ui.templates.SGenTemplateProposalProvider;
 
@@ -37,6 +39,10 @@ public class SGenUiModule extends
 		return SGenSemanticHighlightingCalculator.class;
 	}
 
+	public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration() {
+		return SGenHighlightingConfiguration.class;
+	}
+
 	public Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProvider() {
 		return SGenUserHelpDocumentationProvider.class;
 	}
@@ -59,6 +65,7 @@ public class SGenUiModule extends
 		return SGenTemplateProposalProvider.class;
 	}
 
+	@Override
 	public com.google.inject.Provider<org.eclipse.xtext.resource.containers.IAllContainersState> provideIAllContainersState() {
 		return Access.getWorkspaceProjectsState();
 	}

+ 25 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/highlighting/SGenHighlightingConfiguration.java

@@ -0,0 +1,25 @@
+package org.yakindu.sct.generator.genmodel.ui.highlighting;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor;
+import org.eclipse.xtext.ui.editor.utils.TextStyle;
+
+public class SGenHighlightingConfiguration extends
+		DefaultHighlightingConfiguration {
+
+	public static final String DEPRECATION = "deprecation";
+
+	@Override
+	public void configure(IHighlightingConfigurationAcceptor acceptor) {
+		super.configure(acceptor);
+		acceptor.acceptDefaultHighlighting(DEPRECATION, "Deprecation",
+				deprecationTextStyle());
+	}
+
+	public TextStyle deprecationTextStyle() {
+		TextStyle textStyle = defaultTextStyle().copy();
+		textStyle.setStyle(SWT.UNDERLINE_SQUIGGLE);
+		return textStyle;
+	}
+}

+ 24 - 1
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/highlighting/SGenSemanticHighlightingCalculator.java

@@ -11,8 +11,10 @@ import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
 import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
 import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
+import org.yakindu.sct.model.sgen.DeprecatableElement;
 import org.yakindu.sct.model.sgen.GeneratorEntry;
 import org.yakindu.sct.model.sgen.SGenPackage;
+import org.yakindu.sct.model.sgen.impl.FeatureConfigurationImpl;
 
 public class SGenSemanticHighlightingCalculator implements
 		ISemanticHighlightingCalculator {
@@ -21,14 +23,16 @@ public class SGenSemanticHighlightingCalculator implements
 			IHighlightedPositionAcceptor acceptor) {
 		if (resource == null || resource.getParseResult() == null)
 			return;
-
 		TreeIterator<EObject> allContents = resource.getAllContents();
 		while (allContents.hasNext()) {
 			final EObject object = allContents.next();
 			if (object instanceof GeneratorEntry) {
 				GeneratorEntry entry = (GeneratorEntry) object;
+
 				List<INode> nodes = NodeModelUtils.findNodesForFeature(entry,
 						SGenPackage.Literals.GENERATOR_ENTRY__CONTENT_TYPE);
+				List<INode> features = NodeModelUtils.findNodesForFeature(
+						entry, SGenPackage.Literals.GENERATOR_ENTRY__FEATURES);
 				for (INode node : nodes) {
 					if (node instanceof LeafNode
 							&& !((LeafNode) node).isHidden()) {
@@ -37,6 +41,25 @@ public class SGenSemanticHighlightingCalculator implements
 								DefaultHighlightingConfiguration.KEYWORD_ID);
 					}
 				}
+				for (INode node : features) {
+					if (node.getSemanticElement() instanceof FeatureConfigurationImpl) {
+						FeatureConfigurationImpl feature = (FeatureConfigurationImpl) node
+								.getSemanticElement();
+						if (feature.getType() instanceof DeprecatableElement) {
+
+							DeprecatableElement deprecatableElement = feature
+									.getType();
+							if (deprecatableElement.isDeprecated()) {
+								acceptor.addPosition(
+										node.getTotalOffset(),
+										node.getTotalLength(),
+										SGenHighlightingConfiguration.DEPRECATION);
+							}
+						}
+
+					}
+
+				}
 				allContents.prune();
 			}
 		}