[Text-UI] Improve type safety of token data of TextStyleManager

Follow-up-to: 7b9c6940ea4a784b401ff606d6fbc93360706f61
Change-Id: I4f7343981ee12709fa26d392e3be43e2d34e2a27
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractRuleBasedScanner.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractRuleBasedScanner.java
index 6f2dc67..2b4e57d 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractRuleBasedScanner.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractRuleBasedScanner.java
@@ -19,10 +19,11 @@
 
 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
 import org.eclipse.jface.text.rules.IRule;
-import org.eclipse.jface.text.rules.IToken;
 
 import org.eclipse.statet.jcommons.lang.NonNullByDefault;
 
+import org.eclipse.statet.ecommons.text.ui.presentation.TextStyleManager.TextStyleToken;
+
 
 /**
  * BufferedRuleBasedScanner with managed text styles/tokens.
@@ -31,10 +32,10 @@
 public abstract class AbstractRuleBasedScanner extends BufferedRuleBasedScanner {
 	
 	
-	private final TextStyleManager textStyles;
+	private final TextStyleManager<?> textStyles;
 	
 	
-	public AbstractRuleBasedScanner(final TextStyleManager textStyles) {
+	public AbstractRuleBasedScanner(final TextStyleManager<?> textStyles) {
 		this.textStyles= textStyles;
 	}
 	
@@ -48,7 +49,7 @@
 	protected abstract void createRules(final List<IRule> rules);
 	
 	
-	protected IToken getToken(final String key) {
+	protected TextStyleToken<?> getToken(final String key) {
 		return this.textStyles.getToken(key);
 	}
 	
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractTextStylesConfigurationBlock.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractTextStylesConfigurationBlock.java
index 1e0557c..82e04a1 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractTextStylesConfigurationBlock.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/AbstractTextStylesConfigurationBlock.java
@@ -531,7 +531,7 @@
 	private Button strikethroughCheckbox;
 	private Button underlineCheckbox;
 	
-	private PreferenceStoreTextStyleManager textStyles;
+	private PreferenceStoreTextStyleManager<TextAttribute> textStyles;
 	
 	protected SourceViewer previewViewer;
 	private SourceEditorViewerConfiguration configuration;
@@ -725,7 +725,8 @@
 	}
 	
 	protected abstract SourceEditorViewerConfiguration getSourceEditorViewerConfiguration(
-			IPreferenceStore preferenceStore, PreferenceStoreTextStyleManager textStyles);
+			IPreferenceStore preferenceStore,
+			PreferenceStoreTextStyleManager<TextAttribute> textStyles);
 	
 	protected abstract IDocumentSetupParticipant getDocumentSetupParticipant();
 	
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/BasicTextStyleManager.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/BasicTextStyleManager.java
index b714947..634a2a1 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/BasicTextStyleManager.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/BasicTextStyleManager.java
@@ -17,17 +17,58 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.Token;
-
 import org.eclipse.statet.jcommons.lang.NonNullByDefault;
 
 
 @NonNullByDefault
-public abstract class BasicTextStyleManager<TAttributes> implements TextStyleManager {
+public abstract class BasicTextStyleManager<TStyleData> implements TextStyleManager<TStyleData> {
 	
 	
-	private final Map<String, Token> tokenMap= new HashMap<>();
+	protected static class BasicTextStyleToken<TStyleData> implements TextStyleToken<TStyleData> {
+		
+		
+		private TStyleData data;
+		
+		
+		public BasicTextStyleToken(final TStyleData data) {
+			this.data= data;
+		}
+		
+		
+		protected void setData(final TStyleData data) {
+			this.data= data;
+		}
+		
+		
+		@Override
+		public boolean isUndefined() {
+			return false;
+		}
+		
+		@Override
+		public boolean isWhitespace() {
+			return false;
+		}
+		
+		@Override
+		public boolean isEOF() {
+			return false;
+		}
+		
+		@Override
+		public boolean isOther() {
+			return false;
+		}
+		
+		@Override
+		public TStyleData getData() {
+			return this.data;
+		}
+		
+	}
+	
+	
+	private final Map<String, BasicTextStyleToken<TStyleData>> tokenMap= new HashMap<>();
 	
 	
 	public BasicTextStyleManager() {
@@ -41,21 +82,21 @@
 	 * @return token with text style attribute
 	 */
 	@Override
