diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings index 7aecb25d4b0006126cf5e460d0f4675f5bfe8dcf..4d53ae602cf2a4142cbca9352f96882befce8fe9 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings @@ -2,6 +2,6 @@ AdvancedTreeViewerEditorBase.java 9d9eded6848ee78991d1416592d1136efd71d2b7 GREEN FormsEditorBase.java b113501b98ffffcac362ca9f474ad02a42bde186 GREEN GEFEditorBase.java e668f596f45f07215994cbbd3929a9438331718f GREEN SourceEditorBase.java 47e69e2e6788b9897339c384cd03f9a22755037c GREEN -SourceEditorConfigurationBase.java e8b810c0d974c475f0a8e6f21aa5b6fd9e17c33a GREEN +SourceEditorConfigurationBase.java 67c674248e31d467937ed33e455c07587ad0b3b1 GREEN SourceEditorUndoRedo.java 08127a8e0afb4f9c2f4c21294ca3220282c25bf0 GREEN TreeViewerEditorBase.java 1c59689ff57c4f3cc180d85f13021fc03461ecb0 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/SourceEditorConfigurationBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/SourceEditorConfigurationBase.java index e8b810c0d974c475f0a8e6f21aa5b6fd9e17c33a..67c674248e31d467937ed33e455c07587ad0b3b1 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/SourceEditorConfigurationBase.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/SourceEditorConfigurationBase.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2012 fortiss GmbH | +| Copyright 2023 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -19,6 +19,7 @@ import static java.lang.Character.isLetterOrDigit; import static org.eclipse.jface.text.IDocument.DEFAULT_CONTENT_TYPE; import static org.eclipse.wb.swt.SWTResourceManager.getColor; +import java.util.ArrayList; import java.util.List; import org.eclipse.emf.ecore.EObject; @@ -29,6 +30,7 @@ import org.eclipse.jface.text.rules.IRule; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.ITokenScanner; import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.PatternRule; import org.eclipse.jface.text.rules.RuleBasedScanner; import org.eclipse.jface.text.rules.WordRule; import org.eclipse.jface.text.source.IAnnotationHover; @@ -53,12 +55,21 @@ public abstract class SourceEditorConfigurationBase<T extends EObject> this.editor = editor; } - /** Color constant used to display code dark red. */ + /** Color constant used to display code in dark red. */ protected Color DARK_RED = getColor(128, 0, 0); - /** Color constant used to display code dark blue. */ + /** Color constant used to display code in dark blue. */ protected Color DARK_BLUE = getColor(0, 0, 128); + /** Color constant used to display comments (green). */ + protected Color COMMENT_COLOR = getColor(0, 148, 0); + + /** Identifier for the start of a comment. */ + public static final String COMMENT_START_IDENTIFIER = "/*"; + + /** Identifier for the end of a comment. */ + public static final String COMMENT_END_IDENTIFIER = "*/"; + /** Detector used to create the scanners. */ protected IWordDetector detector = new IWordDetector() { /** {@inheritDoc} */ @@ -99,10 +110,17 @@ public abstract class SourceEditorConfigurationBase<T extends EObject> /** Returns the rule based scanner. */ private RuleBasedScanner getScannerForSyntaxHighlighting() { - List<WordRule> rules = getCommonRules(); - rules.add(getRuleSpecificToEditor()); + List<IRule> allRules = new ArrayList<IRule>(); + + allRules.addAll(getCommonRules()); + allRules.add(getRuleSpecificToEditor()); + allRules.add(getCommentRuleSpecificToEditor()); + + IRule[] rules = allRules.toArray(new IRule[0]); + RuleBasedScanner scanner = new RuleBasedScanner(); - scanner.setRules(rules.toArray(new IRule[0])); + scanner.setRules(rules); + return scanner; } @@ -112,6 +130,9 @@ public abstract class SourceEditorConfigurationBase<T extends EObject> /** Returns a rule specific to the editor. */ abstract protected WordRule getRuleSpecificToEditor(); + /** Returns the comment rule specific to the editor. */ + abstract protected PatternRule getCommentRuleSpecificToEditor(); + /** Adds the words to the rule with the given token. */ protected void addWordsToRule(List<String> words, WordRule rule, IToken token) { for(String word : words) {