-	public IToken getToken(final String key) {
-		Token token= this.tokenMap.get(key);
+	public TextStyleToken<TStyleData> getToken(final String key) {
+		BasicTextStyleToken<TStyleData> token= this.tokenMap.get(key);
 		if (token == null) {
-			token= new Token(createTextAttributes(key));
+			token= new BasicTextStyleToken<>(createStyleData(key));
 			this.tokenMap.put(key, token);
 		}
 		return token;
 	}
 	
-	protected abstract TAttributes createTextAttributes(String key);
+	protected abstract TStyleData createStyleData(String key);
 	
 	
 	protected void updateTextStyles() {
-		for (final Map.Entry<String, Token> token : this.tokenMap.entrySet()) {
-			token.getValue().setData(createTextAttributes(token.getKey()));
+		for (final var token : this.tokenMap.entrySet()) {
+			token.getValue().setData(createStyleData(token.getKey()));
 		}
 	}
 	
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/FixTokenScanner.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/FixTokenScanner.java
index 9097d79..a4b3e0c 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/FixTokenScanner.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/FixTokenScanner.java
@@ -30,7 +30,7 @@
 public class FixTokenScanner implements ITokenScanner {
 	
 	
-	private final TextStyleManager textStyles;
+	private final TextStyleManager<?> textStyles;
 	private final IToken defaultToken;
 	
 	private ImList<ITypedRegion> styleRegions;
@@ -44,7 +44,7 @@
 	private int tokenLength;
 	
 	
-	public FixTokenScanner(final TextStyleManager textStyles, final String defaultTokenKey) {
+	public FixTokenScanner(final TextStyleManager<?> textStyles, final String defaultTokenKey) {
 		this.textStyles= textStyles;
 		this.defaultToken= textStyles.getToken(defaultTokenKey);
 		
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/SingleTokenScanner.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/SingleTokenScanner.java
index 1f244a6..8235ba6 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/SingleTokenScanner.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/SingleTokenScanner.java
@@ -29,7 +29,7 @@
 	private static final byte DEFAULT= 1;
 	
 	
-	private final TextStyleManager textStyles;
+	private final TextStyleManager<?> textStyles;
 	
 	private final IToken defaultToken;
 	
@@ -39,7 +39,7 @@
 	private byte state;
 	
 	
-	public SingleTokenScanner(final TextStyleManager textStyles, final String defaultTokenKey) {
+	public SingleTokenScanner(final TextStyleManager<?> textStyles, final String defaultTokenKey) {
 		this.textStyles= textStyles;
 		
 		this.defaultToken= this.textStyles.getToken(defaultTokenKey);
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/TextStyleManager.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/TextStyleManager.java
index 2b905c0..fc20024 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/TextStyleManager.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/presentation/TextStyleManager.java
@@ -20,7 +20,16 @@
 
 
 @NonNullByDefault
-public interface TextStyleManager {
+public interface TextStyleManager<TStyleData> {
+	
+	
+	public interface TextStyleToken<TStyleData> extends IToken {
+		
+		
+		@Override
+		public TStyleData getData();
+		
+	}
 	
 	
 	/**
@@ -29,7 +38,7 @@
 	 * @param key id and prefix for preference keys
 	 * @return token with text style attribute
 	 */
-	public IToken getToken(String key);
+	public TextStyleToken<TStyleData> getToken(String key);
 	
 	
 }
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/CssTextStyleManager.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/CssTextStyleManager.java
index 957f22b..22f03fe 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/CssTextStyleManager.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/CssTextStyleManager.java
@@ -65,8 +65,14 @@
 	}
 	
 	
+	@SuppressWarnings("null")
+	public TextStyleToken<String> getRootStyleToken() {
+		return getToken(ROOT_STYLE_KEY);
+	}
+	
+	
 	@Override
-	protected @Nullable String createTextAttributes(String key) {
+	protected @Nullable String createStyleData(String key) {
 		if (key != ROOT_STYLE_KEY) {
 			key= resolveUsedKey(key);
 			if (key.equals(this.defaultStyleKey)) {
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/JFaceTextStyleManager.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/JFaceTextStyleManager.java
index fa7cfe2..abed68e 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/JFaceTextStyleManager.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/JFaceTextStyleManager.java
@@ -37,7 +37,7 @@
 	
 	
 	@Override
-	protected TextAttribute createTextAttributes(String key) {
+	protected TextAttribute createStyleData(String key) {
 		key= resolveUsedKey(key);
 		
 		final RGB rgb= PreferenceConverter.getColor(this.preferenceStore, key + ITextPresentationConstants.TEXTSTYLE_COLOR_SUFFIX);
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/PreferenceStoreTextStyleManager.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/PreferenceStoreTextStyleManager.java
index 6e96b8d..0baedf8 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/PreferenceStoreTextStyleManager.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ecommons/text/ui/settings/PreferenceStoreTextStyleManager.java
@@ -20,6 +20,7 @@
 import org.eclipse.jface.preference.IPreferenceStore;
 
 import org.eclipse.statet.jcommons.lang.NonNullByDefault;
+import org.eclipse.statet.jcommons.lang.Nullable;
 
 import org.eclipse.statet.ecommons.preferences.SettingsChangeNotifier.ManageListener;
 import org.eclipse.statet.ecommons.text.ui.presentation.BasicTextStyleManager;
@@ -66,14 +67,15 @@
 	 * @since 3.0
 	 */
 	@Override
-	protected abstract TAttributes createTextAttributes(String key);
+	protected abstract TAttributes createStyleData(String key);
 	
 	
 	public boolean affectsTextPresentation(final Set<String> groupIds) {
 		return (groupIds.contains(this.stylesGroupId));
 	}
 	
-	public void handleSettingsChanged(final Set<String> groupIds, final Map<String, Object> options) {
+	public void handleSettingsChanged(final Set<String> groupIds,
+			final @Nullable Map<String, Object> options) {
 		if (affectsTextPresentation(groupIds)) {
 			updateTextStyles();
 			if (options != null) {
diff --git a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/SourceEditorViewerConfiguration.java b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/SourceEditorViewerConfiguration.java
index ee59a02..a5a437d 100644
--- a/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/SourceEditorViewerConfiguration.java
+++ b/ltk/org.eclipse.statet.ltk.ui/src/org/eclipse/statet/ltk/ui/sourceediting/SourceEditorViewerConfiguration.java
@@ -45,6 +45,7 @@
 import org.eclipse.jface.text.ITextHover;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.TextAttribute;
 import org.eclipse.jface.text.contentassist.IContentAssistant;
 import org.eclipse.jface.text.information.IInformationPresenter;
 import org.eclipse.jface.text.information.IInformationProvider;
@@ -173,7 +174,7 @@
 	
 	private final SourceEditor editor;
 	
-	private PreferenceStoreTextStyleManager textStyles;
+	private PreferenceStoreTextStyleManager<TextAttribute> textStyles;
 	private final CopyOnWriteIdentityListSet<ISettingsChangedHandler> settingsHandler= new CopyOnWriteIdentityListSet<>();
 	
 	private Map<String, ITokenScanner> scanners;
@@ -218,11 +219,11 @@
 	protected void initTextStyles() {
 	}
 	
-	protected void setTextStyles(final PreferenceStoreTextStyleManager textStyles) {
+	protected void setTextStyles(final PreferenceStoreTextStyleManager<TextAttribute> textStyles) {
 		this.textStyles= textStyles;
 	}
 	
-	protected TextStyleManager getTextStyles() {
+	protected TextStyleManager<TextAttribute> getTextStyles() {
 		if (this.textStyles == null) {
 			initTextStyles();
 		}