From 33d1aea326c6cf4e501bf01320a13afba1472137 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 19 Nov 2021 12:19:25 +0100 Subject: [PATCH 001/202] Release Notes for 4.4 --- RELEASE_NOTES.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index cfb94193e..8588d5df6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,12 +4,34 @@ This page describes the noteworthy improvements provided by each release of Ecli ### Next release... -## 0.4.3 +### 0.4.4 + +### Latest release * 📅 Release Date (tentative): ? +* All changes: https://github.com/eclipse/tm4e/compare/0.4.3...master + +## 0.4.3 + +* 📅 Release Date: 19th November 2021 * All changes: https://github.com/eclipse/tm4e/compare/0.4.2...0.4.3 -### Latest release +#### Support locations outside a local file system + +This allows to have syntax highlighting for buffers that are not backed by a filesystem locations. + +#### Compatible with viewers that are not IProjectionViewer + +Avoid an exception making TM4E incompatible with most simple ITextViewer in some case. + +#### Fix content-type detection + +Parent content-type are taken into account and allow to enable syntax highlighting for the children of content-types which are bound to a grammar/scope as well, without extra configuration. + +#### Choose default theme according to background color of the widget + +By default, TM4E now decides of the best theme to use according to the background color of the text widget. This allows to get a better text theme when mixing dark global them with light background or editor, or light global theme with dark background in editor. + ## 0.4.2 From d0c57533206cb0f5e48baed973b499ec0ee5ac07 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:18:30 +0100 Subject: [PATCH 002/202] Remove unnecessary cast --- .../tm4e/ui/internal/text/StyleRangesCollector.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java index f343ee66d..2f52559ca 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java @@ -1,9 +1,9 @@ /** * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -27,7 +27,7 @@ public class StyleRangesCollector implements ITMPresentationReconcilerListener { private Command command; private Integer waitForToLineNumber; private boolean isFinished; - + private StringBuilder currentRanges; private Object lock = new Object(); @@ -61,7 +61,7 @@ public void colorize(TextPresentation presentation, Throwable error) { e.printStackTrace(); } } - ((Command) command).setStyleRanges("[" + currentRanges.toString() + "]"); + command.setStyleRanges("[" + currentRanges.toString() + "]"); synchronized (lock) { lock.notifyAll(); } From db9a97d1687fb7bd8312475e1ef741f4c81d856a Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:19:33 +0100 Subject: [PATCH 003/202] Remove unnecessary semicolons --- .../core/internal/oniguruma/OnigString.java | 2 +- .../eclipse/tm4e/core/model/DecodeMap.java | 32 +++++++++---------- .../AbstractGrammarRegistryManager.java | 10 +++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java index b8c91e5b9..989c430b5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java @@ -105,7 +105,7 @@ public int convertUtf8OffsetToUtf16(int posInBytes) { private void computeOffsets() { if (this.utf8_value.length != this.string.length()) { charsPosFromBytePos = new int[this.utf8_value.length]; - int bytesLen = 0;; + int bytesLen = 0; int charsLen = 0; int length = this.utf8_value.length; for (int i = 0; i < length;) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java index 3500e4448..70557bc90 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java @@ -1,18 +1,18 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/Microsoft/vscode-textmate/ + * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. + * Initial license: MIT + * + * Contributors: + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.model; @@ -25,7 +25,7 @@ class DecodeMap { Map scopeToTokenIds; Map tokenToTokenId; Map tokenIdToToken; - TMTokenDecodeData prevToken;; + TMTokenDecodeData prevToken; public DecodeMap() { this.lastAssignedId = 0; diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java index e204b6188..3cc8e1ff5 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java @@ -1,9 +1,9 @@ /** * Copyright (c) 2015-2019 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -58,7 +58,7 @@ public InputStream getInputStream(String scopeName) throws IOException { IGrammarDefinition info = registry.getDefinition(scopeName); return info != null ? info.getInputStream() : null; } - }; + } public AbstractGrammarRegistryManager() { this(new EclipseRegistryOptions()); From f97944f6d5824a8d5217913763ff26b89b726ed0 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:20:28 +0100 Subject: [PATCH 004/202] Remove unnecessary @SuppressWarnings annotation --- .../preferences/LanguageConfigurationPreferencePage.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java index 7e6c15741..ada5331eb 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java @@ -1,9 +1,9 @@ /** * Copyright (c) 2015-2018 Angelo ZERR and others. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -258,7 +258,6 @@ private int computeMinimumColumnWidth(GC gc, String string) { * * @return list of selected definitions which was created by the user. */ - @SuppressWarnings("unchecked") private Collection getSelectedUserDefinitions() { IStructuredSelection selection = definitionViewer.getStructuredSelection(); if (selection.isEmpty()) { From 1c390fb24044489ccd1b2bf40fd750e5722d654d Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:21:10 +0100 Subject: [PATCH 005/202] Use try-with-resources --- .../src/main/java/org/eclipse/tm4e/core/registry/Registry.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index 19a6e2e50..264c0fe5e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -98,8 +98,7 @@ private IGrammar _loadGrammar(String initialScopeName) { continue; } - try { - InputStream in = this.locator.getInputStream(scopeName); + try (InputStream in = this.locator.getInputStream(scopeName)) { IRawGrammar grammar = GrammarReader.readGrammarSync(filePath, in); Collection injections = this.locator.getInjections(scopeName); From 66afbabf4f55e9f33756cfa3bffaa302179e1fbd Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:23:47 +0100 Subject: [PATCH 006/202] Fix @link type reference --- .../org/eclipse/tm4e/ui/text/TMPresentationReconciler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index e9168969d..93248095f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -84,7 +84,7 @@ * *
    *
  • a TextMate grammar {@link IGrammar} used to initialize the TextMate model - * {@link ITMDocumentModel}.
  • + * {@link TMDocumentModel}. *
  • a token provider {@link ITokenProvider} to retrieve the {@link IToken} * from a TextMate token type .
  • *
@@ -762,7 +762,7 @@ public static TMPresentationReconciler getTMPresentationReconciler(ITextViewer t // that was available at the current build. This code also works with any implementation that follows the // internal structure if also an ITextViewer. //If these assumptions are false, the method should return null. Logging causes repeat noise. - } + } return null; } From 5ae948e8e6b0ab2646b3af034ec7046df80ba4d7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:26:03 +0100 Subject: [PATCH 007/202] Fix warning "ListenerList is a raw type. References to generic type ListenerList should be parameterized" --- .../eclipse/tm4e/ui/utils/ContentTypeHelper.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java index eff03af33..e2d41511b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java @@ -44,7 +44,7 @@ public class ContentTypeHelper { /** * Find the content types from the given {@link IDocument} and null otherwise. - * + * * @param document * @return the content types from the given {@link IDocument} and null * otherwise. @@ -62,7 +62,7 @@ public static ContentTypeInfo findContentTypes(IDocument document) throws CoreEx /** * Find the content type with the given contentTypeId - * + * * @param contentTypeId * @return matching content type or null */ @@ -76,7 +76,7 @@ public static IContentType getContentTypeById(String contentTypeId) { /** * Find the content types from the given {@link IDocument} by using * {@link ITextFileBufferManager} and null otherwise. - * + * * @param document * @return the content types from the given {@link IDocument} by using * {@link ITextFileBufferManager} and null otherwise. @@ -93,7 +93,7 @@ private static ContentTypeInfo findContentTypesFromFileBuffers(IDocument documen /** * Returns the content types from the given {@link ITextFileBuffer}. - * + * * @param buffer * @return the content types from the given {@link ITextFileBuffer}. * @throws CoreException @@ -133,7 +133,7 @@ private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws Co /** * Returns the content of the given buffer. - * + * * @param buffer * @return the content of the given buffer. * @throws CoreException @@ -155,7 +155,7 @@ private static InputStream getContents(ITextFileBuffer buffer) throws CoreExcept /** * Find the content types from the given {@link IDocument} by using * {@link IEditorInput} and null otherwise. - * + * * @param document * @return the content types from the given {@link IDocument} by using * {@link IEditorInput} and null otherwise. @@ -189,7 +189,7 @@ private static ContentTypeInfo findContentTypesFromEditorInput(IDocument documen /** * Returns the {@link IEditorInput} from the given document and null otherwise. - * + * * @param document * @return the {@link IEditorInput} from the given document and null otherwise. */ @@ -205,7 +205,7 @@ private static IEditorInput getEditorInput(IDocument document) { // ISorageEditorInput, see StorageDocumentProvider) // get list of IDocumentListener - ListenerList listeners = ClassHelper.getFieldValue(document, "fDocumentListeners"); + ListenerList listeners = ClassHelper.getFieldValue(document, "fDocumentListeners"); if (listeners != null) { // Get AbstractDocumentProvider#ElementInfo Object[] l = listeners.getListeners(); From 5a4dc5683e8b206847e12e2c039213035f6433b3 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:28:32 +0100 Subject: [PATCH 008/202] add missing @SuppressWarnings("unchecked") --- .../main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java index ab86f0fb4..dc7496a25 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java @@ -1,9 +1,9 @@ /** * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -19,6 +19,7 @@ */ public class ClassHelper { + @SuppressWarnings("unchecked") public static T getFieldValue(Object object, String name, Class clazz) { Field f = getDeclaredField(clazz, name); if (f != null) { From 96e77dec1b60125c030b54c8d5e714e90c91b9c7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 3 Dec 2021 22:31:44 +0100 Subject: [PATCH 009/202] Fix javadoc parameters --- .../LanguageConfigurationImportWizard.java | 2 +- .../tm4e/registry/GrammarDefinition.java | 14 +++++----- .../org/eclipse/tm4e/registry/TMResource.java | 10 +++---- .../tm4e/ui/internal/snippets/Snippet.java | 12 ++++---- .../org/eclipse/tm4e/ui/themes/Theme.java | 12 ++++---- .../tm4e/ui/themes/ThemeAssociation.java | 28 +++++++++---------- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java index 914f5b1a0..ca757e9aa 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java @@ -46,7 +46,7 @@ public LanguageConfigurationImportWizard(boolean save) { /** * Set registry to use to add the created grammar definitions. * - * @param grammarRegistryManager + * @param registryManager */ public void setRegistryManager(ILanguageConfigurationRegistryManager registryManager) { this.registryManager = registryManager; diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java index 9685cb0d3..a067c4dbe 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java @@ -1,9 +1,9 @@ /** * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -16,7 +16,7 @@ /** * Grammar definition defined by the "org.eclipse.tm4e.registry.grammars" * extension point. Here a sample to register TypeScript TextMate grammar. - * + * *
  * 
@@ -41,8 +41,8 @@ public GrammarDefinition() {
 
 	/**
 	 * Constructor for extension point.
-	 * 
-	 * @param element
+	 *
+	 * @param scopeName
 	 */
 	public GrammarDefinition(String scopeName, String path) {
 		super(path);
diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java
index 8c4e77a87..94d3ed259 100644
--- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java
+++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -40,7 +40,7 @@ public TMResource() {
 	/**
 	 * Constructor for extension point.
 	 *
-	 * @param element
+	 * @param path
 	 */
 	public TMResource(String path) {
 		this.path = path;
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java
index 1068a4535..0c9ae773c 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -30,8 +30,8 @@ public Snippet() {
 
 	/**
 	 * Constructor for extension point.
-	 * 
-	 * @param element
+	 *
+	 * @param scopeName
 	 */
 	public Snippet(String scopeName, String path, String name) {
 		super(path);
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java
index df2873c18..df11feea7 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -48,8 +48,8 @@ public Theme() {
 
 	/**
 	 * Constructor for extension point.
-	 * 
-	 * @param element
+	 *
+	 * @param id
 	 */
 	public Theme(String id, String path, String name, boolean dark, boolean isDefault) {
 		super(path);
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java
index 69783db51..14c165bbd 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -11,10 +11,10 @@
  */
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -24,10 +24,10 @@
 
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -59,10 +59,10 @@ public ThemeAssociation() {
 
 	/**
 	 * Constructor to register theme associations for a given scope name.
-	 * 
+	 *
 	 * @param themeId
-	 * @param eclipseThemeId
 	 * @param scopeName
+	 * @param whenDark
 	 */
 	public ThemeAssociation(String themeId, String scopeName, boolean whenDark) {
 		this.themeId = themeId;

From 7cdc027e00055b1bb63dd55d8f75eb616d7067f7 Mon Sep 17 00:00:00 2001
From: sebthom 
Date: Fri, 3 Dec 2021 22:36:18 +0100
Subject: [PATCH 010/202] add missing @Override annotations

---
 .../css/AbstractCombinatorCondition.java      |  9 +--
 .../tm4e/core/internal/css/CSSValueImpl.java  | 62 ++++---------------
 .../tm4e/core/internal/css/Measure.java       | 25 +++-----
 .../tm4e/core/internal/css/RGBColorImpl.java  | 34 +++-------
 4 files changed, 31 insertions(+), 99 deletions(-)

diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java
index cb6dbf062..80b5d732d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -37,6 +37,7 @@ public Condition getSecondCondition() {
 		return secondCondition;
 	}
 
+	@Override
 	public int getSpecificity() {
 		return ((ExtendedCondition) getFirstCondition()).getSpecificity()
 				+ ((ExtendedCondition) getSecondCondition()).getSpecificity();
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java
index e085f8bf6..b6f58b6e1 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java
@@ -22,30 +22,18 @@ public abstract class CSSValueImpl implements CSSPrimitiveValue, CSSValue {
 
 	// W3C CSSValue API methods
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSValue#getCssText()
-	 */
+	@Override
 	public String getCssText() {
 		// TODO Auto-generated method stub
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSValue#getCssValueType()
-	 */
+	@Override
 	public short getCssValueType() {
 		return CSS_PRIMITIVE_VALUE;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSValue#setCssText(java.lang.String)
-	 */
+	@Override
 	public void setCssText(String cssText) throws DOMException {
 		// TODO Auto-generated method stub
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
@@ -53,69 +41,40 @@ public void setCssText(String cssText) throws DOMException {
 
 	// W3C CSSPrimitiveValue API methods
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()
-	 */
+	@Override
 	public short getPrimitiveType() {
 		// TODO Auto-generated method stub
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#getCounterValue()
-	 */
+	@Override
 	public Counter getCounterValue() throws DOMException {
 		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "COUNTER_ERROR");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#getRGBColorValue()
-	 */
+	@Override
 	public RGBColor getRGBColorValue() throws DOMException {
 		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "RGBCOLOR_ERROR");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#getRectValue()
-	 */
+	@Override
 	public Rect getRectValue() throws DOMException {
 		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "RECT_ERROR");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#getStringValue()
-	 */
+	@Override
 	public String getStringValue() throws DOMException {
 		// TODO Auto-generated method stub
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short, float)
-	 */
+	@Override
 	public void setFloatValue(short arg0, float arg1) throws DOMException {
 		// TODO Auto-generated method stub
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,
-	 * java.lang.String)
-	 */
+	@Override
 	public void setStringValue(short arg0, String arg1) throws DOMException {
 		// TODO Auto-generated method stub
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
@@ -123,6 +82,7 @@ public void setStringValue(short arg0, String arg1) throws DOMException {
 
 	// Additional methods
 
+	@Override
 	public float getFloatValue(short valueType) throws DOMException {
 		// TODO Auto-generated method stub
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java
index 4ca24ad7f..fc51fccee 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java
@@ -4,7 +4,7 @@
  * 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:
  *      IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -26,11 +26,12 @@ public Measure(LexicalUnit value) {
 
 	/**
 	 * Return a float representation of the receiver's value.
-	 * 
+	 *
 	 * @param valueType
 	 *            a short representing the value type, see
 	 *            {@link CSSValue#getCssValueType()}
 	 */
+	@Override
 	public float getFloatValue(short valueType) throws DOMException {
 		// If it's actually a SAC_INTEGER return the integer value, callers tend
 		// to expect and cast
@@ -48,7 +49,7 @@ public float getFloatValue(short valueType) throws DOMException {
 
 	/**
 	 * Return an int representation of the receiver's value.
-	 * 
+	 *
 	 * @param valueType
 	 *            a short representing the value type, see
 	 *            {@link CSSValue#getCssValueType()}
@@ -57,11 +58,7 @@ public int getIntegerValue(short valueType) throws DOMException {
 		return value.getIntegerValue();
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#getStringValue()
-	 */
+	@Override
 	public String getStringValue() throws DOMException {
 		short lexicalUnit = value.getLexicalUnitType();
 		if ((lexicalUnit == LexicalUnit.SAC_IDENT) || (lexicalUnit == LexicalUnit.SAC_STRING_VALUE)
@@ -71,11 +68,7 @@ public String getStringValue() throws DOMException {
 		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()
-	 */
+	@Override
 	public short getPrimitiveType() {
 		switch (value.getLexicalUnitType()) {
 		case LexicalUnit.SAC_IDENT:
@@ -112,11 +105,7 @@ public short getPrimitiveType() {
 				"NOT YET IMPLEMENTED - LexicalUnit type: " + value.getLexicalUnitType());
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.dom.css.CSSValue#getCssText()
-	 */
+	@Override
 	public String getCssText() {
 		// TODO: All LexicalUnit.SAC_OPERATOR_* except for COMMA left undone for
 		// now as it's not even clear whether they should be treated as measures
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
index 636c46d03..13fb8a64d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
@@ -21,7 +21,7 @@ public class RGBColorImpl extends CSSValueImpl implements RGBColor {
 	private CSSPrimitiveValue red;
 	private CSSPrimitiveValue green;
 	private CSSPrimitiveValue blue;
-	
+
 	public RGBColorImpl(LexicalUnit lexicalUnit) {
 		LexicalUnit nextUnit = lexicalUnit.getParameters();
 		red = new Measure(nextUnit);
@@ -31,50 +31,32 @@ public RGBColorImpl(LexicalUnit lexicalUnit) {
 		blue = new Measure(nextUnit);
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.w3c.dom.css.RGBColor#getRed()
-	 */
+	@Override
 	public CSSPrimitiveValue getRed() {
 		return red;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.w3c.dom.css.RGBColor#getGreen()
-	 */
+	@Override
 	public CSSPrimitiveValue getGreen() {
 		return green;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.w3c.dom.css.RGBColor#getBlue()
-	 */
+	@Override
 	public CSSPrimitiveValue getBlue() {
 		return blue;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.w3c.dom.css.CSSValue#getRGBColorValue()
-	 */
+	@Override
 	public RGBColor getRGBColorValue() throws DOMException {
 		return this;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.w3c.dom.css.CSSValue#getPrimitiveType()
-	 */
+	@Override
 	public short getPrimitiveType() {
 		return CSS_RGBCOLOR;
 	}
-	
-	/*
-	 * (non-Javadoc)
-	 * @see org.w3c.dom.css.CSSValue#getCssText()
-	 */
+
+	@Override
 	public String getCssText() {
 		return "rgb(" + red.getCssText() + ", " + green.getCssText() + ", "
 				+ blue.getCssText() + ")";

From 48bcb32615061f5040e1527381df4e56e516dfd0 Mon Sep 17 00:00:00 2001
From: sebthom 
Date: Sat, 4 Dec 2021 13:03:59 +0100
Subject: [PATCH 011/202] bump versions

---
 org.eclipse.tm4e.core/META-INF/MANIFEST.MF                  | 2 +-
 org.eclipse.tm4e.core/pom.xml                               | 2 +-
 org.eclipse.tm4e.feature/feature.xml                        | 2 +-
 org.eclipse.tm4e.feature/pom.xml                            | 2 +-
 org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF | 2 +-
 org.eclipse.tm4e.languageconfiguration/pom.xml              | 2 +-
 org.eclipse.tm4e.registry/META-INF/MANIFEST.MF              | 2 +-
 org.eclipse.tm4e.registry/pom.xml                           | 2 +-
 org.eclipse.tm4e.ui/META-INF/MANIFEST.MF                    | 2 +-
 org.eclipse.tm4e.ui/pom.xml                                 | 2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF
index 41cdec9dd..7af9b5720 100644
--- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tm4e.core
-Bundle-Version: 0.4.3.qualifier
+Bundle-Version: 0.4.4.qualifier
 Require-Bundle: org.apache.batik.css;bundle-version="1.9.1";resolution:=optional,
  org.apache.batik.util;bundle-version="1.9.1";resolution:=optional,
  com.google.gson;resolution:=optional,
diff --git a/org.eclipse.tm4e.core/pom.xml b/org.eclipse.tm4e.core/pom.xml
index c882d2ab5..f4241abff 100644
--- a/org.eclipse.tm4e.core/pom.xml
+++ b/org.eclipse.tm4e.core/pom.xml
@@ -2,7 +2,7 @@
   4.0.0
   org.eclipse.tm4e.core
   eclipse-plugin
-  0.4.3-SNAPSHOT
+  0.4.4-SNAPSHOT
   
     org.eclipse
     org.eclipse.tm4e
diff --git a/org.eclipse.tm4e.feature/feature.xml b/org.eclipse.tm4e.feature/feature.xml
index 3a72d29f5..41a74fd68 100644
--- a/org.eclipse.tm4e.feature/feature.xml
+++ b/org.eclipse.tm4e.feature/feature.xml
@@ -2,7 +2,7 @@
 
diff --git a/org.eclipse.tm4e.feature/pom.xml b/org.eclipse.tm4e.feature/pom.xml
index 3c1cc94e0..f46e34610 100644
--- a/org.eclipse.tm4e.feature/pom.xml
+++ b/org.eclipse.tm4e.feature/pom.xml
@@ -7,5 +7,5 @@
   
   org.eclipse.tm4e.feature
   eclipse-feature
-  0.4.4-SNAPSHOT
+  0.4.5-SNAPSHOT
 
diff --git a/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF b/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF
index 16c5017ea..8c40e17c8 100644
--- a/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF
+++ b/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tm4e.languageconfiguration;singleton:=true
-Bundle-Version: 0.4.0.qualifier
+Bundle-Version: 0.4.1.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Require-Bundle: org.eclipse.jface.text,
  org.eclipse.ui.genericeditor,
diff --git a/org.eclipse.tm4e.languageconfiguration/pom.xml b/org.eclipse.tm4e.languageconfiguration/pom.xml
index 8726c136b..dc41a526e 100644
--- a/org.eclipse.tm4e.languageconfiguration/pom.xml
+++ b/org.eclipse.tm4e.languageconfiguration/pom.xml
@@ -2,7 +2,7 @@
   4.0.0
   org.eclipse.tm4e.languageconfiguration
   eclipse-plugin
-  0.4.0-SNAPSHOT
+  0.4.1-SNAPSHOT
   
     org.eclipse
     org.eclipse.tm4e
diff --git a/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF b/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF
index 738661f85..8d718c40a 100644
--- a/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF
+++ b/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-SymbolicName: org.eclipse.tm4e.registry;singleton:=true
-Bundle-Version: 0.5.0.qualifier
+Bundle-Version: 0.5.1.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Require-Bundle: org.eclipse.tm4e.core,
  org.eclipse.core.runtime,
diff --git a/org.eclipse.tm4e.registry/pom.xml b/org.eclipse.tm4e.registry/pom.xml
index b06147cff..83044e50d 100644
--- a/org.eclipse.tm4e.registry/pom.xml
+++ b/org.eclipse.tm4e.registry/pom.xml
@@ -2,7 +2,7 @@
   4.0.0
   org.eclipse.tm4e.registry
   eclipse-plugin
-  0.5.0-SNAPSHOT
+  0.5.1-SNAPSHOT
   
     org.eclipse
     org.eclipse.tm4e
diff --git a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF
index 9ebf3cd00..f18dbd9e7 100644
--- a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tm4e.ui;singleton:=true
-Bundle-Version: 0.5.0.qualifier
+Bundle-Version: 0.5.1.qualifier
 Require-Bundle: org.eclipse.tm4e.core,
  org.eclipse.jface.text,
  org.eclipse.core.runtime,
diff --git a/org.eclipse.tm4e.ui/pom.xml b/org.eclipse.tm4e.ui/pom.xml
index d93101e23..e7b771348 100644
--- a/org.eclipse.tm4e.ui/pom.xml
+++ b/org.eclipse.tm4e.ui/pom.xml
@@ -2,7 +2,7 @@
   4.0.0
   org.eclipse.tm4e.ui
   eclipse-plugin
-  0.5.0-SNAPSHOT
+  0.5.1-SNAPSHOT
   
     org.eclipse
     org.eclipse.tm4e

From 2c990b736ce90a1cd7f42aac3def4ab0de09e8fe Mon Sep 17 00:00:00 2001
From: sebthom 
Date: Sat, 4 Dec 2021 13:27:38 +0100
Subject: [PATCH 012/202] add GHA builds

---
 .github/workflows/build.yml                   | 87 +++++++++++++++++++
 README.md                                     |  3 +
 .../META-INF/MANIFEST.MF                      |  2 +-
 org.eclipse.tm4e.markdown/pom.xml             |  2 +-
 org.eclipse.tm4e.samples/META-INF/MANIFEST.MF |  2 +-
 org.eclipse.tm4e.samples/pom.xml              |  2 +-
 6 files changed, 94 insertions(+), 4 deletions(-)
 create mode 100644 .github/workflows/build.yml

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 000000000..6c52987a8
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,87 @@
+# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
+name: Build
+
+on:
+  push:
+    branches:     # build all branches
+    - '**'
+    tags-ignore:  # but don't build tags
+    - '**'
+    paths-ignore:
+    - '**/*.md'
+    - '.github/*.yml'
+  pull_request:
+  workflow_dispatch:
+    # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
+    inputs:
+      additional_maven_args:
+        description: 'Additional Maven Args'
+        required: false
+        default: ''
+
+defaults:
+  run:
+    shell: bash
+
+jobs:
+
+  build:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Git Checkout
+      uses: actions/checkout@v2 #https://github.com/actions/checkout
+
+    - name: Set up JDK 11
+      uses: actions/setup-java@v2 # https://github.com/actions/setup-java
+      with:
+        distribution: 'zulu'
+        java-version: 11
+
+    - name: Install xvfb
+      run: sudo apt-get install -o Acquire::Retries=3 --no-install-recommends -y xvfb
+
+    - name: "Cache: Local Maven Repository"
+      uses: actions/cache@v2
+      with:
+        path: |
+          ~/.m2/repository
+          !~/.m2/**/*SNAPSHOT*
+        key: ${{ runner.os }}-mvnrepo-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('**/target-platform/tm4e-target.target') }}
+        restore-keys: |
+          ${{ runner.os }}-mvnrepo-
+
+    - name: Set up Maven
+      uses: stCarolas/setup-maven@v4.2
+      with:
+        maven-version: 3.8.2
+
+
+    - name: Build with Maven
+      id: maven-build
+      run: |
+        set -eu
+
+        MAVEN_OPTS="${MAVEN_OPTS:-}"
+        MAVEN_OPTS="$MAVEN_OPTS -XX:+TieredCompilation -XX:TieredStopAtLevel=1" # https://zeroturnaround.com/rebellabs/your-maven-build-is-slow-speed-it-up/
+        MAVEN_OPTS="$MAVEN_OPTS -Djava.security.egd=file:/dev/./urandom" # https://stackoverflow.com/questions/58991966/what-java-security-egd-option-is-for/59097932#59097932
+        MAVEN_OPTS="$MAVEN_OPTS -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS" # https://stackoverflow.com/questions/5120470/how-to-time-the-different-stages-of-maven-execution/49494561#49494561
+        MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dhttps.protocols=TLSv1.2"
+        echo "  -> MAVEN_OPTS: $MAVEN_OPTS"
+        export MAVEN_OPTS
+
+        # prevent "org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]"
+        xvfb-run mvn \
+          --errors \
+          --update-snapshots \
+          --batch-mode \
+          --show-version \
+          --no-transfer-progress \
+          ${{ github.event.inputs.additional_maven_args }} \
+          clean verify
+
+    - name: "Delete intermediate build artifacts"
+      uses: geekyeggo/delete-artifact@1-glob-support # https://github.com/GeekyEggo/delete-artifact/
+      with:
+        name: "*"
+        useGlob: true
+        failOnError: false
diff --git a/README.md b/README.md
index d0b6e7172..f2aef8091 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
 # Eclipse tm4e - TextMate and language-configuration support for Java and in Eclipse IDE
 
+[![Build Status](https://github.com/eclipse/tm4e/actions/workflows/build.yml/badge.svg)](https://github.com/eclipse/tm4e/actions/workflows/build.yml)
+[![License](https://img.shields.io/github/license/eclipse/tm4e.svg?color=blue)](LICENSE)
+
 TM4E brings Java API to tokenize textual documents according to TextMate grammars with an Eclipse IDE client that can do syntax highlighting according to this tokenization; and Eclipse IDE client for  VSCode [Language Configuration](https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages) to support matching bracket, auto close, on enter support.
 
 `tm4e` is an [official Eclipse.org project](https://projects.eclipse.org/projects/technology.tm4e) so it conforms to typical Eclipse.org requirements and guarantees.
diff --git a/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF b/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF
index 9f7a22989..e669c8696 100644
--- a/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF
+++ b/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tm4e.markdown;singleton:=true
-Bundle-Version: 0.3.5.qualifier
+Bundle-Version: 0.3.6.qualifier
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.tm4e.core,
  org.eclipse.tm4e.registry,
diff --git a/org.eclipse.tm4e.markdown/pom.xml b/org.eclipse.tm4e.markdown/pom.xml
index de99f8992..b9f0ba6d3 100644
--- a/org.eclipse.tm4e.markdown/pom.xml
+++ b/org.eclipse.tm4e.markdown/pom.xml
@@ -2,7 +2,7 @@
   4.0.0
   org.eclipse.tm4e.markdown
   eclipse-plugin
-  0.3.5-SNAPSHOT
+  0.3.6-SNAPSHOT
   
     org.eclipse
     org.eclipse.tm4e
diff --git a/org.eclipse.tm4e.samples/META-INF/MANIFEST.MF b/org.eclipse.tm4e.samples/META-INF/MANIFEST.MF
index c4426f2fd..3a8a53abf 100644
--- a/org.eclipse.tm4e.samples/META-INF/MANIFEST.MF
+++ b/org.eclipse.tm4e.samples/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tm4e.samples;singleton:=true
-Bundle-Version: 0.3.6.qualifier
+Bundle-Version: 0.3.7.qualifier
 Require-Bundle: org.eclipse.jface.text,
  org.eclipse.core.runtime,
  org.eclipse.ui,
diff --git a/org.eclipse.tm4e.samples/pom.xml b/org.eclipse.tm4e.samples/pom.xml
index d302e4f6c..66422b70b 100644
--- a/org.eclipse.tm4e.samples/pom.xml
+++ b/org.eclipse.tm4e.samples/pom.xml
@@ -2,7 +2,7 @@
   4.0.0
   org.eclipse.tm4e.samples
   eclipse-plugin
-  0.3.6-SNAPSHOT
+  0.3.7-SNAPSHOT
   
     org.eclipse
     org.eclipse.tm4e

From 8269c53f011b99b42626c911ead91fcc8a2a4b8a Mon Sep 17 00:00:00 2001
From: sebthom 
Date: Sat, 4 Dec 2021 14:15:15 +0100
Subject: [PATCH 013/202] Fix ClassCastException: ContentTypeHandler cannot be
 cast to String

---
 .../widgets/ContentTypeLabelProvider.java     | 23 ++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java
index 878513688..7be1ba9c2 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -34,12 +34,19 @@ public String getText(Object element) {
 
 	@Override
 	public String getColumnText(Object element, int columnIndex) {
-		String contentTypeId = (String) element;
 		switch (columnIndex) {
 		case 0:
-			IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId);
-			if (contentType == null) {
-				return contentTypeId;
+			IContentType contentType = null;
+			if(element instanceof IContentType) {
+				contentType = (IContentType) element;
+			} else if(element instanceof String) {
+				String contentTypeId = (String) element;
+				contentType = Platform.getContentTypeManager().getContentType(contentTypeId);
+				if (contentType == null) {
+					return contentTypeId;
+				}
+			} else {
+				return ""; //$NON-NLS-1$
 			}
 			return contentType.getName() + " (" + contentType.getId() + ")";
 		default:

From 119d120141078526fcbbc74eec19f352fd2e463b Mon Sep 17 00:00:00 2001
From: Sebastian Thomschke 
Date: Sat, 4 Dec 2021 15:03:50 +0100
Subject: [PATCH 014/202] minor code cleanup (#302)

* Make private fields final where possible

* Use/improve lambdas

* Make inner classes static where possible

* Use primitive boolean instead of Boolean

* Remove redundant String.substring() parameter

* Remove redundant modifiers

* Use try-with-resources

* Use diamond operator

* Use int auto-unboxing

* Create arrays with curly
---
 .../tm4e/core/internal/css/RGBColorImpl.java  |   6 +-
 .../core/internal/grammar/LineTokenizer.java  |   6 +-
 .../core/internal/grammar/LineTokens.java     |   2 +-
 .../tm4e/core/internal/grammar/Token.java     |   4 +-
 .../grammar/reader/GrammarReader.java         |   4 +-
 .../grammar/reader/SyncGrammarReader.java     |   4 +-
 .../core/internal/matcher/IMatchesName.java   |   2 +-
 .../tm4e/core/internal/matcher/Matcher.java   |   6 +-
 .../core/internal/oniguruma/OnigRegExp.java   |   2 +-
 .../internal/parser/json/JSONPListParser.java |   2 +-
 .../tm4e/core/internal/rule/BeginEndRule.java |   4 +-
 .../core/internal/rule/BeginWhileRule.java    |   4 +-
 .../tm4e/core/internal/rule/MatchRule.java    |   2 +-
 .../tm4e/core/internal/rule/RegExpSource.java |   6 +-
 .../core/internal/rule/RegExpSourceList.java  |  12 +-
 .../eclipse/tm4e/core/internal/rule/Rule.java |   8 +-
 .../tm4e/core/internal/rule/RuleFactory.java  |   2 +-
 .../tm4e/core/internal/utils/RegexSource.java |   2 +-
 .../org/eclipse/tm4e/core/model/TMModel.java  |   6 +-
 .../org/eclipse/tm4e/core/model/TMState.java  |   2 +-
 .../tm4e/core/registry/IRegistryOptions.java  |   2 +-
 .../core/theme/css/ISACParserFactory.java     |   4 +-
 .../eclipse/tm4e/core/grammar/MarkDown.java   |  16 +-
 .../ILanguageConfiguration.java               | 170 ++---
 .../ToggleLineCommentHandler.java             | 580 ++++++++--------
 .../LanguageConfigurationDefinition.java      |  10 +-
 .../LanguageConfigurationPreferencePage.java  |   2 +-
 .../supports/AutoClosingPairConditional.java  |  24 +-
 .../supports/CharacterPairSupport.java        |  10 +-
 .../internal/supports/CommentSupport.java     | 126 ++--
 .../internal/supports/OnEnterSupport.java     |  12 +-
 .../widgets/CharacterPairsTableWidget.java    | 222 +++---
 .../widgets/OnEnterRuleTableWidget.java       | 266 ++++----
 ...SelectLanguageConfigurationWizardPage.java | 632 +++++++++---------
 .../eclipse/tm4e/registry/ITMResource.java    |  10 +-
 .../org/eclipse/tm4e/registry/TMResource.java |   8 +-
 .../preferences/PreferenceHelper.java         |  17 +-
 .../ui/internal/menus/ThemeContribution.java  |  10 +-
 .../internal/model/DocumentInputStream.java   |   2 +-
 .../ui/internal/model/DocumentLineList.java   |  10 +-
 .../ui/internal/model/TMDocumentModel.java    |  26 +-
 .../preferences/PreferenceHelper.java         |  16 +-
 .../ui/internal/snippets/SnippetManager.java  |  24 +-
 ...TMPresentationReconcilerTestGenerator.java |  10 +-
 .../internal/themes/AbstractThemeManager.java |  13 +-
 .../themes/BaseThemeAssociationRegistry.java  |  10 +-
 .../themes/ThemeAssociationRegistry.java      |  10 +-
 .../widgets/ThemeAssociationsWidget.java      |  14 +-
 .../wizards/SelectGrammarWizardPage.java      |  10 +-
 .../tm4e/ui/themes/ThemeIdConstants.java      |  16 +-
 .../tm4e/ui/themes/css/CSSTokenProvider.java  |  10 +-
 51 files changed, 1176 insertions(+), 1202 deletions(-)

diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
index 13fb8a64d..e449970e0 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
@@ -18,9 +18,9 @@
 
 public class RGBColorImpl extends CSSValueImpl implements RGBColor {
 
-	private CSSPrimitiveValue red;
-	private CSSPrimitiveValue green;
-	private CSSPrimitiveValue blue;
+	private final CSSPrimitiveValue red;
+	private final CSSPrimitiveValue green;
+	private final CSSPrimitiveValue blue;
 
 	public RGBColorImpl(LexicalUnit lexicalUnit) {
 		LexicalUnit nextUnit = lexicalUnit.getParameters();
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java
index da70a91f9..ce888e5c1 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java
@@ -39,7 +39,7 @@ class LineTokenizer {
 
 	private static final Logger LOGGER = Logger.getLogger(LineTokenizer.class.getName());
 
-	class WhileStack {
+	static class WhileStack {
 
 		public final StackElement stack;
 		public final BeginWhileRule rule;
@@ -50,7 +50,7 @@ public WhileStack(StackElement stack, BeginWhileRule rule) {
 		}
 	}
 
-	class WhileCheckResult {
+	static class WhileCheckResult {
 
 		public final StackElement stack;
 		public final int linePos;
@@ -391,7 +391,7 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs
 		}
 
 		int len = Math.min(captures.size(), captureIndices.length);
-		List localStack = new ArrayList();
+		List localStack = new ArrayList<>();
 		int maxEnd = captureIndices[0].getEnd();
 		IOnigCaptureIndex captureIndex;
 
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java
index 7c609b7e8..00d36aa26 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java
@@ -36,7 +36,7 @@ class LineTokens {
 	private final List tokens;
 
 
-	private boolean emitBinaryTokens;
+	private final boolean emitBinaryTokens;
 
 	/**
 	 * used only if `_emitBinaryTokens` is true.
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java
index 99f420aa3..dddd607ca 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java
@@ -24,9 +24,9 @@ class Token implements IToken {
 
 	private int startIndex;
 
-	private int endIndex;
+	private final int endIndex;
 
-	private List scopes;
+	private final List scopes;
 
 	public Token(int startIndex, int endIndex, List scopes) {
 		this.startIndex = startIndex;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java
index c1e0b3acb..897f086df 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java
@@ -37,7 +37,7 @@ private GrammarReader() {
 
 	public static final IGrammarParser XML_PARSER = new IGrammarParser() {
 
-		private XMLPListParser parser = new XMLPListParser<>(false);
+		private final XMLPListParser parser = new XMLPListParser<>(false);
 
 		@Override
 		public IRawGrammar parse(InputStream contents) throws Exception {
@@ -47,7 +47,7 @@ public IRawGrammar parse(InputStream contents) throws Exception {
 
 	public static final IGrammarParser JSON_PARSER = new IGrammarParser() {
 
-		private JSONPListParser parser = new JSONPListParser<>(false);
+		private final JSONPListParser parser = new JSONPListParser<>(false);
 
 		@Override
 		public IRawGrammar parse(InputStream contents) throws Exception {
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java
index 5f94d6630..062f2e687 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java
@@ -22,8 +22,8 @@
 
 public class SyncGrammarReader {
 
-	private InputStream in;
-	private IGrammarParser parser;
+	private final InputStream in;
+	private final IGrammarParser parser;
 
 	SyncGrammarReader(InputStream in, IGrammarParser parser) {
 		this.in = in;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java
index 27f9b5e5c..9da15570a 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java
@@ -22,7 +22,7 @@
 
 public interface IMatchesName {
 
-	public static final IMatchesName> NAME_MATCHER = new IMatchesName>() {
+	IMatchesName> NAME_MATCHER = new IMatchesName<>() {
 
 		@Override
 		public boolean match(Collection identifers, List scopes) {
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java
index 48e1f2dc4..06b418c3b 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java
@@ -37,7 +37,7 @@ public static Collection>> createMatchers(Strin
 	}
 
 	private static  Collection> createMatchers(String selector, IMatchesName matchesName) {
-		return new Matcher(selector, matchesName).results;
+		return new Matcher<>(selector, matchesName).results;
 	}
 
 	private final List> results;
@@ -68,7 +68,7 @@ public Matcher(String expression, IMatchesName matchesName) {
 			}
 			Predicate matcher = parseConjunction();
 			if (matcher != null) {
-				results.add(new MatcherWithPriority(matcher, priority));
+				results.add(new MatcherWithPriority<>(matcher, priority));
 			}
 			if (!",".equals(token)) {
 				break;
@@ -164,7 +164,7 @@ private static class Tokenizer {
 
 		private static final Pattern REGEXP = Pattern.compile("([LR]:|[\\w\\.:]+|[\\,\\|\\-\\(\\)])");
 
-		private java.util.regex.Matcher regex;
+		private final java.util.regex.Matcher regex;
 
 		public Tokenizer(String input) {
 			this.regex = REGEXP.matcher(input);
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java
index 98b5e0046..98ce14a3d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java
@@ -39,7 +39,7 @@ public class OnigRegExp {
 	private OnigString lastSearchString;
 	private int lastSearchPosition;
 	private OnigResult lastSearchResult;
-	private Regex regex;
+	private final Regex regex;
 
 	public OnigRegExp(String source) {
 		lastSearchString = null;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java
index 2885057eb..05fb5ae92 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java
@@ -29,7 +29,7 @@ public JSONPListParser(boolean theme) {
 	}
 
 	public T parse(InputStream contents) throws Exception {
-		PList pList = new PList(theme);
+		PList pList = new PList<>(theme);
 		JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8));
 		// reader.setLenient(true);
 		boolean parsing = true;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java
index 3f89bbed2..83ea384f1 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java
@@ -22,9 +22,9 @@
 
 public class BeginEndRule extends Rule {
 
-	private RegExpSource begin;
+	private final RegExpSource begin;
 	public List beginCaptures;
-	private RegExpSource end;
+	private final RegExpSource end;
 	public boolean endHasBackReferences;
 	public List endCaptures;
 	public boolean applyEndPatternLast;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java
index 7c34aa67f..947e50ddc 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java
@@ -22,10 +22,10 @@
 
 public class BeginWhileRule extends Rule {
 
-	private RegExpSource begin;
+	private final RegExpSource begin;
 	public final List beginCaptures;
 	public final List whileCaptures;
-	private RegExpSource _while;
+	private final RegExpSource _while;
 	public final boolean whileHasBackReferences;
 	public final boolean hasMissingPatterns;
 	public final Integer[] patterns;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java
index dd6e01713..6d1d25747 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java
@@ -20,7 +20,7 @@
 
 public class MatchRule extends Rule {
 
-	private RegExpSource match;
+	private final RegExpSource match;
 	public final List captures;
 	private RegExpSourceList cachedCompiledPatterns;
 
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java
index d0692b2c9..a9fef1f52 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java
@@ -36,9 +36,9 @@ public class RegExpSource {
 	private static final Pattern REGEXP_CHARACTERS = Pattern
 			.compile("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\,\\[\\]\\(\\)\\#\\s]");
 
-	private int ruleId;
+	private final int ruleId;
 	private boolean _hasAnchor;
-	private boolean _hasBackReferences;
+	private final boolean _hasBackReferences;
 	private IRegExpSourceAnchorCache anchorCache;
 	private String source;
 
@@ -130,7 +130,7 @@ public String resolveBackReferences(String lineText, IOnigCaptureIndex[] capture
 		StringBuffer sb = new StringBuffer();
 		while (m.find()) {
 			String g1 = m.group();
-			int index = Integer.parseInt(g1.substring(1, g1.length()));
+			int index = Integer.parseInt(g1.substring(1));
 			String replacement = escapeRegExpCharacters(capturedValues.size() > index ? capturedValues.get(index) : "");
 			m.appendReplacement(sb, replacement);
 		}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java
index b3c53d1c5..0bc6b0922 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java
@@ -29,7 +29,7 @@
  */
 public class RegExpSourceList {
 
-	private class RegExpSourceListAnchorCache {
+	private static class RegExpSourceListAnchorCache {
 
 		public ICompiledRule A0_G0;
 		public ICompiledRule A0_G1;
@@ -38,13 +38,13 @@ private class RegExpSourceListAnchorCache {
 
 	}
 
-	private List _items;
+	private final List _items;
 	private boolean _hasAnchors;
 	private ICompiledRule _cached;
 	private final RegExpSourceListAnchorCache _anchorCache;
 
 	public RegExpSourceList() {
-		this._items = new ArrayList();
+		this._items = new ArrayList<>();
 		this._hasAnchors = false;
 		this._cached = null;
 		this._anchorCache = new RegExpSourceListAnchorCache();
@@ -80,7 +80,7 @@ public void setSource(int index, String newSource) {
 	public ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) {
 		if (!this._hasAnchors) {
 			if (this._cached == null) {
-				List regexps = new ArrayList();
+				List regexps = new ArrayList<>();
 				for (RegExpSource regExpSource : _items) {
 					regexps.add(regExpSource.getSource());
 				}
@@ -122,7 +122,7 @@ public ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allo
 	}
 
 	private ICompiledRule _resolveAnchors(boolean allowA, boolean allowG) {
-		List regexps = new ArrayList();
+		List regexps = new ArrayList<>();
 		for (RegExpSource regExpSource : _items) {
 			regexps.add(regExpSource.resolveAnchors(allowA, allowG));
 		}
@@ -134,7 +134,7 @@ private OnigScanner createOnigScanner(String[] regexps) {
 	}
 
 	private Integer[] getRules() {
-		Collection ruleIds = new ArrayList();
+		Collection ruleIds = new ArrayList<>();
 		for (RegExpSource item : this._items) {
 			ruleIds.add(item.getRuleId());
 		}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java
index e7d2544a0..ac0c4d0d9 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java
@@ -23,11 +23,11 @@ public abstract class Rule {
 
 	public final int id;
 
-	private boolean nameIsCapturing;
-	private String name;
+	private final boolean nameIsCapturing;
+	private final String name;
 
-	private boolean contentNameIsCapturing;
-	private String contentName;
+	private final boolean contentNameIsCapturing;
+	private final String contentName;
 
 	public Rule(int id, String name, String contentName) {
 		this.id = id;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java
index c5dd96a44..f269dcb35 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java
@@ -139,7 +139,7 @@ private static int parseInt(String string, int base) {
 
 	private static ICompilePatternsResult _compilePatterns(Collection patterns, IRuleFactoryHelper helper,
 			IRawRepository repository) {
-		Collection r = new ArrayList();
+		Collection r = new ArrayList<>();
 		int patternId;
 		IRawGrammar externalGrammar;
 		Rule rule;
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java
index 2906064e5..17d041678 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java
@@ -59,7 +59,7 @@ private static String getReplacement(String match, String captureSource, IOnigCa
 			index = Integer.parseInt(match.substring(2, doublePointIndex));
 			command = match.substring(doublePointIndex + 2, match.length() - 1);
 		} else {
-			index = Integer.parseInt(match.substring(1, match.length()));
+			index = Integer.parseInt(match.substring(1));
 		}
 		IOnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null;
 		if (capture != null) {
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java
index 4628a2c83..2cb18a216 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java
@@ -44,7 +44,7 @@ public class TMModel implements ITMModel {
 	private TokenizerThread fThread;
 
 	private final IModelLines lines;
-	private PriorityBlockingQueue invalidLines = new PriorityBlockingQueue<>();
+	private final PriorityBlockingQueue invalidLines = new PriorityBlockingQueue<>();
 
 	public TMModel(IModelLines lines) {
 		this.listeners = new ArrayList<>();
@@ -64,7 +64,7 @@ public TMModel(IModelLines lines) {
 	 *
 	 */
 	static class TokenizerThread extends Thread {
-		private TMModel model;
+		private final TMModel model;
 		private TMState lastState;
 
 		/**
@@ -92,7 +92,7 @@ public void run() {
 					Integer toProcess = model.invalidLines.take();
 					if (model.lines.get(toProcess).isInvalid) {
 						try {
-							this.revalidateTokensNow(toProcess.intValue(), null);
+							this.revalidateTokensNow(toProcess, null);
 						} catch (Exception t) {
 							LOGGER.severe(t.getMessage());
 							if (toProcess < model.lines.getNumberOfLines()) {
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java
index a473b8ae1..0e20b0cfc 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java
@@ -22,7 +22,7 @@
 
 public class TMState {
 
-	private TMState parentEmbedderState;
+	private final TMState parentEmbedderState;
 	private StackElement ruleStack;
 
 	public TMState(TMState parentEmbedderState, StackElement ruleStatck) {
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java
index 0ea3e58bb..dc7276d7c 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java
@@ -24,7 +24,7 @@
 
 public interface IRegistryOptions {
 
-	public static final IRegistryOptions DEFAULT_LOCATOR = new IRegistryOptions() {
+	IRegistryOptions DEFAULT_LOCATOR = new IRegistryOptions() {
 
 		@Override
 		public String getFilePath(String scopeName) {
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java
index 8768bfac0..1f9959ca8 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java
@@ -23,7 +23,7 @@ public interface ISACParserFactory {
 	 * this method search teh SAC Parser class name to instanciate into System
 	 * property with key org.w3c.css.sac.parser.
 	 */
-	public Parser makeParser() throws ClassNotFoundException,
+	Parser makeParser() throws ClassNotFoundException,
 			IllegalAccessException, InstantiationException,
 			NullPointerException, ClassCastException;
 
@@ -39,7 +39,7 @@ public Parser makeParser() throws ClassNotFoundException,
 	 * @throws NullPointerException
 	 * @throws ClassCastException
 	 */
-	public abstract Parser makeParser(String name)
+	Parser makeParser(String name)
 			throws ClassNotFoundException, IllegalAccessException,
 			InstantiationException, NullPointerException, ClassCastException;
 }
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java
index bc413b064..8a67876fa 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -27,19 +27,13 @@ public static void main(String[] args) throws Exception {
 		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
 		
 		List lines = new ArrayList<>();
-		BufferedReader reader = null;
-		try {
-			reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("test.md.txt")));
+		try (BufferedReader reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("test.md.txt")))) {
 			String line = null;
 			while ((line = reader.readLine()) != null) {
 				lines.add(line);
 			}
 		} catch (Exception e) {
 			e.printStackTrace();
-		} finally {
-			if (reader != null) {
-				reader.close();
-			}
 		}
 
 		
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java
index ce80cb208..c8743a7f3 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java
@@ -1,85 +1,85 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration;
-
-import java.util.List;
-
-import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.Folding;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
-
-public interface ILanguageConfiguration {
-	/**
-	 * Returns the language's comments. The comments are used by
-	 * {@link AutoClosingPairConditional} when notIn contains
-	 * comment
-	 *
-	 * @return the language's comments or null if not set
-	 */
-	Comments getComments();
-
-	/**
-	 * Returns the language's brackets. This configuration implicitly affects
-	 * pressing Enter around these brackets.
-	 *
-	 * @return the language's brackets. This configuration implicitly affects
-	 *         pressing Enter around these brackets.
-	 */
-	public List getBrackets();
-
-	/**
-	 * Returns the language's auto closing pairs. The 'close' character is
-	 * automatically inserted with the 'open' character is typed. If not set, the
-	 * configured brackets will be used.
-	 *
-	 * @return the language's auto closing pairs. The 'close' character is
-	 *         autautomatically inserted with the 'open' character is typed. If not
-	 *         set, the configured brackets will be used.
-	 */
-	public List getAutoClosingPairs();
-
-	/**
-	 * Returns the language's rules to be evaluated when pressing Enter.
-	 *
-	 * @return the language's rules to be evaluated when pressing Enter.
-	 */
-	public List getOnEnterRules();
-
-	/**
-	 * Returns the language's surrounding pairs. When the 'open' character is typed
-	 * on a selection, the selected string is surrounded by the open and close
-	 * characters. If not set, the autoclosing pairs settings will be used.
-	 *
-	 * @return the language's surrounding pairs. When the 'open' character is typed
-	 *         on a selection, the selected string is surrounded by the open and
-	 *         close characters. If not set, the autoclosing pairs settings will be
-	 *         used.
-	 */
-	public List getSurroundingPairs();
-
-	/**
-	 * Returns the language's folding rules.
-	 *
-	 * @return the language's folding or null if not set
-	 */
-	Folding getFolding();
-
-	/**
-	 * Returns the language's definition of a word. This is the regex used when
-	 * refering to a word.
-	 *
-	 * @return the language's word pattern or null if not set
-	 */
-	String getWordPattern();
-}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration;
+
+import java.util.List;
+
+import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.Folding;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
+
+public interface ILanguageConfiguration {
+	/**
+	 * Returns the language's comments. The comments are used by
+	 * {@link AutoClosingPairConditional} when notIn contains
+	 * comment
+	 *
+	 * @return the language's comments or null if not set
+	 */
+	Comments getComments();
+
+	/**
+	 * Returns the language's brackets. This configuration implicitly affects
+	 * pressing Enter around these brackets.
+	 *
+	 * @return the language's brackets. This configuration implicitly affects
+	 *         pressing Enter around these brackets.
+	 */
+	List getBrackets();
+
+	/**
+	 * Returns the language's auto closing pairs. The 'close' character is
+	 * automatically inserted with the 'open' character is typed. If not set, the
+	 * configured brackets will be used.
+	 *
+	 * @return the language's auto closing pairs. The 'close' character is
+	 *         autautomatically inserted with the 'open' character is typed. If not
+	 *         set, the configured brackets will be used.
+	 */
+	List getAutoClosingPairs();
+
+	/**
+	 * Returns the language's rules to be evaluated when pressing Enter.
+	 *
+	 * @return the language's rules to be evaluated when pressing Enter.
+	 */
+	List getOnEnterRules();
+
+	/**
+	 * Returns the language's surrounding pairs. When the 'open' character is typed
+	 * on a selection, the selected string is surrounded by the open and close
+	 * characters. If not set, the autoclosing pairs settings will be used.
+	 *
+	 * @return the language's surrounding pairs. When the 'open' character is typed
+	 *         on a selection, the selected string is surrounded by the open and
+	 *         close characters. If not set, the autoclosing pairs settings will be
+	 *         used.
+	 */
+	List getSurroundingPairs();
+
+	/**
+	 * Returns the language's folding rules.
+	 *
+	 * @return the language's folding or null if not set
+	 */
+	Folding getFolding();
+
+	/**
+	 * Returns the language's definition of a word. This is the regex used when
+	 * refering to a word.
+	 *
+	 * @return the language's word pattern or null if not set
+	 */
+	String getWordPattern();
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java
index 0c68557c9..90c0910ce 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java
@@ -1,291 +1,291 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.IRewriteTarget;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport;
-import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils;
-import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
-import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-public class ToggleLineCommentHandler extends AbstractHandler {
-	public static final String TOGGLE_LINE_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.togglelinecommentcommand";
-	public static final String ADD_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.addblockcommentcommand";
-	public static final String REMOVE_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.removeblockcommentcommand";
-
-	@Override
-	public Object execute(ExecutionEvent event) throws ExecutionException {
-		IEditorPart part = HandlerUtil.getActiveEditor(event);
-		if (!(part instanceof ITextEditor)) {
-			return null;
-		}
-		ITextEditor editor = (ITextEditor) part;
-		ISelection selection = editor.getSelectionProvider().getSelection();
-		if (!(selection instanceof ITextSelection)) {
-			return null;
-		}
-		ITextSelection textSelection = (ITextSelection) selection;
-		IEditorInput input = editor.getEditorInput();
-		IDocumentProvider docProvider = editor.getDocumentProvider();
-		if (docProvider == null || input == null) {
-			return null;
-		}
-
-		IDocument document = docProvider.getDocument(input);
-		if (document == null) {
-			return null;
-		}
-
-		ContentTypeInfo info;
-		try {
-			info = ContentTypeHelper.findContentTypes(document);
-		} catch (CoreException e) {
-			return null;
-		}
-		IContentType[] contentTypes = info.getContentTypes();
-		Command command = event.getCommand();
-		CommentSupport commentSupport = getCommentSupport(contentTypes);
-		if (commentSupport == null) {
-			return null;
-		}
-		// Check if comment support is valid according the command to do.
-		if (!isValid(commentSupport, command)) {
-			return null;
-		}
-
-		IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
-		if (target != null) {
-			target.beginCompoundChange();
-		}
-		try {
-			if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && commentSupport.getLineComment() != null) {
-				updateLineComment(document, textSelection, commentSupport.getLineComment(), editor);
-			} else {
-				IRegion existingBlock = getBlockComment(document, textSelection, commentSupport);
-				if (ADD_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock == null) {
-					addBlockComment(document, textSelection, commentSupport.getBlockComment(), editor);
-				} else if (REMOVE_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock != null) {
-					removeBlockComment(document, textSelection, existingBlock, commentSupport.getBlockComment(),
-							editor);
-				}
-			}
-		} catch (BadLocationException e) {
-			// Caught by making no changes
-		} finally {
-			if (target != null) {
-				target.endCompoundChange();
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * Returns true if comment support is valid according the command to do and
-	 * false otherwise.
-	 * 
-	 * @param commentSupport
-	 * @param command
-	 * @return true if comment support is valid according the command to do and
-	 *         false otherwise.
-	 */
-	private boolean isValid(CommentSupport commentSupport, Command command) {
-		if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId())) {
-			// check if line comment is valid.
-			return commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty();
-		}
-		// check if block comment is valid
-		CharacterPair characterPair = commentSupport.getBlockComment();
-		return characterPair != null && characterPair.getKey() != null && !characterPair.getKey().isEmpty()
-				&& characterPair.getValue() != null && !characterPair.getValue().isEmpty();
-	}
-
-	/**
-	 * Returns the comment support from the given list of content types and null
-	 * otherwise.
-	 * 
-	 * @param contentTypes
-	 * @return the comment support from the given list of content types and null
-	 *         otherwise.
-	 */
-	private CommentSupport getCommentSupport(IContentType[] contentTypes) {
-		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
-		for (IContentType contentType : contentTypes) {
-			if (!registry.shouldComment(contentType)) {
-				continue;
-			}
-			CommentSupport commentSupport = registry.getCommentSupport(contentType);
-			if (commentSupport != null) {
-				return commentSupport;
-			}
-		}
-		return null;
-	}
-
-	private void updateLineComment(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
-			throws BadLocationException {
-		if (areLinesCommented(document, selection, comment)) {
-			removeLineComments(document, selection, comment, editor);
-		} else {
-			addLineComments(document, selection, comment, editor);
-		}
-	}
-
-	private boolean areLinesCommented(IDocument document, ITextSelection selection, String comment)
-			throws BadLocationException {
-		int lineNumber = selection.getStartLine();
-		while (lineNumber <= selection.getEndLine()) {
-			IRegion lineRegion = document.getLineInformation(lineNumber);
-			if (!document.get(lineRegion.getOffset(), lineRegion.getLength()).trim().startsWith(comment)) {
-				return false;
-			}
-			lineNumber++;
-		}
-		return true;
-	}
-
-	private IRegion getBlockComment(IDocument document, ITextSelection selection, CommentSupport commentSupport)
-			throws BadLocationException {
-		if (selection.getText() == null) {
-			return null;
-		}
-		String text = document.get();
-		String open = commentSupport.getBlockComment().getKey();
-		String close = commentSupport.getBlockComment().getValue();
-		int selectionStart = selection.getOffset();
-		int selectionEnd = selectionStart + selection.getLength();
-		int openOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionStart, open);
-		if (openOffset == -1) {
-			openOffset = text.lastIndexOf(open, selectionStart);
-			if (openOffset == -1 || openOffset < document.getLineOffset(selection.getStartLine())) {
-				return null;
-			}
-		}
-
-		int closeOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionEnd, close);
-		if (closeOffset == -1 || closeOffset < openOffset + open.length()) {
-			closeOffset = text.indexOf(close, selectionEnd);
-			IRegion endLineRegion = document.getLineInformation(document.getLineOfOffset(selectionEnd));
-			if (openOffset == -1 || closeOffset < openOffset + open.length()
-					|| closeOffset > endLineRegion.getOffset() + endLineRegion.getLength()) {
-				return null;
-			}
-		}
-
-		// Make sure there isn't a different block closer before the one we found
-		int othercloseOffset = text.indexOf(close, openOffset + open.length());
-		while (othercloseOffset != -1 && othercloseOffset < closeOffset) {
-			int startOfLineOffset = document.getLineOffset(document.getLineOfOffset(othercloseOffset));
-			if (commentSupport.getLineComment() != null && text.substring(startOfLineOffset, othercloseOffset)
-					.indexOf(commentSupport.getLineComment()) != -1) {
-				return null;
-			}
-			othercloseOffset = text.indexOf(close, othercloseOffset + close.length());
-		}
-		return new Region(openOffset, closeOffset - openOffset);
-	}
-
-	private void removeLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
-			throws BadLocationException {
-		int lineNumber = selection.getStartLine();
-		int endLineNumber = selection.getEndLine();
-		String oldText = document.get();
-		int deletedChars = 0;
-		Boolean isStartBeforeComment = false;
-
-		while (lineNumber <= endLineNumber) {
-			int commentOffset = oldText.indexOf(comment, document.getLineOffset(lineNumber) + deletedChars);
-			document.replace(commentOffset - deletedChars, comment.length(), "");
-			if (deletedChars == 0) {
-				isStartBeforeComment = commentOffset > selection.getOffset();
-			}
-			if (lineNumber != endLineNumber) {
-				deletedChars += comment.length();
-			}
-			lineNumber++;
-		}
-		ITextSelection newSelection = new TextSelection(
-				selection.getOffset() - (isStartBeforeComment ? 0 : comment.length()),
-				selection.getLength() - deletedChars);
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
-
-	private void addLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
-			throws BadLocationException {
-		int lineNumber = selection.getStartLine();
-		int endLineNumber = selection.getEndLine();
-		int insertedChars = 0;
-
-		while (lineNumber <= endLineNumber) {
-			document.replace(document.getLineOffset(lineNumber), 0, comment);
-			if (lineNumber != endLineNumber) {
-				insertedChars += comment.length();
-			}
-			lineNumber++;
-		}
-		ITextSelection newSelection = new TextSelection(selection.getOffset() + comment.length(),
-				selection.getLength() + insertedChars);
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
-
-	private void removeBlockComment(IDocument document, ITextSelection selection, IRegion existingBlock,
-			CharacterPair blockComment, ITextEditor editor) throws BadLocationException {
-		int openOffset = existingBlock.getOffset();
-		int openLength = blockComment.getKey().length();
-		int closeOffset = existingBlock.getOffset() + existingBlock.getLength();
-		int closeLength = blockComment.getValue().length();
-		document.replace(openOffset, openLength, "");
-		document.replace(closeOffset - openLength, closeLength, "");
-
-		int offsetFix = openLength;
-		int lengthFix = 0;
-		if (selection.getOffset() < openOffset + openLength) {
-			offsetFix = selection.getOffset() - openOffset;
-			lengthFix = openLength - offsetFix;
-		}
-		if (selection.getOffset() + selection.getLength() > closeOffset) {
-			lengthFix += selection.getOffset() + selection.getLength() - closeOffset;
-		}
-		ITextSelection newSelection = new TextSelection(selection.getOffset() - offsetFix,
-				selection.getLength() - lengthFix);
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
-
-	private void addBlockComment(IDocument document, ITextSelection selection, CharacterPair blockComment,
-			ITextEditor editor) throws BadLocationException {
-		document.replace(selection.getOffset(), 0, blockComment.getKey());
-		document.replace(selection.getOffset() + selection.getLength() + blockComment.getKey().length(), 0,
-				blockComment.getValue());
-		ITextSelection newSelection = new TextSelection(selection.getOffset() + blockComment.getKey().length(),
-				selection.getLength());
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.IRewriteTarget;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport;
+import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils;
+import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
+import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class ToggleLineCommentHandler extends AbstractHandler {
+	public static final String TOGGLE_LINE_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.togglelinecommentcommand";
+	public static final String ADD_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.addblockcommentcommand";
+	public static final String REMOVE_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.removeblockcommentcommand";
+
+	@Override
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		IEditorPart part = HandlerUtil.getActiveEditor(event);
+		if (!(part instanceof ITextEditor)) {
+			return null;
+		}
+		ITextEditor editor = (ITextEditor) part;
+		ISelection selection = editor.getSelectionProvider().getSelection();
+		if (!(selection instanceof ITextSelection)) {
+			return null;
+		}
+		ITextSelection textSelection = (ITextSelection) selection;
+		IEditorInput input = editor.getEditorInput();
+		IDocumentProvider docProvider = editor.getDocumentProvider();
+		if (docProvider == null || input == null) {
+			return null;
+		}
+
+		IDocument document = docProvider.getDocument(input);
+		if (document == null) {
+			return null;
+		}
+
+		ContentTypeInfo info;
+		try {
+			info = ContentTypeHelper.findContentTypes(document);
+		} catch (CoreException e) {
+			return null;
+		}
+		IContentType[] contentTypes = info.getContentTypes();
+		Command command = event.getCommand();
+		CommentSupport commentSupport = getCommentSupport(contentTypes);
+		if (commentSupport == null) {
+			return null;
+		}
+		// Check if comment support is valid according the command to do.
+		if (!isValid(commentSupport, command)) {
+			return null;
+		}
+
+		IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
+		if (target != null) {
+			target.beginCompoundChange();
+		}
+		try {
+			if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && commentSupport.getLineComment() != null) {
+				updateLineComment(document, textSelection, commentSupport.getLineComment(), editor);
+			} else {
+				IRegion existingBlock = getBlockComment(document, textSelection, commentSupport);
+				if (ADD_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock == null) {
+					addBlockComment(document, textSelection, commentSupport.getBlockComment(), editor);
+				} else if (REMOVE_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock != null) {
+					removeBlockComment(document, textSelection, existingBlock, commentSupport.getBlockComment(),
+							editor);
+				}
+			}
+		} catch (BadLocationException e) {
+			// Caught by making no changes
+		} finally {
+			if (target != null) {
+				target.endCompoundChange();
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Returns true if comment support is valid according the command to do and
+	 * false otherwise.
+	 * 
+	 * @param commentSupport
+	 * @param command
+	 * @return true if comment support is valid according the command to do and
+	 *         false otherwise.
+	 */
+	private boolean isValid(CommentSupport commentSupport, Command command) {
+		if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId())) {
+			// check if line comment is valid.
+			return commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty();
+		}
+		// check if block comment is valid
+		CharacterPair characterPair = commentSupport.getBlockComment();
+		return characterPair != null && characterPair.getKey() != null && !characterPair.getKey().isEmpty()
+				&& characterPair.getValue() != null && !characterPair.getValue().isEmpty();
+	}
+
+	/**
+	 * Returns the comment support from the given list of content types and null
+	 * otherwise.
+	 * 
+	 * @param contentTypes
+	 * @return the comment support from the given list of content types and null
+	 *         otherwise.
+	 */
+	private CommentSupport getCommentSupport(IContentType[] contentTypes) {
+		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
+		for (IContentType contentType : contentTypes) {
+			if (!registry.shouldComment(contentType)) {
+				continue;
+			}
+			CommentSupport commentSupport = registry.getCommentSupport(contentType);
+			if (commentSupport != null) {
+				return commentSupport;
+			}
+		}
+		return null;
+	}
+
+	private void updateLineComment(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
+			throws BadLocationException {
+		if (areLinesCommented(document, selection, comment)) {
+			removeLineComments(document, selection, comment, editor);
+		} else {
+			addLineComments(document, selection, comment, editor);
+		}
+	}
+
+	private boolean areLinesCommented(IDocument document, ITextSelection selection, String comment)
+			throws BadLocationException {
+		int lineNumber = selection.getStartLine();
+		while (lineNumber <= selection.getEndLine()) {
+			IRegion lineRegion = document.getLineInformation(lineNumber);
+			if (!document.get(lineRegion.getOffset(), lineRegion.getLength()).trim().startsWith(comment)) {
+				return false;
+			}
+			lineNumber++;
+		}
+		return true;
+	}
+
+	private IRegion getBlockComment(IDocument document, ITextSelection selection, CommentSupport commentSupport)
+			throws BadLocationException {
+		if (selection.getText() == null) {
+			return null;
+		}
+		String text = document.get();
+		String open = commentSupport.getBlockComment().getKey();
+		String close = commentSupport.getBlockComment().getValue();
+		int selectionStart = selection.getOffset();
+		int selectionEnd = selectionStart + selection.getLength();
+		int openOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionStart, open);
+		if (openOffset == -1) {
+			openOffset = text.lastIndexOf(open, selectionStart);
+			if (openOffset == -1 || openOffset < document.getLineOffset(selection.getStartLine())) {
+				return null;
+			}
+		}
+
+		int closeOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionEnd, close);
+		if (closeOffset == -1 || closeOffset < openOffset + open.length()) {
+			closeOffset = text.indexOf(close, selectionEnd);
+			IRegion endLineRegion = document.getLineInformation(document.getLineOfOffset(selectionEnd));
+			if (openOffset == -1 || closeOffset < openOffset + open.length()
+					|| closeOffset > endLineRegion.getOffset() + endLineRegion.getLength()) {
+				return null;
+			}
+		}
+
+		// Make sure there isn't a different block closer before the one we found
+		int othercloseOffset = text.indexOf(close, openOffset + open.length());
+		while (othercloseOffset != -1 && othercloseOffset < closeOffset) {
+			int startOfLineOffset = document.getLineOffset(document.getLineOfOffset(othercloseOffset));
+			if (commentSupport.getLineComment() != null && text.substring(startOfLineOffset, othercloseOffset)
+					.indexOf(commentSupport.getLineComment()) != -1) {
+				return null;
+			}
+			othercloseOffset = text.indexOf(close, othercloseOffset + close.length());
+		}
+		return new Region(openOffset, closeOffset - openOffset);
+	}
+
+	private void removeLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
+			throws BadLocationException {
+		int lineNumber = selection.getStartLine();
+		int endLineNumber = selection.getEndLine();
+		String oldText = document.get();
+		int deletedChars = 0;
+		boolean isStartBeforeComment = false;
+
+		while (lineNumber <= endLineNumber) {
+			int commentOffset = oldText.indexOf(comment, document.getLineOffset(lineNumber) + deletedChars);
+			document.replace(commentOffset - deletedChars, comment.length(), "");
+			if (deletedChars == 0) {
+				isStartBeforeComment = commentOffset > selection.getOffset();
+			}
+			if (lineNumber != endLineNumber) {
+				deletedChars += comment.length();
+			}
+			lineNumber++;
+		}
+		ITextSelection newSelection = new TextSelection(
+				selection.getOffset() - (isStartBeforeComment ? 0 : comment.length()),
+				selection.getLength() - deletedChars);
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
+
+	private void addLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
+			throws BadLocationException {
+		int lineNumber = selection.getStartLine();
+		int endLineNumber = selection.getEndLine();
+		int insertedChars = 0;
+
+		while (lineNumber <= endLineNumber) {
+			document.replace(document.getLineOffset(lineNumber), 0, comment);
+			if (lineNumber != endLineNumber) {
+				insertedChars += comment.length();
+			}
+			lineNumber++;
+		}
+		ITextSelection newSelection = new TextSelection(selection.getOffset() + comment.length(),
+				selection.getLength() + insertedChars);
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
+
+	private void removeBlockComment(IDocument document, ITextSelection selection, IRegion existingBlock,
+			CharacterPair blockComment, ITextEditor editor) throws BadLocationException {
+		int openOffset = existingBlock.getOffset();
+		int openLength = blockComment.getKey().length();
+		int closeOffset = existingBlock.getOffset() + existingBlock.getLength();
+		int closeLength = blockComment.getValue().length();
+		document.replace(openOffset, openLength, "");
+		document.replace(closeOffset - openLength, closeLength, "");
+
+		int offsetFix = openLength;
+		int lengthFix = 0;
+		if (selection.getOffset() < openOffset + openLength) {
+			offsetFix = selection.getOffset() - openOffset;
+			lengthFix = openLength - offsetFix;
+		}
+		if (selection.getOffset() + selection.getLength() > closeOffset) {
+			lengthFix += selection.getOffset() + selection.getLength() - closeOffset;
+		}
+		ITextSelection newSelection = new TextSelection(selection.getOffset() - offsetFix,
+				selection.getLength() - lengthFix);
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
+
+	private void addBlockComment(IDocument document, ITextSelection selection, CharacterPair blockComment,
+			ITextEditor editor) throws BadLocationException {
+		document.replace(selection.getOffset(), 0, blockComment.getKey());
+		document.replace(selection.getOffset() + selection.getLength() + blockComment.getKey().length(), 0,
+				blockComment.getValue());
+		ITextSelection newSelection = new TextSelection(selection.getOffset() + blockComment.getKey().length(),
+				selection.getLength());
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java
index d48f329a2..5dc7c6e63 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -34,7 +34,7 @@
  */
 public class LanguageConfigurationDefinition extends TMResource implements ILanguageConfigurationDefinition {
 
-	private IContentType contentType;
+	private final IContentType contentType;
 	private boolean onEnterEnabled = true;
 	private boolean bracketAutoClosingEnabled = true;
 	private boolean matchingPairsEnabled = true;
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java
index ada5331eb..b01768526 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java
@@ -63,7 +63,7 @@ public class LanguageConfigurationPreferencePage extends PreferencePage implemen
 
 	public final static String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$
 
-	private ILanguageConfigurationRegistryManager manager;
+	private final ILanguageConfigurationRegistryManager manager;
 
 	private TableViewer definitionViewer;
 
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java
index fdfb35e98..8395bd522 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java
@@ -1,14 +1,14 @@
-/**
- * Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr  - initial API and implementation
- */
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr  - initial API and implementation
+ */
 package org.eclipse.tm4e.languageconfiguration.internal.supports;
 
 import java.util.List;
@@ -16,7 +16,7 @@
 @SuppressWarnings("serial")
 public class AutoClosingPairConditional extends CharacterPair {
 
-	private List notIn;
+	private final List notIn;
 
 	public AutoClosingPairConditional(String open, String close, List notIn) {
 		super(open, close);
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java
index 10ec3eb8f..c9b920bc6 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -22,7 +22,7 @@
 public class CharacterPairSupport {
 
 	private List autoClosingPairs;
-	private List surroundingPairs;
+	private final List surroundingPairs;
 
 	public CharacterPairSupport(List brackets, List autoClosingPairs,
 			List surroundingPairs) {
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java
index 3c83bd1c4..19ce7fbed 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java
@@ -1,63 +1,63 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-
-public class CommentSupport {
-
-	private Comments comments;
-
-	public CommentSupport(Comments comments) {
-		this.comments = comments;
-	}
-
-	public boolean isInComment(IDocument document, int offset) {
-		try {
-			if (isInBlockComment(document.get(0, offset))) {
-				return true;
-			}
-			int line = document.getLineOfOffset(offset);
-			int lineOffset = document.getLineOffset(line);
-			return isInLineComment(document.get(lineOffset, offset - lineOffset));
-		} catch (BadLocationException e) {
-			return false;
-		}
-	}
-
-	public String getLineComment() {
-		return comments.getLineComment();
-	}
-
-	public CharacterPair getBlockComment() {
-		return comments.getBlockComment();
-	}
-
-	private boolean isInLineComment(String indexLinePrefix) {
-		return indexLinePrefix.indexOf(comments.getLineComment()) != -1;
-	}
-
-	private boolean isInBlockComment(String indexPrefix) {
-		String commentOpen = comments.getBlockComment().getKey();
-		String commentClose = comments.getBlockComment().getValue();
-		int index = indexPrefix.indexOf(commentOpen);
-		while (index != -1 && index < indexPrefix.length()) {
-			int closeIndex = indexPrefix.indexOf(commentClose, index + commentOpen.length());
-			if (closeIndex == -1) {
-				return true;
-			}
-			index = indexPrefix.indexOf(commentOpen, closeIndex + commentClose.length());
-		}
-		return false;
-	}
-}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+public class CommentSupport {
+
+	private final Comments comments;
+
+	public CommentSupport(Comments comments) {
+		this.comments = comments;
+	}
+
+	public boolean isInComment(IDocument document, int offset) {
+		try {
+			if (isInBlockComment(document.get(0, offset))) {
+				return true;
+			}
+			int line = document.getLineOfOffset(offset);
+			int lineOffset = document.getLineOffset(line);
+			return isInLineComment(document.get(lineOffset, offset - lineOffset));
+		} catch (BadLocationException e) {
+			return false;
+		}
+	}
+
+	public String getLineComment() {
+		return comments.getLineComment();
+	}
+
+	public CharacterPair getBlockComment() {
+		return comments.getBlockComment();
+	}
+
+	private boolean isInLineComment(String indexLinePrefix) {
+		return indexLinePrefix.indexOf(comments.getLineComment()) != -1;
+	}
+
+	private boolean isInBlockComment(String indexPrefix) {
+		String commentOpen = comments.getBlockComment().getKey();
+		String commentClose = comments.getBlockComment().getValue();
+		int index = indexPrefix.indexOf(commentOpen);
+		while (index != -1 && index < indexPrefix.length()) {
+			int closeIndex = indexPrefix.indexOf(commentClose, index + commentOpen.length());
+			if (closeIndex == -1) {
+				return true;
+			}
+			index = indexPrefix.indexOf(commentOpen, closeIndex + commentClose.length());
+		}
+		return false;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java
index 050f8332c..4fd1f58bb 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -35,9 +35,7 @@ public class OnEnterSupport {
 
 	public OnEnterSupport(List brackets, List regExpRules) {
 		this.brackets = (brackets != null ? brackets : DEFAULT_BRACKETS).stream().filter(el -> el != null)
-				.map((bracket -> {
-					return new ProcessedBracketPair(bracket.getKey(), bracket.getValue());
-				})).collect(Collectors.toList());
+				.map((bracket -> new ProcessedBracketPair(bracket.getKey(), bracket.getValue()))).collect(Collectors.toList());
 
 		this.regExpRules = regExpRules != null ? regExpRules : Collections.emptyList();
 	}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java
index 6ce7ffee9..f99689248 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java
@@ -1,111 +1,111 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.widgets;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-
-public class CharacterPairsTableWidget extends TableViewer {
-
-	public CharacterPairsTableWidget(Table table) {
-		super(table);
-		setContentProvider(new CharacterPairContentProvider());
-		setLabelProvider(new CharacterPairLabelProvider());
-
-		GC gc = new GC(table.getShell());
-		gc.setFont(JFaceResources.getDialogFont());
-		TableColumnLayout columnLayout = new TableColumnLayout();
-
-		TableColumn column1 = new TableColumn(table, SWT.NONE);
-		column1.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_start);
-		int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_start);
-		columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true));
-
-		TableColumn column2 = new TableColumn(table, SWT.NONE);
-		column2.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_end);
-		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_end);
-		columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true));
-	}
-
-	protected int computeMinimumColumnWidth(GC gc, String string) {
-		return gc.stringExtent(string).x + 10;
-	}
-
-	protected class CharacterPairContentProvider implements IStructuredContentProvider {
-
-		private List characterPairList;
-
-		@Override
-		public Object[] getElements(Object input) {
-			return characterPairList.toArray(new CharacterPair[characterPairList.size()]);
-		}
-
-		@SuppressWarnings("unchecked")
-		@Override
-		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-			if (newInput == null) {
-				characterPairList = Collections.EMPTY_LIST;
-			} else {
-				characterPairList = (List) newInput;
-			}
-		}
-
-		@Override
-		public void dispose() {
-			characterPairList = null;
-		}
-	}
-
-	protected class CharacterPairLabelProvider extends LabelProvider implements ITableLabelProvider {
-
-		@Override
-		public Image getColumnImage(Object element, int columnIndex) {
-			return null;
-		}
-
-		@Override
-		public String getText(Object element) {
-			return getColumnText(element, 0);
-		}
-
-		@Override
-		public String getColumnText(Object element, int columnIndex) {
-			CharacterPair pair = (CharacterPair) element;
-
-			switch (columnIndex) {
-			case 0:
-				return pair.getKey();
-			case 1:
-				return pair.getValue();
-			default:
-				return ""; //$NON-NLS-1$
-			}
-		}
-	}
-
-}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.widgets;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+
+public class CharacterPairsTableWidget extends TableViewer {
+
+	public CharacterPairsTableWidget(Table table) {
+		super(table);
+		setContentProvider(new CharacterPairContentProvider());
+		setLabelProvider(new CharacterPairLabelProvider());
+
+		GC gc = new GC(table.getShell());
+		gc.setFont(JFaceResources.getDialogFont());
+		TableColumnLayout columnLayout = new TableColumnLayout();
+
+		TableColumn column1 = new TableColumn(table, SWT.NONE);
+		column1.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_start);
+		int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_start);
+		columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true));
+
+		TableColumn column2 = new TableColumn(table, SWT.NONE);
+		column2.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_end);
+		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_end);
+		columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true));
+	}
+
+	protected int computeMinimumColumnWidth(GC gc, String string) {
+		return gc.stringExtent(string).x + 10;
+	}
+
+	protected static class CharacterPairContentProvider implements IStructuredContentProvider {
+
+		private List characterPairList;
+
+		@Override
+		public Object[] getElements(Object input) {
+			return characterPairList.toArray(new CharacterPair[characterPairList.size()]);
+		}
+
+		@SuppressWarnings("unchecked")
+		@Override
+		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+			if (newInput == null) {
+				characterPairList = Collections.EMPTY_LIST;
+			} else {
+				characterPairList = (List) newInput;
+			}
+		}
+
+		@Override
+		public void dispose() {
+			characterPairList = null;
+		}
+	}
+
+	protected static class CharacterPairLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+		@Override
+		public Image getColumnImage(Object element, int columnIndex) {
+			return null;
+		}
+
+		@Override
+		public String getText(Object element) {
+			return getColumnText(element, 0);
+		}
+
+		@Override
+		public String getColumnText(Object element, int columnIndex) {
+			CharacterPair pair = (CharacterPair) element;
+
+			switch (columnIndex) {
+			case 0:
+				return pair.getKey();
+			case 1:
+				return pair.getValue();
+			default:
+				return ""; //$NON-NLS-1$
+			}
+		}
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java
index c0e918f5a..7958babf7 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java
@@ -1,133 +1,133 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.widgets;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
-
-public class OnEnterRuleTableWidget extends TableViewer {
-
-	public OnEnterRuleTableWidget(Table table) {
-		super(table);
-		setContentProvider(new OnEnterRuleContentProvider());
-		setLabelProvider(new OnEnterRuleLabelProvider());
-
-		GC gc = new GC(table.getShell());
-		gc.setFont(JFaceResources.getDialogFont());
-		TableColumnLayout columnLayout = new TableColumnLayout();
-
-		TableColumn column1 = new TableColumn(table, SWT.NONE);
-		column1.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText);
-		int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText);
-		columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true));
-
-		TableColumn column2 = new TableColumn(table, SWT.NONE);
-		column2.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText);
-		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText);
-		columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true));
-
-		TableColumn column3 = new TableColumn(table, SWT.NONE);
-		column3.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction);
-		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction);
-		columnLayout.setColumnData(column3, new ColumnWeightData(1, minWidth, true));
-
-		TableColumn column4 = new TableColumn(table, SWT.NONE);
-		column4.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText);
-		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText);
-		columnLayout.setColumnData(column4, new ColumnWeightData(1, minWidth, true));
-
-		TableColumn column5 = new TableColumn(table, SWT.NONE);
-		column5.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText);
-		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText);
-		columnLayout.setColumnData(column5, new ColumnWeightData(1, minWidth, true));
-	}
-
-	protected int computeMinimumColumnWidth(GC gc, String string) {
-		return gc.stringExtent(string).x + 10;
-	}
-
-	protected class OnEnterRuleContentProvider implements IStructuredContentProvider {
-
-		private List onEnterRulesList;
-
-		@Override
-		public Object[] getElements(Object input) {
-			return onEnterRulesList.toArray(new OnEnterRule[onEnterRulesList.size()]);
-		}
-
-		@SuppressWarnings("unchecked")
-		@Override
-		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-			if (newInput == null) {
-				onEnterRulesList = Collections.EMPTY_LIST;
-			} else {
-				onEnterRulesList = (List) newInput;
-			}
-		}
-
-		@Override
-		public void dispose() {
-			onEnterRulesList = null;
-		}
-	}
-
-	protected class OnEnterRuleLabelProvider extends LabelProvider implements ITableLabelProvider {
-
-		@Override
-		public Image getColumnImage(Object element, int columnIndex) {
-			return null;
-		}
-
-		@Override
-		public String getText(Object element) {
-			return getColumnText(element, 0);
-		}
-
-		@Override
-		public String getColumnText(Object element, int columnIndex) {
-			OnEnterRule rule = (OnEnterRule) element;
-			EnterAction action = rule.getAction();
-
-			switch (columnIndex) {
-			case 0:
-				return rule.getBeforeText().pattern();
-			case 1:
-				return rule.getAfterText() == null ? "" : rule.getAfterText().pattern(); //$NON-NLS-1$
-			case 2:
-				return action.getIndentAction().toString();
-			case 3:
-				return action.getAppendText() == null ? "" : action.getAppendText(); //$NON-NLS-1$
-			case 4:
-				return action.getRemoveText() == null ? "" : action.getRemoveText().toString(); //$NON-NLS-1$
-			default:
-				return ""; //$NON-NLS-1$
-			}
-		}
-	}
-}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.widgets;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
+
+public class OnEnterRuleTableWidget extends TableViewer {
+
+	public OnEnterRuleTableWidget(Table table) {
+		super(table);
+		setContentProvider(new OnEnterRuleContentProvider());
+		setLabelProvider(new OnEnterRuleLabelProvider());
+
+		GC gc = new GC(table.getShell());
+		gc.setFont(JFaceResources.getDialogFont());
+		TableColumnLayout columnLayout = new TableColumnLayout();
+
+		TableColumn column1 = new TableColumn(table, SWT.NONE);
+		column1.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText);
+		int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText);
+		columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true));
+
+		TableColumn column2 = new TableColumn(table, SWT.NONE);
+		column2.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText);
+		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText);
+		columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true));
+
+		TableColumn column3 = new TableColumn(table, SWT.NONE);
+		column3.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction);
+		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction);
+		columnLayout.setColumnData(column3, new ColumnWeightData(1, minWidth, true));
+
+		TableColumn column4 = new TableColumn(table, SWT.NONE);
+		column4.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText);
+		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText);
+		columnLayout.setColumnData(column4, new ColumnWeightData(1, minWidth, true));
+
+		TableColumn column5 = new TableColumn(table, SWT.NONE);
+		column5.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText);
+		minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText);
+		columnLayout.setColumnData(column5, new ColumnWeightData(1, minWidth, true));
+	}
+
+	protected int computeMinimumColumnWidth(GC gc, String string) {
+		return gc.stringExtent(string).x + 10;
+	}
+
+	protected static class OnEnterRuleContentProvider implements IStructuredContentProvider {
+
+		private List onEnterRulesList;
+
+		@Override
+		public Object[] getElements(Object input) {
+			return onEnterRulesList.toArray(new OnEnterRule[onEnterRulesList.size()]);
+		}
+
+		@SuppressWarnings("unchecked")
+		@Override
+		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+			if (newInput == null) {
+				onEnterRulesList = Collections.EMPTY_LIST;
+			} else {
+				onEnterRulesList = (List) newInput;
+			}
+		}
+
+		@Override
+		public void dispose() {
+			onEnterRulesList = null;
+		}
+	}
+
+	protected static class OnEnterRuleLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+		@Override
+		public Image getColumnImage(Object element, int columnIndex) {
+			return null;
+		}
+
+		@Override
+		public String getText(Object element) {
+			return getColumnText(element, 0);
+		}
+
+		@Override
+		public String getColumnText(Object element, int columnIndex) {
+			OnEnterRule rule = (OnEnterRule) element;
+			EnterAction action = rule.getAction();
+
+			switch (columnIndex) {
+			case 0:
+				return rule.getBeforeText().pattern();
+			case 1:
+				return rule.getAfterText() == null ? "" : rule.getAfterText().pattern(); //$NON-NLS-1$
+			case 2:
+				return action.getIndentAction().toString();
+			case 3:
+				return action.getAppendText() == null ? "" : action.getAppendText(); //$NON-NLS-1$
+			case 4:
+				return action.getRemoveText() == null ? "" : action.getRemoveText().toString(); //$NON-NLS-1$
+			default:
+				return ""; //$NON-NLS-1$
+			}
+		}
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java
index b4a31c65f..4d1a216e9 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java
@@ -1,316 +1,316 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.wizards;
-
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.core.runtime.content.IContentTypeManager;
-import org.eclipse.jface.dialogs.DialogPage;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration;
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfiguration;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationPlugin;
-import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationInfoWidget;
-import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
-import org.eclipse.ui.dialogs.ResourceSelectionDialog;
-
-public class SelectLanguageConfigurationWizardPage extends WizardPage implements Listener {
-	private static final String PAGE_NAME = SelectLanguageConfigurationWizardPage.class.getName();
-
-	protected static final String[] TEXTMATE_EXTENSIONS = new String[] { "*language-configuration.json" }; //$NON-NLS-1$
-
-	private Button browseFileSystemButton;
-	private Button browseWorkspaceButton;
-	private Text fileText;
-	private Text contentTypeText;
-	private LanguageConfigurationInfoWidget infoWidget;
-
-	private ILanguageConfigurationRegistryManager registryManager;
-
-	protected SelectLanguageConfigurationWizardPage(String pageName) {
-		super(pageName);
-	}
-
-	public SelectLanguageConfigurationWizardPage(ILanguageConfigurationRegistryManager registryManager) {
-		super(PAGE_NAME);
-		this.registryManager = registryManager;
-		super.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_title);
-		super.setDescription(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_description);
-	}
-
-	@Override
-	public final void createControl(Composite parent) {
-		initializeDialogUnits(parent);
-		Composite topLevel = new Composite(parent, SWT.NONE);
-		topLevel.setLayout(new GridLayout());
-		topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
-		topLevel.setFont(parent.getFont());
-
-		createBody(topLevel);
-		setPageComplete(false);
-		setControl(topLevel);
-	}
-
-	@Override
-	public void handleEvent(Event event) {
-		validateAndUpdateStatus(event);
-	}
-
-	private void validateAndUpdateStatus(Event event) {
-		IStatus status = validatePage(event);
-		statusChanged(status == null ? Status.OK_STATUS : status);
-	}
-
-	public void statusChanged(IStatus status) {
-		setPageComplete(!status.matches(IStatus.ERROR));
-		applyToStatusLine(this, status);
-	}
-
-	private static void applyToStatusLine(DialogPage page, IStatus status) {
-		String message = Status.OK_STATUS.equals(status) ? null : status.getMessage();
-		switch (status.getSeverity()) {
-		case IStatus.OK:
-			page.setMessage(message, IMessageProvider.NONE);
-			page.setErrorMessage(null);
-			break;
-		case IStatus.WARNING:
-			page.setMessage(message, IMessageProvider.WARNING);
-			page.setErrorMessage(null);
-			break;
-		case IStatus.INFO:
-			page.setMessage(message, IMessageProvider.INFORMATION);
-			page.setErrorMessage(null);
-			break;
-		default:
-			if (message != null && message.length() == 0) {
-				message = null;
-			}
-			page.setMessage(null);
-			page.setErrorMessage(message);
-			break;
-		}
-	}
-
-	protected void createBody(Composite ancestor) {
-		Composite parent = new Composite(ancestor, SWT.NONE);
-		parent.setFont(parent.getFont());
-		parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		parent.setLayout(new GridLayout(2, false));
-
-		fileText = createText(parent, LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_file);
-		fileText.addListener(SWT.Modify, this);
-
-		Composite buttons = new Composite(parent, SWT.NONE);
-		buttons.setLayout(new GridLayout(2, false));
-		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
-		gd.horizontalSpan = 2;
-		gd.horizontalAlignment = SWT.RIGHT;
-		buttons.setLayoutData(gd);
-
-		infoWidget = new LanguageConfigurationInfoWidget(parent, SWT.NONE);
-		GridData data = new GridData(GridData.FILL_HORIZONTAL);
-		data.horizontalSpan = 2;
-		infoWidget.setLayoutData(data);
-
-		browseFileSystemButton = new Button(buttons, SWT.NONE);
-		browseFileSystemButton
-				.setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_fileSystem);
-		browseFileSystemButton.addSelectionListener(new SelectionAdapter() {
-			@Override
-			public void widgetSelected(SelectionEvent e) {
-				FileDialog dialog = new FileDialog(parent.getShell());
-				dialog.setFilterExtensions(TEXTMATE_EXTENSIONS);
-				dialog.setFilterPath(fileText.getText());
-				String result = dialog.open();
-				if (result != null && result.length() > 0) {
-					fileText.setText(result);
-				}
-			}
-		});
-
-		browseWorkspaceButton = new Button(buttons, SWT.NONE);
-		browseWorkspaceButton
-				.setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_workspace);
-		browseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
-			@Override
-			public void widgetSelected(SelectionEvent e) {
-				ResourceSelectionDialog dialog = new ResourceSelectionDialog(browseWorkspaceButton.getShell(),
-						ResourcesPlugin.getWorkspace().getRoot(),
-						LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_description);
-				dialog.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_title);
-				int returnCode = dialog.open();
-				Object[] results = dialog.getResult();
-				if (returnCode == 0 && results.length > 0) {
-					fileText.setText(((IResource) results[0]).getFullPath().makeRelative().toString());
-				}
-			}
-		});
-		contentTypeText = createText(parent,
-				LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentType);
-		contentTypeText.addListener(SWT.Modify, this);
-		createContentTypeTreeViewer(parent);
-	}
-
-	private void createContentTypeTreeViewer(Composite composite) {
-		TreeViewer contentTypesViewer = new TreeViewer(composite,
-				SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
-		contentTypesViewer.getControl().setFont(composite.getFont());
-		contentTypesViewer.setContentProvider(new ContentTypesContentProvider());
-		contentTypesViewer.setLabelProvider(new ContentTypesLabelProvider());
-		contentTypesViewer.setComparator(new ViewerComparator());
-		contentTypesViewer.setInput(Platform.getContentTypeManager());
-		GridData data = new GridData(GridData.FILL_HORIZONTAL);
-		data.horizontalSpan = 2;
-		contentTypesViewer.getControl().setLayoutData(data);
-
-		contentTypesViewer.addSelectionChangedListener(event -> contentTypeText
-				.setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString()));
-	}
-
-	private class ContentTypesLabelProvider extends LabelProvider {
-		@Override
-		public String getText(Object element) {
-			IContentType contentType = (IContentType) element;
-			return contentType.getName();
-		}
-	}
-
-	private class ContentTypesContentProvider implements ITreeContentProvider {
-
-		private IContentTypeManager manager = Platform.getContentTypeManager();
-
-		@Override
-		public Object[] getChildren(Object parentElement) {
-			List elements = new ArrayList<>();
-			IContentType baseType = (IContentType) parentElement;
-			for (IContentType contentType : manager.getAllContentTypes()) {
-				if ((contentType.getBaseType() == null && baseType == null)
-						|| ((contentType.getBaseType() != null && contentType.getBaseType().equals(baseType)))) {
-					elements.add(contentType);
-				}
-			}
-			return elements.toArray();
-		}
-
-		@Override
-		public Object getParent(Object element) {
-			IContentType contentType = (IContentType) element;
-			return contentType.getBaseType();
-		}
-
-		@Override
-		public boolean hasChildren(Object element) {
-			return getChildren(element).length > 0;
-		}
-
-		@Override
-		public Object[] getElements(Object inputElement) {
-			return getChildren(null);
-		}
-
-		@Override
-		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-			manager = (IContentTypeManager) newInput;
-		}
-	}
-
-	private Text createText(Composite parent, String s) {
-		Label label = new Label(parent, SWT.NONE);
-		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-		label.setText(s);
-
-		Text text = new Text(parent, SWT.BORDER);
-		text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		return text;
-	}
-
-	protected IStatus validatePage(Event event) {
-		infoWidget.refresh(null);
-		String path = fileText.getText();
-		if (path.length() == 0) {
-			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
-					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_noSelection);
-		}
-		IPath p = new Path(path);
-		if (!p.isAbsolute()) {
-			p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation();
-		}
-		try {
-			ILanguageConfiguration configuration = LanguageConfiguration.load(new FileReader(p.toFile()));
-			if (configuration == null) {
-				return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
-						LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_invalid);
-			}
-			infoWidget.refresh(configuration);
-		} catch (Exception e) {
-			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
-					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_error
-							+ e.getLocalizedMessage());
-		}
-		if (contentTypeText.getText().isEmpty()) {
-			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
-					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_noSelection);
-		}
-		IContentType contentType = ContentTypeHelper.getContentTypeById(contentTypeText.getText());
-		if (contentType == null) {
-			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
-					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_invalid);
-		}
-		if (registryManager.getLanguageConfigurationFor(new IContentType[] { contentType }) != null) {
-			return new Status(IStatus.WARNING, LanguageConfigurationPlugin.PLUGIN_ID,
-					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate);
-		}
-		return null;
-	}
-
-	public ILanguageConfigurationDefinition getDefinition() {
-		IPath p = new Path(fileText.getText());
-		if (!p.isAbsolute()) {
-			p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation();
-		}
-		return new LanguageConfigurationDefinition(ContentTypeHelper.getContentTypeById(contentTypeText.getText()),
-				p.toString());
-	}
-
-}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.wizards;
+
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration;
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfiguration;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationPlugin;
+import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationInfoWidget;
+import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
+import org.eclipse.ui.dialogs.ResourceSelectionDialog;
+
+public class SelectLanguageConfigurationWizardPage extends WizardPage implements Listener {
+	private static final String PAGE_NAME = SelectLanguageConfigurationWizardPage.class.getName();
+
+	protected static final String[] TEXTMATE_EXTENSIONS = { "*language-configuration.json" }; //$NON-NLS-1$
+
+	private Button browseFileSystemButton;
+	private Button browseWorkspaceButton;
+	private Text fileText;
+	private Text contentTypeText;
+	private LanguageConfigurationInfoWidget infoWidget;
+
+	private ILanguageConfigurationRegistryManager registryManager;
+
+	protected SelectLanguageConfigurationWizardPage(String pageName) {
+		super(pageName);
+	}
+
+	public SelectLanguageConfigurationWizardPage(ILanguageConfigurationRegistryManager registryManager) {
+		super(PAGE_NAME);
+		this.registryManager = registryManager;
+		super.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_title);
+		super.setDescription(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_description);
+	}
+
+	@Override
+	public final void createControl(Composite parent) {
+		initializeDialogUnits(parent);
+		Composite topLevel = new Composite(parent, SWT.NONE);
+		topLevel.setLayout(new GridLayout());
+		topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
+		topLevel.setFont(parent.getFont());
+
+		createBody(topLevel);
+		setPageComplete(false);
+		setControl(topLevel);
+	}
+
+	@Override
+	public void handleEvent(Event event) {
+		validateAndUpdateStatus(event);
+	}
+
+	private void validateAndUpdateStatus(Event event) {
+		IStatus status = validatePage(event);
+		statusChanged(status == null ? Status.OK_STATUS : status);
+	}
+
+	public void statusChanged(IStatus status) {
+		setPageComplete(!status.matches(IStatus.ERROR));
+		applyToStatusLine(this, status);
+	}
+
+	private static void applyToStatusLine(DialogPage page, IStatus status) {
+		String message = Status.OK_STATUS.equals(status) ? null : status.getMessage();
+		switch (status.getSeverity()) {
+		case IStatus.OK:
+			page.setMessage(message, IMessageProvider.NONE);
+			page.setErrorMessage(null);
+			break;
+		case IStatus.WARNING:
+			page.setMessage(message, IMessageProvider.WARNING);
+			page.setErrorMessage(null);
+			break;
+		case IStatus.INFO:
+			page.setMessage(message, IMessageProvider.INFORMATION);
+			page.setErrorMessage(null);
+			break;
+		default:
+			if (message != null && message.length() == 0) {
+				message = null;
+			}
+			page.setMessage(null);
+			page.setErrorMessage(message);
+			break;
+		}
+	}
+
+	protected void createBody(Composite ancestor) {
+		Composite parent = new Composite(ancestor, SWT.NONE);
+		parent.setFont(parent.getFont());
+		parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		parent.setLayout(new GridLayout(2, false));
+
+		fileText = createText(parent, LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_file);
+		fileText.addListener(SWT.Modify, this);
+
+		Composite buttons = new Composite(parent, SWT.NONE);
+		buttons.setLayout(new GridLayout(2, false));
+		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+		gd.horizontalSpan = 2;
+		gd.horizontalAlignment = SWT.RIGHT;
+		buttons.setLayoutData(gd);
+
+		infoWidget = new LanguageConfigurationInfoWidget(parent, SWT.NONE);
+		GridData data = new GridData(GridData.FILL_HORIZONTAL);
+		data.horizontalSpan = 2;
+		infoWidget.setLayoutData(data);
+
+		browseFileSystemButton = new Button(buttons, SWT.NONE);
+		browseFileSystemButton
+				.setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_fileSystem);
+		browseFileSystemButton.addSelectionListener(new SelectionAdapter() {
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				FileDialog dialog = new FileDialog(parent.getShell());
+				dialog.setFilterExtensions(TEXTMATE_EXTENSIONS);
+				dialog.setFilterPath(fileText.getText());
+				String result = dialog.open();
+				if (result != null && result.length() > 0) {
+					fileText.setText(result);
+				}
+			}
+		});
+
+		browseWorkspaceButton = new Button(buttons, SWT.NONE);
+		browseWorkspaceButton
+				.setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_workspace);
+		browseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				ResourceSelectionDialog dialog = new ResourceSelectionDialog(browseWorkspaceButton.getShell(),
+						ResourcesPlugin.getWorkspace().getRoot(),
+						LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_description);
+				dialog.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_title);
+				int returnCode = dialog.open();
+				Object[] results = dialog.getResult();
+				if (returnCode == 0 && results.length > 0) {
+					fileText.setText(((IResource) results[0]).getFullPath().makeRelative().toString());
+				}
+			}
+		});
+		contentTypeText = createText(parent,
+				LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentType);
+		contentTypeText.addListener(SWT.Modify, this);
+		createContentTypeTreeViewer(parent);
+	}
+
+	private void createContentTypeTreeViewer(Composite composite) {
+		TreeViewer contentTypesViewer = new TreeViewer(composite,
+				SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+		contentTypesViewer.getControl().setFont(composite.getFont());
+		contentTypesViewer.setContentProvider(new ContentTypesContentProvider());
+		contentTypesViewer.setLabelProvider(new ContentTypesLabelProvider());
+		contentTypesViewer.setComparator(new ViewerComparator());
+		contentTypesViewer.setInput(Platform.getContentTypeManager());
+		GridData data = new GridData(GridData.FILL_HORIZONTAL);
+		data.horizontalSpan = 2;
+		contentTypesViewer.getControl().setLayoutData(data);
+
+		contentTypesViewer.addSelectionChangedListener(event -> contentTypeText
+				.setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString()));
+	}
+
+	private static class ContentTypesLabelProvider extends LabelProvider {
+		@Override
+		public String getText(Object element) {
+			IContentType contentType = (IContentType) element;
+			return contentType.getName();
+		}
+	}
+
+	private static class ContentTypesContentProvider implements ITreeContentProvider {
+
+		private IContentTypeManager manager = Platform.getContentTypeManager();
+
+		@Override
+		public Object[] getChildren(Object parentElement) {
+			List elements = new ArrayList<>();
+			IContentType baseType = (IContentType) parentElement;
+			for (IContentType contentType : manager.getAllContentTypes()) {
+				if ((contentType.getBaseType() == null && baseType == null)
+						|| ((contentType.getBaseType() != null && contentType.getBaseType().equals(baseType)))) {
+					elements.add(contentType);
+				}
+			}
+			return elements.toArray();
+		}
+
+		@Override
+		public Object getParent(Object element) {
+			IContentType contentType = (IContentType) element;
+			return contentType.getBaseType();
+		}
+
+		@Override
+		public boolean hasChildren(Object element) {
+			return getChildren(element).length > 0;
+		}
+
+		@Override
+		public Object[] getElements(Object inputElement) {
+			return getChildren(null);
+		}
+
+		@Override
+		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+			manager = (IContentTypeManager) newInput;
+		}
+	}
+
+	private Text createText(Composite parent, String s) {
+		Label label = new Label(parent, SWT.NONE);
+		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+		label.setText(s);
+
+		Text text = new Text(parent, SWT.BORDER);
+		text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		return text;
+	}
+
+	protected IStatus validatePage(Event event) {
+		infoWidget.refresh(null);
+		String path = fileText.getText();
+		if (path.length() == 0) {
+			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
+					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_noSelection);
+		}
+		IPath p = new Path(path);
+		if (!p.isAbsolute()) {
+			p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation();
+		}
+		try {
+			ILanguageConfiguration configuration = LanguageConfiguration.load(new FileReader(p.toFile()));
+			if (configuration == null) {
+				return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
+						LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_invalid);
+			}
+			infoWidget.refresh(configuration);
+		} catch (Exception e) {
+			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
+					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_error
+							+ e.getLocalizedMessage());
+		}
+		if (contentTypeText.getText().isEmpty()) {
+			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
+					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_noSelection);
+		}
+		IContentType contentType = ContentTypeHelper.getContentTypeById(contentTypeText.getText());
+		if (contentType == null) {
+			return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID,
+					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_invalid);
+		}
+		if (registryManager.getLanguageConfigurationFor(new IContentType[] { contentType }) != null) {
+			return new Status(IStatus.WARNING, LanguageConfigurationPlugin.PLUGIN_ID,
+					LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate);
+		}
+		return null;
+	}
+
+	public ILanguageConfigurationDefinition getDefinition() {
+		IPath p = new Path(fileText.getText());
+		if (!p.isAbsolute()) {
+			p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation();
+		}
+		return new LanguageConfigurationDefinition(ContentTypeHelper.getContentTypeById(contentTypeText.getText()),
+				p.toString());
+	}
+
+}
diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java
index 01a4f4519..7358d08b6 100644
--- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java
+++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -33,5 +33,5 @@ public interface ITMResource extends ITMDefinition {
 	 * @return the stream of the TextMate resource.
 	 * @throws IOException
 	 */
-	public InputStream getInputStream() throws IOException;
+	InputStream getInputStream() throws IOException;
 }
diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java
index 94d3ed259..3e5e4b055 100644
--- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java
+++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java
@@ -92,15 +92,9 @@ protected String getResourceContent() {
 	}
 
 	private static String convertStreamToString(InputStream is) {
-		Scanner s = null;
-		try {
-			s = new Scanner(is);
+		try (Scanner s = new Scanner(is)) {
 			s.useDelimiter("\\A");
 			return s.hasNext() ? s.next() : "";
-		} finally {
-			if (s != null) {
-				s.close();
-			}
 		}
 	}
 }
diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java
index 2f3a6952b..a3542b21f 100644
--- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java
+++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -11,7 +11,6 @@
  */
 package org.eclipse.tm4e.registry.internal.preferences;
 
-import java.lang.reflect.Type;
 import java.util.Collection;
 
 import org.eclipse.tm4e.registry.GrammarDefinition;
@@ -31,12 +30,8 @@ public class PreferenceHelper {
 
 	static {
 		DEFAULT_GSON = new GsonBuilder()
-				.registerTypeAdapter(IGrammarDefinition.class, new InstanceCreator() {
-					@Override
-					public GrammarDefinition createInstance(Type type) {
-						return new GrammarDefinition();
-					}
-				}).create();
+				.registerTypeAdapter(IGrammarDefinition.class, (InstanceCreator) type -> new GrammarDefinition())
+				.create();
 	}
 
 	public static IGrammarDefinition[] loadGrammars(String json) {
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java
index 311ab2837..fb549daae 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -48,7 +48,7 @@ public void initialize(IServiceLocator serviceLocator) {
 
 	@Override
 	protected IContributionItem[] getContributionItems() {
-		List items = new ArrayList();
+		List items = new ArrayList<>();
 		if (handlerService != null) {
 			IEditorPart editorPart = getActivePart(handlerService.getCurrentState());
 			if (editorPart != null) {
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java
index eb5b9cd81..1b5ff2dc8 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java
@@ -21,7 +21,7 @@
  */
 public class DocumentInputStream extends InputStream {
 	
-	private IDocument fDocument;
+	private final IDocument fDocument;
 	private int fCurrPos;
 	
 	public DocumentInputStream(IDocument document) {
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java
index 5e0a86d6b..e4fd88b6d 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -31,7 +31,7 @@
 public class DocumentLineList extends AbstractLineList {
 
 	private final IDocument document;
-	private InternalListener listener;
+	private final InternalListener listener;
 
 	public DocumentLineList(IDocument document) {
 		this.document = document;
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java
index 35e7f9d80..31dae8949 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java
@@ -1,22 +1,22 @@
-/**
- * Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr  - initial API and implementation
- */
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr  - initial API and implementation
+ */
 package org.eclipse.tm4e.ui.internal.model;
 
-import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocument;
 import org.eclipse.tm4e.core.model.TMModel;
 
 public class TMDocumentModel extends TMModel {
 
-	private IDocument document;
+	private final IDocument document;
 
 	public TMDocumentModel(IDocument document) {
 		super(new DocumentLineList(document));
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java
index 1ec96e32f..2114f5ecd 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -11,7 +11,6 @@
  */
 package org.eclipse.tm4e.ui.internal.preferences;
 
-import java.lang.reflect.Type;
 import java.util.Collection;
 
 import org.eclipse.tm4e.ui.themes.IThemeAssociation;
@@ -30,12 +29,7 @@ public class PreferenceHelper {
 	private static final Gson DEFAULT_GSON;
 
 	static {
-		DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(IThemeAssociation.class, new InstanceCreator() {
-			@Override
-			public ThemeAssociation createInstance(Type type) {
-				return new ThemeAssociation();
-			}
-		}).create();
+		DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(IThemeAssociation.class, (InstanceCreator) type -> new ThemeAssociation()).create();
 	}
 
 	public static IThemeAssociation[] loadThemeAssociations(String json) {
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java
index 427ca9a89..8e8ba08bc 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java
@@ -1,14 +1,14 @@
-/**
- * Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr  - initial API and implementation
- */
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr  - initial API and implementation
+ */
 package org.eclipse.tm4e.ui.internal.snippets;
 
 import java.util.ArrayList;
@@ -24,7 +24,7 @@
 
 public class SnippetManager implements ISnippetManager {
 
-	private static final ISnippet[] EMPTY_SNIPPETS = new ISnippet[0];
+	private static final ISnippet[] EMPTY_SNIPPETS = {};
 
 	private static final String SNIPPET_ELT = "snippet";
 
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java
index b654f665a..a5227d354 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -26,7 +26,7 @@ public class TMPresentationReconcilerTestGenerator
 	private ITextViewer viewer;
 	private IDocument document;
 
-	private StringBuilder code = new StringBuilder();
+	private final StringBuilder code = new StringBuilder();
 
 	/*private List commands;
 
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java
index 43c68e4e0..f1b2b4e4d 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015, 2021 Angelo ZERR and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -79,9 +79,8 @@ public ITheme getDefaultTheme(boolean dark) {
 	@Override
 	public ITheme[] getThemes(boolean dark) {
 		Collection themes = this.themes.values();
-		return themes.stream().filter(theme -> {
-			return theme.isDark() == dark;
-		}).collect(Collectors.toList()).toArray(new ITheme[0]);
+		return themes.stream().filter(theme -> (theme.isDark() == dark))
+		   .collect(Collectors.toList()).toArray(new ITheme[0]);
 	}
 
 	@Override
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java
index 60f816bcb..ff6efec12 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2018 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -28,7 +28,7 @@ public class BaseThemeAssociationRegistry {
 
 	private IThemeAssociation defaultAssociation;
 	private final Map> eclipseThemeIds;
-	private List allAssociations;
+	private final List allAssociations;
 
 	public BaseThemeAssociationRegistry() {
 		eclipseThemeIds = new HashMap<>();
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java
index 55a9ed591..2f06f5ce6 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -27,7 +27,7 @@ public class ThemeAssociationRegistry {
 
 	private final Map scopes;
 
-	private class EclipseThemeAssociation {
+	private static class EclipseThemeAssociation {
 
 		private IThemeAssociation light;
 		private IThemeAssociation dark;
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java
index 20b570c99..fd400ee31 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -36,7 +36,7 @@
  */
 public class ThemeAssociationsWidget extends TableAndButtonsWidget {
 
-	private IThemeManager themeManager;
+	private final IThemeManager themeManager;
 
 	private Button editButton;
 	private Button removeButton;
@@ -55,7 +55,7 @@ protected void createButtons(Composite parent) {
 		editButton = new Button(parent, SWT.PUSH);
 		editButton.setText(TMUIMessages.Button_edit);
 		editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		editButton.addListener(SWT.Selection, (e) -> {
+		editButton.addListener(SWT.Selection, e -> {
 			// Open the wizard to create association between theme and grammar.
 			CreateThemeAssociationWizard wizard = new CreateThemeAssociationWizard(false);
 			wizard.setInitialDefinition(definition);
@@ -73,7 +73,7 @@ protected void createButtons(Composite parent) {
 		removeButton = new Button(parent, SWT.PUSH);
 		removeButton.setText(TMUIMessages.Button_remove);
 		removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		removeButton.addListener(SWT.Selection, (e) -> {
+		removeButton.addListener(SWT.Selection, e -> {
 
 			if (MessageDialog.openConfirm(getShell(), TMUIMessages.ThemeAssociationsWidget_remove_dialog_title,
 					TMUIMessages.ThemeAssociationsWidget_remove_dialog_message)) {
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java
index e9482bf50..015e85d93 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -45,7 +45,7 @@ public class SelectGrammarWizardPage extends AbstractWizardPage {
 
 	private static final String PAGE_NAME = SelectGrammarWizardPage.class.getName();
 
-	protected static final String[] TEXTMATE_EXTENSIONS = new String[] {"*.tmLanguage","*.json"};
+	protected static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json"};
 
 	private Button browseFileSystemButton;
 	private Button browseWorkspaceButton;
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java
index a44e152c3..aa57143ce 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -17,9 +17,9 @@
  */
 public interface ThemeIdConstants {
 
-	public static final String Light = "org.eclipse.tm4e.ui.themes.Light";
-	public static final String Monokai = "org.eclipse.tm4e.ui.themes.Monokai";
-	public static final String SolarizedLight = "org.eclipse.tm4e.ui.themes.SolarizedLight";
-	public static final String Dark = "org.eclipse.tm4e.ui.themes.Dark";
+	String Light = "org.eclipse.tm4e.ui.themes.Light";
+	String Monokai = "org.eclipse.tm4e.ui.themes.Monokai";
+	String SolarizedLight = "org.eclipse.tm4e.ui.themes.SolarizedLight";
+	String Dark = "org.eclipse.tm4e.ui.themes.Dark";
 
 }
diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java
index cd84260d0..349bb38ca 100644
--- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java
+++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java
@@ -1,9 +1,9 @@
 /**
  *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  *  Contributors:
@@ -31,7 +31,7 @@
 
 public class CSSTokenProvider extends AbstractTokenProvider {
 
-	private Map tokenMaps;
+	private final Map tokenMaps;
 	private CSSParser parser;
 
 	public CSSTokenProvider(InputStream in) {

From 3f80d3d9dc1ea672e6e8a0b59337830c9ff93b8d Mon Sep 17 00:00:00 2001
From: Sebastian Thomschke 
Date: Sun, 5 Dec 2021 18:44:44 +0100
Subject: [PATCH 015/202] Improve .gitignore settings (#303)

---
 .gitignore                                    |  20 +-
 .project                                      |  17 +
 org.eclipse.tm4e.core.tests/.gitignore        |   2 -
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 org.eclipse.tm4e.core/.gitignore              |   2 -
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 .../.gitignore                                |   1 -
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 .../.gitignore                                |   2 -
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 org.eclipse.tm4e.registry/.gitignore          |   1 -
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 org.eclipse.tm4e.repository/.gitignore        |   1 -
 org.eclipse.tm4e.samples/.gitignore           |   2 -
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 org.eclipse.tm4e.ui.tests/.gitignore          |   2 -
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 .../.settings/org.eclipse.jdt.core.prefs      | 518 ++++++++++++++++++
 19 files changed, 4696 insertions(+), 16 deletions(-)
 create mode 100644 .project
 delete mode 100644 org.eclipse.tm4e.core.tests/.gitignore
 create mode 100644 org.eclipse.tm4e.core.tests/.settings/org.eclipse.jdt.core.prefs
 delete mode 100644 org.eclipse.tm4e.core/.gitignore
 create mode 100644 org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs
 delete mode 100644 org.eclipse.tm4e.languageconfiguration.tests/.gitignore
 create mode 100644 org.eclipse.tm4e.languageconfiguration.tests/.settings/org.eclipse.jdt.core.prefs
 delete mode 100644 org.eclipse.tm4e.languageconfiguration/.gitignore
 create mode 100644 org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs
 create mode 100644 org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs
 delete mode 100644 org.eclipse.tm4e.registry/.gitignore
 create mode 100644 org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs
 delete mode 100644 org.eclipse.tm4e.repository/.gitignore
 delete mode 100644 org.eclipse.tm4e.samples/.gitignore
 create mode 100644 org.eclipse.tm4e.samples/.settings/org.eclipse.jdt.core.prefs
 delete mode 100644 org.eclipse.tm4e.ui.tests/.gitignore
 create mode 100644 org.eclipse.tm4e.ui.tests/.settings/org.eclipse.jdt.core.prefs
 create mode 100644 org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs

diff --git a/.gitignore b/.gitignore
index 3d081ef4e..cca875399 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,18 @@
-.settings
+# Eclipse
 /bin
-/.project
-target
\ No newline at end of file
+/*/bin
+**/.settings/*
+!**/.settings/org.eclipse.core.resoures.prefs
+!**/.settings/org.eclipse.jdt.core.prefs
+!**/.settings/org.eclipse.pde.core.prefs
+
+# Maven
+/target
+/*/target
+
+# OSX
+.DS_Store
+
+# Vim
+*.swo
+*.swp
diff --git a/.project b/.project
new file mode 100644
index 000000000..1548310c4
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+	tm4e
+	
+	
+	
+	
+		
+			org.eclipse.m2e.core.maven2Builder
+			
+			
+		
+	
+	
+		org.eclipse.m2e.core.maven2Nature
+	
+
diff --git a/org.eclipse.tm4e.core.tests/.gitignore b/org.eclipse.tm4e.core.tests/.gitignore
deleted file mode 100644
index 934e0e06f..000000000
--- a/org.eclipse.tm4e.core.tests/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/bin
-/target
diff --git a/org.eclipse.tm4e.core.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.core.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.core.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.core/.gitignore b/org.eclipse.tm4e.core/.gitignore
deleted file mode 100644
index 934e0e06f..000000000
--- a/org.eclipse.tm4e.core/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/bin
-/target
diff --git a/org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.languageconfiguration.tests/.gitignore b/org.eclipse.tm4e.languageconfiguration.tests/.gitignore
deleted file mode 100644
index ae3c17260..000000000
--- a/org.eclipse.tm4e.languageconfiguration.tests/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bin/
diff --git a/org.eclipse.tm4e.languageconfiguration.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.languageconfiguration.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.languageconfiguration.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.languageconfiguration/.gitignore b/org.eclipse.tm4e.languageconfiguration/.gitignore
deleted file mode 100644
index 934e0e06f..000000000
--- a/org.eclipse.tm4e.languageconfiguration/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/bin
-/target
diff --git a/org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.registry/.gitignore b/org.eclipse.tm4e.registry/.gitignore
deleted file mode 100644
index ae3c17260..000000000
--- a/org.eclipse.tm4e.registry/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bin/
diff --git a/org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.repository/.gitignore b/org.eclipse.tm4e.repository/.gitignore
deleted file mode 100644
index b83d22266..000000000
--- a/org.eclipse.tm4e.repository/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/target/
diff --git a/org.eclipse.tm4e.samples/.gitignore b/org.eclipse.tm4e.samples/.gitignore
deleted file mode 100644
index 934e0e06f..000000000
--- a/org.eclipse.tm4e.samples/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/bin
-/target
diff --git a/org.eclipse.tm4e.samples/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.samples/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.samples/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.ui.tests/.gitignore b/org.eclipse.tm4e.ui.tests/.gitignore
deleted file mode 100644
index 934e0e06f..000000000
--- a/org.eclipse.tm4e.ui.tests/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/bin
-/target
diff --git a/org.eclipse.tm4e.ui.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.ui.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.ui.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f648802b5
--- /dev/null
+++ b/org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,518 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=info
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=info
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

From 8d2f7e71c0a2edb167ee681dd11eb60f450f8ead Mon Sep 17 00:00:00 2001
From: sebthom 
Date: Sun, 5 Dec 2021 21:19:40 +0100
Subject: [PATCH 016/202] Normalize new line chars

---
 .../tm4e/core/grammar/GrammarSuiteTest.java   |  176 +-
 .../tm4e/core/grammar/GrammarTest.java        |  226 +-
 .../grammar/internal/MatcherTestImpl.java     |   68 +-
 .../core/grammar/internal/RawTestImpl.java    |  320 +-
 .../core/grammar/internal/RawTestLine.java    |   48 +-
 .../tm4e/core/grammar/internal/RawToken.java  |   88 +-
 .../tm4e/core/theme/ThemeMatchingTest.java    |  542 +--
 .../tm4e/core/theme/ThemeParsingTest.java     |  130 +-
 .../tm4e/core/theme/ThemeResolvingTest.java   |  802 ++--
 .../suite1/fixtures/Markdown.tmLanguage       | 2214 ++++-----
 .../themes/syntaxes/Platform.tmLanguage       |    2 +-
 .../org/eclipse/tm4e/core/TMException.java    |   50 +-
 .../org/eclipse/tm4e/core/grammar/IToken.java |   32 +-
 .../core/grammar/ITokenizeLineResult.java     |   40 +-
 .../eclipse/tm4e/core/grammar/Injection.java  |   46 +-
 .../tm4e/core/grammar/StackElement.java       |   20 +-
 .../css/AbstractAttributeCondition.java       |   70 +-
 .../css/AbstractCombinatorCondition.java      |   90 +-
 .../internal/css/AbstractElementSelector.java |   84 +-
 .../core/internal/css/CSSAndCondition.java    |   74 +-
 .../internal/css/CSSAttributeCondition.java   |  136 +-
 .../core/internal/css/CSSClassCondition.java  |   64 +-
 .../internal/css/CSSConditionFactory.java     |  196 +-
 .../internal/css/CSSConditionalSelector.java  |  134 +-
 .../core/internal/css/CSSDocumentHandler.java |  302 +-
 .../core/internal/css/CSSElementSelector.java |   70 +-
 .../core/internal/css/CSSSelectorFactory.java |  200 +-
 .../tm4e/core/internal/css/CSSValueImpl.java  |  180 +-
 .../core/internal/css/ExtendedCondition.java  |   40 +-
 .../core/internal/css/ExtendedSelector.java   |   44 +-
 .../tm4e/core/internal/css/Measure.java       |  272 +-
 .../tm4e/core/internal/css/RGBColorImpl.java  |  126 +-
 .../core/internal/grammar/LineTokens.java     |   58 +-
 .../internal/grammar/LocalStackElement.java   |   44 +-
 .../core/internal/grammar/MetadataConsts.java |   72 +-
 .../internal/grammar/ScopeListElement.java    |  234 +-
 .../core/internal/grammar/ScopeMetadata.java  |   40 +-
 .../grammar/ScopeMetadataProvider.java        |  308 +-
 .../grammar/StackElementMetadata.java         |  132 +-
 .../internal/grammar/StandardTokenType.java   |   54 +-
 .../tm4e/core/internal/grammar/Token.java     |  108 +-
 .../internal/grammar/TokenizeLineResult.java  |   66 +-
 .../internal/grammar/TokenizeLineResult2.java |   62 +-
 .../internal/grammar/parser/PListGrammar.java |   36 +-
 .../core/internal/grammar/parser/Raw.java     |  600 +--
 .../grammar/reader/GrammarReader.java         |   38 +-
 .../grammar/reader/SyncGrammarReader.java     |   38 +-
 .../matcher/IMatchInjectionsResult.java       |   18 +-
 .../core/internal/matcher/IMatchResult.java   |   24 +-
 .../internal/matcher/MatcherWithPriority.java |   70 +-
 .../internal/oniguruma/IOnigCaptureIndex.java |   26 +-
 .../oniguruma/IOnigNextMatchResult.java       |   18 +-
 .../oniguruma/OnigNextMatchResult.java        |  236 +-
 .../core/internal/oniguruma/OnigSearcher.java |   82 +-
 .../tm4e/core/internal/parser/PList.java      |  256 +-
 .../core/internal/parser/PListObject.java     |  122 +-
 .../internal/parser/json/JSONPListParser.java |  166 +-
 .../internal/parser/xml/XMLPListParser.java   |   78 +-
 .../tm4e/core/internal/rule/BeginEndRule.java |  146 +-
 .../core/internal/rule/BeginWhileRule.java    |  152 +-
 .../tm4e/core/internal/rule/CaptureRule.java  |   26 +-
 .../internal/rule/ICompilePatternsResult.java |   26 +-
 .../core/internal/rule/ICompiledRule.java     |   30 +-
 .../core/internal/rule/IGrammarRegistry.java  |   20 +-
 .../rule/IRegExpSourceAnchorCache.java        |   34 +-
 .../internal/rule/IRuleFactoryHelper.java     |   12 +-
 .../core/internal/rule/IRuleRegistry.java     |   16 +-
 .../core/internal/rule/IncludeOnlyRule.java   |   64 +-
 .../tm4e/core/internal/rule/MatchRule.java    |   60 +-
 .../tm4e/core/internal/rule/RegExpSource.java |  420 +-
 .../core/internal/rule/RegExpSourceList.java  |  216 +-
 .../eclipse/tm4e/core/internal/rule/Rule.java |   82 +-
 .../tm4e/core/internal/rule/RuleFactory.java  |  434 +-
 .../tm4e/core/internal/theme/PListTheme.java  |   36 +-
 .../tm4e/core/internal/theme/ThemeRaw.java    |   84 +-
 .../tm4e/core/internal/types/IBaseRaw.java    |   12 +-
 .../core/internal/types/IRawCaptures.java     |   16 +-
 .../tm4e/core/internal/types/IRawGrammar.java |   52 +-
 .../core/internal/types/IRawRepository.java   |   36 +-
 .../tm4e/core/internal/types/IRawRule.java    |  126 +-
 .../tm4e/core/internal/utils/CloneUtils.java  |  124 +-
 .../core/internal/utils/CompareUtils.java     |  114 +-
 .../tm4e/core/internal/utils/RegexSource.java |  116 +-
 .../eclipse/tm4e/core/model/DecodeMap.java    |  154 +-
 .../eclipse/tm4e/core/model/IModelLines.java  |  140 +-
 .../model/IModelTokensChangedListener.java    |   30 +-
 .../org/eclipse/tm4e/core/model/ITMModel.java |  118 +-
 .../tm4e/core/model/ITokenizationSupport.java |   30 +-
 .../eclipse/tm4e/core/model/LineTokens.java   |   58 +-
 .../eclipse/tm4e/core/model/ModelLine.java    |   86 +-
 .../core/model/ModelTokensChangedEvent.java   |   48 +-
 .../model/ModelTokensChangedEventBuilder.java |   68 +-
 .../org/eclipse/tm4e/core/model/Range.java    |   26 +-
 .../org/eclipse/tm4e/core/model/TMModel.java  |  664 +--
 .../org/eclipse/tm4e/core/model/TMState.java  |   78 +-
 .../org/eclipse/tm4e/core/model/TMToken.java  |   26 +-
 .../tm4e/core/model/TMTokenDecodeData.java    |   32 +-
 .../eclipse/tm4e/core/model/Tokenizer.java    |  192 +-
 .../tm4e/core/registry/IRegistryOptions.java  |   64 +-
 .../org/eclipse/tm4e/core/theme/ColorMap.java |  108 +-
 .../eclipse/tm4e/core/theme/FontStyle.java    |   52 +-
 .../eclipse/tm4e/core/theme/IRawTheme.java    |   22 +-
 .../tm4e/core/theme/IRawThemeSetting.java     |   46 +-
 .../org/eclipse/tm4e/core/theme/IStyle.java   |   48 +-
 .../tm4e/core/theme/IThemeProvider.java       |   22 +-
 .../tm4e/core/theme/IThemeSetting.java        |   20 +-
 .../tm4e/core/theme/ParsedThemeRule.java      |  158 +-
 .../java/org/eclipse/tm4e/core/theme/RGB.java |   42 +-
 .../org/eclipse/tm4e/core/theme/Theme.java    |  510 +--
 .../tm4e/core/theme/ThemeTrieElement.java     |  366 +-
 .../tm4e/core/theme/ThemeTrieElementRule.java |  178 +-
 .../tm4e/core/theme/css/CSSParser.java        |  172 +-
 .../eclipse/tm4e/core/theme/css/CSSStyle.java |  174 +-
 .../test/java/org/eclipse/tm4e/core/Data.java |   24 +-
 .../org/eclipse/tm4e/core/TestGrammar.java    |   54 +-
 .../org/eclipse/tm4e/core/TestOngurama.java   |   50 +-
 .../eclipse/tm4e/core/css/CSSParserTest.java  |   50 +-
 .../core/grammar/GrammarInjectionTest.java    |  162 +-
 .../tm4e/core/grammar/GrammarTest.java        |  186 +-
 .../tm4e/core/grammar/GrammarTest2.java       |  130 +-
 .../eclipse/tm4e/core/grammar/MarkDown.java   |  126 +-
 .../parser/json/JSONPListParserTest.java      |   46 +-
 .../parser/xml/XMLPlistParserTest.java        |   46 +-
 .../tm4e/core/Angular2TypeScript.tmLanguage   | 4004 ++++++++---------
 .../org/eclipse/tm4e/core/Markdown.tmLanguage | 2214 ++++-----
 .../ILanguageConfiguration.java               |  170 +-
 ...LanguageConfigurationAutoEditStrategy.java |  468 +-
 ...uageConfigurationCharacterPairMatcher.java |  278 +-
 .../ToggleLineCommentHandler.java             |  580 +--
 .../internal/LanguageConfiguration.java       |  550 +--
 .../LanguageConfigurationDefinition.java      |  318 +-
 .../LanguageConfigurationMessages.java        |  142 +-
 .../internal/LanguageConfigurationPlugin.java |   72 +-
 .../LanguageConfigurationPreferencePage.java  |  584 +--
 .../preferences/PreferenceConstants.java      |   36 +-
 .../preferences/PreferenceHelper.java         |  130 +-
 .../supports/AutoClosingPairConditional.java  |   58 +-
 .../internal/supports/CharacterPair.java      |   44 +-
 .../supports/CharacterPairSupport.java        |  148 +-
 .../internal/supports/CommentSupport.java     |  126 +-
 .../internal/supports/EnterAction.java        |  214 +-
 .../supports/EnterActionAndIndent.java        |   52 +-
 .../internal/supports/IndentationRule.java    |   10 +-
 .../internal/supports/OnEnterRule.java        |   94 +-
 .../internal/supports/OnEnterSupport.java     |  236 +-
 .../internal/utils/RegExpUtils.java           |   76 +-
 .../internal/utils/TabSpacesInfo.java         |   40 +-
 .../internal/utils/TextUtils.java             |  354 +-
 .../widgets/CharacterPairsTableWidget.java    |  222 +-
 .../widgets/OnEnterRuleTableWidget.java       |  266 +-
 ...SelectLanguageConfigurationWizardPage.java |  632 +--
 .../internal/supports/OnEnterSupportTest.java |  294 +-
 .../eclipse/tm4e/markdown/TMHTMLRenderer.java |  224 +-
 .../tm4e/markdown/TMMarkdownPlugin.java       |   70 +-
 .../tm4e/markdown/marked/BlockRules.java      |  204 +-
 .../tm4e/markdown/marked/HTMLRenderer.java    |  320 +-
 .../eclipse/tm4e/markdown/marked/Helpers.java |   46 +-
 .../tm4e/markdown/marked/IRenderer.java       |  104 +-
 .../tm4e/markdown/marked/InlineLexer.java     |  162 +-
 .../tm4e/markdown/marked/InlineRules.java     |  190 +-
 .../eclipse/tm4e/markdown/marked/Lexer.java   |  230 +-
 .../eclipse/tm4e/markdown/marked/Marked.java  |   44 +-
 .../eclipse/tm4e/markdown/marked/Options.java |   98 +-
 .../eclipse/tm4e/markdown/marked/Parser.java  |  142 +-
 .../eclipse/tm4e/markdown/marked/RegExp.java  |  116 +-
 .../eclipse/tm4e/markdown/marked/Token.java   |   70 +-
 .../tm4e/markdown/marked/TokenType.java       |   14 +-
 .../eclipse/tm4e/markdown/marked/Tokens.java  |   46 +-
 .../tm4e/registry/GrammarDefinition.java      |  122 +-
 .../tm4e/registry/IGrammarDefinition.java     |   44 +-
 .../registry/IGrammarRegistryManager.java     |  192 +-
 .../eclipse/tm4e/registry/ITMDefinition.java  |   46 +-
 .../eclipse/tm4e/registry/ITMResource.java    |   74 +-
 .../registry/TMEclipseRegistryPlugin.java     |  116 +-
 .../org/eclipse/tm4e/registry/TMResource.java |  200 +-
 .../WorkingCopyGrammarRegistryManager.java    |  182 +-
 .../eclipse/tm4e/registry/XMLConstants.java   |   66 +-
 .../AbstractGrammarRegistryManager.java       |  472 +-
 .../tm4e/registry/internal/GrammarCache.java  |  244 +-
 .../internal/GrammarRegistryManager.java      |  220 +-
 .../preferences/PreferenceConstants.java      |   44 +-
 .../preferences/PreferenceHelper.java         |   90 +-
 .../eclipse/tm4e/samples/TMSamplesPlugin.java |  148 +-
 .../tm4e/samples/angular2/Angular2Editor.java |   34 +-
 .../angular2/Angular2ViewerConfiguration.java |  128 +-
 .../samples/freemarker/FreemarkerEditor.java  |   34 +-
 .../FreemarkerViewerConfiguration.java        |   46 +-
 .../eclipse/tm4e/samples/html/HTMLEditor.java |   34 +-
 .../samples/html/HTMLViewerConfiguration.java |   46 +-
 .../eclipse/tm4e/samples/php/PHPEditor.java   |   34 +-
 .../samples/php/PHPViewerConfiguration.java   |   46 +-
 .../tm4e/samples/typescript/JSXEditor.java    |   34 +-
 .../typescript/JSXViewerConfiguration.java    |   80 +-
 .../samples/typescript/TypeScriptEditor.java  |   34 +-
 .../TypeScriptViewerConfiguration.java        |   82 +-
 .../eclipse/tm4e/samples/yaml/YAMLEditor.java |   34 +-
 .../samples/yaml/YAMLViewerConfiguration.java |   46 +-
 .../syntaxes/YAML.tmLanguage                  | 2326 +++++-----
 .../syntaxes/ftl.tmLanguage                   |  292 +-
 .../internal/model/DocumentLineListTest.java  |   14 +-
 .../tm4e/ui/internal/text/Command.java        |  138 +-
 .../internal/text/DocumentReplaceCommand.java |  100 +-
 .../ui/internal/text/DocumentSetCommand.java  |   74 +-
 .../internal/text/StyleRangesCollector.java   |  230 +-
 ...ewerInvalidateTextPresentationCommand.java |  100 +-
 .../org/eclipse/tm4e/ui/text/ICommand.java    |   18 +-
 .../org/eclipse/tm4e/ui/text/TMEditor.java    |  156 +-
 ...MPresentationReconcilerTypeScriptTest.java |  652 +--
 .../tm4e/ui/themes/MockThemeManager.java      |   26 +-
 .../tm4e/ui/themes/ThemeManagerTest.java      |  134 +-
 .../java/org/eclipse/tm4e/ui/TMUIPlugin.java  |  268 +-
 .../tm4e/ui/internal/TMPropertyTester.java    |   70 +-
 .../tm4e/ui/internal/TMUIMessages.java        |  178 +-
 .../ui/internal/menus/ThemeContribution.java  |  208 +-
 .../ui/internal/model/DocumentHelper.java     |  110 +-
 .../internal/model/DocumentInputStream.java   |   98 +-
 .../ui/internal/model/DocumentLineList.java   |  220 +-
 .../ui/internal/model/TMDocumentModel.java    |   60 +-
 .../ui/internal/model/TMModelManager.java     |  106 +-
 .../preferences/PreferenceConstants.java      |   48 +-
 .../preferences/PreferenceHelper.java         |   84 +-
 .../tm4e/ui/internal/snippets/Snippet.java    |  124 +-
 .../ui/internal/snippets/SnippetManager.java  |  184 +-
 ...TMPresentationReconcilerTestGenerator.java |  410 +-
 .../internal/themes/AbstractThemeManager.java |  296 +-
 .../themes/BaseThemeAssociationRegistry.java  |  278 +-
 .../themes/ThemeAssociationRegistry.java      |  334 +-
 .../tm4e/ui/internal/themes/ThemeManager.java |  354 +-
 .../themes/WorkingCopyThemeManager.java       |  242 +-
 .../widgets/ColumnSelectionAdapter.java       |   86 +-
 .../widgets/ColumnViewerComparator.java       |  144 +-
 .../widgets/ContentTypeLabelProvider.java     |  110 +-
 .../widgets/ContentTypesBindingWidget.java    |   60 +-
 .../GrammarDefinitionContentProvider.java     |   74 +-
 .../GrammarDefinitionLabelProvider.java       |   88 +-
 .../internal/widgets/GrammarInfoWidget.java   |  196 +-
 .../tm4e/ui/internal/widgets/TMViewer.java    |  160 +-
 .../widgets/TableAndButtonsWidget.java        |  238 +-
 .../ThemeAssociationLabelProvider.java        |  112 +-
 .../widgets/ThemeAssociationsWidget.java      |  240 +-
 .../widgets/ThemeContentProvider.java         |   74 +-
 .../internal/widgets/ThemeLabelProvider.java  |   88 +-
 .../internal/wizards/AbstractWizardPage.java  |  210 +-
 .../wizards/CreateThemeAssociationWizard.java |  176 +-
 .../CreateThemeAssociationWizardPage.java     |  254 +-
 .../wizards/SelectGrammarWizardPage.java      |  312 +-
 .../wizards/TextMateGrammarImportWizard.java  |  164 +-
 .../tm4e/ui/model/ITMModelManager.java        |   66 +-
 .../eclipse/tm4e/ui/snippets/ISnippet.java    |   78 +-
 .../tm4e/ui/snippets/ISnippetManager.java     |   46 +-
 .../ITMPresentationReconcilerListener.java    |   84 +-
 .../ui/text/TMPresentationReconciler.java     | 1712 +++----
 .../tm4e/ui/themes/AbstractTokenProvider.java |   32 +-
 .../org/eclipse/tm4e/ui/themes/ITheme.java    |  130 +-
 .../tm4e/ui/themes/IThemeAssociation.java     |   66 +-
 .../eclipse/tm4e/ui/themes/IThemeManager.java |  278 +-
 .../tm4e/ui/themes/ITokenProvider.java        |   72 +-
 .../org/eclipse/tm4e/ui/themes/Theme.java     |  360 +-
 .../tm4e/ui/themes/ThemeAssociation.java      |  278 +-
 .../tm4e/ui/themes/ThemeIdConstants.java      |   50 +-
 .../tm4e/ui/themes/css/CSSTokenProvider.java  |  252 +-
 .../eclipse/tm4e/ui/utils/ClassHelper.java    |  106 +-
 .../tm4e/ui/utils/ContentTypeHelper.java      |  462 +-
 .../tm4e/ui/utils/ContentTypeInfo.java        |   54 +-
 .../tm4e/ui/utils/PreferenceUtils.java        |  108 +-
 265 files changed, 24674 insertions(+), 24674 deletions(-)

diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java
index 34205c120..d5df4ae72 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java
@@ -1,92 +1,92 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.tm4e.core.grammar.internal.MatcherTestImpl;
-import org.eclipse.tm4e.core.grammar.internal.RawTestImpl;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.DynamicTest;
-import org.junit.jupiter.api.TestFactory;
-
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonIOException;
-import com.google.gson.JsonSyntaxException;
-import com.google.gson.reflect.TypeToken;
-
-/**
- * VSCode TextMate grammar tests which uses same vscode-textmate tests located
- * at src\test\resources\test-cases
- * 
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts
- *
- */
-public class GrammarSuiteTest {
-
-	private static final File REPO_ROOT = new File("src/test/resources");
-
-	// TODO: fix thoses tests:
-	// It seems that problem comes from with encoding. OnigString should support UTF-16 like https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc 
-	private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66");
-
-	@TestFactory @DisplayName("Tokenization /first-mate/")
-	Collection firstMate() throws Exception {
-		return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/first-mate/tests.json"));
-	}
-	
-	@TestFactory @DisplayName("Tokenization /suite1/ tests.json")
-	Collection testsJSon() throws Exception {
-		return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/tests.json"));
-	}
-	
-	@TestFactory @DisplayName("Tokenization /suite1/ whileTests.json")
-	Collection whileTests() throws Exception {
-		return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/whileTests.json"));
-	}
-
-
-	private List  createVSCodeTestSuite(File testLocation) throws Exception {
-		Type listType = new TypeToken>() {
-		}.getType();
-		List tests = new GsonBuilder().create().fromJson(new FileReader(testLocation), listType);
-		List dynamicTests = new ArrayList<>();
-		for (RawTestImpl test : tests) {
-			if (!IGNORE_TESTS.contains(test.getDesc())) {
-				test.setTestLocation(testLocation);
-				dynamicTests.add(DynamicTest.dynamicTest(test.getDesc(), () -> test.executeTest()));
-			}
-		}
-		return dynamicTests;
-	}
-	
-	@TestFactory @DisplayName("Matcher tests")
-	Collection dynamicTestsWithCollection() throws JsonIOException, JsonSyntaxException, FileNotFoundException {
-		Type listType = new TypeToken>() {
-		}.getType();
-		List tests = new GsonBuilder().create()
-				.fromJson(new FileReader(new File(REPO_ROOT, "matcher-tests.json")), listType);
-		List dynamicTests = new ArrayList<>();
-		int i = 0;
-		for (MatcherTestImpl test : tests) {
-			dynamicTests.add(DynamicTest.dynamicTest("Test #" + (i++), () -> test.executeTest()));
-		}
-		return dynamicTests;
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.tm4e.core.grammar.internal.MatcherTestImpl;
+import org.eclipse.tm4e.core.grammar.internal.RawTestImpl;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.DynamicTest;
+import org.junit.jupiter.api.TestFactory;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonIOException;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.reflect.TypeToken;
+
+/**
+ * VSCode TextMate grammar tests which uses same vscode-textmate tests located
+ * at src\test\resources\test-cases
+ * 
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts
+ *
+ */
+public class GrammarSuiteTest {
+
+	private static final File REPO_ROOT = new File("src/test/resources");
+
+	// TODO: fix thoses tests:
+	// It seems that problem comes from with encoding. OnigString should support UTF-16 like https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc 
+	private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66");
+
+	@TestFactory @DisplayName("Tokenization /first-mate/")
+	Collection firstMate() throws Exception {
+		return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/first-mate/tests.json"));
+	}
+	
+	@TestFactory @DisplayName("Tokenization /suite1/ tests.json")
+	Collection testsJSon() throws Exception {
+		return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/tests.json"));
+	}
+	
+	@TestFactory @DisplayName("Tokenization /suite1/ whileTests.json")
+	Collection whileTests() throws Exception {
+		return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/whileTests.json"));
+	}
+
+
+	private List  createVSCodeTestSuite(File testLocation) throws Exception {
+		Type listType = new TypeToken>() {
+		}.getType();
+		List tests = new GsonBuilder().create().fromJson(new FileReader(testLocation), listType);
+		List dynamicTests = new ArrayList<>();
+		for (RawTestImpl test : tests) {
+			if (!IGNORE_TESTS.contains(test.getDesc())) {
+				test.setTestLocation(testLocation);
+				dynamicTests.add(DynamicTest.dynamicTest(test.getDesc(), () -> test.executeTest()));
+			}
+		}
+		return dynamicTests;
+	}
+	
+	@TestFactory @DisplayName("Matcher tests")
+	Collection dynamicTestsWithCollection() throws JsonIOException, JsonSyntaxException, FileNotFoundException {
+		Type listType = new TypeToken>() {
+		}.getType();
+		List tests = new GsonBuilder().create()
+				.fromJson(new FileReader(new File(REPO_ROOT, "matcher-tests.json")), listType);
+		List dynamicTests = new ArrayList<>();
+		int i = 0;
+		for (MatcherTestImpl test : tests) {
+			dynamicTests.add(DynamicTest.dynamicTest("Test #" + (i++), () -> test.executeTest()));
+		}
+		return dynamicTests;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarTest.java
index 2e90abc3d..225556c9e 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarTest.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarTest.java
@@ -1,117 +1,117 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar;
-
-import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata;
-import org.eclipse.tm4e.core.internal.grammar.StandardTokenType;
-import org.eclipse.tm4e.core.theme.FontStyle;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * {@link StackElementMetadata} tests same than vscode-textmate.
- * 
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/grammar.test.ts
- *
- */
-public class GrammarTest {
-
-	@Test
-	public void testWorks() {
-		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
-				102);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
-	}
-
-	@Test
-	public void testCanOverwriteLanguageId() {
-		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
-				102);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
-
-		value = StackElementMetadata.set(value, 2, StandardTokenType.Other, FontStyle.NotSet, 0, 0);
-		assertEquals(value, 2, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
-	}
-
-	@Test
-	public void testCanOverwriteTokenType() {
-		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
-				102);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
-
-		value = StackElementMetadata.set(value, 0, StandardTokenType.Comment, FontStyle.NotSet, 0, 0);
-		assertEquals(value, 1, StandardTokenType.Comment, FontStyle.Underline | FontStyle.Bold, 101, 102);
-	}
-
-	@Test
-	public void testCanOverwriteFontStyle() {
-		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
-				102);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
-
-		value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.None, 0, 0);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
-	}
-
-	@Test
-	public void testCanOverwriteForeground() {
-		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
-				102);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
-
-		value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 5, 0);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 5, 102);
-	}
-
-	@Test
-	public void testCanOverwriteBackground() {
-		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
-				102);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
-
-		value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 0, 7);
-		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 7);
-	}
-
-	@Test
-	public void testCanWorkAtMaxValues() {
-		int maxLangId = 255;
-		int maxTokenType = StandardTokenType.Comment | StandardTokenType.Other | StandardTokenType.RegEx
-				| StandardTokenType.String;
-		int maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline;
-		int maxForeground = 511;
-		int maxBackground = 511;
-
-		int value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
-		assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
-	}
-	
-	private static void assertEquals(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) {
-		String actual = "{\n" + 
-			"languageId: " + StackElementMetadata.getLanguageId(metadata) + ",\n" +
-			"tokenType: " + StackElementMetadata.getTokenType(metadata) + ",\n" +
-			"fontStyle: " + StackElementMetadata.getFontStyle(metadata) + ",\n" +
-			"foreground: " + StackElementMetadata.getForeground(metadata) + ",\n" +
-			"background: " + StackElementMetadata.getBackground(metadata) + ",\n" +			
-		"}";
-
-		String expected = "{\n" + 
-				"languageId: " + languageId + ",\n" +
-				"tokenType: " + tokenType + ",\n" +
-				"fontStyle: " + fontStyle + ",\n" +
-				"foreground: " + foreground + ",\n" +
-				"background: " + background + ",\n" +			
-			"}";
-		
-		Assertions.assertEquals(expected, actual, "equals for " + StackElementMetadata.toBinaryStr(metadata));
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar;
+
+import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata;
+import org.eclipse.tm4e.core.internal.grammar.StandardTokenType;
+import org.eclipse.tm4e.core.theme.FontStyle;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * {@link StackElementMetadata} tests same than vscode-textmate.
+ * 
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/grammar.test.ts
+ *
+ */
+public class GrammarTest {
+
+	@Test
+	public void testWorks() {
+		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
+				102);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
+	}
+
+	@Test
+	public void testCanOverwriteLanguageId() {
+		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
+				102);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
+
+		value = StackElementMetadata.set(value, 2, StandardTokenType.Other, FontStyle.NotSet, 0, 0);
+		assertEquals(value, 2, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
+	}
+
+	@Test
+	public void testCanOverwriteTokenType() {
+		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
+				102);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
+
+		value = StackElementMetadata.set(value, 0, StandardTokenType.Comment, FontStyle.NotSet, 0, 0);
+		assertEquals(value, 1, StandardTokenType.Comment, FontStyle.Underline | FontStyle.Bold, 101, 102);
+	}
+
+	@Test
+	public void testCanOverwriteFontStyle() {
+		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
+				102);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
+
+		value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.None, 0, 0);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
+	}
+
+	@Test
+	public void testCanOverwriteForeground() {
+		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
+				102);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
+
+		value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 5, 0);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 5, 102);
+	}
+
+	@Test
+	public void testCanOverwriteBackground() {
+		int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101,
+				102);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
+
+		value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 0, 7);
+		assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 7);
+	}
+
+	@Test
+	public void testCanWorkAtMaxValues() {
+		int maxLangId = 255;
+		int maxTokenType = StandardTokenType.Comment | StandardTokenType.Other | StandardTokenType.RegEx
+				| StandardTokenType.String;
+		int maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline;
+		int maxForeground = 511;
+		int maxBackground = 511;
+
+		int value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
+		assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
+	}
+	
+	private static void assertEquals(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) {
+		String actual = "{\n" + 
+			"languageId: " + StackElementMetadata.getLanguageId(metadata) + ",\n" +
+			"tokenType: " + StackElementMetadata.getTokenType(metadata) + ",\n" +
+			"fontStyle: " + StackElementMetadata.getFontStyle(metadata) + ",\n" +
+			"foreground: " + StackElementMetadata.getForeground(metadata) + ",\n" +
+			"background: " + StackElementMetadata.getBackground(metadata) + ",\n" +			
+		"}";
+
+		String expected = "{\n" + 
+				"languageId: " + languageId + ",\n" +
+				"tokenType: " + tokenType + ",\n" +
+				"fontStyle: " + fontStyle + ",\n" +
+				"foreground: " + foreground + ",\n" +
+				"background: " + background + ",\n" +			
+			"}";
+		
+		Assertions.assertEquals(expected, actual, "equals for " + StackElementMetadata.toBinaryStr(metadata));
+	}
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java
index 4bedf4fd2..15591e48a 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java
@@ -1,38 +1,38 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar.internal;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.tm4e.core.internal.matcher.Matcher;
-import org.eclipse.tm4e.core.internal.matcher.MatcherWithPriority;
-
-public class MatcherTestImpl {
-
-	private String expression;
-	private List input;
-	private boolean result;
-
-	public MatcherTestImpl() {
-	}
-
-
-	public void executeTest() {
-		Collection>> matcher = Matcher.createMatchers(expression);
-		boolean result = matcher.stream().anyMatch(m -> m.matcher.test(input));
-		assertEquals(result, this.result);
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar.internal;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.tm4e.core.internal.matcher.Matcher;
+import org.eclipse.tm4e.core.internal.matcher.MatcherWithPriority;
+
+public class MatcherTestImpl {
+
+	private String expression;
+	private List input;
+	private boolean result;
+
+	public MatcherTestImpl() {
+	}
+
+
+	public void executeTest() {
+		Collection>> matcher = Matcher.createMatchers(expression);
+		boolean result = matcher.stream().anyMatch(m -> m.matcher.test(input));
+		assertEquals(result, this.result);
+	}
+
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java
index 90189bb06..85d293116 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java
@@ -1,160 +1,160 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar.internal;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import org.eclipse.tm4e.core.grammar.IGrammar;
-import org.eclipse.tm4e.core.grammar.IToken;
-import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
-import org.eclipse.tm4e.core.grammar.StackElement;
-import org.eclipse.tm4e.core.registry.IRegistryOptions;
-import org.eclipse.tm4e.core.registry.Registry;
-
-public class RawTestImpl {
-
-	private String desc;
-	private List grammars;
-	private String grammarPath;
-	private String grammarScopeName;
-	private List grammarInjections;
-	private List lines;
-	private File testLocation;
-
-	public String getDesc() {
-		return desc;
-	}
-
-	public List getGrammars() {
-		return grammars;
-	}
-
-	public String getGrammarPath() {
-		return grammarPath;
-	}
-
-	public String getGrammarScopeName() {
-		return grammarScopeName;
-	}
-
-	public List getGrammarInjections() {
-		return grammarInjections;
-	}
-
-	public List getLines() {
-		return lines;
-	}
-
-	public void executeTest() throws Exception {
-		IRegistryOptions locator = new IRegistryOptions() {
-
-			@Override
-			public String getFilePath(String scopeName) {
-				return null;
-			}
-
-			@Override
-			public InputStream getInputStream(String scopeName) throws IOException {
-				return null;
-			}
-
-			@Override
-			public Collection getInjections(String scopeName) {
-				if (scopeName.equals(getGrammarScopeName())) {
-					return getGrammarInjections();
-				}
-				return null;
-			}
-		};
-
-		Registry registry = new Registry(locator);
-		IGrammar grammar = getGrammar(registry, testLocation.getParentFile());
-
-		if (getGrammarScopeName() != null) {
-			grammar = registry.grammarForScopeName(getGrammarScopeName());
-		}
-
-		if (grammar == null) {
-			throw new Exception("I HAVE NO GRAMMAR FOR TEST");
-		}
-
-		StackElement prevState = null;
-		for (RawTestLine testLine : getLines()) {
-			prevState = assertLineTokenization(grammar, testLine, prevState);
-		}
-	}
-
-	private IGrammar getGrammar(Registry registry, File testLocation) throws Exception {
-		IGrammar grammar = null;
-		for (String grammarPath : getGrammars()) {
-			IGrammar tmpGrammar = registry.loadGrammarFromPathSync(new File(testLocation, grammarPath));
-			if (grammarPath.equals(getGrammarPath())) {
-				grammar = tmpGrammar;
-			}
-		}
-		return grammar;
-	}
-
-	private static StackElement assertLineTokenization(IGrammar grammar, RawTestLine testCase, StackElement prevState) {
-		ITokenizeLineResult actual = grammar.tokenizeLine(testCase.getLine(), prevState);
-
-		List actualTokens = getActualTokens(actual.getTokens(), testCase);
-
-		List expectedTokens = testCase.getTokens();
-		// // TODO@Alex: fix tests instead of working around
-		if (testCase.getLine().length() > 0) {
-			// Remove empty tokens...
-			expectedTokens = testCase.getTokens().stream().filter(token -> token.getValue().length() > 0)
-					.collect(Collectors.toList());
-		}
-		deepEqual(actualTokens, expectedTokens, "Tokenizing line '" + testCase.getLine() + "'");
-
-		return actual.getRuleStack();
-	}
-
-	private static void deepEqual(List actualTokens, List expextedTokens, String message) {
-		// compare collection size
-		assertEquals(expextedTokens.size(), actualTokens.size(), message + " (collection size problem)");
-		// compare item
-		for (int i = 0; i < expextedTokens.size(); i++) {
-			RawToken expected = expextedTokens.get(i);
-			RawToken actual = actualTokens.get(i);
-			assertEquals(expected.getValue(), actual.getValue(), message + " (value of item '" + i + "' problem)");
-			assertEquals(expected.getScopes(), actual.getScopes(), message + " (tokens of item '" + i + "' problem)");
-		}
-
-	}
-
-	private static List getActualTokens(IToken[] tokens, RawTestLine testCase) {
-		List actualTokens = new ArrayList<>();
-		for (IToken token : tokens) {
-			String value = testCase.getLine().substring(token.getStartIndex(),
-					token.getEndIndex() < testCase.getLine().length() ? token.getEndIndex()
-							: testCase.getLine().length());
-			actualTokens.add(new RawToken(value, token.getScopes()));
-		}
-		return actualTokens;
-	}
-
-	public void setTestLocation(File testLocation) {
-		this.testLocation = testLocation;
-	}
-
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar.internal;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.tm4e.core.grammar.IGrammar;
+import org.eclipse.tm4e.core.grammar.IToken;
+import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
+import org.eclipse.tm4e.core.grammar.StackElement;
+import org.eclipse.tm4e.core.registry.IRegistryOptions;
+import org.eclipse.tm4e.core.registry.Registry;
+
+public class RawTestImpl {
+
+	private String desc;
+	private List grammars;
+	private String grammarPath;
+	private String grammarScopeName;
+	private List grammarInjections;
+	private List lines;
+	private File testLocation;
+
+	public String getDesc() {
+		return desc;
+	}
+
+	public List getGrammars() {
+		return grammars;
+	}
+
+	public String getGrammarPath() {
+		return grammarPath;
+	}
+
+	public String getGrammarScopeName() {
+		return grammarScopeName;
+	}
+
+	public List getGrammarInjections() {
+		return grammarInjections;
+	}
+
+	public List getLines() {
+		return lines;
+	}
+
+	public void executeTest() throws Exception {
+		IRegistryOptions locator = new IRegistryOptions() {
+
+			@Override
+			public String getFilePath(String scopeName) {
+				return null;
+			}
+
+			@Override
+			public InputStream getInputStream(String scopeName) throws IOException {
+				return null;
+			}
+
+			@Override
+			public Collection getInjections(String scopeName) {
+				if (scopeName.equals(getGrammarScopeName())) {
+					return getGrammarInjections();
+				}
+				return null;
+			}
+		};
+
+		Registry registry = new Registry(locator);
+		IGrammar grammar = getGrammar(registry, testLocation.getParentFile());
+
+		if (getGrammarScopeName() != null) {
+			grammar = registry.grammarForScopeName(getGrammarScopeName());
+		}
+
+		if (grammar == null) {
+			throw new Exception("I HAVE NO GRAMMAR FOR TEST");
+		}
+
+		StackElement prevState = null;
+		for (RawTestLine testLine : getLines()) {
+			prevState = assertLineTokenization(grammar, testLine, prevState);
+		}
+	}
+
+	private IGrammar getGrammar(Registry registry, File testLocation) throws Exception {
+		IGrammar grammar = null;
+		for (String grammarPath : getGrammars()) {
+			IGrammar tmpGrammar = registry.loadGrammarFromPathSync(new File(testLocation, grammarPath));
+			if (grammarPath.equals(getGrammarPath())) {
+				grammar = tmpGrammar;
+			}
+		}
+		return grammar;
+	}
+
+	private static StackElement assertLineTokenization(IGrammar grammar, RawTestLine testCase, StackElement prevState) {
+		ITokenizeLineResult actual = grammar.tokenizeLine(testCase.getLine(), prevState);
+
+		List actualTokens = getActualTokens(actual.getTokens(), testCase);
+
+		List expectedTokens = testCase.getTokens();
+		// // TODO@Alex: fix tests instead of working around
+		if (testCase.getLine().length() > 0) {
+			// Remove empty tokens...
+			expectedTokens = testCase.getTokens().stream().filter(token -> token.getValue().length() > 0)
+					.collect(Collectors.toList());
+		}
+		deepEqual(actualTokens, expectedTokens, "Tokenizing line '" + testCase.getLine() + "'");
+
+		return actual.getRuleStack();
+	}
+
+	private static void deepEqual(List actualTokens, List expextedTokens, String message) {
+		// compare collection size
+		assertEquals(expextedTokens.size(), actualTokens.size(), message + " (collection size problem)");
+		// compare item
+		for (int i = 0; i < expextedTokens.size(); i++) {
+			RawToken expected = expextedTokens.get(i);
+			RawToken actual = actualTokens.get(i);
+			assertEquals(expected.getValue(), actual.getValue(), message + " (value of item '" + i + "' problem)");
+			assertEquals(expected.getScopes(), actual.getScopes(), message + " (tokens of item '" + i + "' problem)");
+		}
+
+	}
+
+	private static List getActualTokens(IToken[] tokens, RawTestLine testCase) {
+		List actualTokens = new ArrayList<>();
+		for (IToken token : tokens) {
+			String value = testCase.getLine().substring(token.getStartIndex(),
+					token.getEndIndex() < testCase.getLine().length() ? token.getEndIndex()
+							: testCase.getLine().length());
+			actualTokens.add(new RawToken(value, token.getScopes()));
+		}
+		return actualTokens;
+	}
+
+	public void setTestLocation(File testLocation) {
+		this.testLocation = testLocation;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java
index ea02dec23..1afc9b679 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java
@@ -1,28 +1,28 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar.internal;
-
-import java.util.List;
-
-public class RawTestLine {
-
-	private String line;
-	private List tokens;
-
-	public String getLine() {
-		return line;
-	}
-	
-	public List getTokens() {
-		return tokens;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar.internal;
+
+import java.util.List;
+
+public class RawTestLine {
+
+	private String line;
+	private List tokens;
+
+	public String getLine() {
+		return line;
+	}
+	
+	public List getTokens() {
+		return tokens;
+	}
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java
index 7934f68f8..d7eda0a25 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java
@@ -1,48 +1,48 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar.internal;
-
-import java.util.List;
-
-public class RawToken {
-
-	private String value;
-	private List scopes;
-
-	public RawToken() {
-	}
-
-	public RawToken(String value, List scopes) {
-		this.value = value;
-		this.scopes = scopes;
-	}
-
-	public String getValue() {
-		return value;
-	}
-
-	public List getScopes() {
-		return scopes;
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (!(obj instanceof RawToken)) {
-			return false;
-		}
-		RawToken other = (RawToken) obj;
-		if (!(this.value.equals(other.value))) {
-			return false;
-		}
-		return this.scopes.equals(other.scopes);
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar.internal;
+
+import java.util.List;
+
+public class RawToken {
+
+	private String value;
+	private List scopes;
+
+	public RawToken() {
+	}
+
+	public RawToken(String value, List scopes) {
+		this.value = value;
+		this.scopes = scopes;
+	}
+
+	public String getValue() {
+		return value;
+	}
+
+	public List getScopes() {
+		return scopes;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (!(obj instanceof RawToken)) {
+			return false;
+		}
+		RawToken other = (RawToken) obj;
+		if (!(this.value.equals(other.value))) {
+			return false;
+		}
+		return this.scopes.equals(other.scopes);
+	}
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java
index c7bc7b632..0af252213 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java
@@ -1,275 +1,275 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.io.ByteArrayInputStream;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.tm4e.core.internal.grammar.ScopeListElement;
-import org.eclipse.tm4e.core.internal.grammar.ScopeMetadata;
-import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata;
-import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader;
-import org.junit.jupiter.api.Test;
-
-/**
- * 
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts
- *
- */
-class ThemeMatchingTest {
-
-	@Test
-	void testGivesHigherPriorityToDeeperMatches() throws Exception {
-		Theme theme = loadTheme("{" + 
-			"\"settings\": ["+
-						"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
-						"{ \"scope\": \"punctuation.definition.string.begin.html\", \"settings\": { \"foreground\": \"#300000\" } },"+
-						"{ \"scope\": \"meta.tag punctuation.definition.string\", \"settings\": { \"foreground\": \"#400000\" } }"+
-			"]"+
-		"}");
-
-
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#100000");
-		int _B = colorMap.getId("#200000");
-		int _C = colorMap.getId("#400000");
-		int _D = colorMap.getId("#300000");
-
-		List actual = theme.match("punctuation.definition.string.begin.html");
-
-		assertArrayEquals(
-				new ThemeTrieElementRule[] { new ThemeTrieElementRule(5, null, FontStyle.NotSet, _D, _NOT_SET),
-						new ThemeTrieElementRule(3, Arrays.asList("meta.tag"), FontStyle.NotSet, _C, _NOT_SET) },
-				actual.toArray());
-	}
-
-	@Test
-	void testGivesHigherPriorityToParentMatches1() throws Exception {
-		Theme theme = loadTheme("{" + 
-			"\"settings\": ["+
-						"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
-						"{ \"scope\": \"c a\", \"settings\": { \"foreground\": \"#300000\" } },"+
-						"{ \"scope\": \"d a.b\", \"settings\": { \"foreground\": \"#400000\" } },"+
-						"{ \"scope\": \"a\", \"settings\": { \"foreground\": \"#500000\" } }"+
-			"]"+
-		"}");
-
-
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#100000");
-		int _B = colorMap.getId("#200000");
-		int _C = colorMap.getId("#500000");
-		int _D = colorMap.getId("#300000");
-		int _E = colorMap.getId("#400000");
-		
-		List actual = theme.match("a.b");
-
-		assertArrayEquals(new ThemeTrieElementRule[] {
-				new ThemeTrieElementRule(2, Arrays.asList("d"), FontStyle.NotSet, _E, _NOT_SET),
-				new ThemeTrieElementRule(1, Arrays.asList("c"), FontStyle.NotSet, _D, _NOT_SET),
-				new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET) }, actual.toArray());
-	}
-	
-	@Test
-	void testGivesHigherPriorityToParentMatches2() throws Exception {
-		Theme theme = loadTheme("{" + 
-			"\"settings\": ["+
-						"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
-						"{ \"scope\": \"meta.tag entity\", \"settings\": { \"foreground\": \"#300000\" } },"+
-						"{ \"scope\": \"meta.selector.css entity.name.tag\", \"settings\": { \"foreground\": \"#400000\" } },"+
-						"{ \"scope\": \"entity\", \"settings\": { \"foreground\": \"#500000\" } }"+
-			"]"+
-		"}");
-
-
-		ScopeListElement root = new ScopeListElement(null, "text.html.cshtml", 0);
-		ScopeListElement parent = new ScopeListElement(root, "meta.tag.structure.any.html", 0);
-		int r = ScopeListElement.mergeMetadata(0, parent, new ScopeMetadata("entity.name.tag.structure.any.html", 0, 0,
-				theme.match("entity.name.tag.structure.any.html")));
-		String color = theme.getColor(StackElementMetadata.getForeground(r));
-		assertEquals("#300000", color);
-	}
-
-	@Test
-	void testCanMatch() throws Exception {
-		Theme theme = loadTheme("{" + 
-			"\"settings\": ["+
-				"{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } },"+
-				"{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } },"+
-				"{ \"scope\": [\"bar\", \"baz\"], \"settings\": { \"background\": \"#200000\" } },"+
-				"{ \"scope\": \"source.css selector bar\", \"settings\": { \"fontStyle\": \"bold\" } },"+
-				"{ \"scope\": \"constant\", \"settings\": { \"fontStyle\": \"italic\", \"foreground\": \"#300000\" } },"+
-				"{ \"scope\": \"constant.numeric\", \"settings\": { \"foreground\": \"#400000\" } },"+
-				"{ \"scope\": \"constant.numeric.hex\", \"settings\": { \"fontStyle\": \"bold\" } },"+
-				"{ \"scope\": \"constant.numeric.oct\", \"settings\": { \"fontStyle\": \"bold italic underline\" } },"+
-				"{ \"scope\": \"constant.numeric.dec\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#500000\" } },"+
-				"{ \"scope\": \"storage.object.bar\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#600000\" } }"+
-			"]"+
-		"}");
-
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#F8F8F2");
-		int _B = colorMap.getId("#272822");
-		int _C = colorMap.getId("#200000");
-		int _D = colorMap.getId("#300000");
-		int _E = colorMap.getId("#400000");
-		int _F = colorMap.getId("#500000");
-		int _G = colorMap.getId("#100000");
-		int _H = colorMap.getId("#600000");
-		
-		// matches defaults
-		assertNoMatch(theme, "");
-		assertNoMatch(theme, "bazz");
-		assertNoMatch(theme, "asdfg");
-
-		// matches source
-		assertSimpleMatch(theme, "source", 1, FontStyle.NotSet, _NOT_SET, _G);
-		assertSimpleMatch(theme, "source.ts", 1, FontStyle.NotSet, _NOT_SET, _G);
-		assertSimpleMatch(theme, "source.tss", 1, FontStyle.NotSet, _NOT_SET, _G);
-
-		// matches something
-		assertSimpleMatch(theme, "something", 1, FontStyle.NotSet, _NOT_SET, _G);
-		assertSimpleMatch(theme, "something.ts", 1, FontStyle.NotSet, _NOT_SET, _G);
-		assertSimpleMatch(theme, "something.tss", 1, FontStyle.NotSet, _NOT_SET, _G);
-
-		// matches baz
-		assertSimpleMatch(theme, "baz", 1, FontStyle.NotSet, _NOT_SET, _C);
-		assertSimpleMatch(theme, "baz.ts", 1, FontStyle.NotSet, _NOT_SET, _C);
-		assertSimpleMatch(theme, "baz.tss", 1, FontStyle.NotSet, _NOT_SET, _C);
-
-		// matches constant
-		assertSimpleMatch(theme, "constant", 1, FontStyle.Italic, _D, _NOT_SET);
-		assertSimpleMatch(theme, "constant.string", 1, FontStyle.Italic, _D, _NOT_SET);
-		assertSimpleMatch(theme, "constant.hex", 1, FontStyle.Italic, _D, _NOT_SET);
-
-		// matches constant.numeric
-		assertSimpleMatch(theme, "constant.numeric", 2, FontStyle.Italic, _E, _NOT_SET);
-		assertSimpleMatch(theme, "constant.numeric.baz", 2, FontStyle.Italic, _E, _NOT_SET);
-
-		// matches constant.numeric.hex
-		assertSimpleMatch(theme, "constant.numeric.hex", 3, FontStyle.Bold, _E, _NOT_SET);
-		assertSimpleMatch(theme, "constant.numeric.hex.baz", 3, FontStyle.Bold, _E, _NOT_SET);
-
-		// matches constant.numeric.oct
-		assertSimpleMatch(theme, "constant.numeric.oct", 3, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _E,
-				_NOT_SET);
-		assertSimpleMatch(theme, "constant.numeric.oct.baz", 3, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline,
-				_E, _NOT_SET);
-
-		// matches constant.numeric.dec
-		assertSimpleMatch(theme, "constant.numeric.dec", 3, FontStyle.None, _F, _NOT_SET);
-		assertSimpleMatch(theme, "constant.numeric.dec.baz", 3, FontStyle.None, _F, _NOT_SET);
-
-		// matches storage.object.bar
-		assertSimpleMatch(theme, "storage.object.bar", 3, FontStyle.None, _H, _NOT_SET);
-		assertSimpleMatch(theme, "storage.object.bar.baz", 3, FontStyle.None, _H, _NOT_SET);
-
-		// does not match storage.object.bar
-		assertSimpleMatch(theme, "storage.object.bart", 0, FontStyle.NotSet, _NOT_SET, _NOT_SET);
-		assertSimpleMatch(theme, "storage.object", 0, FontStyle.NotSet, _NOT_SET, _NOT_SET);
-		assertSimpleMatch(theme, "storage", 0, FontStyle.NotSet, _NOT_SET, _NOT_SET);
-
-		assertMatch(theme, "bar",
-				new ThemeTrieElementRule[] { new ThemeTrieElementRule(1, Arrays.asList("selector", "source.css"),
-						FontStyle.Bold, _NOT_SET, _C),
-						new ThemeTrieElementRule(1, null, FontStyle.NotSet, _NOT_SET, _C) });
-	}	
-	
-	@Test
-	void testMicrosoft_vscode_23460() throws Exception {
-		Theme theme = loadTheme("{" + 
-			"\"settings\": ["+
-				"{" + 
-					"\"settings\": {"+
-						"\"foreground\": \"#aec2e0\","+
-						"\"background\": \"#14191f\""+
-					"}"+
-				"}, {"+
-					"\"name\": \"JSON String\","+
-					"\"scope\": \"meta.structure.dictionary.json string.quoted.double.json\","+
-					"\"settings\": {"+
-						"\"foreground\": \"#FF410D\""+
-					"}"+
-				"}, {"+
-					"\"scope\": \"meta.structure.dictionary.json string.quoted.double.json\","+
-					"\"settings\": {"+
-						"\"foreground\": \"#ffffff\""+
-					"}"+
-				"},"+
-				"{"+
-					"\"scope\": \"meta.structure.dictionary.value.json string.quoted.double.json\","+
-					"\"settings\": {"+
-						"\"foreground\": \"#FF410D\""+
-					"}"+
-				"}"+
-			"]"+
-		"}");
-
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#aec2e0");
-		int _B = colorMap.getId("#14191f");
-		int _C = colorMap.getId("#FF410D");
-		int _D = colorMap.getId("#ffffff");
-
-
-		// string.quoted.double.json
-		// meta.structure.dictionary.value.json
-		// meta.structure.dictionary.json
-		// source.json
-		assertMatch(theme, "string.quoted.double.json", new ThemeTrieElementRule[] {
-			new ThemeTrieElementRule(4, Arrays.asList("meta.structure.dictionary.value.json"), FontStyle.NotSet, _C, _NOT_SET),
-			new ThemeTrieElementRule(4, Arrays.asList("meta.structure.dictionary.json"), FontStyle.NotSet, _D, _NOT_SET),
-			new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)
-		});
-
-		ScopeListElement parent3 = new ScopeListElement(null, "source.json", 0);
-		ScopeListElement parent2 = new ScopeListElement(parent3, "meta.structure.dictionary.json", 0);
-		ScopeListElement parent1 = new ScopeListElement(parent2, "meta.structure.dictionary.value.json", 0);
-
-		int r = ScopeListElement.mergeMetadata(
-			0,
-			parent1,
-			new ScopeMetadata("string.quoted.double.json", 0, 0, theme.match("string.quoted.double.json"))
-		);
-		String color = theme.getColor(StackElementMetadata.getForeground(r));
-		assertEquals("#FF410D", color);
-	}
-	
-	private void assertMatch(Theme theme, String scopeName, ThemeTrieElementRule[] expected) {
-		List actual = theme.match(scopeName);
-		assertArrayEquals(expected, actual.toArray(), "when matching <<" + scopeName + ">>");
-	}
-
-	private void assertSimpleMatch(Theme theme, String scopeName, int scopeDepth, int fontStyle, int foreground, int background) {
-		assertMatch(theme, scopeName, new ThemeTrieElementRule [] {
-			new ThemeTrieElementRule(scopeDepth, null, fontStyle, foreground, background)
-		});
-	}
-
-	private void assertNoMatch(Theme theme, String scopeName) {
-		assertMatch(theme, scopeName, new ThemeTrieElementRule [] {
-			new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0 /*_NOT_SET, _NOT_SET*/)
-		});
-	}
-	
-	private Theme loadTheme(String theme) throws Exception {
-		return Theme.createFromRawTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes())));
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.tm4e.core.internal.grammar.ScopeListElement;
+import org.eclipse.tm4e.core.internal.grammar.ScopeMetadata;
+import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata;
+import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader;
+import org.junit.jupiter.api.Test;
+
+/**
+ * 
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts
+ *
+ */
+class ThemeMatchingTest {
+
+	@Test
+	void testGivesHigherPriorityToDeeperMatches() throws Exception {
+		Theme theme = loadTheme("{" + 
+			"\"settings\": ["+
+						"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
+						"{ \"scope\": \"punctuation.definition.string.begin.html\", \"settings\": { \"foreground\": \"#300000\" } },"+
+						"{ \"scope\": \"meta.tag punctuation.definition.string\", \"settings\": { \"foreground\": \"#400000\" } }"+
+			"]"+
+		"}");
+
+
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#100000");
+		int _B = colorMap.getId("#200000");
+		int _C = colorMap.getId("#400000");
+		int _D = colorMap.getId("#300000");
+
+		List actual = theme.match("punctuation.definition.string.begin.html");
+
+		assertArrayEquals(
+				new ThemeTrieElementRule[] { new ThemeTrieElementRule(5, null, FontStyle.NotSet, _D, _NOT_SET),
+						new ThemeTrieElementRule(3, Arrays.asList("meta.tag"), FontStyle.NotSet, _C, _NOT_SET) },
+				actual.toArray());
+	}
+
+	@Test
+	void testGivesHigherPriorityToParentMatches1() throws Exception {
+		Theme theme = loadTheme("{" + 
+			"\"settings\": ["+
+						"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
+						"{ \"scope\": \"c a\", \"settings\": { \"foreground\": \"#300000\" } },"+
+						"{ \"scope\": \"d a.b\", \"settings\": { \"foreground\": \"#400000\" } },"+
+						"{ \"scope\": \"a\", \"settings\": { \"foreground\": \"#500000\" } }"+
+			"]"+
+		"}");
+
+
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#100000");
+		int _B = colorMap.getId("#200000");
+		int _C = colorMap.getId("#500000");
+		int _D = colorMap.getId("#300000");
+		int _E = colorMap.getId("#400000");
+		
+		List actual = theme.match("a.b");
+
+		assertArrayEquals(new ThemeTrieElementRule[] {
+				new ThemeTrieElementRule(2, Arrays.asList("d"), FontStyle.NotSet, _E, _NOT_SET),
+				new ThemeTrieElementRule(1, Arrays.asList("c"), FontStyle.NotSet, _D, _NOT_SET),
+				new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET) }, actual.toArray());
+	}
+	
+	@Test
+	void testGivesHigherPriorityToParentMatches2() throws Exception {
+		Theme theme = loadTheme("{" + 
+			"\"settings\": ["+
+						"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
+						"{ \"scope\": \"meta.tag entity\", \"settings\": { \"foreground\": \"#300000\" } },"+
+						"{ \"scope\": \"meta.selector.css entity.name.tag\", \"settings\": { \"foreground\": \"#400000\" } },"+
+						"{ \"scope\": \"entity\", \"settings\": { \"foreground\": \"#500000\" } }"+
+			"]"+
+		"}");
+
+
+		ScopeListElement root = new ScopeListElement(null, "text.html.cshtml", 0);
+		ScopeListElement parent = new ScopeListElement(root, "meta.tag.structure.any.html", 0);
+		int r = ScopeListElement.mergeMetadata(0, parent, new ScopeMetadata("entity.name.tag.structure.any.html", 0, 0,
+				theme.match("entity.name.tag.structure.any.html")));
+		String color = theme.getColor(StackElementMetadata.getForeground(r));
+		assertEquals("#300000", color);
+	}
+
+	@Test
+	void testCanMatch() throws Exception {
+		Theme theme = loadTheme("{" + 
+			"\"settings\": ["+
+				"{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } },"+
+				"{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } },"+
+				"{ \"scope\": [\"bar\", \"baz\"], \"settings\": { \"background\": \"#200000\" } },"+
+				"{ \"scope\": \"source.css selector bar\", \"settings\": { \"fontStyle\": \"bold\" } },"+
+				"{ \"scope\": \"constant\", \"settings\": { \"fontStyle\": \"italic\", \"foreground\": \"#300000\" } },"+
+				"{ \"scope\": \"constant.numeric\", \"settings\": { \"foreground\": \"#400000\" } },"+
+				"{ \"scope\": \"constant.numeric.hex\", \"settings\": { \"fontStyle\": \"bold\" } },"+
+				"{ \"scope\": \"constant.numeric.oct\", \"settings\": { \"fontStyle\": \"bold italic underline\" } },"+
+				"{ \"scope\": \"constant.numeric.dec\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#500000\" } },"+
+				"{ \"scope\": \"storage.object.bar\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#600000\" } }"+
+			"]"+
+		"}");
+
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#F8F8F2");
+		int _B = colorMap.getId("#272822");
+		int _C = colorMap.getId("#200000");
+		int _D = colorMap.getId("#300000");
+		int _E = colorMap.getId("#400000");
+		int _F = colorMap.getId("#500000");
+		int _G = colorMap.getId("#100000");
+		int _H = colorMap.getId("#600000");
+		
+		// matches defaults
+		assertNoMatch(theme, "");
+		assertNoMatch(theme, "bazz");
+		assertNoMatch(theme, "asdfg");
+
+		// matches source
+		assertSimpleMatch(theme, "source", 1, FontStyle.NotSet, _NOT_SET, _G);
+		assertSimpleMatch(theme, "source.ts", 1, FontStyle.NotSet, _NOT_SET, _G);
+		assertSimpleMatch(theme, "source.tss", 1, FontStyle.NotSet, _NOT_SET, _G);
+
+		// matches something
+		assertSimpleMatch(theme, "something", 1, FontStyle.NotSet, _NOT_SET, _G);
+		assertSimpleMatch(theme, "something.ts", 1, FontStyle.NotSet, _NOT_SET, _G);
+		assertSimpleMatch(theme, "something.tss", 1, FontStyle.NotSet, _NOT_SET, _G);
+
+		// matches baz
+		assertSimpleMatch(theme, "baz", 1, FontStyle.NotSet, _NOT_SET, _C);
+		assertSimpleMatch(theme, "baz.ts", 1, FontStyle.NotSet, _NOT_SET, _C);
+		assertSimpleMatch(theme, "baz.tss", 1, FontStyle.NotSet, _NOT_SET, _C);
+
+		// matches constant
+		assertSimpleMatch(theme, "constant", 1, FontStyle.Italic, _D, _NOT_SET);
+		assertSimpleMatch(theme, "constant.string", 1, FontStyle.Italic, _D, _NOT_SET);
+		assertSimpleMatch(theme, "constant.hex", 1, FontStyle.Italic, _D, _NOT_SET);
+
+		// matches constant.numeric
+		assertSimpleMatch(theme, "constant.numeric", 2, FontStyle.Italic, _E, _NOT_SET);
+		assertSimpleMatch(theme, "constant.numeric.baz", 2, FontStyle.Italic, _E, _NOT_SET);
+
+		// matches constant.numeric.hex
+		assertSimpleMatch(theme, "constant.numeric.hex", 3, FontStyle.Bold, _E, _NOT_SET);
+		assertSimpleMatch(theme, "constant.numeric.hex.baz", 3, FontStyle.Bold, _E, _NOT_SET);
+
+		// matches constant.numeric.oct
+		assertSimpleMatch(theme, "constant.numeric.oct", 3, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _E,
+				_NOT_SET);
+		assertSimpleMatch(theme, "constant.numeric.oct.baz", 3, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline,
+				_E, _NOT_SET);
+
+		// matches constant.numeric.dec
+		assertSimpleMatch(theme, "constant.numeric.dec", 3, FontStyle.None, _F, _NOT_SET);
+		assertSimpleMatch(theme, "constant.numeric.dec.baz", 3, FontStyle.None, _F, _NOT_SET);
+
+		// matches storage.object.bar
+		assertSimpleMatch(theme, "storage.object.bar", 3, FontStyle.None, _H, _NOT_SET);
+		assertSimpleMatch(theme, "storage.object.bar.baz", 3, FontStyle.None, _H, _NOT_SET);
+
+		// does not match storage.object.bar
+		assertSimpleMatch(theme, "storage.object.bart", 0, FontStyle.NotSet, _NOT_SET, _NOT_SET);
+		assertSimpleMatch(theme, "storage.object", 0, FontStyle.NotSet, _NOT_SET, _NOT_SET);
+		assertSimpleMatch(theme, "storage", 0, FontStyle.NotSet, _NOT_SET, _NOT_SET);
+
+		assertMatch(theme, "bar",
+				new ThemeTrieElementRule[] { new ThemeTrieElementRule(1, Arrays.asList("selector", "source.css"),
+						FontStyle.Bold, _NOT_SET, _C),
+						new ThemeTrieElementRule(1, null, FontStyle.NotSet, _NOT_SET, _C) });
+	}	
+	
+	@Test
+	void testMicrosoft_vscode_23460() throws Exception {
+		Theme theme = loadTheme("{" + 
+			"\"settings\": ["+
+				"{" + 
+					"\"settings\": {"+
+						"\"foreground\": \"#aec2e0\","+
+						"\"background\": \"#14191f\""+
+					"}"+
+				"}, {"+
+					"\"name\": \"JSON String\","+
+					"\"scope\": \"meta.structure.dictionary.json string.quoted.double.json\","+
+					"\"settings\": {"+
+						"\"foreground\": \"#FF410D\""+
+					"}"+
+				"}, {"+
+					"\"scope\": \"meta.structure.dictionary.json string.quoted.double.json\","+
+					"\"settings\": {"+
+						"\"foreground\": \"#ffffff\""+
+					"}"+
+				"},"+
+				"{"+
+					"\"scope\": \"meta.structure.dictionary.value.json string.quoted.double.json\","+
+					"\"settings\": {"+
+						"\"foreground\": \"#FF410D\""+
+					"}"+
+				"}"+
+			"]"+
+		"}");
+
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#aec2e0");
+		int _B = colorMap.getId("#14191f");
+		int _C = colorMap.getId("#FF410D");
+		int _D = colorMap.getId("#ffffff");
+
+
+		// string.quoted.double.json
+		// meta.structure.dictionary.value.json
+		// meta.structure.dictionary.json
+		// source.json
+		assertMatch(theme, "string.quoted.double.json", new ThemeTrieElementRule[] {
+			new ThemeTrieElementRule(4, Arrays.asList("meta.structure.dictionary.value.json"), FontStyle.NotSet, _C, _NOT_SET),
+			new ThemeTrieElementRule(4, Arrays.asList("meta.structure.dictionary.json"), FontStyle.NotSet, _D, _NOT_SET),
+			new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)
+		});
+
+		ScopeListElement parent3 = new ScopeListElement(null, "source.json", 0);
+		ScopeListElement parent2 = new ScopeListElement(parent3, "meta.structure.dictionary.json", 0);
+		ScopeListElement parent1 = new ScopeListElement(parent2, "meta.structure.dictionary.value.json", 0);
+
+		int r = ScopeListElement.mergeMetadata(
+			0,
+			parent1,
+			new ScopeMetadata("string.quoted.double.json", 0, 0, theme.match("string.quoted.double.json"))
+		);
+		String color = theme.getColor(StackElementMetadata.getForeground(r));
+		assertEquals("#FF410D", color);
+	}
+	
+	private void assertMatch(Theme theme, String scopeName, ThemeTrieElementRule[] expected) {
+		List actual = theme.match(scopeName);
+		assertArrayEquals(expected, actual.toArray(), "when matching <<" + scopeName + ">>");
+	}
+
+	private void assertSimpleMatch(Theme theme, String scopeName, int scopeDepth, int fontStyle, int foreground, int background) {
+		assertMatch(theme, scopeName, new ThemeTrieElementRule [] {
+			new ThemeTrieElementRule(scopeDepth, null, fontStyle, foreground, background)
+		});
+	}
+
+	private void assertNoMatch(Theme theme, String scopeName) {
+		assertMatch(theme, scopeName, new ThemeTrieElementRule [] {
+			new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0 /*_NOT_SET, _NOT_SET*/)
+		});
+	}
+	
+	private Theme loadTheme(String theme) throws Exception {
+		return Theme.createFromRawTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes())));
+	}
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java
index 574232682..695e8df2c 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java
@@ -1,69 +1,69 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-
-import java.io.ByteArrayInputStream;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader;
-import org.junit.jupiter.api.Test;
-
-/**
- * 
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts
- *
- */
-public class ThemeParsingTest {
-
-	@Test
-	public void testCanParse() throws Exception {
-		List actual = parseTheme("{" + 
-			"\"settings\": [" +
-				"{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } }," +
-				"{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } }," +
-				"{ \"scope\": [\"bar\", \"baz\"], \"settings\": { \"background\": \"#010000\" } }," +
-				"{ \"scope\": \"source.css selector bar\", \"settings\": { \"fontStyle\": \"bold\" } }," +
-				"{ \"scope\": \"constant\", \"settings\": { \"fontStyle\": \"italic\", \"foreground\": \"#ff0000\" } }," +
-				"{ \"scope\": \"constant.numeric\", \"settings\": { \"foreground\": \"#00ff00\" } }," +
-				"{ \"scope\": \"constant.numeric.hex\", \"settings\": { \"fontStyle\": \"bold\" } }," +
-				"{ \"scope\": \"constant.numeric.oct\", \"settings\": { \"fontStyle\": \"bold italic underline\" } }," +
-				"{ \"scope\": \"constant.numeric.dec\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#0000ff\" } }," +
-				"{ \"scope\": \"foo\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#CFA\" } }" + 
-			"]" +
-		"}");
-
-
-		ParsedThemeRule[] expected = new ParsedThemeRule[] {
-				new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#F8F8F2", "#272822"),
-				new ParsedThemeRule("source", null, 1, FontStyle.NotSet, null, "#100000"),
-				new ParsedThemeRule("something", null, 1, FontStyle.NotSet, null, "#100000"),
-				new ParsedThemeRule("bar", null, 2, FontStyle.NotSet, null, "#010000"),
-				new ParsedThemeRule("baz", null, 2, FontStyle.NotSet, null, "#010000"),
-				new ParsedThemeRule("bar", Arrays.asList("selector", "source.css"), 3, FontStyle.Bold, null, null),
-				new ParsedThemeRule("constant", null, 4, FontStyle.Italic, "#ff0000", null),
-				new ParsedThemeRule("constant.numeric", null, 5, FontStyle.NotSet, "#00ff00", null),
-				new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null),
-				new ParsedThemeRule("constant.numeric.oct", null, 7,
-						FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
-				new ParsedThemeRule("constant.numeric.dec", null, 8, FontStyle.None, "#0000ff", null),
-				new ParsedThemeRule("foo", null, 9, FontStyle.None, "#CFA", null), };
-
-		assertArrayEquals(expected, actual.toArray());
-	}	
-	
-	private List parseTheme(String theme) throws Exception {
-		return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes())));
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader;
+import org.junit.jupiter.api.Test;
+
+/**
+ * 
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts
+ *
+ */
+public class ThemeParsingTest {
+
+	@Test
+	public void testCanParse() throws Exception {
+		List actual = parseTheme("{" + 
+			"\"settings\": [" +
+				"{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } }," +
+				"{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } }," +
+				"{ \"scope\": [\"bar\", \"baz\"], \"settings\": { \"background\": \"#010000\" } }," +
+				"{ \"scope\": \"source.css selector bar\", \"settings\": { \"fontStyle\": \"bold\" } }," +
+				"{ \"scope\": \"constant\", \"settings\": { \"fontStyle\": \"italic\", \"foreground\": \"#ff0000\" } }," +
+				"{ \"scope\": \"constant.numeric\", \"settings\": { \"foreground\": \"#00ff00\" } }," +
+				"{ \"scope\": \"constant.numeric.hex\", \"settings\": { \"fontStyle\": \"bold\" } }," +
+				"{ \"scope\": \"constant.numeric.oct\", \"settings\": { \"fontStyle\": \"bold italic underline\" } }," +
+				"{ \"scope\": \"constant.numeric.dec\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#0000ff\" } }," +
+				"{ \"scope\": \"foo\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#CFA\" } }" + 
+			"]" +
+		"}");
+
+
+		ParsedThemeRule[] expected = new ParsedThemeRule[] {
+				new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#F8F8F2", "#272822"),
+				new ParsedThemeRule("source", null, 1, FontStyle.NotSet, null, "#100000"),
+				new ParsedThemeRule("something", null, 1, FontStyle.NotSet, null, "#100000"),
+				new ParsedThemeRule("bar", null, 2, FontStyle.NotSet, null, "#010000"),
+				new ParsedThemeRule("baz", null, 2, FontStyle.NotSet, null, "#010000"),
+				new ParsedThemeRule("bar", Arrays.asList("selector", "source.css"), 3, FontStyle.Bold, null, null),
+				new ParsedThemeRule("constant", null, 4, FontStyle.Italic, "#ff0000", null),
+				new ParsedThemeRule("constant.numeric", null, 5, FontStyle.NotSet, "#00ff00", null),
+				new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null),
+				new ParsedThemeRule("constant.numeric.oct", null, 7,
+						FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
+				new ParsedThemeRule("constant.numeric.dec", null, 8, FontStyle.None, "#0000ff", null),
+				new ParsedThemeRule("foo", null, 9, FontStyle.None, "#CFA", null), };
+
+		assertArrayEquals(expected, actual.toArray());
+	}	
+	
+	private List parseTheme(String theme) throws Exception {
+		return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes())));
+	}
+}
diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java
index cd1a51ebc..a487b2bb4 100644
--- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java
+++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java
@@ -1,405 +1,405 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader;
-import org.eclipse.tm4e.core.internal.utils.CompareUtils;
-import org.junit.jupiter.api.Test;
-
-/**
- * 
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts
- *
- */
-public class ThemeResolvingTest {
-
-	@Test
-	public void testStrcmpWorks() {
-		List actual = Arrays.asList("bar", "z", "zu", "a", "ab", "");
-		actual.sort(CompareUtils::strcmp);
-
-		List expected = Arrays.asList("", "a", "ab", "bar", "z", "zu");
-		assertArrayEquals(expected.toArray(), actual.toArray());
-	}
-
-	@Test
-	public void testStrArrCmpWorks() {
-		assertStrArrCmp("001", null, null, 0);
-		assertStrArrCmp("002", null, Collections.emptyList(), -1);
-		assertStrArrCmp("003", null, Arrays.asList("a"), -1);
-		assertStrArrCmp("004", Collections.emptyList(), null, 1);
-		assertStrArrCmp("005", Arrays.asList("a"), null, 1);
-		assertStrArrCmp("006", Collections.emptyList(), Collections.emptyList(), 0);
-		assertStrArrCmp("007", Collections.emptyList(), Arrays.asList("a"), -1);
-		assertStrArrCmp("008", Arrays.asList("a"), Collections.emptyList(), 1);
-		assertStrArrCmp("009", Arrays.asList("a"), Arrays.asList("a"), 0);
-		assertStrArrCmp("010", Arrays.asList("a", "b"), Arrays.asList("a"), 1);
-		assertStrArrCmp("011", Arrays.asList("a"), Arrays.asList("a", "b"), -1);
-		assertStrArrCmp("012", Arrays.asList("a", "b"), Arrays.asList("a", "b"), 0);
-		assertStrArrCmp("013", Arrays.asList("a", "b"), Arrays.asList("a", "c"), -1);
-		assertStrArrCmp("014", Arrays.asList("a", "c"), Arrays.asList("a", "b"), 1);
-	}
-
-	@Test
-	public void testAlwaysHasDefaults() {
-		Theme actual = Theme.createFromParsedTheme(Collections.emptyList());
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#000000");
-		int _B = colorMap.getId("#ffffff");
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRespectsIncomingDefaults1() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#000000");
-		int _B = colorMap.getId("#ffffff");
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRespectsIncomingDefaults2() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.None, null, null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#000000");
-		int _B = colorMap.getId("#ffffff");
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRespectsIncomingDefaults3() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#000000");
-		int _B = colorMap.getId("#ffffff");
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRespectsIncomingDefaults4() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#ff0000", null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#ff0000");
-		int _B = colorMap.getId("#ffffff");
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRespectsIncomingDefaults5() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"),
-						new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null),
-						new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#00ff00");
-		int _B = colorMap.getId("#ff0000");
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testCanMergeIncomingDefaults() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"),
-						new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null),
-						new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#00ff00");
-		int _B = colorMap.getId("#ff0000");
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testDefaultsAreInherited() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
-						new ParsedThemeRule("var", null, -1, FontStyle.NotSet, "#ff0000", null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#F8F8F2");
-		int _B = colorMap.getId("#272822");
-		int _C = colorMap.getId("#ff0000");
-
-		Map map = new HashMap<>();
-		map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET)));
-
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
-						Collections.emptyList(), map));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testSameRulesGetMerged() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
-						new ParsedThemeRule("var", null, 1, FontStyle.Bold, null, null),
-						new ParsedThemeRule("var", null, 0, FontStyle.NotSet, "#ff0000", null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#F8F8F2");
-		int _B = colorMap.getId("#272822");
-		int _C = colorMap.getId("#ff0000");
-
-		Map map = new HashMap<>();
-		map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET)));
-
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
-						Collections.emptyList(), map));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRulesAreInherited1() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
-						new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null),
-						new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#F8F8F2");
-		int _B = colorMap.getId("#272822");
-		int _C = colorMap.getId("#ff0000");
-		int _D = colorMap.getId("#00ff00");
-
-		Map map1_1 = new HashMap<>();
-		map1_1.put("identifier", new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _D, _NOT_SET)));
-		Map map1 = new HashMap<>();
-		map1.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET),
-				Collections.emptyList(), map1_1));
-
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
-						Collections.emptyList(), map1));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRulesAreInherited2() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
-						new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null),
-						new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null),
-						new ParsedThemeRule("constant", null, 4, FontStyle.Italic, "#100000", null),
-						new ParsedThemeRule("constant.numeric", null, 5, FontStyle.NotSet, "#200000", null),
-						new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null),
-						new ParsedThemeRule("constant.numeric.oct", null, 7,
-								FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
-						new ParsedThemeRule("constant.numeric.dec", null, 8, FontStyle.None, "#300000", null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#F8F8F2");
-		int _B = colorMap.getId("#272822");
-		int _C = colorMap.getId("#100000");
-		int _D = colorMap.getId("#200000");
-		int _E = colorMap.getId("#300000");
-		int _F = colorMap.getId("#ff0000");
-		int _G = colorMap.getId("#00ff00");
-
-		Map mapOfVar = new HashMap<>();
-		mapOfVar.put("identifier",
-				new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _G, _NOT_SET)));
-
-		Map mapOfNumeric = new HashMap<>();
-		mapOfNumeric.put("hex", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold, _D, _NOT_SET)));
-		mapOfNumeric.put("oct", new ThemeTrieElement(new ThemeTrieElementRule(3, null,
-				FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _D, _NOT_SET)));
-		mapOfNumeric.put("dec", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.None, _E, _NOT_SET)));
-
-		Map mapOfConstant = new HashMap<>();
-		mapOfConstant.put("numeric",
-				new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Italic, _D, _NOT_SET),
-						Collections.emptyList(), mapOfNumeric));
-
-		Map mapRoot = new HashMap<>();
-		mapRoot.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _F, _NOT_SET),
-				Collections.emptyList(), mapOfVar));
-		mapRoot.put("constant", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Italic, _C, _NOT_SET),
-				Collections.emptyList(), mapOfConstant));
-
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
-						Collections.emptyList(), mapRoot));
-		assertEquals(actual, expected);
-	}
-
-	@Test
-	public void testRulesWithParentScopes() {
-		Theme actual = Theme.createFromParsedTheme(
-				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
-						new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#100000", null),
-						new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#200000", null),
-						new ParsedThemeRule("var", Arrays.asList("source.css"), 1, FontStyle.Italic, "#300000", null),
-						new ParsedThemeRule("var", Arrays.asList("source.css"), 2, FontStyle.Underline, null, null))));
-		ColorMap colorMap = new ColorMap();
-		int _NOT_SET = 0;
-		int _A = colorMap.getId("#F8F8F2");
-		int _B = colorMap.getId("#272822");
-		int _C = colorMap.getId("#100000");
-		int _D = colorMap.getId("#300000");
-		int _E = colorMap.getId("#200000");
-
-		Map mapOfVar = new HashMap<>();
-		mapOfVar.put("identifier",
-				new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _E, _NOT_SET), Arrays.asList(
-						new ThemeTrieElementRule(1, Arrays.asList("source.css"), FontStyle.Underline, _D, _NOT_SET))));
-
-		Map mapRoot = new HashMap<>();
-		mapRoot.put("var",
-				new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET), Arrays.asList(
-						new ThemeTrieElementRule(1, Arrays.asList("source.css"), FontStyle.Underline, _D, _NOT_SET)),
-						mapOfVar));
-
-		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
-				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
-						Collections.emptyList(), mapRoot));
-		assertEquals(actual, expected);
-	}
-	
-	@Test
-	public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception {
-		List actual = parseTheme("{" +
-			"\"settings\": [{"+
-			"	\"settings\": {"+
-			"		\"background\": \"#222222\","+
-			"		\"foreground\": \"#cccccc\""+
-			"	}"+
-			"}, {"+
-			"	\"name\": \"Variable\","+
-			"	\"scope\": \"variable\","+
-			"	\"settings\": {"+
-			"		\"fontStyle\": \"\""+
-			"	}"+
-			"}, {"+
-			"	\"name\": \"Function argument\","+
-			"	\"scope\": \"variable.parameter\","+
-			"	\"settings\": {"+
-			"		\"fontStyle\": \"italic\","+
-			"		\"foreground\": \"\""+
-			"	}"+
-			"}, {"+
-			"	\"name\": \"Library variable\","+
-			"	\"scope\": \"support.other.variable\","+
-			"	\"settings\": {"+
-			"		\"fontStyle\": \"\""+
-			"	}"+
-			"}, {"+
-			"	\"name\": \"Function argument\","+
-			"	\"scope\": \"variable.other\","+
-			"	\"settings\": {"+
-			"		\"foreground\": \"\","+
-			"		\"fontStyle\": \"normal\""+
-			"	}"+
-			"}, {"+
-			"	\"name\": \"Coffeescript Function argument\","+
-			"	\"scope\": \"variable.parameter.function.coffee\","+
-			"	\"settings\": {"+
-			"		\"foreground\": \"#F9D423\","+
-			"		\"fontStyle\": \"italic\""+
-			"	}"+
-			"}]"+
-		"}");
-
-		List expected = Arrays.asList(
-			new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#cccccc", "#222222"),
-			new ParsedThemeRule("variable", null, 1, FontStyle.None, null, null),
-			new ParsedThemeRule("variable.parameter", null, 2, FontStyle.Italic, null, null),
-			new ParsedThemeRule("support.other.variable", null, 3, FontStyle.None, null, null),
-			new ParsedThemeRule("variable.other", null, 4, FontStyle.None, null, null),
-			new ParsedThemeRule("variable.parameter.function.coffee", null, 5, FontStyle.Italic, "#F9D423", null)
-		);
-
-		assertArrayEquals(expected.toArray(), actual.toArray());
-	}
-	
-	@Test
-	public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exception {
-		List actual = parseTheme("{" +
-			"\"settings\": [{"+
-			"	\"settings\": {"+
-			"		\"background\": \"#25292C\","+
-			"		\"foreground\": \"#EFEFEF\""+
-			"	}"+
-			"}, {"+
-			"	\"name\": \"CSS at-rule keyword control\","+
-			"	\"scope\": \""+
-			"		meta.at-rule.return.scss,\n"+
-			"		meta.at-rule.return.scss punctuation.definition,\n"+
-			"		meta.at-rule.else.scss,\n"+
-			"		meta.at-rule.else.scss punctuation.definition,\n"+
-			"		meta.at-rule.if.scss,\n"+
-			"		meta.at-rule.if.scss punctuation.definition\n"+
-			"	\","+
-			"	\"settings\": {"+
-			"		\"foreground\": \"#CC7832\""+
-			"	}"+
-			"}]"+
-		"}");
-
-		List expected = Arrays.asList(
-				new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#EFEFEF", "#25292C"),
-				new ParsedThemeRule("meta.at-rule.return.scss", null, 1, FontStyle.NotSet, "#CC7832", null),
-				new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.return.scss"), 1, FontStyle.NotSet, "#CC7832", null),
-				new ParsedThemeRule("meta.at-rule.else.scss", null, 1, FontStyle.NotSet, "#CC7832", null),
-				new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.else.scss"), 1, FontStyle.NotSet, "#CC7832", null),
-				new ParsedThemeRule("meta.at-rule.if.scss", null, 1, FontStyle.NotSet, "#CC7832", null),
-				new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.if.scss"), 1, FontStyle.NotSet, "#CC7832", null)
-		);
-
-		assertArrayEquals(expected.toArray(), actual.toArray());
-	}
-	
-	private void assertStrArrCmp(String testCase, List a, List b, int expected) {
-		assertEquals(expected, CompareUtils.strArrCmp(a, b), testCase);
-	}
-	
-	private List parseTheme(String theme) throws Exception {
-		return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes())));
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader;
+import org.eclipse.tm4e.core.internal.utils.CompareUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * 
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts
+ *
+ */
+public class ThemeResolvingTest {
+
+	@Test
+	public void testStrcmpWorks() {
+		List actual = Arrays.asList("bar", "z", "zu", "a", "ab", "");
+		actual.sort(CompareUtils::strcmp);
+
+		List expected = Arrays.asList("", "a", "ab", "bar", "z", "zu");
+		assertArrayEquals(expected.toArray(), actual.toArray());
+	}
+
+	@Test
+	public void testStrArrCmpWorks() {
+		assertStrArrCmp("001", null, null, 0);
+		assertStrArrCmp("002", null, Collections.emptyList(), -1);
+		assertStrArrCmp("003", null, Arrays.asList("a"), -1);
+		assertStrArrCmp("004", Collections.emptyList(), null, 1);
+		assertStrArrCmp("005", Arrays.asList("a"), null, 1);
+		assertStrArrCmp("006", Collections.emptyList(), Collections.emptyList(), 0);
+		assertStrArrCmp("007", Collections.emptyList(), Arrays.asList("a"), -1);
+		assertStrArrCmp("008", Arrays.asList("a"), Collections.emptyList(), 1);
+		assertStrArrCmp("009", Arrays.asList("a"), Arrays.asList("a"), 0);
+		assertStrArrCmp("010", Arrays.asList("a", "b"), Arrays.asList("a"), 1);
+		assertStrArrCmp("011", Arrays.asList("a"), Arrays.asList("a", "b"), -1);
+		assertStrArrCmp("012", Arrays.asList("a", "b"), Arrays.asList("a", "b"), 0);
+		assertStrArrCmp("013", Arrays.asList("a", "b"), Arrays.asList("a", "c"), -1);
+		assertStrArrCmp("014", Arrays.asList("a", "c"), Arrays.asList("a", "b"), 1);
+	}
+
+	@Test
+	public void testAlwaysHasDefaults() {
+		Theme actual = Theme.createFromParsedTheme(Collections.emptyList());
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#000000");
+		int _B = colorMap.getId("#ffffff");
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRespectsIncomingDefaults1() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#000000");
+		int _B = colorMap.getId("#ffffff");
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRespectsIncomingDefaults2() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.None, null, null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#000000");
+		int _B = colorMap.getId("#ffffff");
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRespectsIncomingDefaults3() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#000000");
+		int _B = colorMap.getId("#ffffff");
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRespectsIncomingDefaults4() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#ff0000", null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#ff0000");
+		int _B = colorMap.getId("#ffffff");
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRespectsIncomingDefaults5() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"),
+						new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null),
+						new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#00ff00");
+		int _B = colorMap.getId("#ff0000");
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testCanMergeIncomingDefaults() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"),
+						new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null),
+						new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#00ff00");
+		int _B = colorMap.getId("#ff0000");
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testDefaultsAreInherited() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
+						new ParsedThemeRule("var", null, -1, FontStyle.NotSet, "#ff0000", null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#F8F8F2");
+		int _B = colorMap.getId("#272822");
+		int _C = colorMap.getId("#ff0000");
+
+		Map map = new HashMap<>();
+		map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET)));
+
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
+						Collections.emptyList(), map));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testSameRulesGetMerged() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
+						new ParsedThemeRule("var", null, 1, FontStyle.Bold, null, null),
+						new ParsedThemeRule("var", null, 0, FontStyle.NotSet, "#ff0000", null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#F8F8F2");
+		int _B = colorMap.getId("#272822");
+		int _C = colorMap.getId("#ff0000");
+
+		Map map = new HashMap<>();
+		map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET)));
+
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
+						Collections.emptyList(), map));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRulesAreInherited1() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
+						new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null),
+						new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#F8F8F2");
+		int _B = colorMap.getId("#272822");
+		int _C = colorMap.getId("#ff0000");
+		int _D = colorMap.getId("#00ff00");
+
+		Map map1_1 = new HashMap<>();
+		map1_1.put("identifier", new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _D, _NOT_SET)));
+		Map map1 = new HashMap<>();
+		map1.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET),
+				Collections.emptyList(), map1_1));
+
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
+						Collections.emptyList(), map1));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRulesAreInherited2() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
+						new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null),
+						new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null),
+						new ParsedThemeRule("constant", null, 4, FontStyle.Italic, "#100000", null),
+						new ParsedThemeRule("constant.numeric", null, 5, FontStyle.NotSet, "#200000", null),
+						new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null),
+						new ParsedThemeRule("constant.numeric.oct", null, 7,
+								FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
+						new ParsedThemeRule("constant.numeric.dec", null, 8, FontStyle.None, "#300000", null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#F8F8F2");
+		int _B = colorMap.getId("#272822");
+		int _C = colorMap.getId("#100000");
+		int _D = colorMap.getId("#200000");
+		int _E = colorMap.getId("#300000");
+		int _F = colorMap.getId("#ff0000");
+		int _G = colorMap.getId("#00ff00");
+
+		Map mapOfVar = new HashMap<>();
+		mapOfVar.put("identifier",
+				new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _G, _NOT_SET)));
+
+		Map mapOfNumeric = new HashMap<>();
+		mapOfNumeric.put("hex", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold, _D, _NOT_SET)));
+		mapOfNumeric.put("oct", new ThemeTrieElement(new ThemeTrieElementRule(3, null,
+				FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _D, _NOT_SET)));
+		mapOfNumeric.put("dec", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.None, _E, _NOT_SET)));
+
+		Map mapOfConstant = new HashMap<>();
+		mapOfConstant.put("numeric",
+				new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Italic, _D, _NOT_SET),
+						Collections.emptyList(), mapOfNumeric));
+
+		Map mapRoot = new HashMap<>();
+		mapRoot.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _F, _NOT_SET),
+				Collections.emptyList(), mapOfVar));
+		mapRoot.put("constant", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Italic, _C, _NOT_SET),
+				Collections.emptyList(), mapOfConstant));
+
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
+						Collections.emptyList(), mapRoot));
+		assertEquals(actual, expected);
+	}
+
+	@Test
+	public void testRulesWithParentScopes() {
+		Theme actual = Theme.createFromParsedTheme(
+				new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"),
+						new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#100000", null),
+						new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#200000", null),
+						new ParsedThemeRule("var", Arrays.asList("source.css"), 1, FontStyle.Italic, "#300000", null),
+						new ParsedThemeRule("var", Arrays.asList("source.css"), 2, FontStyle.Underline, null, null))));
+		ColorMap colorMap = new ColorMap();
+		int _NOT_SET = 0;
+		int _A = colorMap.getId("#F8F8F2");
+		int _B = colorMap.getId("#272822");
+		int _C = colorMap.getId("#100000");
+		int _D = colorMap.getId("#300000");
+		int _E = colorMap.getId("#200000");
+
+		Map mapOfVar = new HashMap<>();
+		mapOfVar.put("identifier",
+				new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _E, _NOT_SET), Arrays.asList(
+						new ThemeTrieElementRule(1, Arrays.asList("source.css"), FontStyle.Underline, _D, _NOT_SET))));
+
+		Map mapRoot = new HashMap<>();
+		mapRoot.put("var",
+				new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET), Arrays.asList(
+						new ThemeTrieElementRule(1, Arrays.asList("source.css"), FontStyle.Underline, _D, _NOT_SET)),
+						mapOfVar));
+
+		Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
+				new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET),
+						Collections.emptyList(), mapRoot));
+		assertEquals(actual, expected);
+	}
+	
+	@Test
+	public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception {
+		List actual = parseTheme("{" +
+			"\"settings\": [{"+
+			"	\"settings\": {"+
+			"		\"background\": \"#222222\","+
+			"		\"foreground\": \"#cccccc\""+
+			"	}"+
+			"}, {"+
+			"	\"name\": \"Variable\","+
+			"	\"scope\": \"variable\","+
+			"	\"settings\": {"+
+			"		\"fontStyle\": \"\""+
+			"	}"+
+			"}, {"+
+			"	\"name\": \"Function argument\","+
+			"	\"scope\": \"variable.parameter\","+
+			"	\"settings\": {"+
+			"		\"fontStyle\": \"italic\","+
+			"		\"foreground\": \"\""+
+			"	}"+
+			"}, {"+
+			"	\"name\": \"Library variable\","+
+			"	\"scope\": \"support.other.variable\","+
+			"	\"settings\": {"+
+			"		\"fontStyle\": \"\""+
+			"	}"+
+			"}, {"+
+			"	\"name\": \"Function argument\","+
+			"	\"scope\": \"variable.other\","+
+			"	\"settings\": {"+
+			"		\"foreground\": \"\","+
+			"		\"fontStyle\": \"normal\""+
+			"	}"+
+			"}, {"+
+			"	\"name\": \"Coffeescript Function argument\","+
+			"	\"scope\": \"variable.parameter.function.coffee\","+
+			"	\"settings\": {"+
+			"		\"foreground\": \"#F9D423\","+
+			"		\"fontStyle\": \"italic\""+
+			"	}"+
+			"}]"+
+		"}");
+
+		List expected = Arrays.asList(
+			new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#cccccc", "#222222"),
+			new ParsedThemeRule("variable", null, 1, FontStyle.None, null, null),
+			new ParsedThemeRule("variable.parameter", null, 2, FontStyle.Italic, null, null),
+			new ParsedThemeRule("support.other.variable", null, 3, FontStyle.None, null, null),
+			new ParsedThemeRule("variable.other", null, 4, FontStyle.None, null, null),
+			new ParsedThemeRule("variable.parameter.function.coffee", null, 5, FontStyle.Italic, "#F9D423", null)
+		);
+
+		assertArrayEquals(expected.toArray(), actual.toArray());
+	}
+	
+	@Test
+	public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exception {
+		List actual = parseTheme("{" +
+			"\"settings\": [{"+
+			"	\"settings\": {"+
+			"		\"background\": \"#25292C\","+
+			"		\"foreground\": \"#EFEFEF\""+
+			"	}"+
+			"}, {"+
+			"	\"name\": \"CSS at-rule keyword control\","+
+			"	\"scope\": \""+
+			"		meta.at-rule.return.scss,\n"+
+			"		meta.at-rule.return.scss punctuation.definition,\n"+
+			"		meta.at-rule.else.scss,\n"+
+			"		meta.at-rule.else.scss punctuation.definition,\n"+
+			"		meta.at-rule.if.scss,\n"+
+			"		meta.at-rule.if.scss punctuation.definition\n"+
+			"	\","+
+			"	\"settings\": {"+
+			"		\"foreground\": \"#CC7832\""+
+			"	}"+
+			"}]"+
+		"}");
+
+		List expected = Arrays.asList(
+				new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#EFEFEF", "#25292C"),
+				new ParsedThemeRule("meta.at-rule.return.scss", null, 1, FontStyle.NotSet, "#CC7832", null),
+				new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.return.scss"), 1, FontStyle.NotSet, "#CC7832", null),
+				new ParsedThemeRule("meta.at-rule.else.scss", null, 1, FontStyle.NotSet, "#CC7832", null),
+				new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.else.scss"), 1, FontStyle.NotSet, "#CC7832", null),
+				new ParsedThemeRule("meta.at-rule.if.scss", null, 1, FontStyle.NotSet, "#CC7832", null),
+				new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.if.scss"), 1, FontStyle.NotSet, "#CC7832", null)
+		);
+
+		assertArrayEquals(expected.toArray(), actual.toArray());
+	}
+	
+	private void assertStrArrCmp(String testCase, List a, List b, int expected) {
+		assertEquals(expected, CompareUtils.strArrCmp(a, b), testCase);
+	}
+	
+	private List parseTheme(String theme) throws Exception {
+		return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes())));
+	}
+}
diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Markdown.tmLanguage b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Markdown.tmLanguage
index fa056f47a..9a5ca66b5 100644
--- a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Markdown.tmLanguage
+++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Markdown.tmLanguage
@@ -1,1108 +1,1108 @@
-
-
-
-
-	fileTypes
-	
-		md
-		mdown
-		markdown
-		markdn
-	
-	keyEquivalent
-	^~M
-	name
-	Markdown
-	patterns
-	
-		
-			include
-			#block
-		
-	
-	repository
-	
-		block
-		
-			patterns
-			
-				
-					include
-					#separator
-				
-				
-					include
-					#heading
-				
-				
-					include
-					#blockquote
-				
-				
-					include
-					#lists
-				
-				
-					include
-					#raw_block
-				
-				
-					include
-					#link-def
-				
-				
-					include
-					#html
-				
-				
-					include
-					#paragraph
-				
-			
-			repository
-			
-				blockquote
-				
-					begin
-					(^|\G)(>) ?
-					captures
-					
-						2
-						
-							name
-							punctuation.definition.quote.markdown
-						
-					
-					name
-					markup.quote.markdown
-					patterns
-					
-						
-							include
-							#block
-						
-					
-					while
-					(^|\G)(>) ?
-				
-				heading
-				
-					begin
-					(?:^|\G)(#{1,6})\s*(?=[\S[^#]])
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.heading.markdown
-						
-					
-					contentName
-					entity.name.section.markdown
-					end
-					\s*(#{1,6})?$\n?
-					name
-					markup.heading.markdown
-					patterns
-					
-						
-							include
-							#inline
-						
-					
-				
-				heading-setext
-				
-					patterns
-					
-						
-							match
-							^(={3,})(?=[ \t]*$\n?)
-							name
-							markup.heading.setext.1.markdown
-						
-						
-							match
-							^(-{3,})(?=[ \t]*$\n?)
-							name
-							markup.heading.setext.2.markdown
-						
-					
-				
-				html
-				
-					patterns
-					
-						
-							begin
-							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del).*</\2\s*>\s*$)
-							end
-							$
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-						
-						
-							begin
-							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del))
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-							while
-							\G(?!</\2\s*>)
-						
-					
-				
-				link-def
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.constant.markdown
-						
-						10
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						11
-						
-							name
-							string.other.link.description.title.markdown
-						
-						12
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						13
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						2
-						
-							name
-							constant.other.reference.link.markdown
-						
-						3
-						
-							name
-							punctuation.definition.constant.markdown
-						
-						4
-						
-							name
-							punctuation.separator.key-value.markdown
-						
-						5
-						
-							name
-							punctuation.definition.link.markdown
-						
-						6
-						
-							name
-							markup.underline.link.markdown
-						
-						7
-						
-							name
-							punctuation.definition.link.markdown
-						
-						8
-						
-							name
-							string.other.link.description.title.markdown
-						
-						9
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-					
-					match
-					^(?x:
-									\s*						# Leading whitespace
-									(\[)(.+?)(\])(:)		# Reference name
-									[ \t]*					# Optional whitespace
-									(<?)(\S+?)(>?)			# The url
-									[ \t]*					# Optional whitespace
-									(?:
-										  ((\().+?(\)))		# Match title in quotes…
-										| ((").+?("))		# or in parens.
-									)?						# Title is optional
-									\s*						# Optional whitespace
-									$
-								)
-					name
-					meta.link.reference.def.markdown
-				
-				list_paragraph
-				
-					begin
-					(^|\G)(?=\S)(?![*+-]\s|[0-9]+\.\s)
-					name
-					meta.paragraph.markdown
-					patterns
-					
-						
-							include
-							#inline
-						
-						
-							include
-							text.html.basic
-						
-						
-							include
-							#heading-setext
-						
-					
-					while
-					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|>|[ ]{0,3}[*+-]|[ ]{0,3}[0-9]+\.)
-				
-				lists
-				
-					patterns
-					
-						
-							begin
-							(^|\G)([ ]{0,3})([*+-])([ ]{1,3}|\t)
-							beginCaptures
-							
-								3
-								
-									name
-									punctuation.definition.list.markdown
-								
-							
-							comment
-							Currently does not support un-indented second lines.
-							name
-							markup.list.unnumbered.markdown
-							patterns
-							
-								
-									include
-									#list_paragraph
-								
-								
-									include
-									#block
-								
-							
-							while
-							\G([ ]{4}|\t|$)
-						
-						
-							begin
-							(^|\G)([ ]{0,3})([0-9]+\.)([ ]{1,3}|\t)
-							beginCaptures
-							
-								3
-								
-									name
-									punctuation.definition.list.markdown
-								
-							
-							name
-							markup.list.numbered.markdown
-							patterns
-							
-								
-									include
-									#list_paragraph
-								
-								
-									include
-									#block
-								
-							
-							while
-							\G([ ]{4}|\t|$)
-						
-					
-				
-				paragraph
-				
-					begin
-					(^|\G)(?=\S)
-					name
-					meta.paragraph.markdown
-					patterns
-					
-						
-							include
-							#inline
-						
-						
-							include
-							text.html.basic
-						
-						
-							include
-							#heading-setext
-						
-					
-					while
-					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|\s*\[.+?\]:|>)
-				
-				raw_block
-				
-					begin
-					(^|\G)([ ]{4}|\t)
-					name
-					markup.raw.block.markdown
-					while
-					(^|\G)([ ]{4}|\t)
-				
-				separator
-				
-					match
-					(^|\G)[ ]{0,3}([-*_])([ ]{0,2}\2){2,}[ \t]*$\n?
-					name
-					meta.separator.markdown
-				
-			
-		
-		inline
-		
-			patterns
-			
-				
-					include
-					#ampersand
-				
-				
-					include
-					#bracket
-				
-				
-					include
-					#bold
-				
-				
-					include
-					#italic
-				
-				
-					include
-					#raw
-				
-				
-					include
-					#escape
-				
-				
-					include
-					#image-inline
-				
-				
-					include
-					#image-ref
-				
-				
-					include
-					#link-email
-				
-				
-					include
-					#link-inet
-				
-				
-					include
-					#link-inline
-				
-				
-					include
-					#link-ref
-				
-				
-					include
-					#link-ref-literal
-				
-			
-			repository
-			
-				ampersand
-				
-					comment
-					
-						Markdown will convert this for us. We match it so that the
-						HTML grammar will not mark it up as invalid.
-					
-					match
-					&(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);)
-					name
-					meta.other.valid-ampersand.markdown
-				
-				bold
-				
-					begin
-					(?x)
-								(\*\*|__)(?=\S)								# Open
-								(?=
-									(
-									    <[^>]*+>							# HTML tags
-									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
-																			# Raw
-									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
-									  | \[
-										(
-										        (?<square>					# Named group
-													[^\[\]\\]				# Match most chars
-										          | \\.						# Escaped chars
-										          | \[ \g<square>*+ \]		# Nested brackets
-										        )*+
-											\]
-											(
-												(							# Reference Link
-													[ ]?					# Optional space
-													\[[^\]]*+\]				# Ref name
-												)
-											  | (							# Inline Link
-													\(						# Opening paren
-														[ \t]*+				# Optional whtiespace
-														<?(.*?)>?			# URL
-														[ \t]*+				# Optional whtiespace
-														(					# Optional Title
-															(?<title>['"])
-															(.*?)
-															\k<title>
-														)?
-													\)
-												)
-											)
-										)
-									  | (?!(?<=\S)\1).						# Everything besides
-																			# style closer
-									)++
-									(?<=\S)\1								# Close
-								)
-							
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.bold.markdown
-						
-					
-					end
-					(?<=\S)(\1)
-					name
-					markup.bold.markdown
-					patterns
-					
-						
-							applyEndPatternLast
-							1
-							begin
-							(?=<[^>]*?>)
-							end
-							(?<=>)
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-						
-						
-							include
-							#escape
-						
-						
-							include
-							#ampersand
-						
-						
-							include
-							#bracket
-						
-						
-							include
-							#raw
-						
-						
-							include
-							#italic
-						
-						
-							include
-							#image-inline
-						
-						
-							include
-							#link-inline
-						
-						
-							include
-							#link-inet
-						
-						
-							include
-							#link-email
-						
-						
-							include
-							#image-ref
-						
-						
-							include
-							#link-ref-literal
-						
-						
-							include
-							#link-ref
-						
-					
-				
-				bracket
-				
-					comment
-					
-						Markdown will convert this for us. We match it so that the
-						HTML grammar will not mark it up as invalid.
-					
-					match
-					<(?![a-z/?\$!])
-					name
-					meta.other.valid-bracket.markdown
-				
-				escape
-				
-					match
-					\\[-`*_#+.!(){}\[\]\\>]
-					name
-					constant.character.escape.markdown
-				
-				image-inline
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						10
-						
-							name
-							string.other.link.description.title.markdown
-						
-						11
-						
-							name
-							punctuation.definition.string.markdown
-						
-						12
-						
-							name
-							punctuation.definition.string.markdown
-						
-						13
-						
-							name
-							string.other.link.description.title.markdown
-						
-						14
-						
-							name
-							punctuation.definition.string.markdown
-						
-						15
-						
-							name
-							punctuation.definition.string.markdown
-						
-						16
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						2
-						
-							name
-							string.other.link.description.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							invalid.illegal.whitespace.markdown
-						
-						6
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						7
-						
-							name
-							punctuation.definition.link.markdown
-						
-						8
-						
-							name
-							markup.underline.link.image.markdown
-						
-						9
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(?x:
-						\!							# Images start with !
-						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])
-													# Match the link text.
-						([ ])?						# Space not allowed
-						(\()						# Opening paren for url
-							(<?)(\S+?)(>?)			# The url
-							[ \t]*					# Optional whitespace
-							(?:
-								  ((\().+?(\)))		# Match title in parens…
-								| ((").+?("))		# or in quotes.
-							)?						# Title is optional
-							\s*						# Optional whitespace
-						(\))
-					 )
-					name
-					meta.image.inline.markdown
-				
-				image-ref
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						2
-						
-							name
-							string.other.link.description.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						5
-						
-							name
-							punctuation.definition.constant.markdown
-						
-						6
-						
-							name
-							constant.other.reference.link.markdown
-						
-						7
-						
-							name
-							punctuation.definition.constant.markdown
-						
-					
-					match
-					\!(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(.*?)(\])
-					name
-					meta.image.reference.markdown
-				
-				italic
-				
-					begin
-					(?x)
-								(\*|_)(?=\S)								# Open
-								(?=
-									(
-									    <[^>]*+>							# HTML tags
-									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
-																			# Raw
-									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
-									  | \[
-										(
-										        (?<square>					# Named group
-													[^\[\]\\]				# Match most chars
-										          | \\.						# Escaped chars
-										          | \[ \g<square>*+ \]		# Nested brackets
-										        )*+
-											\]
-											(
-												(							# Reference Link
-													[ ]?					# Optional space
-													\[[^\]]*+\]				# Ref name
-												)
-											  | (							# Inline Link
-													\(						# Opening paren
-														[ \t]*+				# Optional whtiespace
-														<?(.*?)>?			# URL
-														[ \t]*+				# Optional whtiespace
-														(					# Optional Title
-															(?<title>['"])
-															(.*?)
-															\k<title>
-														)?
-													\)
-												)
-											)
-										)
-									  | \1\1								# Must be bold closer
-									  | (?!(?<=\S)\1).						# Everything besides
-																			# style closer
-									)++
-									(?<=\S)\1								# Close
-								)
-							
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.italic.markdown
-						
-					
-					end
-					(?<=\S)(\1)((?!\1)|(?=\1\1))
-					name
-					markup.italic.markdown
-					patterns
-					
-						
-							applyEndPatternLast
-							1
-							begin
-							(?=<[^>]*?>)
-							end
-							(?<=>)
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-						
-						
-							include
-							#escape
-						
-						
-							include
-							#ampersand
-						
-						
-							include
-							#bracket
-						
-						
-							include
-							#raw
-						
-						
-							include
-							#bold
-						
-						
-							include
-							#image-inline
-						
-						
-							include
-							#link-inline
-						
-						
-							include
-							#link-inet
-						
-						
-							include
-							#link-email
-						
-						
-							include
-							#image-ref
-						
-						
-							include
-							#link-ref-literal
-						
-						
-							include
-							#link-ref
-						
-					
-				
-				link-email
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.link.markdown
-						
-						2
-						
-							name
-							markup.underline.link.markdown
-						
-						4
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(<)((?:mailto:)?[-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(>)
-					name
-					meta.link.email.lt-gt.markdown
-				
-				link-inet
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.link.markdown
-						
-						2
-						
-							name
-							markup.underline.link.markdown
-						
-						3
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(<)((?:https?|ftp)://.*?)(>)
-					name
-					meta.link.inet.markdown
-				
-				link-inline
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						10
-						
-							name
-							string.other.link.description.title.markdown
-						
-						11
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						12
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						13
-						
-							name
-							string.other.link.description.title.markdown
-						
-						14
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						15
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						16
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						2
-						
-							name
-							string.other.link.title.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							invalid.illegal.whitespace.markdown
-						
-						6
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						7
-						
-							name
-							punctuation.definition.link.markdown
-						
-						8
-						
-							name
-							markup.underline.link.markdown
-						
-						9
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(?x:
-						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])
-													# Match the link text.
-						([ ])?						# Space not allowed
-						(\()						# Opening paren for url
-							(<?)(.*?)(>?)			# The url
-							[ \t]*					# Optional whitespace
-							(?:
-								  ((\().+?(\)))		# Match title in parens…
-								| ((").+?("))		# or in quotes.
-							)?						# Title is optional
-							\s*						# Optional whitespace
-						(\))
-					 )
-					name
-					meta.link.inline.markdown
-				
-				link-ref
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						2
-						
-							name
-							string.other.link.title.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							punctuation.definition.constant.begin.markdown
-						
-						6
-						
-							name
-							constant.other.reference.link.markdown
-						
-						7
-						
-							name
-							punctuation.definition.constant.end.markdown
-						
-					
-					match
-					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)([^\]]*+)(\])
-					name
-					meta.link.reference.markdown
-				
-				link-ref-literal
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						2
-						
-							name
-							string.other.link.title.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							punctuation.definition.constant.begin.markdown
-						
-						6
-						
-							name
-							punctuation.definition.constant.end.markdown
-						
-					
-					match
-					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(\])
-					name
-					meta.link.reference.literal.markdown
-				
-				raw
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.raw.markdown
-						
-						2
-						
-						3
-						
-							name
-							punctuation.definition.raw.markdown
-						
-					
-					match
-					(`+)([^`]|(?!(?<!`)\1(?!`))`)*+(\1)
-					name
-					markup.raw.inline.markdown
-				
-			
-		
-	
-	scopeName
-	text.html.markdown
-	uuid
-	0A1D9874-B448-11D9-BD50-000D93B6E43C
-
+
+
+
+
+	fileTypes
+	
+		md
+		mdown
+		markdown
+		markdn
+	
+	keyEquivalent
+	^~M
+	name
+	Markdown
+	patterns
+	
+		
+			include
+			#block
+		
+	
+	repository
+	
+		block
+		
+			patterns
+			
+				
+					include
+					#separator
+				
+				
+					include
+					#heading
+				
+				
+					include
+					#blockquote
+				
+				
+					include
+					#lists
+				
+				
+					include
+					#raw_block
+				
+				
+					include
+					#link-def
+				
+				
+					include
+					#html
+				
+				
+					include
+					#paragraph
+				
+			
+			repository
+			
+				blockquote
+				
+					begin
+					(^|\G)(>) ?
+					captures
+					
+						2
+						
+							name
+							punctuation.definition.quote.markdown
+						
+					
+					name
+					markup.quote.markdown
+					patterns
+					
+						
+							include
+							#block
+						
+					
+					while
+					(^|\G)(>) ?
+				
+				heading
+				
+					begin
+					(?:^|\G)(#{1,6})\s*(?=[\S[^#]])
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.heading.markdown
+						
+					
+					contentName
+					entity.name.section.markdown
+					end
+					\s*(#{1,6})?$\n?
+					name
+					markup.heading.markdown
+					patterns
+					
+						
+							include
+							#inline
+						
+					
+				
+				heading-setext
+				
+					patterns
+					
+						
+							match
+							^(={3,})(?=[ \t]*$\n?)
+							name
+							markup.heading.setext.1.markdown
+						
+						
+							match
+							^(-{3,})(?=[ \t]*$\n?)
+							name
+							markup.heading.setext.2.markdown
+						
+					
+				
+				html
+				
+					patterns
+					
+						
+							begin
+							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del).*</\2\s*>\s*$)
+							end
+							$
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+						
+						
+							begin
+							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del))
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+							while
+							\G(?!</\2\s*>)
+						
+					
+				
+				link-def
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.constant.markdown
+						
+						10
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						11
+						
+							name
+							string.other.link.description.title.markdown
+						
+						12
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						13
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						2
+						
+							name
+							constant.other.reference.link.markdown
+						
+						3
+						
+							name
+							punctuation.definition.constant.markdown
+						
+						4
+						
+							name
+							punctuation.separator.key-value.markdown
+						
+						5
+						
+							name
+							punctuation.definition.link.markdown
+						
+						6
+						
+							name
+							markup.underline.link.markdown
+						
+						7
+						
+							name
+							punctuation.definition.link.markdown
+						
+						8
+						
+							name
+							string.other.link.description.title.markdown
+						
+						9
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+					
+					match
+					^(?x:
+									\s*						# Leading whitespace
+									(\[)(.+?)(\])(:)		# Reference name
+									[ \t]*					# Optional whitespace
+									(<?)(\S+?)(>?)			# The url
+									[ \t]*					# Optional whitespace
+									(?:
+										  ((\().+?(\)))		# Match title in quotes…
+										| ((").+?("))		# or in parens.
+									)?						# Title is optional
+									\s*						# Optional whitespace
+									$
+								)
+					name
+					meta.link.reference.def.markdown
+				
+				list_paragraph
+				
+					begin
+					(^|\G)(?=\S)(?![*+-]\s|[0-9]+\.\s)
+					name
+					meta.paragraph.markdown
+					patterns
+					
+						
+							include
+							#inline
+						
+						
+							include
+							text.html.basic
+						
+						
+							include
+							#heading-setext
+						
+					
+					while
+					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|>|[ ]{0,3}[*+-]|[ ]{0,3}[0-9]+\.)
+				
+				lists
+				
+					patterns
+					
+						
+							begin
+							(^|\G)([ ]{0,3})([*+-])([ ]{1,3}|\t)
+							beginCaptures
+							
+								3
+								
+									name
+									punctuation.definition.list.markdown
+								
+							
+							comment
+							Currently does not support un-indented second lines.
+							name
+							markup.list.unnumbered.markdown
+							patterns
+							
+								
+									include
+									#list_paragraph
+								
+								
+									include
+									#block
+								
+							
+							while
+							\G([ ]{4}|\t|$)
+						
+						
+							begin
+							(^|\G)([ ]{0,3})([0-9]+\.)([ ]{1,3}|\t)
+							beginCaptures
+							
+								3
+								
+									name
+									punctuation.definition.list.markdown
+								
+							
+							name
+							markup.list.numbered.markdown
+							patterns
+							
+								
+									include
+									#list_paragraph
+								
+								
+									include
+									#block
+								
+							
+							while
+							\G([ ]{4}|\t|$)
+						
+					
+				
+				paragraph
+				
+					begin
+					(^|\G)(?=\S)
+					name
+					meta.paragraph.markdown
+					patterns
+					
+						
+							include
+							#inline
+						
+						
+							include
+							text.html.basic
+						
+						
+							include
+							#heading-setext
+						
+					
+					while
+					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|\s*\[.+?\]:|>)
+				
+				raw_block
+				
+					begin
+					(^|\G)([ ]{4}|\t)
+					name
+					markup.raw.block.markdown
+					while
+					(^|\G)([ ]{4}|\t)
+				
+				separator
+				
+					match
+					(^|\G)[ ]{0,3}([-*_])([ ]{0,2}\2){2,}[ \t]*$\n?
+					name
+					meta.separator.markdown
+				
+			
+		
+		inline
+		
+			patterns
+			
+				
+					include
+					#ampersand
+				
+				
+					include
+					#bracket
+				
+				
+					include
+					#bold
+				
+				
+					include
+					#italic
+				
+				
+					include
+					#raw
+				
+				
+					include
+					#escape
+				
+				
+					include
+					#image-inline
+				
+				
+					include
+					#image-ref
+				
+				
+					include
+					#link-email
+				
+				
+					include
+					#link-inet
+				
+				
+					include
+					#link-inline
+				
+				
+					include
+					#link-ref
+				
+				
+					include
+					#link-ref-literal
+				
+			
+			repository
+			
+				ampersand
+				
+					comment
+					
+						Markdown will convert this for us. We match it so that the
+						HTML grammar will not mark it up as invalid.
+					
+					match
+					&(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);)
+					name
+					meta.other.valid-ampersand.markdown
+				
+				bold
+				
+					begin
+					(?x)
+								(\*\*|__)(?=\S)								# Open
+								(?=
+									(
+									    <[^>]*+>							# HTML tags
+									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
+																			# Raw
+									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
+									  | \[
+										(
+										        (?<square>					# Named group
+													[^\[\]\\]				# Match most chars
+										          | \\.						# Escaped chars
+										          | \[ \g<square>*+ \]		# Nested brackets
+										        )*+
+											\]
+											(
+												(							# Reference Link
+													[ ]?					# Optional space
+													\[[^\]]*+\]				# Ref name
+												)
+											  | (							# Inline Link
+													\(						# Opening paren
+														[ \t]*+				# Optional whtiespace
+														<?(.*?)>?			# URL
+														[ \t]*+				# Optional whtiespace
+														(					# Optional Title
+															(?<title>['"])
+															(.*?)
+															\k<title>
+														)?
+													\)
+												)
+											)
+										)
+									  | (?!(?<=\S)\1).						# Everything besides
+																			# style closer
+									)++
+									(?<=\S)\1								# Close
+								)
+							
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.bold.markdown
+						
+					
+					end
+					(?<=\S)(\1)
+					name
+					markup.bold.markdown
+					patterns
+					
+						
+							applyEndPatternLast
+							1
+							begin
+							(?=<[^>]*?>)
+							end
+							(?<=>)
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+						
+						
+							include
+							#escape
+						
+						
+							include
+							#ampersand
+						
+						
+							include
+							#bracket
+						
+						
+							include
+							#raw
+						
+						
+							include
+							#italic
+						
+						
+							include
+							#image-inline
+						
+						
+							include
+							#link-inline
+						
+						
+							include
+							#link-inet
+						
+						
+							include
+							#link-email
+						
+						
+							include
+							#image-ref
+						
+						
+							include
+							#link-ref-literal
+						
+						
+							include
+							#link-ref
+						
+					
+				
+				bracket
+				
+					comment
+					
+						Markdown will convert this for us. We match it so that the
+						HTML grammar will not mark it up as invalid.
+					
+					match
+					<(?![a-z/?\$!])
+					name
+					meta.other.valid-bracket.markdown
+				
+				escape
+				
+					match
+					\\[-`*_#+.!(){}\[\]\\>]
+					name
+					constant.character.escape.markdown
+				
+				image-inline
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						10
+						
+							name
+							string.other.link.description.title.markdown
+						
+						11
+						
+							name
+							punctuation.definition.string.markdown
+						
+						12
+						
+							name
+							punctuation.definition.string.markdown
+						
+						13
+						
+							name
+							string.other.link.description.title.markdown
+						
+						14
+						
+							name
+							punctuation.definition.string.markdown
+						
+						15
+						
+							name
+							punctuation.definition.string.markdown
+						
+						16
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						2
+						
+							name
+							string.other.link.description.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							invalid.illegal.whitespace.markdown
+						
+						6
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						7
+						
+							name
+							punctuation.definition.link.markdown
+						
+						8
+						
+							name
+							markup.underline.link.image.markdown
+						
+						9
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(?x:
+						\!							# Images start with !
+						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])
+													# Match the link text.
+						([ ])?						# Space not allowed
+						(\()						# Opening paren for url
+							(<?)(\S+?)(>?)			# The url
+							[ \t]*					# Optional whitespace
+							(?:
+								  ((\().+?(\)))		# Match title in parens…
+								| ((").+?("))		# or in quotes.
+							)?						# Title is optional
+							\s*						# Optional whitespace
+						(\))
+					 )
+					name
+					meta.image.inline.markdown
+				
+				image-ref
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						2
+						
+							name
+							string.other.link.description.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						5
+						
+							name
+							punctuation.definition.constant.markdown
+						
+						6
+						
+							name
+							constant.other.reference.link.markdown
+						
+						7
+						
+							name
+							punctuation.definition.constant.markdown
+						
+					
+					match
+					\!(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(.*?)(\])
+					name
+					meta.image.reference.markdown
+				
+				italic
+				
+					begin
+					(?x)
+								(\*|_)(?=\S)								# Open
+								(?=
+									(
+									    <[^>]*+>							# HTML tags
+									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
+																			# Raw
+									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
+									  | \[
+										(
+										        (?<square>					# Named group
+													[^\[\]\\]				# Match most chars
+										          | \\.						# Escaped chars
+										          | \[ \g<square>*+ \]		# Nested brackets
+										        )*+
+											\]
+											(
+												(							# Reference Link
+													[ ]?					# Optional space
+													\[[^\]]*+\]				# Ref name
+												)
+											  | (							# Inline Link
+													\(						# Opening paren
+														[ \t]*+				# Optional whtiespace
+														<?(.*?)>?			# URL
+														[ \t]*+				# Optional whtiespace
+														(					# Optional Title
+															(?<title>['"])
+															(.*?)
+															\k<title>
+														)?
+													\)
+												)
+											)
+										)
+									  | \1\1								# Must be bold closer
+									  | (?!(?<=\S)\1).						# Everything besides
+																			# style closer
+									)++
+									(?<=\S)\1								# Close
+								)
+							
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.italic.markdown
+						
+					
+					end
+					(?<=\S)(\1)((?!\1)|(?=\1\1))
+					name
+					markup.italic.markdown
+					patterns
+					
+						
+							applyEndPatternLast
+							1
+							begin
+							(?=<[^>]*?>)
+							end
+							(?<=>)
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+						
+						
+							include
+							#escape
+						
+						
+							include
+							#ampersand
+						
+						
+							include
+							#bracket
+						
+						
+							include
+							#raw
+						
+						
+							include
+							#bold
+						
+						
+							include
+							#image-inline
+						
+						
+							include
+							#link-inline
+						
+						
+							include
+							#link-inet
+						
+						
+							include
+							#link-email
+						
+						
+							include
+							#image-ref
+						
+						
+							include
+							#link-ref-literal
+						
+						
+							include
+							#link-ref
+						
+					
+				
+				link-email
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.link.markdown
+						
+						2
+						
+							name
+							markup.underline.link.markdown
+						
+						4
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(<)((?:mailto:)?[-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(>)
+					name
+					meta.link.email.lt-gt.markdown
+				
+				link-inet
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.link.markdown
+						
+						2
+						
+							name
+							markup.underline.link.markdown
+						
+						3
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(<)((?:https?|ftp)://.*?)(>)
+					name
+					meta.link.inet.markdown
+				
+				link-inline
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						10
+						
+							name
+							string.other.link.description.title.markdown
+						
+						11
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						12
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						13
+						
+							name
+							string.other.link.description.title.markdown
+						
+						14
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						15
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						16
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						2
+						
+							name
+							string.other.link.title.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							invalid.illegal.whitespace.markdown
+						
+						6
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						7
+						
+							name
+							punctuation.definition.link.markdown
+						
+						8
+						
+							name
+							markup.underline.link.markdown
+						
+						9
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(?x:
+						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])
+													# Match the link text.
+						([ ])?						# Space not allowed
+						(\()						# Opening paren for url
+							(<?)(.*?)(>?)			# The url
+							[ \t]*					# Optional whitespace
+							(?:
+								  ((\().+?(\)))		# Match title in parens…
+								| ((").+?("))		# or in quotes.
+							)?						# Title is optional
+							\s*						# Optional whitespace
+						(\))
+					 )
+					name
+					meta.link.inline.markdown
+				
+				link-ref
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						2
+						
+							name
+							string.other.link.title.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							punctuation.definition.constant.begin.markdown
+						
+						6
+						
+							name
+							constant.other.reference.link.markdown
+						
+						7
+						
+							name
+							punctuation.definition.constant.end.markdown
+						
+					
+					match
+					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)([^\]]*+)(\])
+					name
+					meta.link.reference.markdown
+				
+				link-ref-literal
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						2
+						
+							name
+							string.other.link.title.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							punctuation.definition.constant.begin.markdown
+						
+						6
+						
+							name
+							punctuation.definition.constant.end.markdown
+						
+					
+					match
+					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(\])
+					name
+					meta.link.reference.literal.markdown
+				
+				raw
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.raw.markdown
+						
+						2
+						
+						3
+						
+							name
+							punctuation.definition.raw.markdown
+						
+					
+					match
+					(`+)([^`]|(?!(?<!`)\1(?!`))`)*+(\1)
+					name
+					markup.raw.inline.markdown
+				
+			
+		
+	
+	scopeName
+	text.html.markdown
+	uuid
+	0A1D9874-B448-11D9-BD50-000D93B6E43C
+
 
\ No newline at end of file
diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Platform.tmLanguage b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Platform.tmLanguage
index 1f16cf6e6..8e64534d2 100644
--- a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Platform.tmLanguage
+++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Platform.tmLanguage
@@ -1,4 +1,4 @@
-
+
 
 
 
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java
index e9ff82962..68d8810a2 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java
@@ -1,29 +1,29 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core;
-
-/**
- * TextMate exception.
- *
- */
-public class TMException extends RuntimeException {
-
-	private static final long serialVersionUID = 1L;
-
-	public TMException(String message) {
-		super(message);
-	}
-
-	public TMException(String message, Throwable cause) {
-		super(message, cause);
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core;
+
+/**
+ * TextMate exception.
+ *
+ */
+public class TMException extends RuntimeException {
+
+	private static final long serialVersionUID = 1L;
+
+	public TMException(String message) {
+		super(message);
+	}
+
+	public TMException(String message, Throwable cause) {
+		super(message, cause);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IToken.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IToken.java
index 810402f85..1cfef609e 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IToken.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IToken.java
@@ -13,19 +13,19 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.grammar;
-
-import java.util.List;
-
-public interface IToken {
-
-	int getStartIndex();
-
-	void setStartIndex(int startIndex);
-
-	int getEndIndex();
-
-	List getScopes();
-
-}
+ */
+package org.eclipse.tm4e.core.grammar;
+
+import java.util.List;
+
+public interface IToken {
+
+	int getStartIndex();
+
+	void setStartIndex(int startIndex);
+
+	int getEndIndex();
+
+	List getScopes();
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java
index 9312a1221..ecc16be53 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java
@@ -13,23 +13,23 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.grammar;
-
-/**
- * Result of the line tokenization API.
- *
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts
- */
-public interface ITokenizeLineResult {
-
-	IToken[] getTokens();
-
-	/**
-	 * Returns the `prevState` to be passed on to the next line tokenization.
-	 * 
-	 * @return the `prevState` to be passed on to the next line tokenization.
-	 */
-	StackElement getRuleStack();
-
-}
+ */
+package org.eclipse.tm4e.core.grammar;
+
+/**
+ * Result of the line tokenization API.
+ *
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts
+ */
+public interface ITokenizeLineResult {
+
+	IToken[] getTokens();
+
+	/**
+	 * Returns the `prevState` to be passed on to the next line tokenization.
+	 * 
+	 * @return the `prevState` to be passed on to the next line tokenization.
+	 */
+	StackElement getRuleStack();
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/Injection.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/Injection.java
index 487a0eea5..2064078a5 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/Injection.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/Injection.java
@@ -13,29 +13,29 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.grammar;
-
+ */
+package org.eclipse.tm4e.core.grammar;
+
 import java.util.List;
 import java.util.function.Predicate;
 
-import org.eclipse.tm4e.core.internal.types.IRawGrammar;
-
-public class Injection {
-
-	private final Predicate> matcher;
-	public final int priority; // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R'
-	public final int ruleId;
-	public final IRawGrammar grammar;
-
-	public Injection(Predicate> matcher, int ruleId, IRawGrammar grammar, int priority) {
-		this.matcher = matcher;
-		this.ruleId = ruleId;
-		this.grammar = grammar;
-		this.priority = priority;
-	}
-
-	public boolean match(List states) {
-		return matcher.test(states);
-	}
-}
+import org.eclipse.tm4e.core.internal.types.IRawGrammar;
+
+public class Injection {
+
+	private final Predicate> matcher;
+	public final int priority; // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R'
+	public final int ruleId;
+	public final IRawGrammar grammar;
+
+	public Injection(Predicate> matcher, int ruleId, IRawGrammar grammar, int priority) {
+		this.matcher = matcher;
+		this.ruleId = ruleId;
+		this.grammar = grammar;
+		this.priority = priority;
+	}
+
+	public boolean match(List states) {
+		return matcher.test(states);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java
index 56946a409..72a5993d8 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java
@@ -24,12 +24,12 @@
 import org.eclipse.tm4e.core.internal.rule.IRuleRegistry;
 import org.eclipse.tm4e.core.internal.rule.Rule;
 
-/**
+/**
  * Represents a "pushed" state on the stack (as a linked list element).
- *
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts
- *
- */
+ *
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts
+ *
+ */
 public class StackElement {
 
 	public static final StackElement NULL = new StackElement(null, 0, 0, null, null, null);
@@ -66,8 +66,8 @@ public class StackElement {
 	 * The list of scopes containing the "contentName" (besides "name") for this state.
 	 * This list **must** contain as an element `scopeName`.
 	 */
-	public final ScopeListElement contentNameScopesList;
-
+	public final ScopeListElement contentNameScopesList;
+
 	public StackElement(StackElement parent, int ruleId, int enterPos, String endRule, ScopeListElement nameScopesList, ScopeListElement contentNameScopesList) {
 		this.parent = parent;
 		this.depth = (this.parent != null ? this.parent.depth + 1 : 1);
@@ -75,8 +75,8 @@ public StackElement(StackElement parent, int ruleId, int enterPos, String endRul
 		this.enterPosition = enterPos;
 		this.endRule = endRule;
 		this.nameScopesList = nameScopesList;
-		this.contentNameScopesList = contentNameScopesList;
-	}
+		this.contentNameScopesList = contentNameScopesList;
+	}
 
 	/**
 	 * A structural equals check. Does not take into account `scopes`.
@@ -129,7 +129,7 @@ public StackElement safePop() {
 		}
 		return this;
 	}
-
+
 	public StackElement push(int ruleId, int enterPos, String endRule, ScopeListElement nameScopesList, ScopeListElement contentNameScopesList) {
 		return new StackElement(this, ruleId, enterPos, endRule, nameScopesList, contentNameScopesList);
 	}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java
index ae07b83b4..4740854fb 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java
@@ -1,39 +1,39 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.AttributeCondition;
-
-public abstract class AbstractAttributeCondition implements AttributeCondition, ExtendedCondition {
-
-	/**
-	 * The attribute value.
-	 */
-	protected String value;
-
-	/**
-	 * Creates a new AbstractAttributeCondition object.
-	 */
-	protected AbstractAttributeCondition(String value) {
-		this.value = value;
-	}
-
-	@Override
-	public String getValue() {
-		return value;
-	}
-
-	@Override
-	public int getSpecificity() {
-		return 1 << 8;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.AttributeCondition;
+
+public abstract class AbstractAttributeCondition implements AttributeCondition, ExtendedCondition {
+
+	/**
+	 * The attribute value.
+	 */
+	protected String value;
+
+	/**
+	 * Creates a new AbstractAttributeCondition object.
+	 */
+	protected AbstractAttributeCondition(String value) {
+		this.value = value;
+	}
+
+	@Override
+	public String getValue() {
+		return value;
+	}
+
+	@Override
+	public int getSpecificity() {
+		return 1 << 8;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java
index 80b5d732d..1b0dabb2d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java
@@ -1,45 +1,45 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.CombinatorCondition;
-import org.w3c.css.sac.Condition;
-
-public abstract class AbstractCombinatorCondition implements CombinatorCondition, ExtendedCondition {
-	protected Condition firstCondition;
-
-	protected Condition secondCondition;
-
-	/**
-	 * Creates a new CombinatorCondition object.
-	 */
-	protected AbstractCombinatorCondition(Condition c1, Condition c2) {
-		firstCondition = c1;
-		secondCondition = c2;
-	}
-
-	@Override
-	public Condition getFirstCondition() {
-		return firstCondition;
-	}
-
-	@Override
-	public Condition getSecondCondition() {
-		return secondCondition;
-	}
-
-	@Override
-	public int getSpecificity() {
-		return ((ExtendedCondition) getFirstCondition()).getSpecificity()
-				+ ((ExtendedCondition) getSecondCondition()).getSpecificity();
-	}
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.CombinatorCondition;
+import org.w3c.css.sac.Condition;
+
+public abstract class AbstractCombinatorCondition implements CombinatorCondition, ExtendedCondition {
+	protected Condition firstCondition;
+
+	protected Condition secondCondition;
+
+	/**
+	 * Creates a new CombinatorCondition object.
+	 */
+	protected AbstractCombinatorCondition(Condition c1, Condition c2) {
+		firstCondition = c1;
+		secondCondition = c2;
+	}
+
+	@Override
+	public Condition getFirstCondition() {
+		return firstCondition;
+	}
+
+	@Override
+	public Condition getSecondCondition() {
+		return secondCondition;
+	}
+
+	@Override
+	public int getSpecificity() {
+		return ((ExtendedCondition) getFirstCondition()).getSpecificity()
+				+ ((ExtendedCondition) getSecondCondition()).getSpecificity();
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java
index 025c80127..b871e8021 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java
@@ -1,46 +1,46 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.ElementSelector;
-
-public abstract class AbstractElementSelector implements ElementSelector, ExtendedSelector {
-
-	/**
-	 * The namespace URI.
-	 */
-	protected String namespaceURI;
-
-	/**
-	 * The local name.
-	 */
-	protected String localName;
-
-	/**
-	 * Creates a new ElementSelector object.
-	 */
-	protected AbstractElementSelector(String uri, String name) {
-		namespaceURI = uri;
-		localName = name;
-	}
-
-	@Override
-	public String getNamespaceURI() {
-		return namespaceURI;
-	}
-
-	@Override
-	public String getLocalName() {
-		return localName;
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.ElementSelector;
+
+public abstract class AbstractElementSelector implements ElementSelector, ExtendedSelector {
+
+	/**
+	 * The namespace URI.
+	 */
+	protected String namespaceURI;
+
+	/**
+	 * The local name.
+	 */
+	protected String localName;
+
+	/**
+	 * Creates a new ElementSelector object.
+	 */
+	protected AbstractElementSelector(String uri, String name) {
+		namespaceURI = uri;
+		localName = name;
+	}
+
+	@Override
+	public String getNamespaceURI() {
+		return namespaceURI;
+	}
+
+	@Override
+	public String getLocalName() {
+		return localName;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java
index 914517303..e3672007e 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java
@@ -1,41 +1,41 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.Condition;
-
-public class CSSAndCondition extends AbstractCombinatorCondition {
-
-	/**
-	 * Creates a new CombinatorCondition object.
-	 */
-	public CSSAndCondition(Condition c1, Condition c2) {
-		super(c1, c2);
-	}
-
-	@Override
-	public short getConditionType() {
-		return SAC_AND_CONDITION;
-	}
-
-	@Override
-	public int nbMatch(String... names) {
-		return ((ExtendedCondition) getFirstCondition()).nbMatch(names)
-				+ ((ExtendedCondition) getSecondCondition()).nbMatch(names);
-	}
-	
-	 @Override
-	public int nbClass() {
-		 return ((ExtendedCondition) getFirstCondition()).nbClass()
-					+ ((ExtendedCondition) getSecondCondition()).nbClass();
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.Condition;
+
+public class CSSAndCondition extends AbstractCombinatorCondition {
+
+	/**
+	 * Creates a new CombinatorCondition object.
+	 */
+	public CSSAndCondition(Condition c1, Condition c2) {
+		super(c1, c2);
+	}
+
+	@Override
+	public short getConditionType() {
+		return SAC_AND_CONDITION;
+	}
+
+	@Override
+	public int nbMatch(String... names) {
+		return ((ExtendedCondition) getFirstCondition()).nbMatch(names)
+				+ ((ExtendedCondition) getSecondCondition()).nbMatch(names);
+	}
+	
+	 @Override
+	public int nbClass() {
+		 return ((ExtendedCondition) getFirstCondition()).nbClass()
+					+ ((ExtendedCondition) getSecondCondition()).nbClass();
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java
index 7c518dbca..c1f6f3e67 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java
@@ -1,72 +1,72 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-public class CSSAttributeCondition extends AbstractAttributeCondition {
-
-	/**
-	 * The attribute's local name.
-	 */
-	protected String localName;
-
-	/**
-	 * The attribute's namespace URI.
-	 */
-	protected String namespaceURI;
-
-	/**
-	 * Whether this condition applies to specified attributes.
-	 */
-	protected boolean specified;
-
-	public CSSAttributeCondition(String localName, String namespaceURI, boolean specified, String value) {
-		super(value);
-		this.localName = localName;
-		this.namespaceURI = namespaceURI;
-		this.specified = specified;
-	}
-
-	@Override
-	public String getLocalName() {
-		return localName;
-	}
-
-	@Override
-	public String getNamespaceURI() {
-		return namespaceURI;
-	}
-
-	@Override
-	public boolean getSpecified() {
-		return specified;
-	}
-
-	@Override
-	public short getConditionType() {
-		return SAC_ATTRIBUTE_CONDITION;
-	}
-
-	@Override
-	public int nbMatch(String... names) {
-//		String val = getValue();
-//		if (val == null) {
-//			return !e.getAttribute(getLocalName()).equals("");
-//		}
-//		return e.getAttribute(getLocalName()).equals(val);
-		return 0;
-	}
-	
-	@Override
-	public int nbClass() {
-		return 0;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+public class CSSAttributeCondition extends AbstractAttributeCondition {
+
+	/**
+	 * The attribute's local name.
+	 */
+	protected String localName;
+
+	/**
+	 * The attribute's namespace URI.
+	 */
+	protected String namespaceURI;
+
+	/**
+	 * Whether this condition applies to specified attributes.
+	 */
+	protected boolean specified;
+
+	public CSSAttributeCondition(String localName, String namespaceURI, boolean specified, String value) {
+		super(value);
+		this.localName = localName;
+		this.namespaceURI = namespaceURI;
+		this.specified = specified;
+	}
+
+	@Override
+	public String getLocalName() {
+		return localName;
+	}
+
+	@Override
+	public String getNamespaceURI() {
+		return namespaceURI;
+	}
+
+	@Override
+	public boolean getSpecified() {
+		return specified;
+	}
+
+	@Override
+	public short getConditionType() {
+		return SAC_ATTRIBUTE_CONDITION;
+	}
+
+	@Override
+	public int nbMatch(String... names) {
+//		String val = getValue();
+//		if (val == null) {
+//			return !e.getAttribute(getLocalName()).equals("");
+//		}
+//		return e.getAttribute(getLocalName()).equals(val);
+		return 0;
+	}
+	
+	@Override
+	public int nbClass() {
+		return 0;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java
index 2f6191086..40b1cce42 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java
@@ -1,36 +1,36 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-public class CSSClassCondition extends CSSAttributeCondition {
-
-	public CSSClassCondition(String localName, String namespaceURI, String value) {
-		super(localName, namespaceURI, true, value);
-	}
-
-	@Override
-	public int nbMatch(String... names) {
-		String value = getValue();
-		for (String name : names) {
-			if (name.equals(value)) {
-				return 1;
-			}
-		}
-		return 0;
-	}
-
-	@Override
-	public int nbClass() {
-		return 1;
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+public class CSSClassCondition extends CSSAttributeCondition {
+
+	public CSSClassCondition(String localName, String namespaceURI, String value) {
+		super(localName, namespaceURI, true, value);
+	}
+
+	@Override
+	public int nbMatch(String... names) {
+		String value = getValue();
+		for (String name : names) {
+			if (name.equals(value)) {
+				return 1;
+			}
+		}
+		return 0;
+	}
+
+	@Override
+	public int nbClass() {
+		return 1;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java
index c9ca35194..cf39c75c1 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java
@@ -1,102 +1,102 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.AttributeCondition;
-import org.w3c.css.sac.CSSException;
-import org.w3c.css.sac.CombinatorCondition;
-import org.w3c.css.sac.Condition;
-import org.w3c.css.sac.ConditionFactory;
-import org.w3c.css.sac.ContentCondition;
-import org.w3c.css.sac.LangCondition;
-import org.w3c.css.sac.NegativeCondition;
-import org.w3c.css.sac.PositionalCondition;
-
-public class CSSConditionFactory implements ConditionFactory {
-
-	public static final ConditionFactory INSTANCE = new CSSConditionFactory();
-
-	@Override
-	public AttributeCondition createClassCondition(String namespaceURI, String value) throws CSSException {
-		return new CSSClassCondition(null, "class", value);
-	}
-
-	@Override
-	public AttributeCondition createAttributeCondition(String localName, String namespaceURI, boolean specified,
-			String value) throws CSSException {
-		return new CSSAttributeCondition(localName, namespaceURI, specified, value);
-	}
-
-	@Override
-	public CombinatorCondition createAndCondition(Condition first,
-			Condition second) throws CSSException {
-		return new CSSAndCondition(first, second);
-	}
-
-	@Override
-	public AttributeCondition createBeginHyphenAttributeCondition(String arg0, String arg1, boolean arg2, String arg3)
-			throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public ContentCondition createContentCondition(String arg0) throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public AttributeCondition createIdCondition(String arg0) throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public LangCondition createLangCondition(String arg0) throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public NegativeCondition createNegativeCondition(Condition arg0) throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public AttributeCondition createOneOfAttributeCondition(String arg0, String arg1, boolean arg2, String arg3)
-			throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public Condition createOnlyChildCondition() throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public Condition createOnlyTypeCondition() throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public CombinatorCondition createOrCondition(Condition arg0, Condition arg1) throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public PositionalCondition createPositionalCondition(int arg0, boolean arg1, boolean arg2) throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-	@Override
-	public AttributeCondition createPseudoClassCondition(String arg0, String arg1) throws CSSException {
-		throw new CSSException("Not implemented in CSS2");
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.AttributeCondition;
+import org.w3c.css.sac.CSSException;
+import org.w3c.css.sac.CombinatorCondition;
+import org.w3c.css.sac.Condition;
+import org.w3c.css.sac.ConditionFactory;
+import org.w3c.css.sac.ContentCondition;
+import org.w3c.css.sac.LangCondition;
+import org.w3c.css.sac.NegativeCondition;
+import org.w3c.css.sac.PositionalCondition;
+
+public class CSSConditionFactory implements ConditionFactory {
+
+	public static final ConditionFactory INSTANCE = new CSSConditionFactory();
+
+	@Override
+	public AttributeCondition createClassCondition(String namespaceURI, String value) throws CSSException {
+		return new CSSClassCondition(null, "class", value);
+	}
+
+	@Override
+	public AttributeCondition createAttributeCondition(String localName, String namespaceURI, boolean specified,
+			String value) throws CSSException {
+		return new CSSAttributeCondition(localName, namespaceURI, specified, value);
+	}
+
+	@Override
+	public CombinatorCondition createAndCondition(Condition first,
+			Condition second) throws CSSException {
+		return new CSSAndCondition(first, second);
+	}
+
+	@Override
+	public AttributeCondition createBeginHyphenAttributeCondition(String arg0, String arg1, boolean arg2, String arg3)
+			throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public ContentCondition createContentCondition(String arg0) throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public AttributeCondition createIdCondition(String arg0) throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public LangCondition createLangCondition(String arg0) throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public NegativeCondition createNegativeCondition(Condition arg0) throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public AttributeCondition createOneOfAttributeCondition(String arg0, String arg1, boolean arg2, String arg3)
+			throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public Condition createOnlyChildCondition() throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public Condition createOnlyTypeCondition() throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public CombinatorCondition createOrCondition(Condition arg0, Condition arg1) throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public PositionalCondition createPositionalCondition(int arg0, boolean arg1, boolean arg2) throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+	@Override
+	public AttributeCondition createPseudoClassCondition(String arg0, String arg1) throws CSSException {
+		throw new CSSException("Not implemented in CSS2");
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java
index d632ea49a..5dd1c2641 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java
@@ -1,71 +1,71 @@
-/**
- *  Copyright (c) 2015-2018 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2018 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.Condition;
-import org.w3c.css.sac.ConditionalSelector;
-import org.w3c.css.sac.SimpleSelector;
-
-public class CSSConditionalSelector implements ConditionalSelector, ExtendedSelector {
-
-	/**
-	 * The simple selector.
-	 */
-	protected SimpleSelector simpleSelector;
-
-	/**
-	 * The condition.
-	 */
-	protected Condition condition;
-
-	/**
-	 * Creates a new ConditionalSelector object.
-	 */
-	public CSSConditionalSelector(SimpleSelector simpleSelector, Condition condition) {
-		this.simpleSelector = simpleSelector;
-		this.condition = condition;
-	}
-
-	@Override
-	public short getSelectorType() {
-		return SAC_CONDITIONAL_SELECTOR;
-	}
-
-	@Override
-	public Condition getCondition() {
-		return condition;
-	}
-
-	@Override
-	public SimpleSelector getSimpleSelector() {
-		return simpleSelector;
-	}
-
-	@Override
-	public int getSpecificity() {
-		return ((ExtendedSelector) getSimpleSelector()).getSpecificity()
-				+ ((ExtendedCondition) getCondition()).getSpecificity();
-	}
-
-	@Override
-	public int nbMatch(String... names) {
-		return ((ExtendedSelector)getSimpleSelector()).nbMatch(names) +
-	               ((ExtendedCondition)getCondition()).nbMatch(names);
-	}
-	
-	@Override
-	public int nbClass() {
-		return ((ExtendedSelector) getSimpleSelector()).nbClass()
-				+ ((ExtendedCondition) getCondition()).nbClass();
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.Condition;
+import org.w3c.css.sac.ConditionalSelector;
+import org.w3c.css.sac.SimpleSelector;
+
+public class CSSConditionalSelector implements ConditionalSelector, ExtendedSelector {
+
+	/**
+	 * The simple selector.
+	 */
+	protected SimpleSelector simpleSelector;
+
+	/**
+	 * The condition.
+	 */
+	protected Condition condition;
+
+	/**
+	 * Creates a new ConditionalSelector object.
+	 */
+	public CSSConditionalSelector(SimpleSelector simpleSelector, Condition condition) {
+		this.simpleSelector = simpleSelector;
+		this.condition = condition;
+	}
+
+	@Override
+	public short getSelectorType() {
+		return SAC_CONDITIONAL_SELECTOR;
+	}
+
+	@Override
+	public Condition getCondition() {
+		return condition;
+	}
+
+	@Override
+	public SimpleSelector getSimpleSelector() {
+		return simpleSelector;
+	}
+
+	@Override
+	public int getSpecificity() {
+		return ((ExtendedSelector) getSimpleSelector()).getSpecificity()
+				+ ((ExtendedCondition) getCondition()).getSpecificity();
+	}
+
+	@Override
+	public int nbMatch(String... names) {
+		return ((ExtendedSelector)getSimpleSelector()).nbMatch(names) +
+	               ((ExtendedCondition)getCondition()).nbMatch(names);
+	}
+	
+	@Override
+	public int nbClass() {
+		return ((ExtendedSelector) getSimpleSelector()).nbClass()
+				+ ((ExtendedCondition) getCondition()).nbClass();
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java
index 6ad596ba1..07044d2b0 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java
@@ -1,155 +1,155 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tm4e.core.theme.IStyle;
-import org.eclipse.tm4e.core.theme.RGB;
-import org.eclipse.tm4e.core.theme.css.CSSStyle;
-import org.w3c.css.sac.CSSException;
-import org.w3c.css.sac.DocumentHandler;
-import org.w3c.css.sac.InputSource;
-import org.w3c.css.sac.LexicalUnit;
-import org.w3c.css.sac.SACMediaList;
-import org.w3c.css.sac.SelectorList;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.RGBColor;
-
-public class CSSDocumentHandler implements DocumentHandler {
-
-	private final List list;
-	private CSSStyle currentStyle;
-
-	public CSSDocumentHandler() {
-		list = new ArrayList<>();
-	}
-
-	@Override
-	public void comment(String arg0) throws CSSException {
-
-	}
-
-	@Override
-	public void endDocument(InputSource arg0) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void endFontFace() throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void endMedia(SACMediaList arg0) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void endPage(String arg0, String arg1) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void endSelector(SelectorList selector) throws CSSException {
-		currentStyle = null;
-	}
-
-	@Override
-	public void ignorableAtRule(String arg0) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void importStyle(String arg0, SACMediaList arg1, String arg2) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void namespaceDeclaration(String arg0, String arg1) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void property(String name, LexicalUnit value, boolean arg2) throws CSSException {
-		if (currentStyle != null) {
-			if ("color".equals(name)) {
-				currentStyle.setColor(createRGB(value));
-			} else if ("background-color".equals(name)) {
-				currentStyle.setBackgroundColor(createRGB(value));
-			} else if ("font-weight".equals(name)) {
-				currentStyle.setBold(value.getStringValue().toUpperCase().contains("BOLD"));
-			} else if ("font-style".equals(name)) {
-				currentStyle.setItalic(value.getStringValue().toUpperCase().contains("ITALIC"));
-			}
-			if ("text-decoration".equals(name)) {
-				String decoration = value.getStringValue().toUpperCase();
-				if (decoration.contains("UNDERLINE")) {
-					currentStyle.setUnderline(true);
-				}
-				if (decoration.contains("LINE-THROUGH")) {
-					currentStyle.setStrikeThrough(true);
-				}
-			}
-		}
-	}
-
-	private RGB createRGB(LexicalUnit value) {
-		RGBColor rgbColor = new RGBColorImpl(value);
-		int green = ((int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
-		int red = ((int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
-		int blue = ((int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
-		return new RGB(red, green, blue);
-	}
-
-	@Override
-	public void startDocument(InputSource arg0) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void startFontFace() throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void startMedia(SACMediaList arg0) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void startPage(String arg0, String arg1) throws CSSException {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void startSelector(SelectorList selector) throws CSSException {
-		currentStyle = new CSSStyle(selector);
-		list.add(currentStyle);
-	}
-
-	public List getList() {
-		return list;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tm4e.core.theme.IStyle;
+import org.eclipse.tm4e.core.theme.RGB;
+import org.eclipse.tm4e.core.theme.css.CSSStyle;
+import org.w3c.css.sac.CSSException;
+import org.w3c.css.sac.DocumentHandler;
+import org.w3c.css.sac.InputSource;
+import org.w3c.css.sac.LexicalUnit;
+import org.w3c.css.sac.SACMediaList;
+import org.w3c.css.sac.SelectorList;
+import org.w3c.dom.css.CSSPrimitiveValue;
+import org.w3c.dom.css.RGBColor;
+
+public class CSSDocumentHandler implements DocumentHandler {
+
+	private final List list;
+	private CSSStyle currentStyle;
+
+	public CSSDocumentHandler() {
+		list = new ArrayList<>();
+	}
+
+	@Override
+	public void comment(String arg0) throws CSSException {
+
+	}
+
+	@Override
+	public void endDocument(InputSource arg0) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void endFontFace() throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void endMedia(SACMediaList arg0) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void endPage(String arg0, String arg1) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void endSelector(SelectorList selector) throws CSSException {
+		currentStyle = null;
+	}
+
+	@Override
+	public void ignorableAtRule(String arg0) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void importStyle(String arg0, SACMediaList arg1, String arg2) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void namespaceDeclaration(String arg0, String arg1) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void property(String name, LexicalUnit value, boolean arg2) throws CSSException {
+		if (currentStyle != null) {
+			if ("color".equals(name)) {
+				currentStyle.setColor(createRGB(value));
+			} else if ("background-color".equals(name)) {
+				currentStyle.setBackgroundColor(createRGB(value));
+			} else if ("font-weight".equals(name)) {
+				currentStyle.setBold(value.getStringValue().toUpperCase().contains("BOLD"));
+			} else if ("font-style".equals(name)) {
+				currentStyle.setItalic(value.getStringValue().toUpperCase().contains("ITALIC"));
+			}
+			if ("text-decoration".equals(name)) {
+				String decoration = value.getStringValue().toUpperCase();
+				if (decoration.contains("UNDERLINE")) {
+					currentStyle.setUnderline(true);
+				}
+				if (decoration.contains("LINE-THROUGH")) {
+					currentStyle.setStrikeThrough(true);
+				}
+			}
+		}
+	}
+
+	private RGB createRGB(LexicalUnit value) {
+		RGBColor rgbColor = new RGBColorImpl(value);
+		int green = ((int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
+		int red = ((int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
+		int blue = ((int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
+		return new RGB(red, green, blue);
+	}
+
+	@Override
+	public void startDocument(InputSource arg0) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void startFontFace() throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void startMedia(SACMediaList arg0) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void startPage(String arg0, String arg1) throws CSSException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void startSelector(SelectorList selector) throws CSSException {
+		currentStyle = new CSSStyle(selector);
+		list.add(currentStyle);
+	}
+
+	public List getList() {
+		return list;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java
index ce42b0dc2..619dfa21d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java
@@ -1,39 +1,39 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-public class CSSElementSelector extends AbstractElementSelector {
-
-	public CSSElementSelector(String uri, String name) {
-		super(uri, name);
-	}
-
-	@Override
-	public short getSelectorType() {
-		return SAC_ELEMENT_NODE_SELECTOR;
-	}
-
-	@Override
-	public int getSpecificity() {
-		return (getLocalName() == null) ? 0 : 1;
-	}
-
-	@Override
-	public int nbMatch(String... names) {		
-		return 0;
-	}
-	
-	@Override
-	public int nbClass() {
-		return 0;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+public class CSSElementSelector extends AbstractElementSelector {
+
+	public CSSElementSelector(String uri, String name) {
+		super(uri, name);
+	}
+
+	@Override
+	public short getSelectorType() {
+		return SAC_ELEMENT_NODE_SELECTOR;
+	}
+
+	@Override
+	public int getSpecificity() {
+		return (getLocalName() == null) ? 0 : 1;
+	}
+
+	@Override
+	public int nbMatch(String... names) {		
+		return 0;
+	}
+	
+	@Override
+	public int nbClass() {
+		return 0;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java
index ae262994e..524c7defb 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java
@@ -1,100 +1,100 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- *  Jochen Ulrich  - exception messages
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.CSSException;
-import org.w3c.css.sac.CharacterDataSelector;
-import org.w3c.css.sac.Condition;
-import org.w3c.css.sac.ConditionalSelector;
-import org.w3c.css.sac.DescendantSelector;
-import org.w3c.css.sac.ElementSelector;
-import org.w3c.css.sac.NegativeSelector;
-import org.w3c.css.sac.ProcessingInstructionSelector;
-import org.w3c.css.sac.Selector;
-import org.w3c.css.sac.SelectorFactory;
-import org.w3c.css.sac.SiblingSelector;
-import org.w3c.css.sac.SimpleSelector;
-
-public class CSSSelectorFactory implements SelectorFactory {
-
-	public static final SelectorFactory INSTANCE = new CSSSelectorFactory();
-
-	@Override
-	public SimpleSelector createAnyNodeSelector() throws CSSException {
-		throw new UnsupportedOperationException("CSS any selector is not supported");
-	}
-
-	@Override
-	public CharacterDataSelector createCDataSectionSelector(String arg0) throws CSSException {
-		throw new UnsupportedOperationException("CSS CDATA section is not supported");
-	}
-
-	@Override
-	public DescendantSelector createChildSelector(Selector arg0, SimpleSelector arg1) throws CSSException {
-		throw new UnsupportedOperationException("CSS child selector is not supported");
-	}
-
-	@Override
-	public CharacterDataSelector createCommentSelector(String arg0) throws CSSException {
-		throw new UnsupportedOperationException("CSS comment is not supported");
-	}
-
-	@Override
-	public ConditionalSelector createConditionalSelector(SimpleSelector selector, Condition condition)
-			throws CSSException {
-		return new CSSConditionalSelector(selector, condition);
-	}
-
-	@Override
-	public DescendantSelector createDescendantSelector(Selector arg0, SimpleSelector arg1) throws CSSException {
-		throw new UnsupportedOperationException("CSS descendant selector is not supported");
-	}
-
-	@Override
-	public SiblingSelector createDirectAdjacentSelector(short arg0, Selector arg1, SimpleSelector arg2)
-			throws CSSException {
-		throw new UnsupportedOperationException("CSS direct adjacent selector is not supported");
-	}
-
-	@Override
-	public ElementSelector createElementSelector(String uri, String name) throws CSSException {
-		return new CSSElementSelector(uri, name);
-	}
-
-	@Override
-	public NegativeSelector createNegativeSelector(SimpleSelector arg0) throws CSSException {
-		throw new UnsupportedOperationException("CSS negative selector is not supported");
-	}
-
-	@Override
-	public ProcessingInstructionSelector createProcessingInstructionSelector(String arg0, String arg1)
-			throws CSSException {
-		throw new UnsupportedOperationException("CSS processing instruction is not supported");
-	}
-
-	@Override
-	public ElementSelector createPseudoElementSelector(String arg0, String arg1) throws CSSException {
-		throw new UnsupportedOperationException("CSS pseudo element selector is not supported");
-	}
-
-	@Override
-	public SimpleSelector createRootNodeSelector() throws CSSException {
-		throw new UnsupportedOperationException("CSS root node selector is not supported");
-	}
-
-	@Override
-	public CharacterDataSelector createTextNodeSelector(String arg0) throws CSSException {
-		throw new UnsupportedOperationException("CSS text node selector is not supported");
-	}
-
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ *  Jochen Ulrich  - exception messages
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.CSSException;
+import org.w3c.css.sac.CharacterDataSelector;
+import org.w3c.css.sac.Condition;
+import org.w3c.css.sac.ConditionalSelector;
+import org.w3c.css.sac.DescendantSelector;
+import org.w3c.css.sac.ElementSelector;
+import org.w3c.css.sac.NegativeSelector;
+import org.w3c.css.sac.ProcessingInstructionSelector;
+import org.w3c.css.sac.Selector;
+import org.w3c.css.sac.SelectorFactory;
+import org.w3c.css.sac.SiblingSelector;
+import org.w3c.css.sac.SimpleSelector;
+
+public class CSSSelectorFactory implements SelectorFactory {
+
+	public static final SelectorFactory INSTANCE = new CSSSelectorFactory();
+
+	@Override
+	public SimpleSelector createAnyNodeSelector() throws CSSException {
+		throw new UnsupportedOperationException("CSS any selector is not supported");
+	}
+
+	@Override
+	public CharacterDataSelector createCDataSectionSelector(String arg0) throws CSSException {
+		throw new UnsupportedOperationException("CSS CDATA section is not supported");
+	}
+
+	@Override
+	public DescendantSelector createChildSelector(Selector arg0, SimpleSelector arg1) throws CSSException {
+		throw new UnsupportedOperationException("CSS child selector is not supported");
+	}
+
+	@Override
+	public CharacterDataSelector createCommentSelector(String arg0) throws CSSException {
+		throw new UnsupportedOperationException("CSS comment is not supported");
+	}
+
+	@Override
+	public ConditionalSelector createConditionalSelector(SimpleSelector selector, Condition condition)
+			throws CSSException {
+		return new CSSConditionalSelector(selector, condition);
+	}
+
+	@Override
+	public DescendantSelector createDescendantSelector(Selector arg0, SimpleSelector arg1) throws CSSException {
+		throw new UnsupportedOperationException("CSS descendant selector is not supported");
+	}
+
+	@Override
+	public SiblingSelector createDirectAdjacentSelector(short arg0, Selector arg1, SimpleSelector arg2)
+			throws CSSException {
+		throw new UnsupportedOperationException("CSS direct adjacent selector is not supported");
+	}
+
+	@Override
+	public ElementSelector createElementSelector(String uri, String name) throws CSSException {
+		return new CSSElementSelector(uri, name);
+	}
+
+	@Override
+	public NegativeSelector createNegativeSelector(SimpleSelector arg0) throws CSSException {
+		throw new UnsupportedOperationException("CSS negative selector is not supported");
+	}
+
+	@Override
+	public ProcessingInstructionSelector createProcessingInstructionSelector(String arg0, String arg1)
+			throws CSSException {
+		throw new UnsupportedOperationException("CSS processing instruction is not supported");
+	}
+
+	@Override
+	public ElementSelector createPseudoElementSelector(String arg0, String arg1) throws CSSException {
+		throw new UnsupportedOperationException("CSS pseudo element selector is not supported");
+	}
+
+	@Override
+	public SimpleSelector createRootNodeSelector() throws CSSException {
+		throw new UnsupportedOperationException("CSS root node selector is not supported");
+	}
+
+	@Override
+	public CharacterDataSelector createTextNodeSelector(String arg0) throws CSSException {
+		throw new UnsupportedOperationException("CSS text node selector is not supported");
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java
index b6f58b6e1..7a3bbe3a9 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java
@@ -1,91 +1,91 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2013 Angelo Zerr 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:
- *     Angelo Zerr  - initial API and implementation
- *     IBM Corporation - ongoing development
- *******************************************************************************/
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.CSSValue;
-import org.w3c.dom.css.Counter;
-import org.w3c.dom.css.RGBColor;
-import org.w3c.dom.css.Rect;
-
-public abstract class CSSValueImpl implements CSSPrimitiveValue, CSSValue {
-
-	// W3C CSSValue API methods
-
-	@Override
-	public String getCssText() {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
-	@Override
-	public short getCssValueType() {
-		return CSS_PRIMITIVE_VALUE;
-	}
-
-	@Override
-	public void setCssText(String cssText) throws DOMException {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
-	// W3C CSSPrimitiveValue API methods
-
-	@Override
-	public short getPrimitiveType() {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
-	@Override
-	public Counter getCounterValue() throws DOMException {
-		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "COUNTER_ERROR");
-	}
-
-	@Override
-	public RGBColor getRGBColorValue() throws DOMException {
-		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "RGBCOLOR_ERROR");
-	}
-
-	@Override
-	public Rect getRectValue() throws DOMException {
-		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "RECT_ERROR");
-	}
-
-	@Override
-	public String getStringValue() throws DOMException {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
-	@Override
-	public void setFloatValue(short arg0, float arg1) throws DOMException {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
-	@Override
-	public void setStringValue(short arg0, String arg1) throws DOMException {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
-	// Additional methods
-
-	@Override
-	public float getFloatValue(short valueType) throws DOMException {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Angelo Zerr 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:
+ *     Angelo Zerr  - initial API and implementation
+ *     IBM Corporation - ongoing development
+ *******************************************************************************/
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.css.CSSPrimitiveValue;
+import org.w3c.dom.css.CSSValue;
+import org.w3c.dom.css.Counter;
+import org.w3c.dom.css.RGBColor;
+import org.w3c.dom.css.Rect;
+
+public abstract class CSSValueImpl implements CSSPrimitiveValue, CSSValue {
+
+	// W3C CSSValue API methods
+
+	@Override
+	public String getCssText() {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
+	@Override
+	public short getCssValueType() {
+		return CSS_PRIMITIVE_VALUE;
+	}
+
+	@Override
+	public void setCssText(String cssText) throws DOMException {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
+	// W3C CSSPrimitiveValue API methods
+
+	@Override
+	public short getPrimitiveType() {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
+	@Override
+	public Counter getCounterValue() throws DOMException {
+		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "COUNTER_ERROR");
+	}
+
+	@Override
+	public RGBColor getRGBColorValue() throws DOMException {
+		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "RGBCOLOR_ERROR");
+	}
+
+	@Override
+	public Rect getRectValue() throws DOMException {
+		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "RECT_ERROR");
+	}
+
+	@Override
+	public String getStringValue() throws DOMException {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
+	@Override
+	public void setFloatValue(short arg0, float arg1) throws DOMException {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
+	@Override
+	public void setStringValue(short arg0, String arg1) throws DOMException {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
+	// Additional methods
+
+	@Override
+	public float getFloatValue(short valueType) throws DOMException {
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java
index 4dffc1623..91b08cf66 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java
@@ -1,24 +1,24 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-public interface ExtendedCondition {
-
-	/**
-	 * Returns the specificity of this condition.
-	 */
-	int getSpecificity();
-
-	int nbClass();
-
-	int nbMatch(String... names);
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+public interface ExtendedCondition {
+
+	/**
+	 * Returns the specificity of this condition.
+	 */
+	int getSpecificity();
+
+	int nbClass();
+
+	int nbMatch(String... names);
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedSelector.java
index cbb182064..aa4087c3d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedSelector.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedSelector.java
@@ -1,26 +1,26 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.Selector;
-
-public interface ExtendedSelector extends Selector {
-
-	/**
-	 * Returns the specificity of this selector.
-	 */
-	int getSpecificity();
-
-	int nbMatch(String... names);
-	
-	int nbClass();
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.Selector;
+
+public interface ExtendedSelector extends Selector {
+
+	/**
+	 * Returns the specificity of this selector.
+	 */
+	int getSpecificity();
+
+	int nbMatch(String... names);
+	
+	int nbClass();
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java
index fc51fccee..0e7e6f552 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java
@@ -1,137 +1,137 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2013 IBM Corporation 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:
- *      IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.LexicalUnit;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.css.CSSValue;
-
-public class Measure extends CSSValueImpl {
-
-	LexicalUnit value;
-
-	public Measure(LexicalUnit value) {
-		super();
-		this.value = value;
-	}
-
-	/**
-	 * Return a float representation of the receiver's value.
-	 *
-	 * @param valueType
-	 *            a short representing the value type, see
-	 *            {@link CSSValue#getCssValueType()}
-	 */
-	@Override
-	public float getFloatValue(short valueType) throws DOMException {
-		// If it's actually a SAC_INTEGER return the integer value, callers tend
-		// to expect and cast
-		// There is no getIntegerFloat(short)
-		// TODO Not sure the purpose of arg valyeType, its not referenced in
-		// this method
-		if (value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER)
-			return value.getIntegerValue();
-		// TODO not sure what to do if it's not one of the lexical unit types
-		// that are specified in LexicalUnit#getFloatValue()
-		// ie. SAC_DEGREE, SAC_GRADIAN, SAC_RADIAN, SAC_MILLISECOND, SAC_SECOND,
-		// SAC_HERTZ or SAC_KILOHERTZ
-		return value.getFloatValue();
-	}
-
-	/**
-	 * Return an int representation of the receiver's value.
-	 *
-	 * @param valueType
-	 *            a short representing the value type, see
-	 *            {@link CSSValue#getCssValueType()}
-	 */
-	public int getIntegerValue(short valueType) throws DOMException {
-		return value.getIntegerValue();
-	}
-
-	@Override
-	public String getStringValue() throws DOMException {
-		short lexicalUnit = value.getLexicalUnitType();
-		if ((lexicalUnit == LexicalUnit.SAC_IDENT) || (lexicalUnit == LexicalUnit.SAC_STRING_VALUE)
-				|| (lexicalUnit == LexicalUnit.SAC_URI))
-			return value.getStringValue();
-		// TODO There are more cases to catch of getLexicalUnitType()
-		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
-	}
-
-	@Override
-	public short getPrimitiveType() {
-		switch (value.getLexicalUnitType()) {
-		case LexicalUnit.SAC_IDENT:
-			return CSS_IDENT;
-		case LexicalUnit.SAC_INTEGER:
-		case LexicalUnit.SAC_REAL:
-			return CSS_NUMBER;
-		case LexicalUnit.SAC_URI:
-			return CSS_URI;
-		case LexicalUnit.SAC_PERCENTAGE:
-			return CSS_PERCENTAGE;
-		case LexicalUnit.SAC_PIXEL:
-			return CSS_PX;
-		case LexicalUnit.SAC_CENTIMETER:
-			return CSS_CM;
-		case LexicalUnit.SAC_EM:
-			return CSS_EMS;
-		case LexicalUnit.SAC_EX:
-			return CSS_EXS;
-		case LexicalUnit.SAC_INCH:
-			return CSS_IN;
-		case LexicalUnit.SAC_STRING_VALUE:
-			return CSS_STRING;
-		case LexicalUnit.SAC_DIMENSION:
-			return CSS_DIMENSION;
-		case LexicalUnit.SAC_OPERATOR_COMMA:
-			return CSS_CUSTOM; // TODO don't think this is right, see bug
-								// #278139
-		case LexicalUnit.SAC_INHERIT:
-			return CSS_INHERIT;
-		}
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException(
-				"NOT YET IMPLEMENTED - LexicalUnit type: " + value.getLexicalUnitType());
-	}
-
-	@Override
-	public String getCssText() {
-		// TODO: All LexicalUnit.SAC_OPERATOR_* except for COMMA left undone for
-		// now as it's not even clear whether they should be treated as measures
-		// see bug #278139
-		switch (value.getLexicalUnitType()) {
-		case LexicalUnit.SAC_INTEGER:
-			return String.valueOf(value.getIntegerValue());
-		case LexicalUnit.SAC_REAL:
-			return String.valueOf(value.getFloatValue());
-		case LexicalUnit.SAC_PERCENTAGE:
-		case LexicalUnit.SAC_PIXEL:
-		case LexicalUnit.SAC_CENTIMETER:
-		case LexicalUnit.SAC_EM:
-		case LexicalUnit.SAC_EX:
-		case LexicalUnit.SAC_PICA:
-		case LexicalUnit.SAC_POINT:
-		case LexicalUnit.SAC_INCH:
-		case LexicalUnit.SAC_DEGREE:
-			return String.valueOf(value.getFloatValue()) + value.getDimensionUnitText();
-		case LexicalUnit.SAC_URI:
-			return "url(" + value.getStringValue() + ")";
-		case LexicalUnit.SAC_OPERATOR_COMMA:
-			return ",";
-		case LexicalUnit.SAC_INHERIT:
-			return "inherit";
-		}
-		return value.getStringValue();
-	}
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 IBM Corporation 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:
+ *      IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.LexicalUnit;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.css.CSSValue;
+
+public class Measure extends CSSValueImpl {
+
+	LexicalUnit value;
+
+	public Measure(LexicalUnit value) {
+		super();
+		this.value = value;
+	}
+
+	/**
+	 * Return a float representation of the receiver's value.
+	 *
+	 * @param valueType
+	 *            a short representing the value type, see
+	 *            {@link CSSValue#getCssValueType()}
+	 */
+	@Override
+	public float getFloatValue(short valueType) throws DOMException {
+		// If it's actually a SAC_INTEGER return the integer value, callers tend
+		// to expect and cast
+		// There is no getIntegerFloat(short)
+		// TODO Not sure the purpose of arg valyeType, its not referenced in
+		// this method
+		if (value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER)
+			return value.getIntegerValue();
+		// TODO not sure what to do if it's not one of the lexical unit types
+		// that are specified in LexicalUnit#getFloatValue()
+		// ie. SAC_DEGREE, SAC_GRADIAN, SAC_RADIAN, SAC_MILLISECOND, SAC_SECOND,
+		// SAC_HERTZ or SAC_KILOHERTZ
+		return value.getFloatValue();
+	}
+
+	/**
+	 * Return an int representation of the receiver's value.
+	 *
+	 * @param valueType
+	 *            a short representing the value type, see
+	 *            {@link CSSValue#getCssValueType()}
+	 */
+	public int getIntegerValue(short valueType) throws DOMException {
+		return value.getIntegerValue();
+	}
+
+	@Override
+	public String getStringValue() throws DOMException {
+		short lexicalUnit = value.getLexicalUnitType();
+		if ((lexicalUnit == LexicalUnit.SAC_IDENT) || (lexicalUnit == LexicalUnit.SAC_STRING_VALUE)
+				|| (lexicalUnit == LexicalUnit.SAC_URI))
+			return value.getStringValue();
+		// TODO There are more cases to catch of getLexicalUnitType()
+		throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
+	}
+
+	@Override
+	public short getPrimitiveType() {
+		switch (value.getLexicalUnitType()) {
+		case LexicalUnit.SAC_IDENT:
+			return CSS_IDENT;
+		case LexicalUnit.SAC_INTEGER:
+		case LexicalUnit.SAC_REAL:
+			return CSS_NUMBER;
+		case LexicalUnit.SAC_URI:
+			return CSS_URI;
+		case LexicalUnit.SAC_PERCENTAGE:
+			return CSS_PERCENTAGE;
+		case LexicalUnit.SAC_PIXEL:
+			return CSS_PX;
+		case LexicalUnit.SAC_CENTIMETER:
+			return CSS_CM;
+		case LexicalUnit.SAC_EM:
+			return CSS_EMS;
+		case LexicalUnit.SAC_EX:
+			return CSS_EXS;
+		case LexicalUnit.SAC_INCH:
+			return CSS_IN;
+		case LexicalUnit.SAC_STRING_VALUE:
+			return CSS_STRING;
+		case LexicalUnit.SAC_DIMENSION:
+			return CSS_DIMENSION;
+		case LexicalUnit.SAC_OPERATOR_COMMA:
+			return CSS_CUSTOM; // TODO don't think this is right, see bug
+								// #278139
+		case LexicalUnit.SAC_INHERIT:
+			return CSS_INHERIT;
+		}
+		// TODO Auto-generated method stub
+		throw new UnsupportedOperationException(
+				"NOT YET IMPLEMENTED - LexicalUnit type: " + value.getLexicalUnitType());
+	}
+
+	@Override
+	public String getCssText() {
+		// TODO: All LexicalUnit.SAC_OPERATOR_* except for COMMA left undone for
+		// now as it's not even clear whether they should be treated as measures
+		// see bug #278139
+		switch (value.getLexicalUnitType()) {
+		case LexicalUnit.SAC_INTEGER:
+			return String.valueOf(value.getIntegerValue());
+		case LexicalUnit.SAC_REAL:
+			return String.valueOf(value.getFloatValue());
+		case LexicalUnit.SAC_PERCENTAGE:
+		case LexicalUnit.SAC_PIXEL:
+		case LexicalUnit.SAC_CENTIMETER:
+		case LexicalUnit.SAC_EM:
+		case LexicalUnit.SAC_EX:
+		case LexicalUnit.SAC_PICA:
+		case LexicalUnit.SAC_POINT:
+		case LexicalUnit.SAC_INCH:
+		case LexicalUnit.SAC_DEGREE:
+			return String.valueOf(value.getFloatValue()) + value.getDimensionUnitText();
+		case LexicalUnit.SAC_URI:
+			return "url(" + value.getStringValue() + ")";
+		case LexicalUnit.SAC_OPERATOR_COMMA:
+			return ",";
+		case LexicalUnit.SAC_INHERIT:
+			return "inherit";
+		}
+		return value.getStringValue();
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
index e449970e0..2ec162cd0 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java
@@ -1,64 +1,64 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2013 Angelo Zerr 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:
- *     Angelo Zerr  - initial API and implementation
- *     IBM Corporation - ongoing development
- *******************************************************************************/
-package org.eclipse.tm4e.core.internal.css;
-
-import org.w3c.css.sac.LexicalUnit;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.RGBColor;
-
-public class RGBColorImpl extends CSSValueImpl implements RGBColor {
-
-	private final CSSPrimitiveValue red;
-	private final CSSPrimitiveValue green;
-	private final CSSPrimitiveValue blue;
-
-	public RGBColorImpl(LexicalUnit lexicalUnit) {
-		LexicalUnit nextUnit = lexicalUnit.getParameters();
-		red = new Measure(nextUnit);
-		nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit();
-		green = new Measure(nextUnit);
-		nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit();
-		blue = new Measure(nextUnit);
-	}
-
-	@Override
-	public CSSPrimitiveValue getRed() {
-		return red;
-	}
-
-	@Override
-	public CSSPrimitiveValue getGreen() {
-		return green;
-	}
-
-	@Override
-	public CSSPrimitiveValue getBlue() {
-		return blue;
-	}
-
-	@Override
-	public RGBColor getRGBColorValue() throws DOMException {
-		return this;
-	}
-
-	@Override
-	public short getPrimitiveType() {
-		return CSS_RGBCOLOR;
-	}
-
-	@Override
-	public String getCssText() {
-		return "rgb(" + red.getCssText() + ", " + green.getCssText() + ", "
-				+ blue.getCssText() + ")";
-	}
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Angelo Zerr 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:
+ *     Angelo Zerr  - initial API and implementation
+ *     IBM Corporation - ongoing development
+ *******************************************************************************/
+package org.eclipse.tm4e.core.internal.css;
+
+import org.w3c.css.sac.LexicalUnit;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.css.CSSPrimitiveValue;
+import org.w3c.dom.css.RGBColor;
+
+public class RGBColorImpl extends CSSValueImpl implements RGBColor {
+
+	private final CSSPrimitiveValue red;
+	private final CSSPrimitiveValue green;
+	private final CSSPrimitiveValue blue;
+
+	public RGBColorImpl(LexicalUnit lexicalUnit) {
+		LexicalUnit nextUnit = lexicalUnit.getParameters();
+		red = new Measure(nextUnit);
+		nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit();
+		green = new Measure(nextUnit);
+		nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit();
+		blue = new Measure(nextUnit);
+	}
+
+	@Override
+	public CSSPrimitiveValue getRed() {
+		return red;
+	}
+
+	@Override
+	public CSSPrimitiveValue getGreen() {
+		return green;
+	}
+
+	@Override
+	public CSSPrimitiveValue getBlue() {
+		return blue;
+	}
+
+	@Override
+	public RGBColor getRGBColorValue() throws DOMException {
+		return this;
+	}
+
+	@Override
+	public short getPrimitiveType() {
+		return CSS_RGBCOLOR;
+	}
+
+	@Override
+	public String getCssText() {
+		return "rgb(" + red.getCssText() + ", " + green.getCssText() + ", "
+				+ blue.getCssText() + ")";
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java
index 00d36aa26..d7f0bfd28 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java
@@ -13,9 +13,9 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.grammar;
-
+ */
+package org.eclipse.tm4e.core.internal.grammar;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Level;
@@ -23,16 +23,16 @@
 
 import org.eclipse.tm4e.core.grammar.IToken;
 import org.eclipse.tm4e.core.grammar.StackElement;
-
+
 class LineTokens {
 
-	private static final Logger LOGGER = Logger.getLogger(LineTokens.class.getName());
+	private static final Logger LOGGER = Logger.getLogger(LineTokens.class.getName());
 
 	private final String lineText;
 
 	/**
 	 * used only if `_emitBinaryTokens` is false.
-	 */
+	 */
 	private final List tokens;
 
 
@@ -42,9 +42,9 @@ class LineTokens {
 	 * used only if `_emitBinaryTokens` is true.
 	 */
 	private final List binaryTokens;
-
-	private int lastTokenEndIndex;
-
+
+	private int lastTokenEndIndex;
+
 	LineTokens(boolean emitBinaryTokens, String lineText) {
 		this.emitBinaryTokens = emitBinaryTokens;
 		this.lineText = LOGGER.isLoggable(Level.FINEST) ? lineText : null; // store line only if it's logged
@@ -54,13 +54,13 @@ class LineTokens {
 		} else {
 			this.tokens = new ArrayList<>();
 			this.binaryTokens = null;
-		}
+		}
 		this.lastTokenEndIndex = 0;
-	}
-
+	}
+
 	public void produce(StackElement stack, int endIndex) {
 		this.produceFromScopes(stack.contentNameScopesList, endIndex);
-	}
+	}
 
 	public void produceFromScopes(ScopeListElement scopesList, int endIndex) {
 		if (this.lastTokenEndIndex >= endIndex) {
@@ -94,20 +94,20 @@ public void produceFromScopes(ScopeListElement scopesList, int endIndex) {
 
 		this.lastTokenEndIndex = endIndex;
 	}
-
-	public IToken[] getResult(StackElement stack, int lineLength) {
-		if (!this.tokens.isEmpty() && this.tokens.get(this.tokens.size() - 1).getStartIndex() == lineLength - 1) {
-			// pop produced token for newline
-			this.tokens.remove(this.tokens.size() - 1);
-		}
-
-		if (this.tokens.isEmpty()) {
-			this.lastTokenEndIndex = -1;
-			this.produce(stack, lineLength);
-			this.tokens.get(this.tokens.size() - 1).setStartIndex(0);
-		}
-
-		return this.tokens.toArray(new IToken[0]);
+
+	public IToken[] getResult(StackElement stack, int lineLength) {
+		if (!this.tokens.isEmpty() && this.tokens.get(this.tokens.size() - 1).getStartIndex() == lineLength - 1) {
+			// pop produced token for newline
+			this.tokens.remove(this.tokens.size() - 1);
+		}
+
+		if (this.tokens.isEmpty()) {
+			this.lastTokenEndIndex = -1;
+			this.produce(stack, lineLength);
+			this.tokens.get(this.tokens.size() - 1).setStartIndex(0);
+		}
+
+		return this.tokens.toArray(new IToken[0]);
 	}
 
 	public int[] getBinaryResult(StackElement stack, int lineLength) {
@@ -129,5 +129,5 @@ public int[] getBinaryResult(StackElement stack, int lineLength) {
 		}
 
 		return result;
-	}
-}
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java
index 4d5c7388b..37770d867 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java
@@ -13,25 +13,25 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.grammar;
-
-class LocalStackElement {
-
-	private final ScopeListElement scopes;
-	private final int endPos;
-
-	public LocalStackElement(ScopeListElement scopes, int endPos) {
-		this.scopes = scopes;
-		this.endPos = endPos;
-	}
-
-	public ScopeListElement getScopes() {
-		return scopes;
-	}
-
-	public int getEndPos() {
-		return endPos;
-	}
-
-}
+ */
+package org.eclipse.tm4e.core.internal.grammar;
+
+class LocalStackElement {
+
+	private final ScopeListElement scopes;
+	private final int endPos;
+
+	public LocalStackElement(ScopeListElement scopes, int endPos) {
+		this.scopes = scopes;
+		this.endPos = endPos;
+	}
+
+	public ScopeListElement getScopes() {
+		return scopes;
+	}
+
+	public int getEndPos() {
+		return endPos;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java
index b1e567587..e6d2709bb 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java
@@ -9,45 +9,45 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.internal.grammar;
-
-/**
- * Helpers to manage the "collapsed" metadata of an entire StackElement stack.
- * The following assumptions have been made:
- *  - languageId < 256 => needs 8 bits
- *  - unique color count < 512 => needs 9 bits
- *
- * The binary format is:
- * - -------------------------------------------
- *     3322 2222 2222 1111 1111 1100 0000 0000
- *     1098 7654 3210 9876 5432 1098 7654 3210
- * - -------------------------------------------
- *     xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
- *     bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL
- * - -------------------------------------------
- *  - L = LanguageId (8 bits)
- *  - T = StandardTokenType (3 bits)
- *  - F = FontStyle (3 bits)
- *  - f = foreground color (9 bits)
- *  - b = background color (9 bits)
- */
+package org.eclipse.tm4e.core.internal.grammar;
+
+/**
+ * Helpers to manage the "collapsed" metadata of an entire StackElement stack.
+ * The following assumptions have been made:
+ *  - languageId < 256 => needs 8 bits
+ *  - unique color count < 512 => needs 9 bits
+ *
+ * The binary format is:
+ * - -------------------------------------------
+ *     3322 2222 2222 1111 1111 1100 0000 0000
+ *     1098 7654 3210 9876 5432 1098 7654 3210
+ * - -------------------------------------------
+ *     xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
+ *     bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL
+ * - -------------------------------------------
+ *  - L = LanguageId (8 bits)
+ *  - T = StandardTokenType (3 bits)
+ *  - F = FontStyle (3 bits)
+ *  - f = foreground color (9 bits)
+ *  - b = background color (9 bits)
+ */
 public class MetadataConsts {
 
 	/**
 	 * content should be accessed statically
 	 */
 	private MetadataConsts() {
-	}
-
-	public static final int LANGUAGEID_MASK = 0b00000000000000000000000011111111;
-	public static final int TOKEN_TYPE_MASK = 0b00000000000000000000011100000000;
-	public static final int FONT_STYLE_MASK = 0b00000000000000000011100000000000;
-	public static final int FOREGROUND_MASK = 0b00000000011111111100000000000000;
-	public static final int BACKGROUND_MASK = 0b11111111100000000000000000000000;
-
-	public static final int LANGUAGEID_OFFSET = 0;
-	public static final int TOKEN_TYPE_OFFSET = 8;
-	public static final int FONT_STYLE_OFFSET = 11;
-	public static final int FOREGROUND_OFFSET = 14;
-	public static final int BACKGROUND_OFFSET = 23;
-}
+	}
+
+	public static final int LANGUAGEID_MASK = 0b00000000000000000000000011111111;
+	public static final int TOKEN_TYPE_MASK = 0b00000000000000000000011100000000;
+	public static final int FONT_STYLE_MASK = 0b00000000000000000011100000000000;
+	public static final int FOREGROUND_MASK = 0b00000000011111111100000000000000;
+	public static final int BACKGROUND_MASK = 0b11111111100000000000000000000000;
+
+	public static final int LANGUAGEID_OFFSET = 0;
+	public static final int TOKEN_TYPE_OFFSET = 8;
+	public static final int FONT_STYLE_OFFSET = 11;
+	public static final int FOREGROUND_OFFSET = 14;
+	public static final int BACKGROUND_OFFSET = 23;
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java
index 59e1e47de..6120bee96 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java
@@ -9,8 +9,8 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.internal.grammar;
-
+package org.eclipse.tm4e.core.internal.grammar;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -18,31 +18,31 @@
 import java.util.Objects;
 
 import org.eclipse.tm4e.core.theme.FontStyle;
-import org.eclipse.tm4e.core.theme.ThemeTrieElementRule;
-
-public class ScopeListElement {
-
-	public final ScopeListElement parent;
-	public final String scope;
-	public final int metadata;
-
-	public ScopeListElement(ScopeListElement parent, String scope, int metadata) {
-		this.parent = parent;
-		this.scope = scope;
-		this.metadata = metadata;
-	}
-
-	private static boolean equals(ScopeListElement a, ScopeListElement b) {
-		if (a == b) {
-			return true;
+import org.eclipse.tm4e.core.theme.ThemeTrieElementRule;
+
+public class ScopeListElement {
+
+	public final ScopeListElement parent;
+	public final String scope;
+	public final int metadata;
+
+	public ScopeListElement(ScopeListElement parent, String scope, int metadata) {
+		this.parent = parent;
+		this.scope = scope;
+		this.metadata = metadata;
+	}
+
+	private static boolean equals(ScopeListElement a, ScopeListElement b) {
+		if (a == b) {
+			return true;
 		}
 		if (a == null || b == null) {
 			return false;
-		}
-		return Objects.equals(a.scope, b.scope) && a.metadata == b.metadata && equals(a.parent, b.parent);
-	}
+		}
+		return Objects.equals(a.scope, b.scope) && a.metadata == b.metadata && equals(a.parent, b.parent);
+	}
 
-	@Override
+	@Override
 	public boolean equals(Object other) {
 		if (other == this) {
 			return true;
@@ -52,102 +52,102 @@ public boolean equals(Object other) {
 		}
 		if (!(other instanceof ScopeListElement)) {
 			return false;
-		}
-		return ScopeListElement.equals(this, (ScopeListElement)other);
+		}
+		return ScopeListElement.equals(this, (ScopeListElement)other);
 	}
 
 	@Override public int hashCode() {
 		return Objects.hash(scope, metadata, parent);
 	}
-
-
-	private static boolean matchesScope(String scope, String selector, String selectorWithDot) {
-		return (selector.equals(scope) || scope.startsWith(selectorWithDot));
-	}
-
-	private static boolean matches(ScopeListElement target, List parentScopes) {
-		if (parentScopes == null) {
-			return true;
-		}
-
-		int len = parentScopes.size();
-		int index = 0;
-		String selector = parentScopes.get(index);
-		String selectorWithDot = selector + ".";
-
-		while (target != null) {
-			if (matchesScope(target.scope, selector, selectorWithDot)) {
-				index++;
-				if (index == len) {
-					return true;
-				}
-				selector = parentScopes.get(index);
-				selectorWithDot = selector + '.';
-			}
-			target = target.parent;
-		}
-
-		return false;
-	}
-
-	public static int mergeMetadata(int metadata, ScopeListElement scopesList, ScopeMetadata source) {
-		if (source == null) {
-			return metadata;
-		}
-
-		int fontStyle = FontStyle.NotSet;
-		int foreground = 0;
-		int background = 0;
-
-		if (source.themeData != null) {
-			// Find the first themeData that matches
-			for (ThemeTrieElementRule themeData : source.themeData) {
-				if (matches(scopesList, themeData.parentScopes)) {
-					fontStyle = themeData.fontStyle;
-					foreground = themeData.foreground;
-					background = themeData.background;
-					break;
-				}
-			}
-		}
-
-		return StackElementMetadata.set(metadata, source.languageId, source.tokenType, fontStyle, foreground,
-				background);
-	}
-
-	private static ScopeListElement push(ScopeListElement target, Grammar grammar, List scopes) {
-		for (String scope : scopes) {
-			ScopeMetadata rawMetadata = grammar.getMetadataForScope(scope);
-			int metadata = ScopeListElement.mergeMetadata(target.metadata, target, rawMetadata);
-			target = new ScopeListElement(target, scope, metadata);
-		}
-		return target;
-	}
-
-	public ScopeListElement push(Grammar grammar, String scope) {
-		if (scope == null) {
-			return this;
-		}
-		if (scope.indexOf(' ') >= 0) {
-			// there are multiple scopes to push
-			return ScopeListElement.push(this, grammar, Arrays.asList(scope.split(" ")));// scope.split(/
-																							// /g));
-		}
-		// there is a single scope to push
-		return ScopeListElement.push(this, grammar, Arrays.asList(scope));
-	}
-
-	private static List generateScopes(ScopeListElement scopesList) {
-		List result = new ArrayList<>();
-		while (scopesList != null) {
-			result.add(scopesList.scope);
-			scopesList = scopesList.parent;
-		}
-		Collections.reverse(result);
-		return result;
-	}
-
-	public List generateScopes() {
-		return ScopeListElement.generateScopes(this);
-	}
-}
+
+
+	private static boolean matchesScope(String scope, String selector, String selectorWithDot) {
+		return (selector.equals(scope) || scope.startsWith(selectorWithDot));
+	}
+
+	private static boolean matches(ScopeListElement target, List parentScopes) {
+		if (parentScopes == null) {
+			return true;
+		}
+
+		int len = parentScopes.size();
+		int index = 0;
+		String selector = parentScopes.get(index);
+		String selectorWithDot = selector + ".";
+
+		while (target != null) {
+			if (matchesScope(target.scope, selector, selectorWithDot)) {
+				index++;
+				if (index == len) {
+					return true;
+				}
+				selector = parentScopes.get(index);
+				selectorWithDot = selector + '.';
+			}
+			target = target.parent;
+		}
+
+		return false;
+	}
+
+	public static int mergeMetadata(int metadata, ScopeListElement scopesList, ScopeMetadata source) {
+		if (source == null) {
+			return metadata;
+		}
+
+		int fontStyle = FontStyle.NotSet;
+		int foreground = 0;
+		int background = 0;
+
+		if (source.themeData != null) {
+			// Find the first themeData that matches
+			for (ThemeTrieElementRule themeData : source.themeData) {
+				if (matches(scopesList, themeData.parentScopes)) {
+					fontStyle = themeData.fontStyle;
+					foreground = themeData.foreground;
+					background = themeData.background;
+					break;
+				}
+			}
+		}
+
+		return StackElementMetadata.set(metadata, source.languageId, source.tokenType, fontStyle, foreground,
+				background);
+	}
+
+	private static ScopeListElement push(ScopeListElement target, Grammar grammar, List scopes) {
+		for (String scope : scopes) {
+			ScopeMetadata rawMetadata = grammar.getMetadataForScope(scope);
+			int metadata = ScopeListElement.mergeMetadata(target.metadata, target, rawMetadata);
+			target = new ScopeListElement(target, scope, metadata);
+		}
+		return target;
+	}
+
+	public ScopeListElement push(Grammar grammar, String scope) {
+		if (scope == null) {
+			return this;
+		}
+		if (scope.indexOf(' ') >= 0) {
+			// there are multiple scopes to push
+			return ScopeListElement.push(this, grammar, Arrays.asList(scope.split(" ")));// scope.split(/
+																							// /g));
+		}
+		// there is a single scope to push
+		return ScopeListElement.push(this, grammar, Arrays.asList(scope));
+	}
+
+	private static List generateScopes(ScopeListElement scopesList) {
+		List result = new ArrayList<>();
+		while (scopesList != null) {
+			result.add(scopesList.scope);
+			scopesList = scopesList.parent;
+		}
+		Collections.reverse(result);
+		return result;
+	}
+
+	public List generateScopes() {
+		return ScopeListElement.generateScopes(this);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java
index fab90e9b5..08f07f409 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java
@@ -9,23 +9,23 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.internal.grammar;
-
-import java.util.List;
-
-import org.eclipse.tm4e.core.theme.ThemeTrieElementRule;
-
-public class ScopeMetadata {
-
-	public final String scopeName;
-	public final int languageId;
-	public final int tokenType;
-	public final List themeData;
-
-	public ScopeMetadata(String scopeName, int languageId, int tokenType, List themeData) {
-		this.scopeName = scopeName;
-		this.languageId = languageId;
-		this.tokenType = tokenType;
-		this.themeData = themeData;
-	}
-}
+package org.eclipse.tm4e.core.internal.grammar;
+
+import java.util.List;
+
+import org.eclipse.tm4e.core.theme.ThemeTrieElementRule;
+
+public class ScopeMetadata {
+
+	public final String scopeName;
+	public final int languageId;
+	public final int tokenType;
+	public final List themeData;
+
+	public ScopeMetadata(String scopeName, int languageId, int tokenType, List themeData) {
+		this.scopeName = scopeName;
+		this.languageId = languageId;
+		this.tokenType = tokenType;
+		this.themeData = themeData;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java
index b3d8b0180..8a26a2dc3 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java
@@ -9,8 +9,8 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.internal.grammar;
-
+package org.eclipse.tm4e.core.internal.grammar;
+
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -23,155 +23,155 @@
 
 import org.eclipse.tm4e.core.TMException;
 import org.eclipse.tm4e.core.theme.IThemeProvider;
-import org.eclipse.tm4e.core.theme.ThemeTrieElementRule;
-
-public class ScopeMetadataProvider {
-
-	private static final ScopeMetadata _NULL_SCOPE_METADATA = new ScopeMetadata("", 0, StandardTokenType.Other, null);
-
-	private static final Pattern STANDARD_TOKEN_TYPE_REGEXP = Pattern.compile("\\b(comment|string|regex)\\b");
-	private static final String COMMENT_TOKEN_TYPE = "comment";
-	private static final String STRING_TOKEN_TYPE = "string";
-	private static final String REGEX_TOKEN_TYPE = "regex";
-
-	private final int initialLanguage;
-	private final IThemeProvider themeProvider;
-	private final Map cache;
-	private ScopeMetadata defaultMetaData;
-	private final Map embeddedLanguages;
-	private Pattern embeddedLanguagesRegex;
-
-	public ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider,
-			Map embeddedLanguages) {
-		this.initialLanguage = initialLanguage;
-		this.themeProvider = themeProvider;
-		this.cache = new HashMap<>();
-		this.onDidChangeTheme();
-
-		// embeddedLanguages handling
-		this.embeddedLanguages = new HashMap<>();
-		if (embeddedLanguages != null) {
-			// If embeddedLanguages are configured, fill in
-			// `this._embeddedLanguages`
-			Set> languages = embeddedLanguages.entrySet();
-			for (Entry language : languages) {
-				String scope = language.getKey();
-				int languageId = language.getValue();
-				/*
-				 * if (typeof language !== 'number' || language === 0) {
-				 * console.warn('Invalid embedded language found at scope ' +
-				 * scope + ': <<' + language + '>>'); // never hurts to be too
-				 * careful continue; }
-				 */
-				this.embeddedLanguages.put(scope, languageId);
-			}
-		}
-
-		// create the regex
-		Set escapedScopes = this.embeddedLanguages.keySet().stream()
-				.map(ScopeMetadataProvider::escapeRegExpCharacters)
-				.collect(Collectors.toSet());
-		if (escapedScopes.isEmpty()) {
-			// no scopes registered
-			this.embeddedLanguagesRegex = null;
-		} else {
-			// TODO!!!
-			this.embeddedLanguagesRegex = null;
-			// escapedScopes.sort();
-			// escapedScopes.reverse();
-			// this._embeddedLanguagesRegex = new
-			// RegExp(`^((${escapedScopes.join(')|(')}))($|\\.)`, '');
-		}
-	}
-
-public void onDidChangeTheme() {
-	this.cache.clear();
-	this.defaultMetaData = new ScopeMetadata(
-		"",
-		this.initialLanguage,
-		StandardTokenType.Other,
-		Arrays.asList(this.themeProvider.getDefaults())
-	);
-}
-
-	public ScopeMetadata getDefaultMetadata() {
-		return this.defaultMetaData;
-	}
-
-	/**
-	 * Escapes regular expression characters in a given string
-	 */
-	private static String escapeRegExpCharacters(String value) {
-		// TODO!!!
-		return value; //value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&');
-	}
-
-	public ScopeMetadata getMetadataForScope(String scopeName) {
-		if (scopeName == null) {
-			return ScopeMetadataProvider._NULL_SCOPE_METADATA;
-		}
-		ScopeMetadata value = this.cache.get(scopeName);
-		if (value != null) {
-			return value;
-		}
-		value = this.doGetMetadataForScope(scopeName);
-		this.cache.put(scopeName, value);
-		return value;
-	}
-
-	private ScopeMetadata doGetMetadataForScope(String scopeName) {
-		int languageId = this.scopeToLanguage(scopeName);
-		int standardTokenType = ScopeMetadataProvider.toStandardTokenType(scopeName);
-		List themeData = this.themeProvider.themeMatch(scopeName);
-
-		return new ScopeMetadata(scopeName, languageId, standardTokenType, themeData);
-	}
-
-	/**
-	 * Given a produced TM scope, return the language that token describes or
-	 * null if unknown. e.g. source.html => html, source.css.embedded.html =>
-	 * css, punctuation.definition.tag.html => null
-	 */
-	private int scopeToLanguage(String scope) {
-		if (scope == null) {
-			return 0;
-		}
-		if (this.embeddedLanguagesRegex == null) {
-			// no scopes registered
-			return 0;
-		}
-
-		// TODO!!!!
-
-		/*let m = scope.match(this._embeddedLanguagesRegex);
-		if (!m) {
-			// no scopes matched
-			return 0;
-		}
-
-		let language = this._embeddedLanguages[m[1]] || 0;
-		if (!language) {
-			return 0;
-		}
-
-		return language;*/
-		return 0;
-	}
-
-	private static int toStandardTokenType(String tokenType) {
-		Matcher m = STANDARD_TOKEN_TYPE_REGEXP.matcher(tokenType); // tokenType.match(ScopeMetadataProvider.STANDARD_TOKEN_TYPE_REGEXP);
-		if (!m.find()) {
-			return StandardTokenType.Other;
-		}
-		String group = m.group();
-		if (COMMENT_TOKEN_TYPE.equals(group)) {
-			return StandardTokenType.Comment;
-		} else if (STRING_TOKEN_TYPE.equals(group)) {
-			return StandardTokenType.String;
-		}
-		if (REGEX_TOKEN_TYPE.equals(group)) {
-			return StandardTokenType.RegEx;
-		}
-		throw new TMException("Unexpected match for standard token type!");
-	}
-}
+import org.eclipse.tm4e.core.theme.ThemeTrieElementRule;
+
+public class ScopeMetadataProvider {
+
+	private static final ScopeMetadata _NULL_SCOPE_METADATA = new ScopeMetadata("", 0, StandardTokenType.Other, null);
+
+	private static final Pattern STANDARD_TOKEN_TYPE_REGEXP = Pattern.compile("\\b(comment|string|regex)\\b");
+	private static final String COMMENT_TOKEN_TYPE = "comment";
+	private static final String STRING_TOKEN_TYPE = "string";
+	private static final String REGEX_TOKEN_TYPE = "regex";
+
+	private final int initialLanguage;
+	private final IThemeProvider themeProvider;
+	private final Map cache;
+	private ScopeMetadata defaultMetaData;
+	private final Map embeddedLanguages;
+	private Pattern embeddedLanguagesRegex;
+
+	public ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider,
+			Map embeddedLanguages) {
+		this.initialLanguage = initialLanguage;
+		this.themeProvider = themeProvider;
+		this.cache = new HashMap<>();
+		this.onDidChangeTheme();
+
+		// embeddedLanguages handling
+		this.embeddedLanguages = new HashMap<>();
+		if (embeddedLanguages != null) {
+			// If embeddedLanguages are configured, fill in
+			// `this._embeddedLanguages`
+			Set> languages = embeddedLanguages.entrySet();
+			for (Entry language : languages) {
+				String scope = language.getKey();
+				int languageId = language.getValue();
+				/*
+				 * if (typeof language !== 'number' || language === 0) {
+				 * console.warn('Invalid embedded language found at scope ' +
+				 * scope + ': <<' + language + '>>'); // never hurts to be too
+				 * careful continue; }
+				 */
+				this.embeddedLanguages.put(scope, languageId);
+			}
+		}
+
+		// create the regex
+		Set escapedScopes = this.embeddedLanguages.keySet().stream()
+				.map(ScopeMetadataProvider::escapeRegExpCharacters)
+				.collect(Collectors.toSet());
+		if (escapedScopes.isEmpty()) {
+			// no scopes registered
+			this.embeddedLanguagesRegex = null;
+		} else {
+			// TODO!!!
+			this.embeddedLanguagesRegex = null;
+			// escapedScopes.sort();
+			// escapedScopes.reverse();
+			// this._embeddedLanguagesRegex = new
+			// RegExp(`^((${escapedScopes.join(')|(')}))($|\\.)`, '');
+		}
+	}
+
+public void onDidChangeTheme() {
+	this.cache.clear();
+	this.defaultMetaData = new ScopeMetadata(
+		"",
+		this.initialLanguage,
+		StandardTokenType.Other,
+		Arrays.asList(this.themeProvider.getDefaults())
+	);
+}
+
+	public ScopeMetadata getDefaultMetadata() {
+		return this.defaultMetaData;
+	}
+
+	/**
+	 * Escapes regular expression characters in a given string
+	 */
+	private static String escapeRegExpCharacters(String value) {
+		// TODO!!!
+		return value; //value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&');
+	}
+
+	public ScopeMetadata getMetadataForScope(String scopeName) {
+		if (scopeName == null) {
+			return ScopeMetadataProvider._NULL_SCOPE_METADATA;
+		}
+		ScopeMetadata value = this.cache.get(scopeName);
+		if (value != null) {
+			return value;
+		}
+		value = this.doGetMetadataForScope(scopeName);
+		this.cache.put(scopeName, value);
+		return value;
+	}
+
+	private ScopeMetadata doGetMetadataForScope(String scopeName) {
+		int languageId = this.scopeToLanguage(scopeName);
+		int standardTokenType = ScopeMetadataProvider.toStandardTokenType(scopeName);
+		List themeData = this.themeProvider.themeMatch(scopeName);
+
+		return new ScopeMetadata(scopeName, languageId, standardTokenType, themeData);
+	}
+
+	/**
+	 * Given a produced TM scope, return the language that token describes or
+	 * null if unknown. e.g. source.html => html, source.css.embedded.html =>
+	 * css, punctuation.definition.tag.html => null
+	 */
+	private int scopeToLanguage(String scope) {
+		if (scope == null) {
+			return 0;
+		}
+		if (this.embeddedLanguagesRegex == null) {
+			// no scopes registered
+			return 0;
+		}
+
+		// TODO!!!!
+
+		/*let m = scope.match(this._embeddedLanguagesRegex);
+		if (!m) {
+			// no scopes matched
+			return 0;
+		}
+
+		let language = this._embeddedLanguages[m[1]] || 0;
+		if (!language) {
+			return 0;
+		}
+
+		return language;*/
+		return 0;
+	}
+
+	private static int toStandardTokenType(String tokenType) {
+		Matcher m = STANDARD_TOKEN_TYPE_REGEXP.matcher(tokenType); // tokenType.match(ScopeMetadataProvider.STANDARD_TOKEN_TYPE_REGEXP);
+		if (!m.find()) {
+			return StandardTokenType.Other;
+		}
+		String group = m.group();
+		if (COMMENT_TOKEN_TYPE.equals(group)) {
+			return StandardTokenType.Comment;
+		} else if (STRING_TOKEN_TYPE.equals(group)) {
+			return StandardTokenType.String;
+		}
+		if (REGEX_TOKEN_TYPE.equals(group)) {
+			return StandardTokenType.RegEx;
+		}
+		throw new TMException("Unexpected match for standard token type!");
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java
index 5b5e87f04..1cf7b1d74 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java
@@ -1,70 +1,70 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.grammar;
-
-import org.eclipse.tm4e.core.grammar.StackElement;
-import org.eclipse.tm4e.core.theme.FontStyle;
-
-/**
- *
- * Metadata for {@link StackElement}.
- *
- */
-public class StackElementMetadata {
-
-	/**
-	 * Content should be referenced statically
-	 */
-	private StackElementMetadata() {
-	}
-
-	public static String toBinaryStr(int metadata) {
-		/*
-		 * let r = metadata.toString(2); while (r.length < 32) { r = '0' + r; }
-		 * return r;
-		 */
-		// TODO!!!
-		return null;
-	}
-
-	public static int getLanguageId(int metadata) {
-		return (metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET;
-	}
-
-	public static int getTokenType(int metadata) {
-		return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET;
-	}
-
-	public static int getFontStyle(int metadata) {
-		return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET;
-	}
-
-	public static int getForeground(int metadata) {
-		return (metadata & MetadataConsts.FOREGROUND_MASK) >>> MetadataConsts.FOREGROUND_OFFSET;
-	}
-
-	public static int getBackground(int metadata) {
-		return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET;
-	}
-
-	public static int set(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) {
-		languageId = languageId == 0 ? StackElementMetadata.getLanguageId(metadata) : languageId;
-		tokenType = tokenType == StandardTokenType.Other ? StackElementMetadata.getTokenType(metadata) : tokenType;
-		fontStyle = fontStyle == FontStyle.NotSet ? StackElementMetadata.getFontStyle(metadata) : fontStyle;
-		foreground = foreground == 0 ? StackElementMetadata.getForeground(metadata) : foreground;
-		background = background == 0 ? StackElementMetadata.getBackground(metadata) : background;
-		return ((languageId << MetadataConsts.LANGUAGEID_OFFSET) | (tokenType << MetadataConsts.TOKEN_TYPE_OFFSET)
-				| (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) | (foreground << MetadataConsts.FOREGROUND_OFFSET)
-				| (background << MetadataConsts.BACKGROUND_OFFSET)) >>> 0;
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.grammar;
+
+import org.eclipse.tm4e.core.grammar.StackElement;
+import org.eclipse.tm4e.core.theme.FontStyle;
+
+/**
+ *
+ * Metadata for {@link StackElement}.
+ *
+ */
+public class StackElementMetadata {
+
+	/**
+	 * Content should be referenced statically
+	 */
+	private StackElementMetadata() {
+	}
+
+	public static String toBinaryStr(int metadata) {
+		/*
+		 * let r = metadata.toString(2); while (r.length < 32) { r = '0' + r; }
+		 * return r;
+		 */
+		// TODO!!!
+		return null;
+	}
+
+	public static int getLanguageId(int metadata) {
+		return (metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET;
+	}
+
+	public static int getTokenType(int metadata) {
+		return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET;
+	}
+
+	public static int getFontStyle(int metadata) {
+		return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET;
+	}
+
+	public static int getForeground(int metadata) {
+		return (metadata & MetadataConsts.FOREGROUND_MASK) >>> MetadataConsts.FOREGROUND_OFFSET;
+	}
+
+	public static int getBackground(int metadata) {
+		return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET;
+	}
+
+	public static int set(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) {
+		languageId = languageId == 0 ? StackElementMetadata.getLanguageId(metadata) : languageId;
+		tokenType = tokenType == StandardTokenType.Other ? StackElementMetadata.getTokenType(metadata) : tokenType;
+		fontStyle = fontStyle == FontStyle.NotSet ? StackElementMetadata.getFontStyle(metadata) : fontStyle;
+		foreground = foreground == 0 ? StackElementMetadata.getForeground(metadata) : foreground;
+		background = background == 0 ? StackElementMetadata.getBackground(metadata) : background;
+		return ((languageId << MetadataConsts.LANGUAGEID_OFFSET) | (tokenType << MetadataConsts.TOKEN_TYPE_OFFSET)
+				| (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) | (foreground << MetadataConsts.FOREGROUND_OFFSET)
+				| (background << MetadataConsts.BACKGROUND_OFFSET)) >>> 0;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java
index c215e02bb..cccb08ddd 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java
@@ -1,31 +1,31 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.grammar;
-
-/**
- * Standard TextMate token type.
- *
- */
-public class StandardTokenType {
-
-	/**
-	 * Content should be accessed statically
-	 */
-	private StandardTokenType() {
-	}
-
-	public static final int Other = 0;
-	public static final int Comment = 1;
-	public static final int String = 2;
-	public static final int RegEx = 4;
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.grammar;
+
+/**
+ * Standard TextMate token type.
+ *
+ */
+public class StandardTokenType {
+
+	/**
+	 * Content should be accessed statically
+	 */
+	private StandardTokenType() {
+	}
+
+	public static final int Other = 0;
+	public static final int Comment = 1;
+	public static final int String = 2;
+	public static final int RegEx = 4;
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java
index dddd607ca..83da86459 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java
@@ -13,57 +13,57 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.grammar;
-
-import java.util.List;
-
-import org.eclipse.tm4e.core.grammar.IToken;
-
-class Token implements IToken {
-
-	private int startIndex;
-
-	private final int endIndex;
-
-	private final List scopes;
-
-	public Token(int startIndex, int endIndex, List scopes) {
-		this.startIndex = startIndex;
-		this.endIndex = endIndex;
-		this.scopes = scopes;
-	}
-
-	@Override
-	public int getStartIndex() {
-		return startIndex;
-	}
-
-	@Override
-	public void setStartIndex(int startIndex) {
-		this.startIndex = startIndex;
-	}
-
-	@Override
-	public int getEndIndex() {
-		return endIndex;
-	}
-
-	@Override
-	public List getScopes() {
-		return scopes;
-	}
-	
-	@Override
-	public String toString() {
-		StringBuilder s = new StringBuilder();
-		s.append("{startIndex: ");
-		s.append(startIndex);
-		s.append(", endIndex: ");
-		s.append(endIndex);
-		s.append(", scopes: ");
-		s.append(scopes);
-		s.append("}");
-		return s.toString();
-	}
-}
+ */
+package org.eclipse.tm4e.core.internal.grammar;
+
+import java.util.List;
+
+import org.eclipse.tm4e.core.grammar.IToken;
+
+class Token implements IToken {
+
+	private int startIndex;
+
+	private final int endIndex;
+
+	private final List scopes;
+
+	public Token(int startIndex, int endIndex, List scopes) {
+		this.startIndex = startIndex;
+		this.endIndex = endIndex;
+		this.scopes = scopes;
+	}
+
+	@Override
+	public int getStartIndex() {
+		return startIndex;
+	}
+
+	@Override
+	public void setStartIndex(int startIndex) {
+		this.startIndex = startIndex;
+	}
+
+	@Override
+	public int getEndIndex() {
+		return endIndex;
+	}
+
+	@Override
+	public List getScopes() {
+		return scopes;
+	}
+	
+	@Override
+	public String toString() {
+		StringBuilder s = new StringBuilder();
+		s.append("{startIndex: ");
+		s.append(startIndex);
+		s.append(", endIndex: ");
+		s.append(endIndex);
+		s.append(", scopes: ");
+		s.append(scopes);
+		s.append("}");
+		return s.toString();
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java
index a2853a066..0f17e7191 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java
@@ -13,36 +13,36 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.grammar;
-
-import org.eclipse.tm4e.core.grammar.IToken;
-import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
-import org.eclipse.tm4e.core.grammar.StackElement;
-
-/**
- * 
- * Result of the line tokenization implementation.
- *
- */
-public class TokenizeLineResult implements ITokenizeLineResult {
-
-	private final IToken[] tokens;
-	private final StackElement ruleStack;
-
-	public TokenizeLineResult(IToken[] tokens, StackElement ruleStack) {
-		this.tokens = tokens;
-		this.ruleStack = ruleStack;
-	}
-
-	@Override
-	public IToken[] getTokens() {
-		return tokens;
-	}
-
-	@Override
-	public StackElement getRuleStack() {
-		return ruleStack;
-	}
-
-}
+ */
+package org.eclipse.tm4e.core.internal.grammar;
+
+import org.eclipse.tm4e.core.grammar.IToken;
+import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
+import org.eclipse.tm4e.core.grammar.StackElement;
+
+/**
+ * 
+ * Result of the line tokenization implementation.
+ *
+ */
+public class TokenizeLineResult implements ITokenizeLineResult {
+
+	private final IToken[] tokens;
+	private final StackElement ruleStack;
+
+	public TokenizeLineResult(IToken[] tokens, StackElement ruleStack) {
+		this.tokens = tokens;
+		this.ruleStack = ruleStack;
+	}
+
+	@Override
+	public IToken[] getTokens() {
+		return tokens;
+	}
+
+	@Override
+	public StackElement getRuleStack() {
+		return ruleStack;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java
index 3ec920c90..a7a20fbc2 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java
@@ -13,35 +13,35 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.grammar;
-
+ */
+package org.eclipse.tm4e.core.internal.grammar;
+
 import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2;
-import org.eclipse.tm4e.core.grammar.StackElement;
-
-/**
- * 
- * Result of the line tokenization2 implementation.
- *
- */
-public class TokenizeLineResult2 implements ITokenizeLineResult2 {
-
-	private final int[] tokens;
-	private final StackElement ruleStack;
-
-	public TokenizeLineResult2(int[] tokens, StackElement ruleStack) {
-		this.tokens = tokens;
-		this.ruleStack = ruleStack;
-	}
-
-	@Override
-	public int[] getTokens() {
-		return tokens;
-	}
-
-	@Override
-	public StackElement getRuleStack() {
-		return ruleStack;
-	}
-
-}
+import org.eclipse.tm4e.core.grammar.StackElement;
+
+/**
+ * 
+ * Result of the line tokenization2 implementation.
+ *
+ */
+public class TokenizeLineResult2 implements ITokenizeLineResult2 {
+
+	private final int[] tokens;
+	private final StackElement ruleStack;
+
+	public TokenizeLineResult2(int[] tokens, StackElement ruleStack) {
+		this.tokens = tokens;
+		this.ruleStack = ruleStack;
+	}
+
+	@Override
+	public int[] getTokens() {
+		return tokens;
+	}
+
+	@Override
+	public StackElement getRuleStack() {
+		return ruleStack;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java
index d9597bde0..e4eb0176f 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java
@@ -9,21 +9,21 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.internal.grammar.parser;
-
-import java.util.Map;
-
-import org.eclipse.tm4e.core.internal.parser.PListObject;
-
-public class PListGrammar extends PListObject {
-
-	public PListGrammar(PListObject parent, boolean valueAsArray) {
-		super(parent, valueAsArray);
-	}
-
-	@Override
-	protected Map createRaw() {
-		return new Raw();
-	}
-
-}
+package org.eclipse.tm4e.core.internal.grammar.parser;
+
+import java.util.Map;
+
+import org.eclipse.tm4e.core.internal.parser.PListObject;
+
+public class PListGrammar extends PListObject {
+
+	public PListGrammar(PListObject parent, boolean valueAsArray) {
+		super(parent, valueAsArray);
+	}
+
+	@Override
+	protected Map createRaw() {
+		return new Raw();
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java
index 7c5c15683..a06e669a9 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java
@@ -1,305 +1,305 @@
-/**
- *  Copyright (c) 2015-2019 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2019 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- *  Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes
- */
-package org.eclipse.tm4e.core.internal.grammar.parser;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.tm4e.core.internal.types.IRawCaptures;
-import org.eclipse.tm4e.core.internal.types.IRawGrammar;
-import org.eclipse.tm4e.core.internal.types.IRawRepository;
-import org.eclipse.tm4e.core.internal.types.IRawRule;
-import org.eclipse.tm4e.core.internal.utils.CloneUtils;
-
-/**
- * Raw
- *
- */
-public class Raw extends HashMap implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures {
-	private static final String FIRST_LINE_MATCH = "firstLineMatch";
-	private static final String FILE_TYPES = "fileTypes";
-	private static final String SCOPE_NAME = "scopeName";
-	private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast";
-	private static final String REPOSITORY = "repository";
-	private static final String INJECTION_SELECTOR = "injectionSelector";
-	private static final String INJECTIONS = "injections";
-	private static final String PATTERNS = "patterns";
-	private static final String WHILE_CAPTURES = "whileCaptures";
-	private static final String END_CAPTURES = "endCaptures";
-	private static final String INCLUDE = "include";
-	private static final String WHILE = "while";
-	private static final String END = "end";
-	private static final String BEGIN = "begin";
-	private static final String CAPTURES = "captures";
-	private static final String MATCH = "match";
-	private static final String BEGIN_CAPTURES = "beginCaptures";
-	private static final String CONTENT_NAME = "contentName";
-	private static final String NAME = "name";
-	private static final String ID = "id";
-	private static final String DOLLAR_SELF = "$self";
-	private static final String DOLLAR_BASE = "$base";
-	private static final long serialVersionUID = -2306714541728887963L;
-	private List fileTypes;
-
-	@Override
-	public IRawRule getProp(String name) {
-		return (IRawRule) super.get(name);
-	}
-
-	@Override
-	public IRawRule getBase() {
-		return (IRawRule) super.get(DOLLAR_BASE);
-	}
-
-	@Override
-	public void setBase(IRawRule base) {
-		super.put(DOLLAR_BASE, base);
-	}
-
-	@Override
-	public IRawRule getSelf() {
-		return (IRawRule) super.get(DOLLAR_SELF);
-	}
-
-	@Override
-	public void setSelf(IRawRule self) {
-		super.put(DOLLAR_SELF, self);
-	}
-
-	@Override
-	public Integer getId() {
-		return (Integer) super.get(ID);
-	}
-
-	@Override
-	public void setId(Integer id) {
-		super.put(ID, id);
-	}
-
-	@Override
-	public String getName() {
-		return (String) super.get(NAME);
-	}
-
-	@Override
-	public void setName(String name) {
-		super.put(NAME, name);
-	}
-
-	@Override
-	public String getContentName() {
-		return (String) super.get(CONTENT_NAME);
-	}
-
-	@Override
-	public void setContentName(String name) {
-		super.put(CONTENT_NAME, name);
-	}
-
-	@Override
-	public String getMatch() {
-		return (String) super.get(MATCH);
-	}
-
-	@Override
-	public void setMatch(String match) {
-		super.put(MATCH, match);
-	}
-
-	@Override
-	public IRawCaptures getCaptures() {
-		updateCaptures(CAPTURES);
-		return (IRawCaptures) super.get(CAPTURES);
-	}
-
-	private void updateCaptures(String name) {
-		Object captures = super.get(name);
-		if (captures instanceof List) {
-			Raw rawCaptures = new Raw();
-			int i = 0;
-			for (Object capture : (List) captures) {
-				i++;
-				rawCaptures.put(i + "", capture);
-			}
-			super.put(name, rawCaptures);
-		}
-	}
-
-	@Override
-	public void setCaptures(IRawCaptures captures) {
-		super.put(CAPTURES, captures);
-	}
-
-	@Override
-	public String getBegin() {
-		return (String) super.get(BEGIN);
-	}
-
-	@Override
-	public void setBegin(String begin) {
-		super.put(BEGIN, begin);
-	}
-
-	@Override
-	public String getWhile() {
-		return (String) super.get(WHILE);
-	}
-
-	@Override
-	public String getInclude() {
-		return (String) super.get(INCLUDE);
-	}
-
-	@Override
-	public void setInclude(String include) {
-		super.put(INCLUDE, include);
-	}
-
-	@Override
-	public IRawCaptures getBeginCaptures() {
-		updateCaptures(BEGIN_CAPTURES);
-		return (IRawCaptures) super.get(BEGIN_CAPTURES);
-	}
-
-	@Override
-	public void setBeginCaptures(IRawCaptures beginCaptures) {
-		super.put(BEGIN_CAPTURES, beginCaptures);
-	}
-
-	@Override
-	public String getEnd() {
-		return (String) super.get(END);
-	}
-
-	@Override
-	public void setEnd(String end) {
-		super.put(END, end);
-	}
-
-	@Override
-	public IRawCaptures getEndCaptures() {
-		updateCaptures(END_CAPTURES);
-		return (IRawCaptures) super.get(END_CAPTURES);
-	}
-
-	@Override
-	public void setEndCaptures(IRawCaptures endCaptures) {
-		super.put(END_CAPTURES, endCaptures);
-	}
-
-	@Override
-	public IRawCaptures getWhileCaptures() {
-		updateCaptures(WHILE_CAPTURES);
-		return (IRawCaptures) super.get(WHILE_CAPTURES);
-	}
-
-	@Override
-	public Collection getPatterns() {
-		return (Collection) super.get(PATTERNS);
-	}
-
-	@Override
-	public void setPatterns(Collection patterns) {
-		super.put(PATTERNS, patterns);
-	}
-
-	@Override
-	public Map getInjections() {
-		return (Map) super.get(INJECTIONS);
-	}
-
-	@Override
-	public String getInjectionSelector() {
-		return (String) super.get(INJECTION_SELECTOR);
-	}
-
-	@Override
-	public IRawRepository getRepository() {
-		return (IRawRepository) super.get(REPOSITORY);
-	}
-
-	@Override
-	public void setRepository(IRawRepository repository) {
-		super.put(REPOSITORY, repository);
-	}
-
-	@Override
-	public boolean isApplyEndPatternLast() {
-		Object applyEndPatternLast = super.get(APPLY_END_PATTERN_LAST);
-		if (applyEndPatternLast == null) {
-			return false;
-		}
-		if (applyEndPatternLast instanceof Boolean) {
-			return (Boolean) applyEndPatternLast;
-		}
-		if (applyEndPatternLast instanceof Integer) {
-			return ((Integer) applyEndPatternLast).equals(1);
-		}
-		return false;
-	}
-
-	@Override
-	public void setApplyEndPatternLast(boolean applyEndPatternLast) {
-		super.put(APPLY_END_PATTERN_LAST, applyEndPatternLast);
-	}
-
-	@Override
-	public String getScopeName() {
-		return (String) super.get(SCOPE_NAME);
-	}
-
-	@Override
-	public Collection getFileTypes() {
-		if(fileTypes==null) {
-			List list=new ArrayList<>();
-			Collection unparsedFileTypes = (Collection) super.get(FILE_TYPES);
-			if (unparsedFileTypes != null) {
-				for(Object o: unparsedFileTypes) {
-					String str=o.toString();
-					// #202
-					if(str.startsWith(".")) {
-						str=str.substring(1);
-					}
-					list.add(str);
-				}
-			}
-			fileTypes=list;
-		}
-		return fileTypes;
-	}
-
-	@Override
-	public String getFirstLineMatch() {
-		return (String) super.get(FIRST_LINE_MATCH);
-	}
-
-	@Override
-	public IRawRule getCapture(String captureId) {
-		return getProp(captureId);
-	}
-
-	@Override
-	public Iterator iterator() {
-		return super.keySet().iterator();
-	}
-
-	@Override
-	public Object clone() {
-		return CloneUtils.clone(this);
-	}
-
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ *  Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes
+ */
+package org.eclipse.tm4e.core.internal.grammar.parser;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.tm4e.core.internal.types.IRawCaptures;
+import org.eclipse.tm4e.core.internal.types.IRawGrammar;
+import org.eclipse.tm4e.core.internal.types.IRawRepository;
+import org.eclipse.tm4e.core.internal.types.IRawRule;
+import org.eclipse.tm4e.core.internal.utils.CloneUtils;
+
+/**
+ * Raw
+ *
+ */
+public class Raw extends HashMap implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures {
+	private static final String FIRST_LINE_MATCH = "firstLineMatch";
+	private static final String FILE_TYPES = "fileTypes";
+	private static final String SCOPE_NAME = "scopeName";
+	private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast";
+	private static final String REPOSITORY = "repository";
+	private static final String INJECTION_SELECTOR = "injectionSelector";
+	private static final String INJECTIONS = "injections";
+	private static final String PATTERNS = "patterns";
+	private static final String WHILE_CAPTURES = "whileCaptures";
+	private static final String END_CAPTURES = "endCaptures";
+	private static final String INCLUDE = "include";
+	private static final String WHILE = "while";
+	private static final String END = "end";
+	private static final String BEGIN = "begin";
+	private static final String CAPTURES = "captures";
+	private static final String MATCH = "match";
+	private static final String BEGIN_CAPTURES = "beginCaptures";
+	private static final String CONTENT_NAME = "contentName";
+	private static final String NAME = "name";
+	private static final String ID = "id";
+	private static final String DOLLAR_SELF = "$self";
+	private static final String DOLLAR_BASE = "$base";
+	private static final long serialVersionUID = -2306714541728887963L;
+	private List fileTypes;
+
+	@Override
+	public IRawRule getProp(String name) {
+		return (IRawRule) super.get(name);
+	}
+
+	@Override
+	public IRawRule getBase() {
+		return (IRawRule) super.get(DOLLAR_BASE);
+	}
+
+	@Override
+	public void setBase(IRawRule base) {
+		super.put(DOLLAR_BASE, base);
+	}
+
+	@Override
+	public IRawRule getSelf() {
+		return (IRawRule) super.get(DOLLAR_SELF);
+	}
+
+	@Override
+	public void setSelf(IRawRule self) {
+		super.put(DOLLAR_SELF, self);
+	}
+
+	@Override
+	public Integer getId() {
+		return (Integer) super.get(ID);
+	}
+
+	@Override
+	public void setId(Integer id) {
+		super.put(ID, id);
+	}
+
+	@Override
+	public String getName() {
+		return (String) super.get(NAME);
+	}
+
+	@Override
+	public void setName(String name) {
+		super.put(NAME, name);
+	}
+
+	@Override
+	public String getContentName() {
+		return (String) super.get(CONTENT_NAME);
+	}
+
+	@Override
+	public void setContentName(String name) {
+		super.put(CONTENT_NAME, name);
+	}
+
+	@Override
+	public String getMatch() {
+		return (String) super.get(MATCH);
+	}
+
+	@Override
+	public void setMatch(String match) {
+		super.put(MATCH, match);
+	}
+
+	@Override
+	public IRawCaptures getCaptures() {
+		updateCaptures(CAPTURES);
+		return (IRawCaptures) super.get(CAPTURES);
+	}
+
+	private void updateCaptures(String name) {
+		Object captures = super.get(name);
+		if (captures instanceof List) {
+			Raw rawCaptures = new Raw();
+			int i = 0;
+			for (Object capture : (List) captures) {
+				i++;
+				rawCaptures.put(i + "", capture);
+			}
+			super.put(name, rawCaptures);
+		}
+	}
+
+	@Override
+	public void setCaptures(IRawCaptures captures) {
+		super.put(CAPTURES, captures);
+	}
+
+	@Override
+	public String getBegin() {
+		return (String) super.get(BEGIN);
+	}
+
+	@Override
+	public void setBegin(String begin) {
+		super.put(BEGIN, begin);
+	}
+
+	@Override
+	public String getWhile() {
+		return (String) super.get(WHILE);
+	}
+
+	@Override
+	public String getInclude() {
+		return (String) super.get(INCLUDE);
+	}
+
+	@Override
+	public void setInclude(String include) {
+		super.put(INCLUDE, include);
+	}
+
+	@Override
+	public IRawCaptures getBeginCaptures() {
+		updateCaptures(BEGIN_CAPTURES);
+		return (IRawCaptures) super.get(BEGIN_CAPTURES);
+	}
+
+	@Override
+	public void setBeginCaptures(IRawCaptures beginCaptures) {
+		super.put(BEGIN_CAPTURES, beginCaptures);
+	}
+
+	@Override
+	public String getEnd() {
+		return (String) super.get(END);
+	}
+
+	@Override
+	public void setEnd(String end) {
+		super.put(END, end);
+	}
+
+	@Override
+	public IRawCaptures getEndCaptures() {
+		updateCaptures(END_CAPTURES);
+		return (IRawCaptures) super.get(END_CAPTURES);
+	}
+
+	@Override
+	public void setEndCaptures(IRawCaptures endCaptures) {
+		super.put(END_CAPTURES, endCaptures);
+	}
+
+	@Override
+	public IRawCaptures getWhileCaptures() {
+		updateCaptures(WHILE_CAPTURES);
+		return (IRawCaptures) super.get(WHILE_CAPTURES);
+	}
+
+	@Override
+	public Collection getPatterns() {
+		return (Collection) super.get(PATTERNS);
+	}
+
+	@Override
+	public void setPatterns(Collection patterns) {
+		super.put(PATTERNS, patterns);
+	}
+
+	@Override
+	public Map getInjections() {
+		return (Map) super.get(INJECTIONS);
+	}
+
+	@Override
+	public String getInjectionSelector() {
+		return (String) super.get(INJECTION_SELECTOR);
+	}
+
+	@Override
+	public IRawRepository getRepository() {
+		return (IRawRepository) super.get(REPOSITORY);
+	}
+
+	@Override
+	public void setRepository(IRawRepository repository) {
+		super.put(REPOSITORY, repository);
+	}
+
+	@Override
+	public boolean isApplyEndPatternLast() {
+		Object applyEndPatternLast = super.get(APPLY_END_PATTERN_LAST);
+		if (applyEndPatternLast == null) {
+			return false;
+		}
+		if (applyEndPatternLast instanceof Boolean) {
+			return (Boolean) applyEndPatternLast;
+		}
+		if (applyEndPatternLast instanceof Integer) {
+			return ((Integer) applyEndPatternLast).equals(1);
+		}
+		return false;
+	}
+
+	@Override
+	public void setApplyEndPatternLast(boolean applyEndPatternLast) {
+		super.put(APPLY_END_PATTERN_LAST, applyEndPatternLast);
+	}
+
+	@Override
+	public String getScopeName() {
+		return (String) super.get(SCOPE_NAME);
+	}
+
+	@Override
+	public Collection getFileTypes() {
+		if(fileTypes==null) {
+			List list=new ArrayList<>();
+			Collection unparsedFileTypes = (Collection) super.get(FILE_TYPES);
+			if (unparsedFileTypes != null) {
+				for(Object o: unparsedFileTypes) {
+					String str=o.toString();
+					// #202
+					if(str.startsWith(".")) {
+						str=str.substring(1);
+					}
+					list.add(str);
+				}
+			}
+			fileTypes=list;
+		}
+		return fileTypes;
+	}
+
+	@Override
+	public String getFirstLineMatch() {
+		return (String) super.get(FIRST_LINE_MATCH);
+	}
+
+	@Override
+	public IRawRule getCapture(String captureId) {
+		return getProp(captureId);
+	}
+
+	@Override
+	public Iterator iterator() {
+		return super.keySet().iterator();
+	}
+
+	@Override
+	public Object clone() {
+		return CloneUtils.clone(this);
+	}
+
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java
index 897f086df..2d6027958 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java
@@ -13,19 +13,19 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.grammar.reader;
-
+ */
+package org.eclipse.tm4e.core.internal.grammar.reader;
+
 import java.io.InputStream;
 
 import org.eclipse.tm4e.core.internal.parser.json.JSONPListParser;
 import org.eclipse.tm4e.core.internal.parser.xml.XMLPListParser;
-import org.eclipse.tm4e.core.internal.types.IRawGrammar;
+import org.eclipse.tm4e.core.internal.types.IRawGrammar;
 
 /**
  * TextMate Grammar reader utilities.
  *
- */
+ */
 public class GrammarReader {
 
 	/**
@@ -33,7 +33,7 @@ public class GrammarReader {
 	 */
 	private GrammarReader() {
 
-	}
+	}
 
 	public static final IGrammarParser XML_PARSER = new IGrammarParser() {
 
@@ -54,16 +54,16 @@ public IRawGrammar parse(InputStream contents) throws Exception {
 			return parser.parse(contents);
 		}
 	};
-
-	public static IRawGrammar readGrammarSync(String filePath, InputStream in) throws Exception {
-		SyncGrammarReader reader = new SyncGrammarReader(in, getGrammarParser(filePath));
-		return reader.load();
-	}
-
-	private static IGrammarParser getGrammarParser(String filePath) {
-		if (filePath.endsWith(".json")) {
-			return JSON_PARSER;
-		}
-		return XML_PARSER;
-	}
-}
+
+	public static IRawGrammar readGrammarSync(String filePath, InputStream in) throws Exception {
+		SyncGrammarReader reader = new SyncGrammarReader(in, getGrammarParser(filePath));
+		return reader.load();
+	}
+
+	private static IGrammarParser getGrammarParser(String filePath) {
+		if (filePath.endsWith(".json")) {
+			return JSON_PARSER;
+		}
+		return XML_PARSER;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java
index 062f2e687..d22843f33 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java
@@ -13,24 +13,24 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.grammar.reader;
-
+ */
+package org.eclipse.tm4e.core.internal.grammar.reader;
+
 import java.io.InputStream;
 
-import org.eclipse.tm4e.core.internal.types.IRawGrammar;
-
-public class SyncGrammarReader {
-
-	private final InputStream in;
-	private final IGrammarParser parser;
-
-	SyncGrammarReader(InputStream in, IGrammarParser parser) {
-		this.in = in;
-		this.parser = parser;
-	}
-
-	public IRawGrammar load() throws Exception {
-		return this.parser.parse(in);
-	}
-}
+import org.eclipse.tm4e.core.internal.types.IRawGrammar;
+
+public class SyncGrammarReader {
+
+	private final InputStream in;
+	private final IGrammarParser parser;
+
+	SyncGrammarReader(InputStream in, IGrammarParser parser) {
+		this.in = in;
+		this.parser = parser;
+	}
+
+	public IRawGrammar load() throws Exception {
+		return this.parser.parse(in);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java
index 53ccaf243..1af543828 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java
@@ -13,12 +13,12 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.matcher;
-
-public interface IMatchInjectionsResult extends IMatchResult {
-
-	boolean isPriorityMatch();
-
-
-}
+ */
+package org.eclipse.tm4e.core.internal.matcher;
+
+public interface IMatchInjectionsResult extends IMatchResult {
+
+	boolean isPriorityMatch();
+
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java
index b5d9b8577..9d1ada41c 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java
@@ -13,15 +13,15 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.matcher;
-
-import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
-
-public interface IMatchResult {
-
-	IOnigCaptureIndex[] getCaptureIndices();
-
-	int getMatchedRuleId();
-
-}
+ */
+package org.eclipse.tm4e.core.internal.matcher;
+
+import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
+
+public interface IMatchResult {
+
+	IOnigCaptureIndex[] getCaptureIndices();
+
+	int getMatchedRuleId();
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java
index 4af84d724..2211cb0ee 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java
@@ -1,35 +1,35 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Initial code from https://github.com/Microsoft/vscode-textmate/
- * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved.
- * Initial license: MIT
- *
- * Contributors:
- *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
- *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.matcher;
-
-import java.util.function.Predicate;
-
-public class MatcherWithPriority {
-
-	public final Predicate matcher;
-	public final int priority;
-
-	/**
-	 * @param matcher
-	 * @param priority
-	 */
-	public MatcherWithPriority(Predicate matcher, int priority) {
-		this.matcher = matcher;
-		this.priority = priority;
-	}
-
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Initial code from https://github.com/Microsoft/vscode-textmate/
+ * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved.
+ * Initial license: MIT
+ *
+ * Contributors:
+ *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
+ *  - Angelo Zerr  - translation and adaptation to Java
+ */
+package org.eclipse.tm4e.core.internal.matcher;
+
+import java.util.function.Predicate;
+
+public class MatcherWithPriority {
+
+	public final Predicate matcher;
+	public final int priority;
+
+	/**
+	 * @param matcher
+	 * @param priority
+	 */
+	public MatcherWithPriority(Predicate matcher, int priority) {
+		this.matcher = matcher;
+		this.priority = priority;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java
index 3cb78c456..5012f5fb1 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java
@@ -14,16 +14,16 @@
  *  - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
  */
-package org.eclipse.tm4e.core.internal.oniguruma;
-
-public interface IOnigCaptureIndex {
-
-	int getIndex();
-	
-	int getStart();
-
-	int getEnd();
-
-	int getLength();
-	
-}
+package org.eclipse.tm4e.core.internal.oniguruma;
+
+public interface IOnigCaptureIndex {
+
+	int getIndex();
+	
+	int getStart();
+
+	int getEnd();
+
+	int getLength();
+	
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java
index d2ab77906..be56fb86c 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java
@@ -14,12 +14,12 @@
  *  - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
  */
- 
-package org.eclipse.tm4e.core.internal.oniguruma;
-
-public interface IOnigNextMatchResult {
-
-	int getIndex();
-
-	IOnigCaptureIndex[] getCaptureIndices();
-}
+ 
+package org.eclipse.tm4e.core.internal.oniguruma;
+
+public interface IOnigNextMatchResult {
+
+	int getIndex();
+
+	IOnigCaptureIndex[] getCaptureIndices();
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java
index e028bd2ec..9e5c7d3cb 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java
@@ -1,122 +1,122 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Initial code from https://github.com/atom/node-oniguruma
- * Initial copyright Copyright (c) 2013 GitHub Inc.
- * Initial license: MIT
- *
- * Contributors:
- *  - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license
- *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.oniguruma;
-
-class OnigNextMatchResult implements IOnigNextMatchResult {
-
-	private final int index;
-
-	private final IOnigCaptureIndex[] captureIndices;
-
-	public OnigNextMatchResult(OnigResult result, OnigString source) {
-		this.index = result.getIndex();
-		this.captureIndices = captureIndicesForMatch(result, source);
-	}
-
-	@Override
-	public int getIndex() {
-		return index;
-	}
-
-	@Override
-	public IOnigCaptureIndex[] getCaptureIndices() {
-		return captureIndices;
-	}
-
-	@Override
-	public String toString() {
-		StringBuilder result = new StringBuilder();
-		result.append("{\n");
-		result.append("  \"index\": ");
-		result.append(getIndex());
-		result.append(",\n");
-		result.append("  \"captureIndices\": [\n");
-		int i = 0;
-		for (IOnigCaptureIndex captureIndex : getCaptureIndices()) {
-			if (i > 0) {
-				result.append(",\n");
-			}
-			result.append("    ");
-			result.append(captureIndex);
-			i++;
-		}
-		result.append("\n");
-		result.append("  ]\n");
-		result.append("}");
-		return result.toString();
-	}
-
-	private static IOnigCaptureIndex[] captureIndicesForMatch(OnigResult result, OnigString source) {
-		int resultCount = result.count();
-		IOnigCaptureIndex[] captures = new IOnigCaptureIndex[resultCount];
-		for (int index = 0; index < resultCount; index++) {
-			int captureStart = source.convertUtf8OffsetToUtf16(result.locationAt(index));
-			int captureEnd = source.convertUtf8OffsetToUtf16(result.locationAt(index) + result.lengthAt(index));
-			captures[index] = new OnigCaptureIndex(index, captureStart, captureEnd);
-		}
-		return captures;
-	}
-
-	private static class OnigCaptureIndex implements IOnigCaptureIndex {
-
-		private final int index;
-		private final int start;
-		private final int end;
-
-		public OnigCaptureIndex(int index, int start, int end) {
-			this.index = index;
-			this.start = start >= 0 ? start : 0;
-			this.end = end >= 0 ? end : 0;
-		}
-
-		@Override
-		public int getIndex() {
-			return index;
-		}
-
-		@Override
-		public int getStart() {
-			return start;
-		}
-
-		@Override
-		public int getEnd() {
-			return end;
-		}
-
-		@Override
-		public int getLength() {
-			return end - start;
-		}
-
-		@Override
-		public String toString() {
-			StringBuilder result = new StringBuilder();
-			result.append("{\"index\": ");
-			result.append(getIndex());
-			result.append(", \"start\": ");
-			result.append(getStart());
-			result.append(", \"end\": ");
-			result.append(getEnd());
-			result.append(", \"length\": ");
-			result.append(getLength());
-			result.append("}");
-			return result.toString();
-		}
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Initial code from https://github.com/atom/node-oniguruma
+ * Initial copyright Copyright (c) 2013 GitHub Inc.
+ * Initial license: MIT
+ *
+ * Contributors:
+ *  - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license
+ *  - Angelo Zerr  - translation and adaptation to Java
+ */
+package org.eclipse.tm4e.core.internal.oniguruma;
+
+class OnigNextMatchResult implements IOnigNextMatchResult {
+
+	private final int index;
+
+	private final IOnigCaptureIndex[] captureIndices;
+
+	public OnigNextMatchResult(OnigResult result, OnigString source) {
+		this.index = result.getIndex();
+		this.captureIndices = captureIndicesForMatch(result, source);
+	}
+
+	@Override
+	public int getIndex() {
+		return index;
+	}
+
+	@Override
+	public IOnigCaptureIndex[] getCaptureIndices() {
+		return captureIndices;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder result = new StringBuilder();
+		result.append("{\n");
+		result.append("  \"index\": ");
+		result.append(getIndex());
+		result.append(",\n");
+		result.append("  \"captureIndices\": [\n");
+		int i = 0;
+		for (IOnigCaptureIndex captureIndex : getCaptureIndices()) {
+			if (i > 0) {
+				result.append(",\n");
+			}
+			result.append("    ");
+			result.append(captureIndex);
+			i++;
+		}
+		result.append("\n");
+		result.append("  ]\n");
+		result.append("}");
+		return result.toString();
+	}
+
+	private static IOnigCaptureIndex[] captureIndicesForMatch(OnigResult result, OnigString source) {
+		int resultCount = result.count();
+		IOnigCaptureIndex[] captures = new IOnigCaptureIndex[resultCount];
+		for (int index = 0; index < resultCount; index++) {
+			int captureStart = source.convertUtf8OffsetToUtf16(result.locationAt(index));
+			int captureEnd = source.convertUtf8OffsetToUtf16(result.locationAt(index) + result.lengthAt(index));
+			captures[index] = new OnigCaptureIndex(index, captureStart, captureEnd);
+		}
+		return captures;
+	}
+
+	private static class OnigCaptureIndex implements IOnigCaptureIndex {
+
+		private final int index;
+		private final int start;
+		private final int end;
+
+		public OnigCaptureIndex(int index, int start, int end) {
+			this.index = index;
+			this.start = start >= 0 ? start : 0;
+			this.end = end >= 0 ? end : 0;
+		}
+
+		@Override
+		public int getIndex() {
+			return index;
+		}
+
+		@Override
+		public int getStart() {
+			return start;
+		}
+
+		@Override
+		public int getEnd() {
+			return end;
+		}
+
+		@Override
+		public int getLength() {
+			return end - start;
+		}
+
+		@Override
+		public String toString() {
+			StringBuilder result = new StringBuilder();
+			result.append("{\"index\": ");
+			result.append(getIndex());
+			result.append(", \"start\": ");
+			result.append(getStart());
+			result.append(", \"end\": ");
+			result.append(getEnd());
+			result.append(", \"length\": ");
+			result.append(getLength());
+			result.append("}");
+			return result.toString();
+		}
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java
index e0a845665..cbbcd4dbd 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java
@@ -14,46 +14,46 @@
  *  - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
  */
-
-package org.eclipse.tm4e.core.internal.oniguruma;
-
+
+package org.eclipse.tm4e.core.internal.oniguruma;
+
 import java.util.Arrays;
 import java.util.List;
-import java.util.stream.Collectors;
-
-public class OnigSearcher {
-
-	private final List regExps;
-
-	public OnigSearcher(String[] regexps) {
-		this.regExps = Arrays.stream(regexps).map(OnigRegExp::new).collect(Collectors.toList());
-	}
-
-	public OnigResult search(OnigString source, int charOffset) {
-		int byteOffset = source.convertUtf16OffsetToUtf8(charOffset);
-
-		int bestLocation = 0;
-		OnigResult bestResult = null;
-		int index = 0;
-
-		for (OnigRegExp regExp : regExps) {
-			OnigResult result = regExp.search(source, byteOffset);
-			if (result != null && result.count() > 0) {
-				int location = result.locationAt(0);
-
-				if (bestResult == null || location < bestLocation) {
-					bestLocation = location;
-					bestResult = result;
-					bestResult.setIndex(index);
-				}
-
-				if (location == byteOffset) {
-					break;
-				}
-			}
-			index++;
-		}
-		return bestResult;
-	}
-
-}
+import java.util.stream.Collectors;
+
+public class OnigSearcher {
+
+	private final List regExps;
+
+	public OnigSearcher(String[] regexps) {
+		this.regExps = Arrays.stream(regexps).map(OnigRegExp::new).collect(Collectors.toList());
+	}
+
+	public OnigResult search(OnigString source, int charOffset) {
+		int byteOffset = source.convertUtf16OffsetToUtf8(charOffset);
+
+		int bestLocation = 0;
+		OnigResult bestResult = null;
+		int index = 0;
+
+		for (OnigRegExp regExp : regExps) {
+			OnigResult result = regExp.search(source, byteOffset);
+			if (result != null && result.count() > 0) {
+				int location = result.locationAt(0);
+
+				if (bestResult == null || location < bestLocation) {
+					bestLocation = location;
+					bestResult = result;
+					bestResult.setIndex(index);
+				}
+
+				if (location == byteOffset) {
+					break;
+				}
+			}
+			index++;
+		}
+		return bestResult;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java
index 273893144..8732e8cfb 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java
@@ -1,132 +1,132 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tm4e.core.internal.grammar.parser.PListGrammar;
-import org.eclipse.tm4e.core.internal.theme.PListTheme;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-public class PList extends DefaultHandler {
-
-	private final boolean theme;
-	private final List errors;
-	private PListObject currObject;
-	private T result;
-	private StringBuilder text;
-
-	public PList(boolean theme) {
-		this.theme = theme;
-		this.errors = new ArrayList<>();
-		this.currObject = null;
-	}
-
-	@Override
-	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
-		if ("dict".equals(localName)) {
-			this.currObject = create(currObject, false);
-		} else if ("array".equals(localName)) {
-			this.currObject = create(currObject, true);
-		} else if ("key".equals(localName)) {
-			if (currObject != null) {
-				currObject.setLastKey(null);
-			}
-		}
-		this.text = new StringBuilder("");
-		super.startElement(uri, localName, qName, attributes);
-	}
-
-	private PListObject create(PListObject parent, boolean valueAsArray) {
-		if (theme) {
-			return new PListTheme(parent, valueAsArray);
-		}
-		return new PListGrammar(parent, valueAsArray);
-	}
-
-	@Override
-	public void endElement(String uri, String localName, String qName) throws SAXException {
-		endElement(localName);
-		super.endElement(uri, localName, qName);
-	}
-
-	private void endElement(String tagName) {
-		Object value = null;
-		String text = this.text.toString();
-		if ("key".equals(tagName)) {
-			if (currObject == null || currObject.isValueAsArray()) {
-				errors.add("key can only be used inside an open dict element");
-				return;
-			}
-			currObject.setLastKey(text);
-			return;
-		} else if ("dict".equals(tagName) || "array".equals(tagName)) {
-			if (currObject == null) {
-				errors.add(tagName + " closing tag found, without opening tag");
-				return;
-			}
-			value = currObject.getValue();
-			currObject = currObject.parent;
-		} else if ("string".equals(tagName) || "data".equals(tagName)) {
-			value = text;
-		} else if ("date".equals(tagName)) {
-			// TODO : parse date
-		} else if ("integer".equals(tagName)) {
-			try {
-				value = Integer.parseInt(text);
-			} catch (NumberFormatException e) {
-				errors.add(text + " is not a integer");
-				return;
-			}
-		} else if ("real".equals(tagName)) {
-			try {
-				value = Float.parseFloat(text);
-			} catch (NumberFormatException e) {
-				errors.add(text + " is not a float");
-				return;
-			}
-		} else if ("true".equals(tagName)) {
-			value = true;
-		} else if ("false".equals(tagName)) {
-			value = false;
-		} else if ("plist".equals(tagName)) {
-			return;
-		} else {
-			errors.add("Invalid tag name: " + tagName);
-			return;
-		}
-		if (currObject == null) {
-			result = (T) value;
-		} else if (currObject.isValueAsArray()) {
-			currObject.addValue(value);
-		} else {
-			if (currObject.getLastKey() != null) {
-				currObject.addValue(value);
-			} else {
-				errors.add("Dictionary key missing for value " + value);
-			}
-		}
-	}
-
-	@Override
-	public void characters(char[] ch, int start, int length) throws SAXException {
-		this.text.append(String.valueOf(ch, start, length));
-		super.characters(ch, start, length);
-	}
-
-	public T getResult() {
-		return result;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tm4e.core.internal.grammar.parser.PListGrammar;
+import org.eclipse.tm4e.core.internal.theme.PListTheme;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class PList extends DefaultHandler {
+
+	private final boolean theme;
+	private final List errors;
+	private PListObject currObject;
+	private T result;
+	private StringBuilder text;
+
+	public PList(boolean theme) {
+		this.theme = theme;
+		this.errors = new ArrayList<>();
+		this.currObject = null;
+	}
+
+	@Override
+	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+		if ("dict".equals(localName)) {
+			this.currObject = create(currObject, false);
+		} else if ("array".equals(localName)) {
+			this.currObject = create(currObject, true);
+		} else if ("key".equals(localName)) {
+			if (currObject != null) {
+				currObject.setLastKey(null);
+			}
+		}
+		this.text = new StringBuilder("");
+		super.startElement(uri, localName, qName, attributes);
+	}
+
+	private PListObject create(PListObject parent, boolean valueAsArray) {
+		if (theme) {
+			return new PListTheme(parent, valueAsArray);
+		}
+		return new PListGrammar(parent, valueAsArray);
+	}
+
+	@Override
+	public void endElement(String uri, String localName, String qName) throws SAXException {
+		endElement(localName);
+		super.endElement(uri, localName, qName);
+	}
+
+	private void endElement(String tagName) {
+		Object value = null;
+		String text = this.text.toString();
+		if ("key".equals(tagName)) {
+			if (currObject == null || currObject.isValueAsArray()) {
+				errors.add("key can only be used inside an open dict element");
+				return;
+			}
+			currObject.setLastKey(text);
+			return;
+		} else if ("dict".equals(tagName) || "array".equals(tagName)) {
+			if (currObject == null) {
+				errors.add(tagName + " closing tag found, without opening tag");
+				return;
+			}
+			value = currObject.getValue();
+			currObject = currObject.parent;
+		} else if ("string".equals(tagName) || "data".equals(tagName)) {
+			value = text;
+		} else if ("date".equals(tagName)) {
+			// TODO : parse date
+		} else if ("integer".equals(tagName)) {
+			try {
+				value = Integer.parseInt(text);
+			} catch (NumberFormatException e) {
+				errors.add(text + " is not a integer");
+				return;
+			}
+		} else if ("real".equals(tagName)) {
+			try {
+				value = Float.parseFloat(text);
+			} catch (NumberFormatException e) {
+				errors.add(text + " is not a float");
+				return;
+			}
+		} else if ("true".equals(tagName)) {
+			value = true;
+		} else if ("false".equals(tagName)) {
+			value = false;
+		} else if ("plist".equals(tagName)) {
+			return;
+		} else {
+			errors.add("Invalid tag name: " + tagName);
+			return;
+		}
+		if (currObject == null) {
+			result = (T) value;
+		} else if (currObject.isValueAsArray()) {
+			currObject.addValue(value);
+		} else {
+			if (currObject.getLastKey() != null) {
+				currObject.addValue(value);
+			} else {
+				errors.add("Dictionary key missing for value " + value);
+			}
+		}
+	}
+
+	@Override
+	public void characters(char[] ch, int start, int length) throws SAXException {
+		this.text.append(String.valueOf(ch, start, length));
+		super.characters(ch, start, length);
+	}
+
+	public T getResult() {
+		return result;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java
index 8b21b83a2..b35f26f39 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java
@@ -1,65 +1,65 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public abstract class PListObject {
-
-	public final PListObject parent;
-	private final List arrayValues;
-	private final Map mapValues;
-
-	private String lastKey;
-
-	public PListObject(PListObject parent, boolean valueAsArray) {
-		this.parent = parent;
-		if (valueAsArray) {
-			this.arrayValues = new ArrayList<>();
-			this.mapValues = null;
-		} else {
-			this.arrayValues = null;
-			this.mapValues = createRaw();
-		}
-	}
-
-	public String getLastKey() {
-		return lastKey;
-	}
-
-	public void setLastKey(String lastKey) {
-		this.lastKey = lastKey;
-	}
-
-	public void addValue(Object value) {
-		if (isValueAsArray()) {
-			arrayValues.add(value);
-		} else {
-			mapValues.put(getLastKey(), value);
-		}
-	}
-
-	public boolean isValueAsArray() {
-		return arrayValues != null;
-	}
-
-	public Object getValue() {
-		if (isValueAsArray()) {
-			return arrayValues;
-		}
-		return mapValues;
-	}
-
-	protected abstract Map createRaw();
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public abstract class PListObject {
+
+	public final PListObject parent;
+	private final List arrayValues;
+	private final Map mapValues;
+
+	private String lastKey;
+
+	public PListObject(PListObject parent, boolean valueAsArray) {
+		this.parent = parent;
+		if (valueAsArray) {
+			this.arrayValues = new ArrayList<>();
+			this.mapValues = null;
+		} else {
+			this.arrayValues = null;
+			this.mapValues = createRaw();
+		}
+	}
+
+	public String getLastKey() {
+		return lastKey;
+	}
+
+	public void setLastKey(String lastKey) {
+		this.lastKey = lastKey;
+	}
+
+	public void addValue(Object value) {
+		if (isValueAsArray()) {
+			arrayValues.add(value);
+		} else {
+			mapValues.put(getLastKey(), value);
+		}
+	}
+
+	public boolean isValueAsArray() {
+		return arrayValues != null;
+	}
+
+	public Object getValue() {
+		if (isValueAsArray()) {
+			return arrayValues;
+		}
+		return mapValues;
+	}
+
+	protected abstract Map createRaw();
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java
index 05fb5ae92..9126bbdb6 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java
@@ -1,87 +1,87 @@
-/**
- *  Copyright (c) 2015-2018 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2018 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.parser.json;
-
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-
-import org.eclipse.tm4e.core.internal.parser.PList;
-
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonToken;
-
-public class JSONPListParser {
-
-	private final boolean theme;
-
-	public JSONPListParser(boolean theme) {
-		this.theme = theme;
-	}
-
-	public T parse(InputStream contents) throws Exception {
-		PList pList = new PList<>(theme);
-		JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8));
-		// reader.setLenient(true);
-		boolean parsing = true;
-		while (parsing) {
-			JsonToken nextToken = reader.peek();
-			switch (nextToken) {
-			case BEGIN_ARRAY:
-				pList.startElement(null, "array", null, null);
-				reader.beginArray();
-				break;
-			case END_ARRAY:
-				pList.endElement(null, "array", null);
-				reader.endArray();
-				break;
-			case BEGIN_OBJECT:
-				pList.startElement(null, "dict", null, null);
-				reader.beginObject();
-				break;
-			case END_OBJECT:
-				pList.endElement(null, "dict", null);
-				reader.endObject();
-				break;
-			case NAME:
-				String lastName = reader.nextName();
-				pList.startElement(null, "key", null, null);
-				pList.characters(lastName.toCharArray(), 0, lastName.length());
-				pList.endElement(null, "key", null);
-				break;
-			case NULL:
-				reader.nextNull();
-				break;
-			case BOOLEAN:
-				reader.nextBoolean();
-				break;
-			case NUMBER:
-				reader.nextLong();
-				break;
-			case STRING:
-				String value = reader.nextString();
-				pList.startElement(null, "string", null, null);
-				pList.characters(value.toCharArray(), 0, value.length());
-				pList.endElement(null, "string", null);
-				break;
-			case END_DOCUMENT:
-				parsing = false;
-				break;
-			default:
-				break;
-			}
-		}
-		reader.close();
-		return pList.getResult();
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.parser.json;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+
+import org.eclipse.tm4e.core.internal.parser.PList;
+
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+
+public class JSONPListParser {
+
+	private final boolean theme;
+
+	public JSONPListParser(boolean theme) {
+		this.theme = theme;
+	}
+
+	public T parse(InputStream contents) throws Exception {
+		PList pList = new PList<>(theme);
+		JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8));
+		// reader.setLenient(true);
+		boolean parsing = true;
+		while (parsing) {
+			JsonToken nextToken = reader.peek();
+			switch (nextToken) {
+			case BEGIN_ARRAY:
+				pList.startElement(null, "array", null, null);
+				reader.beginArray();
+				break;
+			case END_ARRAY:
+				pList.endElement(null, "array", null);
+				reader.endArray();
+				break;
+			case BEGIN_OBJECT:
+				pList.startElement(null, "dict", null, null);
+				reader.beginObject();
+				break;
+			case END_OBJECT:
+				pList.endElement(null, "dict", null);
+				reader.endObject();
+				break;
+			case NAME:
+				String lastName = reader.nextName();
+				pList.startElement(null, "key", null, null);
+				pList.characters(lastName.toCharArray(), 0, lastName.length());
+				pList.endElement(null, "key", null);
+				break;
+			case NULL:
+				reader.nextNull();
+				break;
+			case BOOLEAN:
+				reader.nextBoolean();
+				break;
+			case NUMBER:
+				reader.nextLong();
+				break;
+			case STRING:
+				String value = reader.nextString();
+				pList.startElement(null, "string", null, null);
+				pList.characters(value.toCharArray(), 0, value.length());
+				pList.endElement(null, "string", null);
+				break;
+			case END_DOCUMENT:
+				parsing = false;
+				break;
+			default:
+				break;
+			}
+		}
+		reader.close();
+		return pList.getResult();
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java
index c54b9926b..4503ea0cd 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java
@@ -1,43 +1,43 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.parser.xml;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.eclipse.tm4e.core.internal.parser.PList;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
-public class XMLPListParser {
-
-	private final boolean theme;
-
-	public XMLPListParser(boolean theme) {
-		this.theme = theme;
-	}
-
-	public T parse(InputStream contents) throws Exception {
-		SAXParserFactory spf = SAXParserFactory.newInstance();
-		spf.setNamespaceAware(true);
-		SAXParser saxParser = spf.newSAXParser();
-		XMLReader xmlReader = saxParser.getXMLReader();
-		xmlReader.setEntityResolver((arg0, arg1) -> new InputSource(new ByteArrayInputStream("".getBytes())));
-		PList result = new PList<>(theme);
-		xmlReader.setContentHandler(result);
-		xmlReader.parse(new InputSource(contents));
-		return result.getResult();
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.parser.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.eclipse.tm4e.core.internal.parser.PList;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+public class XMLPListParser {
+
+	private final boolean theme;
+
+	public XMLPListParser(boolean theme) {
+		this.theme = theme;
+	}
+
+	public T parse(InputStream contents) throws Exception {
+		SAXParserFactory spf = SAXParserFactory.newInstance();
+		spf.setNamespaceAware(true);
+		SAXParser saxParser = spf.newSAXParser();
+		XMLReader xmlReader = saxParser.getXMLReader();
+		xmlReader.setEntityResolver((arg0, arg1) -> new InputSource(new ByteArrayInputStream("".getBytes())));
+		PList result = new PList<>(theme);
+		xmlReader.setContentHandler(result);
+		xmlReader.parse(new InputSource(contents));
+		return result.getResult();
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java
index 83ea384f1..d89bf5a24 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java
@@ -13,81 +13,81 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
 import java.util.List;
 
-import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
-
-public class BeginEndRule extends Rule {
-
-	private final RegExpSource begin;
-	public List beginCaptures;
-	private final RegExpSource end;
-	public boolean endHasBackReferences;
-	public List endCaptures;
-	public boolean applyEndPatternLast;
-	public final boolean hasMissingPatterns;
-	public Integer[] patterns;
-	private RegExpSourceList cachedCompiledPatterns;
-
-	public BeginEndRule(int id, String name, String contentName, String begin, List beginCaptures,
-			String end, List endCaptures, boolean applyEndPatternLast, ICompilePatternsResult patterns) {
-		super(id, name, contentName);
-		this.begin = new RegExpSource(begin, this.id);
-		this.beginCaptures = beginCaptures;
-		this.end = new RegExpSource(end, -1);
-		this.endHasBackReferences = this.end.hasBackReferences();
-		this.endCaptures = endCaptures;
-		this.applyEndPatternLast = applyEndPatternLast;
-		this.patterns = patterns.patterns;
-		this.hasMissingPatterns = patterns.hasMissingPatterns;
-		this.cachedCompiledPatterns = null;
-	}
-
-	public String getEndWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) {
-		return this.end.resolveBackReferences(lineText, captureIndices);
-	}
-
+import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
+
+public class BeginEndRule extends Rule {
+
+	private final RegExpSource begin;
+	public List beginCaptures;
+	private final RegExpSource end;
+	public boolean endHasBackReferences;
+	public List endCaptures;
+	public boolean applyEndPatternLast;
+	public final boolean hasMissingPatterns;
+	public Integer[] patterns;
+	private RegExpSourceList cachedCompiledPatterns;
+
+	public BeginEndRule(int id, String name, String contentName, String begin, List beginCaptures,
+			String end, List endCaptures, boolean applyEndPatternLast, ICompilePatternsResult patterns) {
+		super(id, name, contentName);
+		this.begin = new RegExpSource(begin, this.id);
+		this.beginCaptures = beginCaptures;
+		this.end = new RegExpSource(end, -1);
+		this.endHasBackReferences = this.end.hasBackReferences();
+		this.endCaptures = endCaptures;
+		this.applyEndPatternLast = applyEndPatternLast;
+		this.patterns = patterns.patterns;
+		this.hasMissingPatterns = patterns.hasMissingPatterns;
+		this.cachedCompiledPatterns = null;
+	}
+
+	public String getEndWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) {
+		return this.end.resolveBackReferences(lineText, captureIndices);
+	}
+
 	@Override
-	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
-		if (isFirst) {
+	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
+		if (isFirst) {
 			for (Integer pattern : this.patterns) {
-				Rule rule = grammar.getRule(pattern);
-				rule.collectPatternsRecursive(grammar, out, false);
-			}
-		} else {
-			out.push(this.begin);
-		}
-	}
-
+				Rule rule = grammar.getRule(pattern);
+				rule.collectPatternsRecursive(grammar, out, false);
+			}
+		} else {
+			out.push(this.begin);
+		}
+	}
+
 	@Override
-	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
-		RegExpSourceList precompiled = this.precompile(grammar);
-		if (this.end.hasBackReferences()) {
-			if (this.applyEndPatternLast) {
-				precompiled.setSource(precompiled.length() - 1, endRegexSource);
-			} else {
-				precompiled.setSource(0, endRegexSource);
-			}
-		}
-		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
-	}
-
-	private RegExpSourceList precompile(IRuleRegistry grammar) {
-		if (this.cachedCompiledPatterns == null) {
-			this.cachedCompiledPatterns = new RegExpSourceList();
-
-			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
-
-			if (this.applyEndPatternLast) {
-				this.cachedCompiledPatterns.push(this.end.hasBackReferences() ? this.end.clone() : this.end);
-			} else {
-				this.cachedCompiledPatterns.unshift(this.end.hasBackReferences() ? this.end.clone() : this.end);
-			}
-		}
-		return this.cachedCompiledPatterns;
-	}
-
-}
+	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
+		RegExpSourceList precompiled = this.precompile(grammar);
+		if (this.end.hasBackReferences()) {
+			if (this.applyEndPatternLast) {
+				precompiled.setSource(precompiled.length() - 1, endRegexSource);
+			} else {
+				precompiled.setSource(0, endRegexSource);
+			}
+		}
+		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
+	}
+
+	private RegExpSourceList precompile(IRuleRegistry grammar) {
+		if (this.cachedCompiledPatterns == null) {
+			this.cachedCompiledPatterns = new RegExpSourceList();
+
+			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
+
+			if (this.applyEndPatternLast) {
+				this.cachedCompiledPatterns.push(this.end.hasBackReferences() ? this.end.clone() : this.end);
+			} else {
+				this.cachedCompiledPatterns.unshift(this.end.hasBackReferences() ? this.end.clone() : this.end);
+			}
+		}
+		return this.cachedCompiledPatterns;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java
index 947e50ddc..f602717e2 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java
@@ -13,83 +13,83 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
 import java.util.List;
 
-import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
-
-public class BeginWhileRule extends Rule {
-
-	private final RegExpSource begin;
-	public final List beginCaptures;
-	public final List whileCaptures;
-	private final RegExpSource _while;
-	public final boolean whileHasBackReferences;
-	public final boolean hasMissingPatterns;
-	public final Integer[] patterns;
-	private RegExpSourceList cachedCompiledPatterns;
-	private RegExpSourceList cachedCompiledWhilePatterns;
-
-	public BeginWhileRule(/* $location:ILocation, */ int id, String name, String contentName, String begin,
-			List beginCaptures, String _while, List whileCaptures,
-			ICompilePatternsResult patterns) {
-		super(/* $location, */id, name, contentName);
-		this.begin = new RegExpSource(begin, this.id);
-		this.beginCaptures = beginCaptures;
-		this.whileCaptures = whileCaptures;
-		this._while = new RegExpSource(_while, -2);
-		this.whileHasBackReferences = this._while.hasBackReferences();
-		this.patterns = patterns.patterns;
-		this.hasMissingPatterns = patterns.hasMissingPatterns;
-		this.cachedCompiledPatterns = null;
-		this.cachedCompiledWhilePatterns = null;
-	}
-
-	public String getWhileWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) {
-		return this._while.resolveBackReferences(lineText, captureIndices);
-	}
-
+import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
+
+public class BeginWhileRule extends Rule {
+
+	private final RegExpSource begin;
+	public final List beginCaptures;
+	public final List whileCaptures;
+	private final RegExpSource _while;
+	public final boolean whileHasBackReferences;
+	public final boolean hasMissingPatterns;
+	public final Integer[] patterns;
+	private RegExpSourceList cachedCompiledPatterns;
+	private RegExpSourceList cachedCompiledWhilePatterns;
+
+	public BeginWhileRule(/* $location:ILocation, */ int id, String name, String contentName, String begin,
+			List beginCaptures, String _while, List whileCaptures,
+			ICompilePatternsResult patterns) {
+		super(/* $location, */id, name, contentName);
+		this.begin = new RegExpSource(begin, this.id);
+		this.beginCaptures = beginCaptures;
+		this.whileCaptures = whileCaptures;
+		this._while = new RegExpSource(_while, -2);
+		this.whileHasBackReferences = this._while.hasBackReferences();
+		this.patterns = patterns.patterns;
+		this.hasMissingPatterns = patterns.hasMissingPatterns;
+		this.cachedCompiledPatterns = null;
+		this.cachedCompiledWhilePatterns = null;
+	}
+
+	public String getWhileWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) {
+		return this._while.resolveBackReferences(lineText, captureIndices);
+	}
+
 	@Override
-	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
-		if (isFirst) {
-			Rule rule;
-			for (Integer pattern : patterns) {
-				rule = grammar.getRule(pattern);
-				rule.collectPatternsRecursive(grammar, out, false);
-			}
-		} else {
-			out.push(this.begin);
-		}
-	}
-
+	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
+		if (isFirst) {
+			Rule rule;
+			for (Integer pattern : patterns) {
+				rule = grammar.getRule(pattern);
+				rule.collectPatternsRecursive(grammar, out, false);
+			}
+		} else {
+			out.push(this.begin);
+		}
+	}
+
 	@Override
-	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
-		this.precompile(grammar);
-		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
-	}
-
-	private void precompile(IRuleRegistry grammar) {
-		if (this.cachedCompiledPatterns == null) {
-			this.cachedCompiledPatterns = new RegExpSourceList();
-			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
-		}
-	}
-
-	public ICompiledRule compileWhile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
-		this.precompileWhile();
-		if (this._while.hasBackReferences()) {
-			this.cachedCompiledWhilePatterns.setSource(0, endRegexSource);
-		}
-		return this.cachedCompiledWhilePatterns.compile(grammar, allowA, allowG);
-	}
-
-	private void precompileWhile() {
-		if (this.cachedCompiledWhilePatterns == null) {
-			this.cachedCompiledWhilePatterns = new RegExpSourceList();
-			this.cachedCompiledWhilePatterns.push(this._while.hasBackReferences() ? this._while.clone() : this._while);
-		}
-	}
-
-}
+	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
+		this.precompile(grammar);
+		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
+	}
+
+	private void precompile(IRuleRegistry grammar) {
+		if (this.cachedCompiledPatterns == null) {
+			this.cachedCompiledPatterns = new RegExpSourceList();
+			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
+		}
+	}
+
+	public ICompiledRule compileWhile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
+		this.precompileWhile();
+		if (this._while.hasBackReferences()) {
+			this.cachedCompiledWhilePatterns.setSource(0, endRegexSource);
+		}
+		return this.cachedCompiledWhilePatterns.compile(grammar, allowA, allowG);
+	}
+
+	private void precompileWhile() {
+		if (this.cachedCompiledWhilePatterns == null) {
+			this.cachedCompiledWhilePatterns = new RegExpSourceList();
+			this.cachedCompiledWhilePatterns.push(this._while.hasBackReferences() ? this._while.clone() : this._while);
+		}
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java
index 6ab5aed9b..c98c39560 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java
@@ -13,16 +13,16 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-public class CaptureRule extends Rule {
-
-	public final Integer retokenizeCapturedWithRuleId;
-
-	public CaptureRule(int id, String name, String contentName, Integer retokenizeCapturedWithRuleId) {
-		super(id, name, contentName);
-		this.retokenizeCapturedWithRuleId = retokenizeCapturedWithRuleId;
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+public class CaptureRule extends Rule {
+
+	public final Integer retokenizeCapturedWithRuleId;
+
+	public CaptureRule(int id, String name, String contentName, Integer retokenizeCapturedWithRuleId) {
+		super(id, name, contentName);
+		this.retokenizeCapturedWithRuleId = retokenizeCapturedWithRuleId;
 	}
 
 	@Override public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
@@ -31,6 +31,6 @@ public CaptureRule(int id, String name, String contentName, Integer retokenizeCa
 
 	@Override public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
 		throw new UnsupportedOperationException();
-	}
-
-}
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java
index 3917a3c7b..3b5fa2b39 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java
@@ -13,19 +13,19 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-import java.util.Collection;
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+import java.util.Collection;
+
 public class ICompilePatternsResult {
 
 	public final Integer[] patterns;
-	public final boolean hasMissingPatterns;
-
-	public ICompilePatternsResult(Collection patterns, boolean hasMissingPatterns) {
-		this.hasMissingPatterns = hasMissingPatterns;
-		this.patterns = patterns.toArray(new Integer[patterns.size()]);
-	}
-
-}
+	public final boolean hasMissingPatterns;
+
+	public ICompilePatternsResult(Collection patterns, boolean hasMissingPatterns) {
+		this.hasMissingPatterns = hasMissingPatterns;
+		this.patterns = patterns.toArray(new Integer[patterns.size()]);
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java
index b0fe90472..393325cdf 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java
@@ -13,18 +13,18 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner;
-
-public class ICompiledRule {
-
-	public final OnigScanner scanner;
-	public final Integer[] rules;
-
-	public ICompiledRule(OnigScanner scanner, Integer[] rules) {
-		this.scanner = scanner;
-		this.rules = rules;
-	}
-}
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner;
+
+public class ICompiledRule {
+
+	public final OnigScanner scanner;
+	public final Integer[] rules;
+
+	public ICompiledRule(OnigScanner scanner, Integer[] rules) {
+		this.scanner = scanner;
+		this.rules = rules;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java
index edcdd10a5..924fe071f 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java
@@ -13,13 +13,13 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-import org.eclipse.tm4e.core.internal.types.IRawGrammar;
-import org.eclipse.tm4e.core.internal.types.IRawRepository;
-
-public interface IGrammarRegistry {
-
-	IRawGrammar getExternalGrammar(String scopeName, IRawRepository repository);
-}
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+import org.eclipse.tm4e.core.internal.types.IRawGrammar;
+import org.eclipse.tm4e.core.internal.types.IRawRepository;
+
+public interface IGrammarRegistry {
+
+	IRawGrammar getExternalGrammar(String scopeName, IRawRepository repository);
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java
index 89a6e3724..f08dc3a30 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java
@@ -13,20 +13,20 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-public class IRegExpSourceAnchorCache {
-
-	public final String A0_G0;
-	public final String A0_G1;
-	public final String A1_G0;
-	public final String A1_G1;
-
-	public IRegExpSourceAnchorCache(String A0_G0, String A0_G1, String A1_G0, String A1_G1) {
-		this.A0_G0 = A0_G0;
-		this.A0_G1 = A0_G1;
-		this.A1_G0 = A1_G0;
-		this.A1_G1 = A1_G1;
-	}
-}
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+public class IRegExpSourceAnchorCache {
+
+	public final String A0_G0;
+	public final String A0_G1;
+	public final String A1_G0;
+	public final String A1_G1;
+
+	public IRegExpSourceAnchorCache(String A0_G0, String A0_G1, String A1_G0, String A1_G1) {
+		this.A0_G0 = A0_G0;
+		this.A0_G1 = A0_G1;
+		this.A1_G0 = A1_G0;
+		this.A1_G1 = A1_G1;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java
index 0a65f6750..59274790c 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java
@@ -13,9 +13,9 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-public interface IRuleFactoryHelper extends IRuleRegistry, IGrammarRegistry {
-
-}
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+public interface IRuleFactoryHelper extends IRuleRegistry, IGrammarRegistry {
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java
index 3a8470487..8ec52b2ea 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java
@@ -13,15 +13,15 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
+ */
 package org.eclipse.tm4e.core.internal.rule;
 
 import java.util.function.IntFunction;
 
-public interface IRuleRegistry {
-
-	Rule getRule(int patternId);
-
-	Rule registerRule(IntFunction factory);
-
-}
+public interface IRuleRegistry {
+
+	Rule getRule(int patternId);
+
+	Rule registerRule(IntFunction factory);
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java
index 42a036250..077dab5ca 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java
@@ -13,37 +13,37 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-public class IncludeOnlyRule extends Rule {
-
-	public final boolean hasMissingPatterns;
-	public final Integer[] patterns;
-	private RegExpSourceList cachedCompiledPatterns;
-
-	public IncludeOnlyRule(int id, String name, String contentName, ICompilePatternsResult patterns) {
-		super(id, name, contentName);
-		this.patterns = patterns.patterns;
-		this.hasMissingPatterns = patterns.hasMissingPatterns;
-		this.cachedCompiledPatterns = null;
-	}
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+public class IncludeOnlyRule extends Rule {
+
+	public final boolean hasMissingPatterns;
+	public final Integer[] patterns;
+	private RegExpSourceList cachedCompiledPatterns;
+
+	public IncludeOnlyRule(int id, String name, String contentName, ICompilePatternsResult patterns) {
+		super(id, name, contentName);
+		this.patterns = patterns.patterns;
+		this.hasMissingPatterns = patterns.hasMissingPatterns;
+		this.cachedCompiledPatterns = null;
+	}
+
 	@Override
-	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
-		for (Integer pattern : this.patterns) {
-			Rule rule = grammar.getRule(pattern);
-			rule.collectPatternsRecursive(grammar, out, false);
-		}
-	}
-
+	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
+		for (Integer pattern : this.patterns) {
+			Rule rule = grammar.getRule(pattern);
+			rule.collectPatternsRecursive(grammar, out, false);
+		}
+	}
+
 	@Override
-	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
-		if (this.cachedCompiledPatterns == null) {
-			this.cachedCompiledPatterns = new RegExpSourceList();
-			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
-		}
-		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
-	}
-
-}
+	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
+		if (this.cachedCompiledPatterns == null) {
+			this.cachedCompiledPatterns = new RegExpSourceList();
+			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
+		}
+		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java
index 6d1d25747..2d1aa9ab5 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java
@@ -13,35 +13,35 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
-import java.util.List;
-
-public class MatchRule extends Rule {
-
-	private final RegExpSource match;
-	public final List captures;
-	private RegExpSourceList cachedCompiledPatterns;
-
-	public MatchRule(int id, String name, String match, List captures) {
-		super(id, name, null);
-		this.match = new RegExpSource(match, this.id);
-		this.captures = captures;
-		this.cachedCompiledPatterns = null;
-	}
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
+import java.util.List;
+
+public class MatchRule extends Rule {
+
+	private final RegExpSource match;
+	public final List captures;
+	private RegExpSourceList cachedCompiledPatterns;
+
+	public MatchRule(int id, String name, String match, List captures) {
+		super(id, name, null);
+		this.match = new RegExpSource(match, this.id);
+		this.captures = captures;
+		this.cachedCompiledPatterns = null;
+	}
+
 	@Override
-	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
-		out.push(this.match);
-	}
-
+	public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) {
+		out.push(this.match);
+	}
+
 	@Override
-	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
-		if (this.cachedCompiledPatterns == null) {
-			this.cachedCompiledPatterns = new RegExpSourceList();
-			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
-		}
-		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
-	}
-}
+	public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) {
+		if (this.cachedCompiledPatterns == null) {
+			this.cachedCompiledPatterns = new RegExpSourceList();
+			this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true);
+		}
+		return this.cachedCompiledPatterns.compile(grammar, allowA, allowG);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java
index a9fef1f52..1a627c2f8 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java
@@ -13,221 +13,221 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
 import java.util.Arrays;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
-import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
-
-/**
- *
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts
- *
- */
-public class RegExpSource {
-
-	private static final Pattern HAS_BACK_REFERENCES = Pattern.compile("\\\\(\\d+)");
-	private static final Pattern BACK_REFERENCING_END = Pattern.compile("\\\\(\\d+)");
-	private static final Pattern REGEXP_CHARACTERS = Pattern
-			.compile("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\,\\[\\]\\(\\)\\#\\s]");
-
-	private final int ruleId;
+import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
+
+/**
+ *
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts
+ *
+ */
+public class RegExpSource {
+
+	private static final Pattern HAS_BACK_REFERENCES = Pattern.compile("\\\\(\\d+)");
+	private static final Pattern BACK_REFERENCING_END = Pattern.compile("\\\\(\\d+)");
+	private static final Pattern REGEXP_CHARACTERS = Pattern
+			.compile("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\,\\[\\]\\(\\)\\#\\s]");
+
+	private final int ruleId;
 	private boolean _hasAnchor;
-	private final boolean _hasBackReferences;
-	private IRegExpSourceAnchorCache anchorCache;
-	private String source;
-
-	public RegExpSource(String regExpSource, int ruleId) {
-		this(regExpSource, ruleId, true);
-	}
-
-	public RegExpSource(String regExpSource, int ruleId, boolean handleAnchors) {
-		if (handleAnchors) {
-			this._handleAnchors(regExpSource);
-		} else {
-			this.source = regExpSource;
-			this._hasAnchor = false;
-		}
-
-		if (this._hasAnchor) {
-			this.anchorCache = this._buildAnchorCache();
-		}
-
-		this.ruleId = ruleId;
-		this._hasBackReferences = HAS_BACK_REFERENCES.matcher(this.source).find();
-
-		// console.log('input: ' + regExpSource + ' => ' + this.source + ', ' +
-		// this.hasAnchor);
-	}
-
+	private final boolean _hasBackReferences;
+	private IRegExpSourceAnchorCache anchorCache;
+	private String source;
+
+	public RegExpSource(String regExpSource, int ruleId) {
+		this(regExpSource, ruleId, true);
+	}
+
+	public RegExpSource(String regExpSource, int ruleId, boolean handleAnchors) {
+		if (handleAnchors) {
+			this._handleAnchors(regExpSource);
+		} else {
+			this.source = regExpSource;
+			this._hasAnchor = false;
+		}
+
+		if (this._hasAnchor) {
+			this.anchorCache = this._buildAnchorCache();
+		}
+
+		this.ruleId = ruleId;
+		this._hasBackReferences = HAS_BACK_REFERENCES.matcher(this.source).find();
+
+		// console.log('input: ' + regExpSource + ' => ' + this.source + ', ' +
+		// this.hasAnchor);
+	}
+
 	@Override
-	public RegExpSource clone() {
-		return new RegExpSource(this.source, this.ruleId, true);
-	}
-
-	public void setSource(String newSource) {
-		if (this.source.equals(newSource)) {
-			return;
-		}
-		this.source = newSource;
-
-		if (this._hasAnchor) {
-			this.anchorCache = this._buildAnchorCache();
-		}
-	}
-
-	private void _handleAnchors(String regExpSource) {
-		if (regExpSource != null) {
-			int len = regExpSource.length();
-			char ch;
-			char nextCh;
-			int lastPushedPos = 0;
-			StringBuilder output = new StringBuilder();
-
-			boolean hasAnchor = false;
-			for (int pos = 0; pos < len; pos++) {
-				ch = regExpSource.charAt(pos);
-
-				if (ch == '\\') {
-					if (pos + 1 < len) {
-						nextCh = regExpSource.charAt(pos + 1);
-						if (nextCh == 'z') {
-							output.append(regExpSource.substring(lastPushedPos, pos));
-							output.append("$(?!\\n)(? capturedValues = Arrays.stream(captureIndices)
-				.map(capture -> lineText.substring(capture.getStart(), capture.getEnd())).collect(Collectors.toList());
-		Matcher m = BACK_REFERENCING_END.matcher(this.source);
-		StringBuffer sb = new StringBuffer();
-		while (m.find()) {
-			String g1 = m.group();
-			int index = Integer.parseInt(g1.substring(1));
-			String replacement = escapeRegExpCharacters(capturedValues.size() > index ? capturedValues.get(index) : "");
-			m.appendReplacement(sb, replacement);
-		}
-		m.appendTail(sb);
-		return sb.toString();
-		}
-		catch(Throwable e) {
-			//e.printStackTrace();
-		}
-
-		return lineText;
-	}
-
-	private String escapeRegExpCharacters(String value) {
-		Matcher m = REGEXP_CHARACTERS.matcher(value);
-		StringBuffer sb = new StringBuffer();
-		while (m.find()) {
-			m.appendReplacement(sb, "\\\\\\\\" + m.group());
-		}
-		m.appendTail(sb);
-		return sb.toString();
-	}
-
-	private IRegExpSourceAnchorCache _buildAnchorCache() {
-
-		// Collection A0_G0_result=new ArrayList();
-		// Collection A0_G1_result=new ArrayList();
-		// Collection A1_G0_result=new ArrayList();
-		// Collection A1_G1_result=new ArrayList();
-
-		StringBuilder A0_G0_result = new StringBuilder();
-		StringBuilder A0_G1_result = new StringBuilder();
-		StringBuilder A1_G0_result = new StringBuilder();
-		StringBuilder A1_G1_result = new StringBuilder();
-		int pos;
-		int len;
-		char ch;
-		char nextCh;
-
-		for (pos = 0, len = this.source.length(); pos < len; pos++) {
-			ch = this.source.charAt(pos);
-			A0_G0_result.append(ch);
-			A0_G1_result.append(ch);
-			A1_G0_result.append(ch);
-			A1_G1_result.append(ch);
-
-			if (ch == '\\') {
-				if (pos + 1 < len) {
-					nextCh = this.source.charAt(pos + 1);
-					if (nextCh == 'A') {
-						A0_G0_result.append('\uFFFF');
-						A0_G1_result.append('\uFFFF');
-						A1_G0_result.append('A');
-						A1_G1_result.append('A');
-					} else if (nextCh == 'G') {
-						A0_G0_result.append('\uFFFF');
-						A0_G1_result.append('G');
-						A1_G0_result.append('\uFFFF');
-						A1_G1_result.append('G');
-					} else {
-						A0_G0_result.append(nextCh);
-						A0_G1_result.append(nextCh);
-						A1_G0_result.append(nextCh);
-						A1_G1_result.append(nextCh);
-					}
-					pos++;
-				}
-			}
-		}
-
-		return new IRegExpSourceAnchorCache(A0_G0_result.toString(), A0_G1_result.toString(), A1_G0_result.toString(),
-				A1_G1_result.toString()
-		// StringUtils.join(A0_G0_result, ""),
-		// StringUtils.join(A0_G1_result, ""),
-		// StringUtils.join(A1_G0_result, ""),
-		// StringUtils.join(A1_G1_result, "")
-		);
-	}
-
-	public String resolveAnchors(boolean allowA, boolean allowG) {
-		if (!this._hasAnchor) {
-			return this.source;
-		}
-
-		if (allowA) {
-			if (allowG) {
-				return this.anchorCache.A1_G1;
-			} else {
-				return this.anchorCache.A1_G0;
-			}
-		} else {
-			if (allowG) {
-				return this.anchorCache.A0_G1;
-			} else {
-				return this.anchorCache.A0_G0;
-			}
-		}
+	public RegExpSource clone() {
+		return new RegExpSource(this.source, this.ruleId, true);
+	}
+
+	public void setSource(String newSource) {
+		if (this.source.equals(newSource)) {
+			return;
+		}
+		this.source = newSource;
+
+		if (this._hasAnchor) {
+			this.anchorCache = this._buildAnchorCache();
+		}
+	}
+
+	private void _handleAnchors(String regExpSource) {
+		if (regExpSource != null) {
+			int len = regExpSource.length();
+			char ch;
+			char nextCh;
+			int lastPushedPos = 0;
+			StringBuilder output = new StringBuilder();
+
+			boolean hasAnchor = false;
+			for (int pos = 0; pos < len; pos++) {
+				ch = regExpSource.charAt(pos);
+
+				if (ch == '\\') {
+					if (pos + 1 < len) {
+						nextCh = regExpSource.charAt(pos + 1);
+						if (nextCh == 'z') {
+							output.append(regExpSource.substring(lastPushedPos, pos));
+							output.append("$(?!\\n)(? capturedValues = Arrays.stream(captureIndices)
+				.map(capture -> lineText.substring(capture.getStart(), capture.getEnd())).collect(Collectors.toList());
+		Matcher m = BACK_REFERENCING_END.matcher(this.source);
+		StringBuffer sb = new StringBuffer();
+		while (m.find()) {
+			String g1 = m.group();
+			int index = Integer.parseInt(g1.substring(1));
+			String replacement = escapeRegExpCharacters(capturedValues.size() > index ? capturedValues.get(index) : "");
+			m.appendReplacement(sb, replacement);
+		}
+		m.appendTail(sb);
+		return sb.toString();
+		}
+		catch(Throwable e) {
+			//e.printStackTrace();
+		}
+
+		return lineText;
+	}
+
+	private String escapeRegExpCharacters(String value) {
+		Matcher m = REGEXP_CHARACTERS.matcher(value);
+		StringBuffer sb = new StringBuffer();
+		while (m.find()) {
+			m.appendReplacement(sb, "\\\\\\\\" + m.group());
+		}
+		m.appendTail(sb);
+		return sb.toString();
+	}
+
+	private IRegExpSourceAnchorCache _buildAnchorCache() {
+
+		// Collection A0_G0_result=new ArrayList();
+		// Collection A0_G1_result=new ArrayList();
+		// Collection A1_G0_result=new ArrayList();
+		// Collection A1_G1_result=new ArrayList();
+
+		StringBuilder A0_G0_result = new StringBuilder();
+		StringBuilder A0_G1_result = new StringBuilder();
+		StringBuilder A1_G0_result = new StringBuilder();
+		StringBuilder A1_G1_result = new StringBuilder();
+		int pos;
+		int len;
+		char ch;
+		char nextCh;
+
+		for (pos = 0, len = this.source.length(); pos < len; pos++) {
+			ch = this.source.charAt(pos);
+			A0_G0_result.append(ch);
+			A0_G1_result.append(ch);
+			A1_G0_result.append(ch);
+			A1_G1_result.append(ch);
+
+			if (ch == '\\') {
+				if (pos + 1 < len) {
+					nextCh = this.source.charAt(pos + 1);
+					if (nextCh == 'A') {
+						A0_G0_result.append('\uFFFF');
+						A0_G1_result.append('\uFFFF');
+						A1_G0_result.append('A');
+						A1_G1_result.append('A');
+					} else if (nextCh == 'G') {
+						A0_G0_result.append('\uFFFF');
+						A0_G1_result.append('G');
+						A1_G0_result.append('\uFFFF');
+						A1_G1_result.append('G');
+					} else {
+						A0_G0_result.append(nextCh);
+						A0_G1_result.append(nextCh);
+						A1_G0_result.append(nextCh);
+						A1_G1_result.append(nextCh);
+					}
+					pos++;
+				}
+			}
+		}
+
+		return new IRegExpSourceAnchorCache(A0_G0_result.toString(), A0_G1_result.toString(), A1_G0_result.toString(),
+				A1_G1_result.toString()
+		// StringUtils.join(A0_G0_result, ""),
+		// StringUtils.join(A0_G1_result, ""),
+		// StringUtils.join(A1_G0_result, ""),
+		// StringUtils.join(A1_G1_result, "")
+		);
+	}
+
+	public String resolveAnchors(boolean allowA, boolean allowG) {
+		if (!this._hasAnchor) {
+			return this.source;
+		}
+
+		if (allowA) {
+			if (allowG) {
+				return this.anchorCache.A1_G1;
+			} else {
+				return this.anchorCache.A1_G0;
+			}
+		} else {
+			if (allowG) {
+				return this.anchorCache.A0_G1;
+			} else {
+				return this.anchorCache.A0_G0;
+			}
+		}
 	}
 
 	public boolean hasAnchor() {
@@ -244,6 +244,6 @@ public Integer getRuleId() {
 
 	public boolean hasBackReferences() {
 		return this._hasBackReferences;
-	}
-
-}
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java
index 0bc6b0922..dee558941 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java
@@ -13,80 +13,80 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner;
-
-/**
- *
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts
- *
- */
-public class RegExpSourceList {
-
-	private static class RegExpSourceListAnchorCache {
-
-		public ICompiledRule A0_G0;
-		public ICompiledRule A0_G1;
-		public ICompiledRule A1_G0;
-		public ICompiledRule A1_G1;
-
-	}
-
-	private final List _items;
-	private boolean _hasAnchors;
-	private ICompiledRule _cached;
-	private final RegExpSourceListAnchorCache _anchorCache;
-
-	public RegExpSourceList() {
-		this._items = new ArrayList<>();
-		this._hasAnchors = false;
-		this._cached = null;
-		this._anchorCache = new RegExpSourceListAnchorCache();
-	}
-
-	public void push(RegExpSource item) {
-		this._items.add(item);
-		this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor();
-	}
-
-	public void unshift(RegExpSource item) {
-		this._items.add(0, item);
-		this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor();
-	}
-
-	public int length() {
-		return this._items.size();
-	}
-
-	public void setSource(int index, String newSource) {
-		RegExpSource r = this._items.get(index);
-		if (!r.getSource().equals(newSource)) {
-			// bust the cache
-			this._cached = null;
-			this._anchorCache.A0_G0 = null;
-			this._anchorCache.A0_G1 = null;
-			this._anchorCache.A1_G0 = null;
-			this._anchorCache.A1_G1 = null;
-			r.setSource(newSource);
-		}
-	}
-
-	public ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) {
-		if (!this._hasAnchors) {
-			if (this._cached == null) {
-				List regexps = new ArrayList<>();
-				for (RegExpSource regExpSource : _items) {
-					regexps.add(regExpSource.getSource());
-				}
-				this._cached = new ICompiledRule(createOnigScanner(regexps.toArray(new String[0])), getRules());
-			}
-			return this._cached;
+import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner;
+
+/**
+ *
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts
+ *
+ */
+public class RegExpSourceList {
+
+	private static class RegExpSourceListAnchorCache {
+
+		public ICompiledRule A0_G0;
+		public ICompiledRule A0_G1;
+		public ICompiledRule A1_G0;
+		public ICompiledRule A1_G1;
+
+	}
+
+	private final List _items;
+	private boolean _hasAnchors;
+	private ICompiledRule _cached;
+	private final RegExpSourceListAnchorCache _anchorCache;
+
+	public RegExpSourceList() {
+		this._items = new ArrayList<>();
+		this._hasAnchors = false;
+		this._cached = null;
+		this._anchorCache = new RegExpSourceListAnchorCache();
+	}
+
+	public void push(RegExpSource item) {
+		this._items.add(item);
+		this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor();
+	}
+
+	public void unshift(RegExpSource item) {
+		this._items.add(0, item);
+		this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor();
+	}
+
+	public int length() {
+		return this._items.size();
+	}
+
+	public void setSource(int index, String newSource) {
+		RegExpSource r = this._items.get(index);
+		if (!r.getSource().equals(newSource)) {
+			// bust the cache
+			this._cached = null;
+			this._anchorCache.A0_G0 = null;
+			this._anchorCache.A0_G1 = null;
+			this._anchorCache.A1_G0 = null;
+			this._anchorCache.A1_G1 = null;
+			r.setSource(newSource);
+		}
+	}
+
+	public ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) {
+		if (!this._hasAnchors) {
+			if (this._cached == null) {
+				List regexps = new ArrayList<>();
+				for (RegExpSource regExpSource : _items) {
+					regexps.add(regExpSource.getSource());
+				}
+				this._cached = new ICompiledRule(createOnigScanner(regexps.toArray(new String[0])), getRules());
+			}
+			return this._cached;
 		} else {
 			if (this._anchorCache.A0_G0 == null) {
 				this._anchorCache.A0_G0 = (allowA == false && allowG == false) ? this._resolveAnchors(allowA, allowG)
@@ -104,41 +104,41 @@ public ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allo
 				this._anchorCache.A1_G1 = (allowA == true && allowG == true) ? this._resolveAnchors(allowA, allowG)
 						: null;
 			}
-			if (allowA) {
-				if (allowG) {
-					return this._anchorCache.A1_G1;
-				} else {
-					return this._anchorCache.A1_G0;
-				}
-			} else {
-				if (allowG) {
-					return this._anchorCache.A0_G1;
-				} else {
-					return this._anchorCache.A0_G0;
-				}
-			}
-		}
-
-	}
-
-	private ICompiledRule _resolveAnchors(boolean allowA, boolean allowG) {
-		List regexps = new ArrayList<>();
-		for (RegExpSource regExpSource : _items) {
-			regexps.add(regExpSource.resolveAnchors(allowA, allowG));
-		}
-		return new ICompiledRule(createOnigScanner(regexps.toArray(new String[0])), getRules());
-	}
-
-	private OnigScanner createOnigScanner(String[] regexps) {
-		return new OnigScanner(regexps);
-	}
-
-	private Integer[] getRules() {
-		Collection ruleIds = new ArrayList<>();
-		for (RegExpSource item : this._items) {
-			ruleIds.add(item.getRuleId());
-		}
-		return ruleIds.toArray(new Integer[0]);
-	}
-
-}
+			if (allowA) {
+				if (allowG) {
+					return this._anchorCache.A1_G1;
+				} else {
+					return this._anchorCache.A1_G0;
+				}
+			} else {
+				if (allowG) {
+					return this._anchorCache.A0_G1;
+				} else {
+					return this._anchorCache.A0_G0;
+				}
+			}
+		}
+
+	}
+
+	private ICompiledRule _resolveAnchors(boolean allowA, boolean allowG) {
+		List regexps = new ArrayList<>();
+		for (RegExpSource regExpSource : _items) {
+			regexps.add(regExpSource.resolveAnchors(allowA, allowG));
+		}
+		return new ICompiledRule(createOnigScanner(regexps.toArray(new String[0])), getRules());
+	}
+
+	private OnigScanner createOnigScanner(String[] regexps) {
+		return new OnigScanner(regexps);
+	}
+
+	private Integer[] getRules() {
+		Collection ruleIds = new ArrayList<>();
+		for (RegExpSource item : this._items) {
+			ruleIds.add(item.getRuleId());
+		}
+		return ruleIds.toArray(new Integer[0]);
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java
index ac0c4d0d9..437576d15 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java
@@ -13,46 +13,46 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
 import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
-import org.eclipse.tm4e.core.internal.utils.RegexSource;
-
-public abstract class Rule {
-
-	public final int id;
-
-	private final boolean nameIsCapturing;
-	private final String name;
-
-	private final boolean contentNameIsCapturing;
-	private final String contentName;
-
-	public Rule(int id, String name, String contentName) {
-		this.id = id;
-		this.name = name;
-		this.nameIsCapturing = RegexSource.hasCaptures(this.name);
-		this.contentName = contentName;
-		this.contentNameIsCapturing = RegexSource.hasCaptures(this.contentName);
-	}
-
-	public String getName(String lineText, IOnigCaptureIndex[] captureIndices) {
-		if (!this.nameIsCapturing) {
-			return this.name;
-		}
-		return RegexSource.replaceCaptures(this.name, lineText, captureIndices);
-	}
-
-	public String getContentName(String lineText, IOnigCaptureIndex[] captureIndices) {
-		if (!this.contentNameIsCapturing) {
-			return this.contentName;
-		}
-		return RegexSource.replaceCaptures(this.contentName, lineText, captureIndices);
-	}
-
-	public abstract void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst);
-
-	public abstract ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG);
-
+import org.eclipse.tm4e.core.internal.utils.RegexSource;
+
+public abstract class Rule {
+
+	public final int id;
+
+	private final boolean nameIsCapturing;
+	private final String name;
+
+	private final boolean contentNameIsCapturing;
+	private final String contentName;
+
+	public Rule(int id, String name, String contentName) {
+		this.id = id;
+		this.name = name;
+		this.nameIsCapturing = RegexSource.hasCaptures(this.name);
+		this.contentName = contentName;
+		this.contentNameIsCapturing = RegexSource.hasCaptures(this.contentName);
+	}
+
+	public String getName(String lineText, IOnigCaptureIndex[] captureIndices) {
+		if (!this.nameIsCapturing) {
+			return this.name;
+		}
+		return RegexSource.replaceCaptures(this.name, lineText, captureIndices);
+	}
+
+	public String getContentName(String lineText, IOnigCaptureIndex[] captureIndices) {
+		if (!this.contentNameIsCapturing) {
+			return this.contentName;
+		}
+		return RegexSource.replaceCaptures(this.contentName, lineText, captureIndices);
+	}
+
+	public abstract void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst);
+
+	public abstract ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG);
+
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java
index f269dcb35..dfd1d1b59 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java
@@ -13,9 +13,9 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.rule;
-
+ */
+package org.eclipse.tm4e.core.internal.rule;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -24,219 +24,219 @@
 import org.eclipse.tm4e.core.internal.types.IRawGrammar;
 import org.eclipse.tm4e.core.internal.types.IRawRepository;
 import org.eclipse.tm4e.core.internal.types.IRawRule;
-import org.eclipse.tm4e.core.internal.utils.CloneUtils;
-
-/**
- *
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts
- *
- */
-public class RuleFactory {
-
-	public static CaptureRule createCaptureRule(IRuleFactoryHelper helper, final String name, final String contentName,
-			final Integer retokenizeCapturedWithRuleId) {
-		return (CaptureRule) helper.registerRule(id -> new CaptureRule(id, name, contentName, retokenizeCapturedWithRuleId));
-	}
-
-	public static int getCompiledRuleId(final IRawRule desc, final IRuleFactoryHelper helper,
-			final IRawRepository repository) {
-		if (desc.getId() == null) {
-
-			helper.registerRule(id -> {
-				desc.setId(id);
-
-				if (desc.getMatch() != null) {
-					return new MatchRule(desc.getId(), desc.getName(), desc.getMatch(),
-							RuleFactory.compileCaptures(desc.getCaptures(), helper, repository));
-				}
-
-				if (desc.getBegin() == null) {
-					IRawRepository r = repository;
-					if (desc.getRepository() != null) {
-						r = CloneUtils.mergeObjects(repository, desc.getRepository());
-					}
-					return new IncludeOnlyRule(desc.getId(), desc.getName(), desc.getContentName(),
-							RuleFactory._compilePatterns(desc.getPatterns(), helper, r));
-				}
-
-				String ruleWhile = desc.getWhile();
-				if (ruleWhile != null) {
-					return new BeginWhileRule(
-							/* desc.$vscodeTextmateLocation, */
-							desc.getId(), desc.getName(), desc.getContentName(), desc.getBegin(),
-							RuleFactory.compileCaptures(
-									desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(),
-									helper, repository),
-							ruleWhile,
-							RuleFactory.compileCaptures(
-									desc.getWhileCaptures() != null ? desc.getWhileCaptures() : desc.getCaptures(),
-									helper, repository),
-							RuleFactory._compilePatterns(desc.getPatterns(), helper, repository));
-				}
-
-				return new BeginEndRule(desc.getId(), desc.getName(), desc.getContentName(), desc.getBegin(),
-						RuleFactory.compileCaptures(
-								desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(),
-								helper, repository),
-						desc.getEnd(),
-						RuleFactory.compileCaptures(
-								desc.getEndCaptures() != null ? desc.getEndCaptures() : desc.getCaptures(), helper,
-								repository),
-						desc.isApplyEndPatternLast(),
-						RuleFactory._compilePatterns(desc.getPatterns(), helper, repository));
-			});
+import org.eclipse.tm4e.core.internal.utils.CloneUtils;
+
+/**
+ *
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts
+ *
+ */
+public class RuleFactory {
+
+	public static CaptureRule createCaptureRule(IRuleFactoryHelper helper, final String name, final String contentName,
+			final Integer retokenizeCapturedWithRuleId) {
+		return (CaptureRule) helper.registerRule(id -> new CaptureRule(id, name, contentName, retokenizeCapturedWithRuleId));
+	}
+
+	public static int getCompiledRuleId(final IRawRule desc, final IRuleFactoryHelper helper,
+			final IRawRepository repository) {
+		if (desc.getId() == null) {
+
+			helper.registerRule(id -> {
+				desc.setId(id);
+
+				if (desc.getMatch() != null) {
+					return new MatchRule(desc.getId(), desc.getName(), desc.getMatch(),
+							RuleFactory.compileCaptures(desc.getCaptures(), helper, repository));
+				}
+
+				if (desc.getBegin() == null) {
+					IRawRepository r = repository;
+					if (desc.getRepository() != null) {
+						r = CloneUtils.mergeObjects(repository, desc.getRepository());
+					}
+					return new IncludeOnlyRule(desc.getId(), desc.getName(), desc.getContentName(),
+							RuleFactory._compilePatterns(desc.getPatterns(), helper, r));
+				}
+
+				String ruleWhile = desc.getWhile();
+				if (ruleWhile != null) {
+					return new BeginWhileRule(
+							/* desc.$vscodeTextmateLocation, */
+							desc.getId(), desc.getName(), desc.getContentName(), desc.getBegin(),
+							RuleFactory.compileCaptures(
+									desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(),
+									helper, repository),
+							ruleWhile,
+							RuleFactory.compileCaptures(
+									desc.getWhileCaptures() != null ? desc.getWhileCaptures() : desc.getCaptures(),
+									helper, repository),
+							RuleFactory._compilePatterns(desc.getPatterns(), helper, repository));
+				}
+
+				return new BeginEndRule(desc.getId(), desc.getName(), desc.getContentName(), desc.getBegin(),
+						RuleFactory.compileCaptures(
+								desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(),
+								helper, repository),
+						desc.getEnd(),
+						RuleFactory.compileCaptures(
+								desc.getEndCaptures() != null ? desc.getEndCaptures() : desc.getCaptures(), helper,
+								repository),
+						desc.isApplyEndPatternLast(),
+						RuleFactory._compilePatterns(desc.getPatterns(), helper, repository));
+			});
 		}
 
-		return desc.getId();
-	}
-
-	private static List compileCaptures(IRawCaptures captures, IRuleFactoryHelper helper,
-			IRawRepository repository) {
-		List r = new ArrayList<>();
-		int numericCaptureId;
-		int maximumCaptureId;
-		int i;
-
-		if (captures != null) {
-			// Find the maximum capture id
-			maximumCaptureId = 0;
-			for (String captureId : captures) {
-				numericCaptureId = parseInt(captureId, 10);
-				if (numericCaptureId > maximumCaptureId) {
-					maximumCaptureId = numericCaptureId;
-				}
-			}
-
-			// Initialize result
-			for (i = 0; i <= maximumCaptureId; i++) {
-				r.add(null);
-			}
-
-			// Fill out result
-			for (String captureId : captures) {
-				numericCaptureId = parseInt(captureId, 10);
-				Integer retokenizeCapturedWithRuleId = null;
-				IRawRule rule = captures.getCapture(captureId);
-				if (rule.getPatterns() != null) {
-					retokenizeCapturedWithRuleId = RuleFactory.getCompiledRuleId(captures.getCapture(captureId), helper,
-							repository);
-				}
-				r.set(numericCaptureId, RuleFactory.createCaptureRule(helper, rule.getName(), rule.getContentName(),
-						retokenizeCapturedWithRuleId));
-			}
-		}
-
-		return r;
-	}
-
-	private static int parseInt(String string, int base) {
-		try {
-			return Integer.parseInt(string, base);
-		} catch (Throwable e) {
-			return 0;
-		}
-	}
-
-	private static ICompilePatternsResult _compilePatterns(Collection patterns, IRuleFactoryHelper helper,
-			IRawRepository repository) {
-		Collection r = new ArrayList<>();
-		int patternId;
-		IRawGrammar externalGrammar;
-		Rule rule;
-		boolean skipRule;
-
-		if (patterns != null) {
-			for (IRawRule pattern : patterns) {
-				patternId = -1;
-
-				if (pattern.getInclude() != null) {
-					if (pattern.getInclude().charAt(0) == '#') {
-						// Local include found in `repository`
-						IRawRule localIncludedRule = repository.getProp(pattern.getInclude().substring(1));
-						if (localIncludedRule != null) {
-							patternId = RuleFactory.getCompiledRuleId(localIncludedRule, helper, repository);
-						} else {
-							// console.warn('CANNOT find rule for scopeName: ' +
-							// pattern.include + ', I am: ',
-							// repository['$base'].name);
-						}
-					} else if (pattern.getInclude().equals("$base") || pattern.getInclude().equals("$self")) {
-						// Special include also found in `repository`
-						patternId = RuleFactory.getCompiledRuleId(repository.getProp(pattern.getInclude()), helper,
-								repository);
-					} else {
-						String externalGrammarName = null, externalGrammarInclude = null;
-						int sharpIndex = pattern.getInclude().indexOf('#');
-						if (sharpIndex >= 0) {
-							externalGrammarName = pattern.getInclude().substring(0, sharpIndex);
-							externalGrammarInclude = pattern.getInclude().substring(sharpIndex + 1);
-						} else {
-							externalGrammarName = pattern.getInclude();
-						}
-						// External include
-						externalGrammar = helper.getExternalGrammar(externalGrammarName, repository);
-
-						if (externalGrammar != null) {
-							if (externalGrammarInclude != null) {
-								IRawRule externalIncludedRule = externalGrammar.getRepository()
-										.getProp(externalGrammarInclude);
-								if (externalIncludedRule != null) {
-									patternId = RuleFactory.getCompiledRuleId(externalIncludedRule, helper,
-											externalGrammar.getRepository());
-								} else {
-									// console.warn('CANNOT find rule for
-									// scopeName: ' + pattern.include + ', I am:
-									// ', repository['$base'].name);
-								}
-							} else {
-								patternId = RuleFactory.getCompiledRuleId(externalGrammar.getRepository().getSelf(),
-										helper, externalGrammar.getRepository());
-							}
-						} else {
-							// console.warn('CANNOT find grammar for scopeName:
-							// ' + pattern.include + ', I am: ',
-							// repository['$base'].name);
-						}
-
-					}
-				} else {
-					patternId = RuleFactory.getCompiledRuleId(pattern, helper, repository);
-				}
-
-				if (patternId != -1) {
-					rule = helper.getRule(patternId);
-
-					skipRule = false;
-
-					if (rule instanceof IncludeOnlyRule) {
-						IncludeOnlyRule ior = (IncludeOnlyRule) rule;
-						if (ior.hasMissingPatterns && ior.patterns.length == 0) {
-							skipRule = true;
-						}
-					} else if (rule instanceof BeginEndRule) {
-						BeginEndRule br = (BeginEndRule) rule;
-						if (br.hasMissingPatterns && br.patterns.length == 0) {
-							skipRule = true;
-						}
-					} else if (rule instanceof BeginWhileRule) {
-						BeginWhileRule br = (BeginWhileRule) rule;
-						if (br.hasMissingPatterns && br.patterns.length == 0) {
-							skipRule = true;
-						}
-					}
-
-					if (skipRule) {
-						// console.log('REMOVING RULE ENTIRELY DUE TO EMPTY
-						// PATTERNS THAT ARE MISSING');
-						continue;
-					}
-
-					r.add(patternId);
-				}
-			}
-		}
-
-		return new ICompilePatternsResult(r, ((patterns != null ? patterns.size() : 0) != r.size()));
-	}
-
-}
+		return desc.getId();
+	}
+
+	private static List compileCaptures(IRawCaptures captures, IRuleFactoryHelper helper,
+			IRawRepository repository) {
+		List r = new ArrayList<>();
+		int numericCaptureId;
+		int maximumCaptureId;
+		int i;
+
+		if (captures != null) {
+			// Find the maximum capture id
+			maximumCaptureId = 0;
+			for (String captureId : captures) {
+				numericCaptureId = parseInt(captureId, 10);
+				if (numericCaptureId > maximumCaptureId) {
+					maximumCaptureId = numericCaptureId;
+				}
+			}
+
+			// Initialize result
+			for (i = 0; i <= maximumCaptureId; i++) {
+				r.add(null);
+			}
+
+			// Fill out result
+			for (String captureId : captures) {
+				numericCaptureId = parseInt(captureId, 10);
+				Integer retokenizeCapturedWithRuleId = null;
+				IRawRule rule = captures.getCapture(captureId);
+				if (rule.getPatterns() != null) {
+					retokenizeCapturedWithRuleId = RuleFactory.getCompiledRuleId(captures.getCapture(captureId), helper,
+							repository);
+				}
+				r.set(numericCaptureId, RuleFactory.createCaptureRule(helper, rule.getName(), rule.getContentName(),
+						retokenizeCapturedWithRuleId));
+			}
+		}
+
+		return r;
+	}
+
+	private static int parseInt(String string, int base) {
+		try {
+			return Integer.parseInt(string, base);
+		} catch (Throwable e) {
+			return 0;
+		}
+	}
+
+	private static ICompilePatternsResult _compilePatterns(Collection patterns, IRuleFactoryHelper helper,
+			IRawRepository repository) {
+		Collection r = new ArrayList<>();
+		int patternId;
+		IRawGrammar externalGrammar;
+		Rule rule;
+		boolean skipRule;
+
+		if (patterns != null) {
+			for (IRawRule pattern : patterns) {
+				patternId = -1;
+
+				if (pattern.getInclude() != null) {
+					if (pattern.getInclude().charAt(0) == '#') {
+						// Local include found in `repository`
+						IRawRule localIncludedRule = repository.getProp(pattern.getInclude().substring(1));
+						if (localIncludedRule != null) {
+							patternId = RuleFactory.getCompiledRuleId(localIncludedRule, helper, repository);
+						} else {
+							// console.warn('CANNOT find rule for scopeName: ' +
+							// pattern.include + ', I am: ',
+							// repository['$base'].name);
+						}
+					} else if (pattern.getInclude().equals("$base") || pattern.getInclude().equals("$self")) {
+						// Special include also found in `repository`
+						patternId = RuleFactory.getCompiledRuleId(repository.getProp(pattern.getInclude()), helper,
+								repository);
+					} else {
+						String externalGrammarName = null, externalGrammarInclude = null;
+						int sharpIndex = pattern.getInclude().indexOf('#');
+						if (sharpIndex >= 0) {
+							externalGrammarName = pattern.getInclude().substring(0, sharpIndex);
+							externalGrammarInclude = pattern.getInclude().substring(sharpIndex + 1);
+						} else {
+							externalGrammarName = pattern.getInclude();
+						}
+						// External include
+						externalGrammar = helper.getExternalGrammar(externalGrammarName, repository);
+
+						if (externalGrammar != null) {
+							if (externalGrammarInclude != null) {
+								IRawRule externalIncludedRule = externalGrammar.getRepository()
+										.getProp(externalGrammarInclude);
+								if (externalIncludedRule != null) {
+									patternId = RuleFactory.getCompiledRuleId(externalIncludedRule, helper,
+											externalGrammar.getRepository());
+								} else {
+									// console.warn('CANNOT find rule for
+									// scopeName: ' + pattern.include + ', I am:
+									// ', repository['$base'].name);
+								}
+							} else {
+								patternId = RuleFactory.getCompiledRuleId(externalGrammar.getRepository().getSelf(),
+										helper, externalGrammar.getRepository());
+							}
+						} else {
+							// console.warn('CANNOT find grammar for scopeName:
+							// ' + pattern.include + ', I am: ',
+							// repository['$base'].name);
+						}
+
+					}
+				} else {
+					patternId = RuleFactory.getCompiledRuleId(pattern, helper, repository);
+				}
+
+				if (patternId != -1) {
+					rule = helper.getRule(patternId);
+
+					skipRule = false;
+
+					if (rule instanceof IncludeOnlyRule) {
+						IncludeOnlyRule ior = (IncludeOnlyRule) rule;
+						if (ior.hasMissingPatterns && ior.patterns.length == 0) {
+							skipRule = true;
+						}
+					} else if (rule instanceof BeginEndRule) {
+						BeginEndRule br = (BeginEndRule) rule;
+						if (br.hasMissingPatterns && br.patterns.length == 0) {
+							skipRule = true;
+						}
+					} else if (rule instanceof BeginWhileRule) {
+						BeginWhileRule br = (BeginWhileRule) rule;
+						if (br.hasMissingPatterns && br.patterns.length == 0) {
+							skipRule = true;
+						}
+					}
+
+					if (skipRule) {
+						// console.log('REMOVING RULE ENTIRELY DUE TO EMPTY
+						// PATTERNS THAT ARE MISSING');
+						continue;
+					}
+
+					r.add(patternId);
+				}
+			}
+		}
+
+		return new ICompilePatternsResult(r, ((patterns != null ? patterns.size() : 0) != r.size()));
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java
index 83144cc74..8a37c89ea 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java
@@ -9,21 +9,21 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.internal.theme;
-
-import java.util.Map;
-
-import org.eclipse.tm4e.core.internal.parser.PListObject;
-
-public class PListTheme extends PListObject {
-
-	public PListTheme(PListObject parent, boolean valueAsArray) {
-		super(parent, valueAsArray);
-	}
-
-	@Override
-	protected Map createRaw() {
-		return new ThemeRaw();
-	}
-
-}
+package org.eclipse.tm4e.core.internal.theme;
+
+import java.util.Map;
+
+import org.eclipse.tm4e.core.internal.parser.PListObject;
+
+public class PListTheme extends PListObject {
+
+	public PListTheme(PListObject parent, boolean valueAsArray) {
+		super(parent, valueAsArray);
+	}
+
+	@Override
+	protected Map createRaw() {
+		return new ThemeRaw();
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java
index 2474837aa..9dabdd447 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java
@@ -9,52 +9,52 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.internal.theme;
-
+package org.eclipse.tm4e.core.internal.theme;
+
 import java.util.Collection;
 import java.util.HashMap;
 
 import org.eclipse.tm4e.core.theme.IRawTheme;
 import org.eclipse.tm4e.core.theme.IRawThemeSetting;
-import org.eclipse.tm4e.core.theme.IThemeSetting;
-
-public class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting {
-
+import org.eclipse.tm4e.core.theme.IThemeSetting;
+
+public class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting {
+
 	private static final long serialVersionUID = -3622927264735492387L;
 
-	@Override
-	public String getName() {
-		return (String) super.get("name");
-	}
-
-	@Override
-	public Collection getSettings() {
-		return (Collection) super.get("settings");
-	}
-
-	@Override
-	public Object getScope() {
-		return super.get("scope");
-	}
-
-	@Override
-	public IThemeSetting getSetting() {
-		return (IThemeSetting) super.get("settings");
-	}
-
-	@Override
-	public Object getFontStyle() {
-		return super.get("fontStyle");
-	}
-
-	@Override
-	public String getBackground() {
-		return (String) super.get("background");
-	}
-
-	@Override
-	public String getForeground() {
-		return (String) super.get("foreground");
-	}
-
-}
+	@Override
+	public String getName() {
+		return (String) super.get("name");
+	}
+
+	@Override
+	public Collection getSettings() {
+		return (Collection) super.get("settings");
+	}
+
+	@Override
+	public Object getScope() {
+		return super.get("scope");
+	}
+
+	@Override
+	public IThemeSetting getSetting() {
+		return (IThemeSetting) super.get("settings");
+	}
+
+	@Override
+	public Object getFontStyle() {
+		return super.get("fontStyle");
+	}
+
+	@Override
+	public String getBackground() {
+		return (String) super.get("background");
+	}
+
+	@Override
+	public String getForeground() {
+		return (String) super.get("foreground");
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java
index c90f34e42..8ecb1a356 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java
@@ -13,9 +13,9 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.types;
-
-public interface IBaseRaw extends Iterable{
-
-}
+ */
+package org.eclipse.tm4e.core.internal.types;
+
+public interface IBaseRaw extends Iterable{
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java
index afc34e170..20b83de8b 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java
@@ -13,11 +13,11 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.types;
-
-public interface IRawCaptures extends IBaseRaw {
-
-	IRawRule getCapture(String captureId);
-
-}
+ */
+package org.eclipse.tm4e.core.internal.types;
+
+public interface IRawCaptures extends IBaseRaw {
+
+	IRawRule getCapture(String captureId);
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java
index 80b6d5f1d..09de8299c 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java
@@ -13,29 +13,29 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.types;
-
-import java.util.Collection;
-import java.util.Map;
-
-public interface IRawGrammar {
-
-	IRawRepository getRepository();
-
-	String getScopeName();
-
-	Collection getPatterns();
-
-	Map getInjections();
-
-	String getInjectionSelector();
-
-	// injections?:{ [expression:string]: IRawRule };
-
-	Collection getFileTypes();
-
-	String getName();
-
-	String getFirstLineMatch();
-}
+ */
+package org.eclipse.tm4e.core.internal.types;
+
+import java.util.Collection;
+import java.util.Map;
+
+public interface IRawGrammar {
+
+	IRawRepository getRepository();
+
+	String getScopeName();
+
+	Collection getPatterns();
+
+	Map getInjections();
+
+	String getInjectionSelector();
+
+	// injections?:{ [expression:string]: IRawRule };
+
+	Collection getFileTypes();
+
+	String getName();
+
+	String getFirstLineMatch();
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java
index e763f115c..c0e63d170 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java
@@ -13,21 +13,21 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.types;
-
-public interface IRawRepository {
-
-	// IRawRule getRule(String name);
-
-	IRawRule getProp(String name);
-
-	IRawRule getBase();
-
-	IRawRule getSelf();
-
-	void setSelf(IRawRule raw);
-
-	void setBase(IRawRule base);
-
-}
+ */
+package org.eclipse.tm4e.core.internal.types;
+
+public interface IRawRepository {
+
+	// IRawRule getRule(String name);
+
+	IRawRule getProp(String name);
+
+	IRawRule getBase();
+
+	IRawRule getSelf();
+
+	void setSelf(IRawRule raw);
+
+	void setBase(IRawRule base);
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java
index 15b948a0d..1eebea10f 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java
@@ -13,66 +13,66 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.types;
-
-import java.util.Collection;
-
-public interface IRawRule {
-
-	Integer getId();
-
-	void setId(Integer id);
-
-	String getInclude();
-
-	void setInclude(String include);
-
-	String getName();
-
-	void setName(String name);
-
-	String getContentName();
-
-	void setContentName(String name);
-
-	String getMatch();
-
-	void setMatch(String match);
-
-	IRawCaptures getCaptures();
-
-	void setCaptures(IRawCaptures captures);
-
-	String getBegin();
-
-	void setBegin(String begin);
-
-	IRawCaptures getBeginCaptures();
-
-	void setBeginCaptures(IRawCaptures beginCaptures);
-
-	String getEnd();
-
-	void setEnd(String end);
-
-	String getWhile();
-	
-	IRawCaptures getEndCaptures();
-
-	void setEndCaptures(IRawCaptures endCaptures);
-
-	IRawCaptures getWhileCaptures();
-
-	Collection getPatterns();
-
-	void setPatterns(Collection patterns);
-
-	IRawRepository getRepository();
-
-	void setRepository(IRawRepository repository);
-
-	boolean isApplyEndPatternLast();
-
-	void setApplyEndPatternLast(boolean applyEndPatternLast);
-}
+ */
+package org.eclipse.tm4e.core.internal.types;
+
+import java.util.Collection;
+
+public interface IRawRule {
+
+	Integer getId();
+
+	void setId(Integer id);
+
+	String getInclude();
+
+	void setInclude(String include);
+
+	String getName();
+
+	void setName(String name);
+
+	String getContentName();
+
+	void setContentName(String name);
+
+	String getMatch();
+
+	void setMatch(String match);
+
+	IRawCaptures getCaptures();
+
+	void setCaptures(IRawCaptures captures);
+
+	String getBegin();
+
+	void setBegin(String begin);
+
+	IRawCaptures getBeginCaptures();
+
+	void setBeginCaptures(IRawCaptures beginCaptures);
+
+	String getEnd();
+
+	void setEnd(String end);
+
+	String getWhile();
+	
+	IRawCaptures getEndCaptures();
+
+	void setEndCaptures(IRawCaptures endCaptures);
+
+	IRawCaptures getWhileCaptures();
+
+	Collection getPatterns();
+
+	void setPatterns(Collection patterns);
+
+	IRawRepository getRepository();
+
+	void setRepository(IRawRepository repository);
+
+	boolean isApplyEndPatternLast();
+
+	void setApplyEndPatternLast(boolean applyEndPatternLast);
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java
index 0bbd390ca..40d31d890 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java
@@ -1,66 +1,66 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.utils;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.eclipse.tm4e.core.internal.grammar.parser.Raw;
-import org.eclipse.tm4e.core.internal.types.IRawRepository;
-
-/**
- * Clone utilities.
- *
- */
-public class CloneUtils {
-
-	/**
-	 * Helper class, use methods statically
-	 */
-	private CloneUtils() {
-
-	}
-
-	public static Object clone(Object value) {
-		if (value instanceof Raw) {
-			Raw rowToClone = (Raw) value;
-			Raw raw = new Raw();
-			for (Entry entry : rowToClone.entrySet()) {
-				raw.put(entry.getKey(), clone(entry.getValue()));
-			}
-			return raw;
-		} else if (value instanceof List) {
-			return ((List) value).stream().map(CloneUtils::clone).collect(Collectors.toList());
-		} else if (value instanceof String) {
-			return value;
-		} else if (value instanceof Integer) {
-			return value;
-		} else if (value instanceof Boolean) {
-			return value;
-		}
-		return value;
-	}
-
-	public static IRawRepository mergeObjects(IRawRepository... sources) {
-		Raw target = new Raw();
-		for (IRawRepository source : sources) {
-			Set> entries = ((Map) source).entrySet();
-			for (Entry entry : entries) {
-				target.put(entry.getKey(), entry.getValue());
-			}
-		}
-		return target;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.utils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.tm4e.core.internal.grammar.parser.Raw;
+import org.eclipse.tm4e.core.internal.types.IRawRepository;
+
+/**
+ * Clone utilities.
+ *
+ */
+public class CloneUtils {
+
+	/**
+	 * Helper class, use methods statically
+	 */
+	private CloneUtils() {
+
+	}
+
+	public static Object clone(Object value) {
+		if (value instanceof Raw) {
+			Raw rowToClone = (Raw) value;
+			Raw raw = new Raw();
+			for (Entry entry : rowToClone.entrySet()) {
+				raw.put(entry.getKey(), clone(entry.getValue()));
+			}
+			return raw;
+		} else if (value instanceof List) {
+			return ((List) value).stream().map(CloneUtils::clone).collect(Collectors.toList());
+		} else if (value instanceof String) {
+			return value;
+		} else if (value instanceof Integer) {
+			return value;
+		} else if (value instanceof Boolean) {
+			return value;
+		}
+		return value;
+	}
+
+	public static IRawRepository mergeObjects(IRawRepository... sources) {
+		Raw target = new Raw();
+		for (IRawRepository source : sources) {
+			Set> entries = ((Map) source).entrySet();
+			for (Entry entry : entries) {
+				target.put(entry.getKey(), entry.getValue());
+			}
+		}
+		return target;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java
index 6eba78849..2beb8ef28 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java
@@ -1,57 +1,57 @@
-package org.eclipse.tm4e.core.internal.utils;
-
-import java.util.List;
-
-public class CompareUtils {
-
-	public static int strcmp(String a, String b) {
-		if (a == null && b == null) {
-			return 0;
-		}
-		if (a == null) {
-			return -1;
-		}
-		if (b == null) {
-			return 1;
-		}
-//		if (a < b) {
-//			return -1;
-//		}
-//		if (a > b) {
-//			return 1;
-//		}
-//		return 0;
-		int result = a.compareTo(b);
-		if (result < 0 ) {
-			return -1;
-		}  else if (result > 0 ) {
-			return 1;
-		} 
-		return 0;
-	}
-
-	public static int strArrCmp(List a, List  b) {
-		if (a == null && b == null) {
-			return 0;
-		}
-		if (a == null) {
-			return -1;
-		}
-		if (b == null) {
-			return 1;
-		}
-		int len1 = a.size();
-		int len2 = b.size();
-		if (len1 == len2) {
-			for (int i = 0; i < len1; i++) {
-				int res = strcmp(a.get(i), b.get(i));
-				if (res != 0) {
-					return res;
-				}
-			}
-			return 0;
-		}
-		return len1 - len2;
-	}
-
-}
+package org.eclipse.tm4e.core.internal.utils;
+
+import java.util.List;
+
+public class CompareUtils {
+
+	public static int strcmp(String a, String b) {
+		if (a == null && b == null) {
+			return 0;
+		}
+		if (a == null) {
+			return -1;
+		}
+		if (b == null) {
+			return 1;
+		}
+//		if (a < b) {
+//			return -1;
+//		}
+//		if (a > b) {
+//			return 1;
+//		}
+//		return 0;
+		int result = a.compareTo(b);
+		if (result < 0 ) {
+			return -1;
+		}  else if (result > 0 ) {
+			return 1;
+		} 
+		return 0;
+	}
+
+	public static int strArrCmp(List a, List  b) {
+		if (a == null && b == null) {
+			return 0;
+		}
+		if (a == null) {
+			return -1;
+		}
+		if (b == null) {
+			return 1;
+		}
+		int len1 = a.size();
+		int len2 = b.size();
+		if (len1 == len2) {
+			for (int i = 0; i < len1; i++) {
+				int res = strcmp(a.get(i), b.get(i));
+				if (res != 0) {
+					return res;
+				}
+			}
+			return 0;
+		}
+		return len1 - len2;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java
index 17d041678..2c91ffd14 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java
@@ -13,70 +13,70 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.internal.utils;
-
+ */
+package org.eclipse.tm4e.core.internal.utils;
+
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
-
-public class RegexSource {
+import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex;
+
+public class RegexSource {
 
 	/**
 	 * Helper class, access members statically
 	 */
 	private RegexSource() {
 	}
-
-	private static final Pattern CAPTURING_REGEX_SOURCE = Pattern
-			.compile("\\$(\\d+)|\\$\\{(\\d+):\\/(downcase|upcase)}");
-
-	public static boolean hasCaptures(String regexSource) {
-		if (regexSource == null) {
-			return false;
-		}
-		return CAPTURING_REGEX_SOURCE.matcher(regexSource).find();
-	}
-
-	public static String replaceCaptures(String regexSource, String captureSource, IOnigCaptureIndex[] captureIndices) {
-		Matcher m = CAPTURING_REGEX_SOURCE.matcher(regexSource);
-		StringBuffer result = new StringBuffer();
-		while (m.find()) {
-			String match = m.group();
-			String replacement = getReplacement(match, captureSource, captureIndices);
-			m.appendReplacement(result, replacement);
-		}
-		m.appendTail(result);
-		return result.toString();
-	}
-
-	private static String getReplacement(String match, String captureSource, IOnigCaptureIndex[] captureIndices) {
-		int index = -1;
-		String command = null;
-		int doublePointIndex = match.indexOf(':');
-		if (doublePointIndex != -1) {
-			index = Integer.parseInt(match.substring(2, doublePointIndex));
-			command = match.substring(doublePointIndex + 2, match.length() - 1);
-		} else {
-			index = Integer.parseInt(match.substring(1));
-		}
-		IOnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null;
-		if (capture != null) {
-			String result = captureSource.substring(capture.getStart(), capture.getEnd());
-			// Remove leading dots that would make the selector invalid
-			while (result.length() > 0 && result.charAt(0) == '.') {
-				result = result.substring(1);
-			}
-			if ("downcase".equals(command)) {
-				return result.toLowerCase();
-			} else if ("upcase".equals(command)) {
-				return result.toUpperCase();
-			} else {
-				return result;
-			}
-		} else {
-			return match;
-		}
-	}
-}
+
+	private static final Pattern CAPTURING_REGEX_SOURCE = Pattern
+			.compile("\\$(\\d+)|\\$\\{(\\d+):\\/(downcase|upcase)}");
+
+	public static boolean hasCaptures(String regexSource) {
+		if (regexSource == null) {
+			return false;
+		}
+		return CAPTURING_REGEX_SOURCE.matcher(regexSource).find();
+	}
+
+	public static String replaceCaptures(String regexSource, String captureSource, IOnigCaptureIndex[] captureIndices) {
+		Matcher m = CAPTURING_REGEX_SOURCE.matcher(regexSource);
+		StringBuffer result = new StringBuffer();
+		while (m.find()) {
+			String match = m.group();
+			String replacement = getReplacement(match, captureSource, captureIndices);
+			m.appendReplacement(result, replacement);
+		}
+		m.appendTail(result);
+		return result.toString();
+	}
+
+	private static String getReplacement(String match, String captureSource, IOnigCaptureIndex[] captureIndices) {
+		int index = -1;
+		String command = null;
+		int doublePointIndex = match.indexOf(':');
+		if (doublePointIndex != -1) {
+			index = Integer.parseInt(match.substring(2, doublePointIndex));
+			command = match.substring(doublePointIndex + 2, match.length() - 1);
+		} else {
+			index = Integer.parseInt(match.substring(1));
+		}
+		IOnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null;
+		if (capture != null) {
+			String result = captureSource.substring(capture.getStart(), capture.getEnd());
+			// Remove leading dots that would make the selector invalid
+			while (result.length() > 0 && result.charAt(0) == '.') {
+				result = result.substring(1);
+			}
+			if ("downcase".equals(command)) {
+				return result.toLowerCase();
+			} else if ("upcase".equals(command)) {
+				return result.toUpperCase();
+			} else {
+				return result;
+			}
+		} else {
+			return match;
+		}
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java
index 70557bc90..ca1fe6fea 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java
@@ -1,77 +1,77 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Initial code from https://github.com/Microsoft/vscode-textmate/
- * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved.
- * Initial license: MIT
- *
- * Contributors:
- *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
- *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-class DecodeMap {
-
-	int lastAssignedId;
-	Map scopeToTokenIds;
-	Map tokenToTokenId;
-	Map tokenIdToToken;
-	TMTokenDecodeData prevToken;
-
-	public DecodeMap() {
-		this.lastAssignedId = 0;
-		this.scopeToTokenIds = new LinkedHashMap<>();
-		this.tokenToTokenId = new LinkedHashMap<>();
-		this.tokenIdToToken = new LinkedHashMap<>();
-		this.prevToken = new TMTokenDecodeData(new String[0], new LinkedHashMap>());
-	}
-
-	public int[] getTokenIds(String scope) {
-		int[] tokens = this.scopeToTokenIds.get(scope);
-		if (tokens != null) {
-			return tokens;
-		}
-		String[] tmpTokens = scope.split("[.]");
-
-		tokens = new int[tmpTokens.length];
-		for (int i = 0; i < tmpTokens.length; i++) {
-			String token = tmpTokens[i];
-			Integer tokenId = this.tokenToTokenId.get(token);
-			if (tokenId == null) {
-				tokenId = (++this.lastAssignedId);
-				this.tokenToTokenId.put(token, tokenId);
-				this.tokenIdToToken.put(tokenId, token);
-			}
-			tokens[i] = tokenId;
-		}
-
-		this.scopeToTokenIds.put(scope, tokens);
-		return tokens;
-	}
-
-	public String getToken(Map tokenMap) {
-		StringBuilder result = new StringBuilder();
-		boolean isFirst = true;
-		for (int i = 1; i <= this.lastAssignedId; i++) {
-			if (tokenMap.containsKey(i)) {
-				if (isFirst) {
-					isFirst = false;
-					result.append(this.tokenIdToToken.get(i));
-				} else {
-					result.append('.');
-					result.append(this.tokenIdToToken.get(i));
-				}
-			}
-		}
-		return result.toString();
-	}
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Initial code from https://github.com/Microsoft/vscode-textmate/
+ * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved.
+ * Initial license: MIT
+ *
+ * Contributors:
+ *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
+ *  - Angelo Zerr  - translation and adaptation to Java
+ */
+package org.eclipse.tm4e.core.model;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+class DecodeMap {
+
+	int lastAssignedId;
+	Map scopeToTokenIds;
+	Map tokenToTokenId;
+	Map tokenIdToToken;
+	TMTokenDecodeData prevToken;
+
+	public DecodeMap() {
+		this.lastAssignedId = 0;
+		this.scopeToTokenIds = new LinkedHashMap<>();
+		this.tokenToTokenId = new LinkedHashMap<>();
+		this.tokenIdToToken = new LinkedHashMap<>();
+		this.prevToken = new TMTokenDecodeData(new String[0], new LinkedHashMap>());
+	}
+
+	public int[] getTokenIds(String scope) {
+		int[] tokens = this.scopeToTokenIds.get(scope);
+		if (tokens != null) {
+			return tokens;
+		}
+		String[] tmpTokens = scope.split("[.]");
+
+		tokens = new int[tmpTokens.length];
+		for (int i = 0; i < tmpTokens.length; i++) {
+			String token = tmpTokens[i];
+			Integer tokenId = this.tokenToTokenId.get(token);
+			if (tokenId == null) {
+				tokenId = (++this.lastAssignedId);
+				this.tokenToTokenId.put(token, tokenId);
+				this.tokenIdToToken.put(tokenId, token);
+			}
+			tokens[i] = tokenId;
+		}
+
+		this.scopeToTokenIds.put(scope, tokens);
+		return tokens;
+	}
+
+	public String getToken(Map tokenMap) {
+		StringBuilder result = new StringBuilder();
+		boolean isFirst = true;
+		for (int i = 1; i <= this.lastAssignedId; i++) {
+			if (tokenMap.containsKey(i)) {
+				if (isFirst) {
+					isFirst = false;
+					result.append(this.tokenIdToToken.get(i));
+				} else {
+					result.append('.');
+					result.append(this.tokenIdToToken.get(i));
+				}
+			}
+		}
+		return result.toString();
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java
index 2913610a9..caccc0e8a 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java
@@ -1,74 +1,74 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.model;
-
-import java.util.function.Consumer;
-
-/**
- * Mode lines API which must be initalize with a document and changed of
- * document.
- *
- */
-public interface IModelLines {
-
-	/**
-	 * Add a new line at specified index line.
-	 *
-	 * @param lineIndex (0-based)
-	 */
-	void addLine(int lineIndex);
-
-	/**
-	 * Remove the line at specified index line.
-	 *
-	 * @param line (0-based)
-	 */
-	void removeLine(int lineIndex);
-
-	/**
-	 * Mark as line is updated.
-	 *
-	 * @param line (0-based)
-	 */
-	void updateLine(int lineIndex);
-
-	/**
-	 * @deprecated use {@link #getNumberOfLines()}
-	 */
-	@Deprecated
-	int getSize();
-
-	/**
-	 *
-	 * @param lineIndex (0-based)
-	 * @return
-	 */
-	ModelLine get(int lineIndex);
-
-	void forEach(Consumer consumer);
-
-	int getNumberOfLines();
-
-	/**
-	 *
-	 * @param line (0-based)
-	 * @return
-	 * @throws Exception
-	 */
-	String getLineText(int lineIndex) throws Exception;
-
-	int getLineLength(int lineIndex) throws Exception;
-
-	void dispose();
-
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.model;
+
+import java.util.function.Consumer;
+
+/**
+ * Mode lines API which must be initalize with a document and changed of
+ * document.
+ *
+ */
+public interface IModelLines {
+
+	/**
+	 * Add a new line at specified index line.
+	 *
+	 * @param lineIndex (0-based)
+	 */
+	void addLine(int lineIndex);
+
+	/**
+	 * Remove the line at specified index line.
+	 *
+	 * @param line (0-based)
+	 */
+	void removeLine(int lineIndex);
+
+	/**
+	 * Mark as line is updated.
+	 *
+	 * @param line (0-based)
+	 */
+	void updateLine(int lineIndex);
+
+	/**
+	 * @deprecated use {@link #getNumberOfLines()}
+	 */
+	@Deprecated
+	int getSize();
+
+	/**
+	 *
+	 * @param lineIndex (0-based)
+	 * @return
+	 */
+	ModelLine get(int lineIndex);
+
+	void forEach(Consumer consumer);
+
+	int getNumberOfLines();
+
+	/**
+	 *
+	 * @param line (0-based)
+	 * @return
+	 * @throws Exception
+	 */
+	String getLineText(int lineIndex) throws Exception;
+
+	int getLineLength(int lineIndex) throws Exception;
+
+	void dispose();
+
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java
index 26b3d1533..3743b0c52 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java
@@ -1,19 +1,19 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.model;
-
-@FunctionalInterface
-public interface IModelTokensChangedListener {
-
-	void modelTokensChanged(ModelTokensChangedEvent e);
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.model;
+
+@FunctionalInterface
+public interface IModelTokensChangedListener {
+
+	void modelTokensChanged(ModelTokensChangedEvent e);
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java
index 5fbb089a1..dbb7945ce 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java
@@ -1,63 +1,63 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.model;
-
-import java.util.List;
-
-import org.eclipse.tm4e.core.grammar.IGrammar;
-
-/**
- * TextMate model API.
- *
- */
-public interface ITMModel {
-
-	/**
-	 * Returns the TextMate grammar to use to parse for each lines of the
-	 * document the TextMate tokens.
-	 *
-	 * @return the TextMate grammar to use to parse for each lines of the
-	 *         document the TextMate tokens.
-	 */
-	IGrammar getGrammar();
-
-	/**
-	 * Set the TextMate grammar to use to parse for each lines of the document
-	 * the TextMate tokens.
-	 * 
-	 * @param grammar
-	 */
-	void setGrammar(IGrammar grammar);
-
-	/**
-	 * Add model tokens changed listener.
-	 * 
-	 * @param listener
-	 *            to add
-	 */
-	void addModelTokensChangedListener(IModelTokensChangedListener listener);
-
-	/**
-	 * Remove model tokens changed listener.
-	 * 
-	 * @param listener
-	 *            to remove
-	 */
-	void removeModelTokensChangedListener(IModelTokensChangedListener listener);
-
-	void dispose();
-
-	List getLineTokens(int line);
-
-	void forceTokenization(int lineNumber);
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.model;
+
+import java.util.List;
+
+import org.eclipse.tm4e.core.grammar.IGrammar;
+
+/**
+ * TextMate model API.
+ *
+ */
+public interface ITMModel {
+
+	/**
+	 * Returns the TextMate grammar to use to parse for each lines of the
+	 * document the TextMate tokens.
+	 *
+	 * @return the TextMate grammar to use to parse for each lines of the
+	 *         document the TextMate tokens.
+	 */
+	IGrammar getGrammar();
+
+	/**
+	 * Set the TextMate grammar to use to parse for each lines of the document
+	 * the TextMate tokens.
+	 * 
+	 * @param grammar
+	 */
+	void setGrammar(IGrammar grammar);
+
+	/**
+	 * Add model tokens changed listener.
+	 * 
+	 * @param listener
+	 *            to add
+	 */
+	void addModelTokensChangedListener(IModelTokensChangedListener listener);
+
+	/**
+	 * Remove model tokens changed listener.
+	 * 
+	 * @param listener
+	 *            to remove
+	 */
+	void removeModelTokensChangedListener(IModelTokensChangedListener listener);
+
+	void dispose();
+
+	List getLineTokens(int line);
+
+	void forceTokenization(int lineNumber);
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java
index 24bb86c27..02cfb236a 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java
@@ -13,18 +13,18 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
-public interface ITokenizationSupport {
-
-	TMState getInitialState();
-
-	LineTokens tokenize(String line, TMState state);
-	
-	// add offsetDelta to each of the returned indices
-	// stop tokenizing at absolute value stopAtOffset (i.e. stream.pos() +
-	// offsetDelta > stopAtOffset)
-	LineTokens tokenize(String line, TMState state, Integer offsetDelta, Integer stopAtOffset);
-
-}
+ */
+package org.eclipse.tm4e.core.model;
+
+public interface ITokenizationSupport {
+
+	TMState getInitialState();
+
+	LineTokens tokenize(String line, TMState state);
+	
+	// add offsetDelta to each of the returned indices
+	// stop tokenizing at absolute value stopAtOffset (i.e. stream.pos() +
+	// offsetDelta > stopAtOffset)
+	LineTokens tokenize(String line, TMState state, Integer offsetDelta, Integer stopAtOffset);
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java
index 99077f677..905e4ab83 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java
@@ -13,32 +13,32 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
-import java.util.List;
-
-public class LineTokens {
-
-	List tokens;
-	int actualStopOffset;
-	TMState endState;
-
-	public LineTokens(List tokens, int actualStopOffset, TMState endState) {
-		this.tokens = tokens;
-		this.actualStopOffset = actualStopOffset;
-		this.endState = endState;
-	}
-
-	public TMState getEndState() {
-		return endState;
-	}
-
-	public void setEndState(TMState endState) {
-		this.endState = endState;
-	}
-
-	public List getTokens() {
-		return tokens;
-	}
-}
+ */
+package org.eclipse.tm4e.core.model;
+
+import java.util.List;
+
+public class LineTokens {
+
+	List tokens;
+	int actualStopOffset;
+	TMState endState;
+
+	public LineTokens(List tokens, int actualStopOffset, TMState endState) {
+		this.tokens = tokens;
+		this.actualStopOffset = actualStopOffset;
+		this.endState = endState;
+	}
+
+	public TMState getEndState() {
+		return endState;
+	}
+
+	public void setEndState(TMState endState) {
+		this.endState = endState;
+	}
+
+	public List getTokens() {
+		return tokens;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java
index 9c042bec2..5c0df7fcf 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java
@@ -1,47 +1,47 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.model;
-
-import java.util.List;
-
-public class ModelLine {
-
-	//String text;
-	boolean isInvalid;
-	TMState state;
-	List tokens;
-
-	public ModelLine(/*String text*/) {
-		//this.text = text;
-	}
-
-	public void resetTokenizationState() {
-		this.state = null;
-		this.tokens = null;
-	}
-
-	public TMState getState() {
-		return state;
-	}
-
-	public void setState(TMState state) {
-		this.state = state;
-	}
-
-	public void setTokens(List tokens) {
-		this.tokens = tokens;
-	}
-
-	public List getTokens() {
-		return tokens;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.model;
+
+import java.util.List;
+
+public class ModelLine {
+
+	//String text;
+	boolean isInvalid;
+	TMState state;
+	List tokens;
+
+	public ModelLine(/*String text*/) {
+		//this.text = text;
+	}
+
+	public void resetTokenizationState() {
+		this.state = null;
+		this.tokens = null;
+	}
+
+	public TMState getState() {
+		return state;
+	}
+
+	public void setState(TMState state) {
+		this.state = state;
+	}
+
+	public void setTokens(List tokens) {
+		this.tokens = tokens;
+	}
+
+	public List getTokens() {
+		return tokens;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java
index d2e2daa62..c2ff2ac15 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java
@@ -13,28 +13,28 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
+ */
+package org.eclipse.tm4e.core.model;
+
 import java.util.Arrays;
-import java.util.List;
-
-/**
- * Model tokens changed event.
- *
- */
-public class ModelTokensChangedEvent {
-
-	public final List ranges;
-	public final ITMModel model;
-
-	public ModelTokensChangedEvent(Range range, ITMModel model) {
-		this(Arrays.asList(range), model);
-	}
-
-	public ModelTokensChangedEvent(List ranges, ITMModel model) {
-		this.ranges = ranges;
-		this.model = model;
-	}
-
-}
+import java.util.List;
+
+/**
+ * Model tokens changed event.
+ *
+ */
+public class ModelTokensChangedEvent {
+
+	public final List ranges;
+	public final ITMModel model;
+
+	public ModelTokensChangedEvent(Range range, ITMModel model) {
+		this(Arrays.asList(range), model);
+	}
+
+	public ModelTokensChangedEvent(List ranges, ITMModel model) {
+		this.ranges = ranges;
+		this.model = model;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java
index b3aac593b..d32b9d92c 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java
@@ -13,38 +13,38 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
+ */
+package org.eclipse.tm4e.core.model;
+
 import java.util.ArrayList;
-import java.util.List;
-
-class ModelTokensChangedEventBuilder {
-
-	private final ITMModel model;
-	private final List ranges;
-
-	public ModelTokensChangedEventBuilder(ITMModel model) {
-		this.model = model;
-		this.ranges = new ArrayList<>();
-	}
-
-	public void registerChangedTokens(int lineNumber) {
-		Range previousRange = ranges.isEmpty() ? null : ranges.get(ranges.size() - 1);
-
-		if (previousRange != null && previousRange.toLineNumber == lineNumber - 1) {
-			// extend previous range
-			previousRange.toLineNumber++;
-		} else {
-			// insert new range
-			ranges.add(new Range(lineNumber));
-		}
-	}
-
-	public ModelTokensChangedEvent build() {
-		if (this.ranges.isEmpty()) {
-			return null;
-		}
-		return new ModelTokensChangedEvent(ranges, model);
-	}
-}
+import java.util.List;
+
+class ModelTokensChangedEventBuilder {
+
+	private final ITMModel model;
+	private final List ranges;
+
+	public ModelTokensChangedEventBuilder(ITMModel model) {
+		this.model = model;
+		this.ranges = new ArrayList<>();
+	}
+
+	public void registerChangedTokens(int lineNumber) {
+		Range previousRange = ranges.isEmpty() ? null : ranges.get(ranges.size() - 1);
+
+		if (previousRange != null && previousRange.toLineNumber == lineNumber - 1) {
+			// extend previous range
+			previousRange.toLineNumber++;
+		} else {
+			// insert new range
+			ranges.add(new Range(lineNumber));
+		}
+	}
+
+	public ModelTokensChangedEvent build() {
+		if (this.ranges.isEmpty()) {
+			return null;
+		}
+		return new ModelTokensChangedEvent(ranges, model);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java
index f67ac1aec..53448f6ab 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java
@@ -13,20 +13,20 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
-public class Range {
-
-	public final int fromLineNumber;
-	public int toLineNumber;
+ */
+package org.eclipse.tm4e.core.model;
+
+public class Range {
+
+	public final int fromLineNumber;
+	public int toLineNumber;
 
 	/**
 	 * Constructs a range made of a single line
 	 * @param lineNumber
-	 */
-	public Range(int lineNumber) {
-		this.fromLineNumber = lineNumber;
-		this.toLineNumber = lineNumber;
-	}
-}
+	 */
+	public Range(int lineNumber) {
+		this.fromLineNumber = lineNumber;
+		this.toLineNumber = lineNumber;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java
index 2cb18a216..782e24ea3 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java
@@ -1,336 +1,336 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.concurrent.PriorityBlockingQueue;
-import java.util.function.Consumer;
-import java.util.logging.Logger;
-
-import org.eclipse.tm4e.core.grammar.IGrammar;
-
-/**
- * TextMate model class.
- *
- */
-public class TMModel implements ITMModel {
-
-	private static final Logger LOGGER = Logger.getLogger(TMModel.class.getName());
-
-	/**
-	 * The TextMate grammar to use to parse for each lines of the document the
-	 * TextMate tokens.
-	 **/
-	private IGrammar grammar;
-
-	/** Listener when TextMate model tokens changed **/
-	private final List listeners;
-
-	Tokenizer tokenizer;
-
-	/** The background thread. */
-	private TokenizerThread fThread;
-
-	private final IModelLines lines;
-	private final PriorityBlockingQueue invalidLines = new PriorityBlockingQueue<>();
-
-	public TMModel(IModelLines lines) {
-		this.listeners = new ArrayList<>();
-		this.lines = lines;
-		((AbstractLineList)lines).setModel(this);
-		lines.forEach(ModelLine::resetTokenizationState);
-		invalidateLine(0);
-	}
-
-	/**
-	 * The {@link TokenizerThread} takes as input an {@link TMModel} and continuously
-	 * runs tokenizing in background on the lines found in {@link TMModel#lines}.
-	 * The {@link TMModel#lines} are expected to be accessed through {@link TMModel#getLines()}
-	 * and manipulated by the UI part to inform of needs to (re)tokenize area, then the {@link TokenizerThread}
-	 * processes them and emits events through the model. UI elements are supposed to subscribe and react to the events with
-	 * {@link TMModel#addModelTokensChangedListener(IModelTokensChangedListener)}.
-	 *
-	 */
-	static class TokenizerThread extends Thread {
-		private final TMModel model;
-		private TMState lastState;
-
-		/**
-		 * Creates a new background thread. The thread runs with minimal
-		 * priority.
-		 *
-		 * @param name
-		 *            the thread's name
-		 */
-		public TokenizerThread(String name, TMModel model) {
-			super(name);
-			this.model = model;
-			setPriority(Thread.MIN_PRIORITY);
-			setDaemon(true);
-		}
-
-		@Override
-		public void run() {
-			if (isInterrupted()) {
-				return;
-			}
-
-			do {
-				try {
-					Integer toProcess = model.invalidLines.take();
-					if (model.lines.get(toProcess).isInvalid) {
-						try {
-							this.revalidateTokensNow(toProcess, null);
-						} catch (Exception t) {
-							LOGGER.severe(t.getMessage());
-							if (toProcess < model.lines.getNumberOfLines()) {
-								model.invalidateLine(toProcess);
-							}
-						}
-					}
-				} catch (InterruptedException e) {
-					interrupt();
-				}
-			} while (!isInterrupted() && model.fThread != null);
-		}
-
-		/**
-		 *
-		 * @param startLine 0-based
-		 * @param toLineIndexOrNull 0-based
-		 */
-		private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) {
-			model.buildEventWithCallback(eventBuilder -> {
-				Integer toLineIndex = toLineIndexOrNull;
-				if (toLineIndex == null || toLineIndex >= model.lines.getNumberOfLines()) {
-					toLineIndex = model.lines.getNumberOfLines() - 1;
-				}
-
-				long tokenizedChars = 0;
-				long currentCharsToTokenize = 0;
-				final long MAX_ALLOWED_TIME = 20;
-				long currentEstimatedTimeToTokenize = 0;
-				long elapsedTime;
-				long startTime = System.currentTimeMillis();
-				// Tokenize at most 1000 lines. Estimate the tokenization speed per
-				// character and stop when:
-				// - MAX_ALLOWED_TIME is reached
-				// - tokenizing the next line would go above MAX_ALLOWED_TIME
-
-				int lineIndex = startLine;
-				while (lineIndex <= toLineIndex && lineIndex < model.getLines().getNumberOfLines()) {
-					elapsedTime = System.currentTimeMillis() - startTime;
-					if (elapsedTime > MAX_ALLOWED_TIME) {
-						// Stop if MAX_ALLOWED_TIME is reached
-						model.invalidateLine(lineIndex);
-						return;
-					}
-
-					// Compute how many characters will be tokenized for this line
-					try {
-						currentCharsToTokenize = model.lines.getLineLength(lineIndex);
-					} catch (Exception e) {
-						LOGGER.severe(e.getMessage());
-					}
-
-					if (tokenizedChars > 0) {
-						// If we have enough history, estimate how long tokenizing this line would take
-						currentEstimatedTimeToTokenize = (long) ((double)elapsedTime / tokenizedChars) * currentCharsToTokenize;
-						if (elapsedTime + currentEstimatedTimeToTokenize > MAX_ALLOWED_TIME) {
-							// Tokenizing this line will go above MAX_ALLOWED_TIME
-							model.invalidateLine(lineIndex);
-							return;
-						}
-					}
-
-					lineIndex = this.updateTokensInRange(eventBuilder, lineIndex, lineIndex) + 1;
-					tokenizedChars += currentCharsToTokenize;
-				}
-			});
-
-		}
-
-		/**
-		 *
-		 * @param eventBuilder
-		 * @param startIndex 0-based
-		 * @param endLineIndex 0-based
-		 * @param emitEvents
-		 * @return the first line index (0-based) that was NOT processed by this operation
-		 */
-		private int updateTokensInRange(ModelTokensChangedEventBuilder eventBuilder, int startIndex, int endLineIndex) {
-			int stopLineTokenizationAfter = 1000000000; // 1 billion, if a line is
-														// so long, you have other
-														// trouble :).
-			// Validate all states up to and including endLineIndex
-			int nextInvalidLineIndex = startIndex;
-			int lineIndex = startIndex;
-			while (lineIndex <= endLineIndex && lineIndex < model.lines.getNumberOfLines()) {
-				int endStateIndex = lineIndex + 1;
-				LineTokens r = null;
-				String text = null;
-				ModelLine modeLine = model.lines.get(lineIndex);
-				try {
-					text = model.lines.getLineText(lineIndex);
-					// Tokenize only the first X characters
-					r = model.tokenizer.tokenize(text, modeLine.getState(), 0, stopLineTokenizationAfter);
-				} catch (Exception e) {
-					LOGGER.severe(e.getMessage());
-				}
-
-				if (r != null && r.tokens != null && !r.tokens.isEmpty()) {
-					// Cannot have a stop offset before the last token
-					r.actualStopOffset = Math.max(r.actualStopOffset, r.tokens.get(r.tokens.size() - 1).startIndex + 1);
-				}
-
-				if (r != null && r.actualStopOffset < text.length()) {
-					// Treat the rest of the line (if above limit) as one default token
-					r.tokens.add(new TMToken(r.actualStopOffset, ""));
-					// Use as end state the starting state
-					r.endState = modeLine.getState();
-				}
-
-				if (r == null) {
-					r = new LineTokens(Collections.singletonList(new TMToken(0, "")), text.length(), modeLine.getState());
-				}
-				modeLine.setTokens(r.tokens);
-				eventBuilder.registerChangedTokens(lineIndex + 1);
-				modeLine.isInvalid = false;
-
-				if (endStateIndex < model.lines.getNumberOfLines()) {
-					ModelLine endStateLine = model.lines.get(endStateIndex);
-					if (endStateLine.getState() != null && r.endState.equals(endStateLine.getState())) {
-						// The end state of this line remains the same
-						nextInvalidLineIndex = lineIndex + 1;
-						while (nextInvalidLineIndex < model.lines.getNumberOfLines()) {
-							boolean isLastLine = nextInvalidLineIndex + 1 >= model.lines.getNumberOfLines();
-							if (model.lines.get(nextInvalidLineIndex).isInvalid
-								|| (!isLastLine && model.lines.get(nextInvalidLineIndex + 1).getState() == null)
-								|| (isLastLine && this.lastState == null)) {
-								break;
-							}
-							nextInvalidLineIndex++;
-						}
-						lineIndex = nextInvalidLineIndex;
-					} else {
-						endStateLine.setState(r.endState);
-						lineIndex++;
-					}
-				} else {
-					this.lastState = r.endState;
-					lineIndex++;
-				}
-			}
-			return nextInvalidLineIndex;
-		}
-
-	}
-
-	@Override
-	public IGrammar getGrammar() {
-		return grammar;
-	}
-
-	@Override
-	public void setGrammar(IGrammar grammar) {
-		if (!Objects.equals(grammar, this.grammar)) {
-			this.grammar = grammar;
-			this.tokenizer = new Tokenizer(grammar);
-			lines.get(0).setState(tokenizer.getInitialState());
-		}
-	}
-
-	@Override
-	public void addModelTokensChangedListener(IModelTokensChangedListener listener) {
-		if (this.fThread == null || this.fThread.isInterrupted()) {
-			this.fThread = new TokenizerThread(getClass().getName(), this);
-		}
-		if (!this.fThread.isAlive()) {
-			this.fThread.start();
-		}
-		if (!listeners.contains(listener)) {
-			listeners.add(listener);
-		}
-	}
-
-	@Override
-	public void removeModelTokensChangedListener(IModelTokensChangedListener listener) {
-		listeners.remove(listener);
-		if (listeners.isEmpty()) {
-			// no need to keep tokenizing if no-one cares
-			stop();
-		}
-	}
-
-	@Override
-	public void dispose() {
-		stop();
-		getLines().dispose();
-	}
-
-	/**
-	 * Interrupt the thread.
-	 */
-	private void stop() {
-		if (fThread == null) {
-			return;
-		}
-		this.fThread.interrupt();
-		this.fThread = null;
-	}
-
-	private void buildEventWithCallback(Consumer callback) {
-		ModelTokensChangedEventBuilder eventBuilder = new ModelTokensChangedEventBuilder(this);
-
-		callback.accept(eventBuilder);
-
-		ModelTokensChangedEvent e = eventBuilder.build();
-		if (e != null) {
-			this.emit(e);
-		}
-	}
-
-	private void emit(ModelTokensChangedEvent e) {
-		for (IModelTokensChangedListener listener : listeners) {
-			listener.modelTokensChanged(e);
-		}
-	}
-
-	@Override
-	public void forceTokenization(int lineNumber) {
-		this.buildEventWithCallback(eventBuilder ->
-			this.fThread.updateTokensInRange(eventBuilder, lineNumber, lineNumber)
-		);
-	}
-
-	@Override
-	public List getLineTokens(int lineNumber) {
-		return lines.get(lineNumber).tokens;
-	}
-
-	public boolean isLineInvalid(int lineNumber) {
-		return lines.get(lineNumber).isInvalid;
-	}
-
-	void invalidateLine(int lineIndex) {
-		this.lines.get(lineIndex).isInvalid = true;
-		this.invalidLines.add(lineIndex);
-	}
-
-	public IModelLines getLines() {
-		return this.lines;
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.function.Consumer;
+import java.util.logging.Logger;
+
+import org.eclipse.tm4e.core.grammar.IGrammar;
+
+/**
+ * TextMate model class.
+ *
+ */
+public class TMModel implements ITMModel {
+
+	private static final Logger LOGGER = Logger.getLogger(TMModel.class.getName());
+
+	/**
+	 * The TextMate grammar to use to parse for each lines of the document the
+	 * TextMate tokens.
+	 **/
+	private IGrammar grammar;
+
+	/** Listener when TextMate model tokens changed **/
+	private final List listeners;
+
+	Tokenizer tokenizer;
+
+	/** The background thread. */
+	private TokenizerThread fThread;
+
+	private final IModelLines lines;
+	private final PriorityBlockingQueue invalidLines = new PriorityBlockingQueue<>();
+
+	public TMModel(IModelLines lines) {
+		this.listeners = new ArrayList<>();
+		this.lines = lines;
+		((AbstractLineList)lines).setModel(this);
+		lines.forEach(ModelLine::resetTokenizationState);
+		invalidateLine(0);
+	}
+
+	/**
+	 * The {@link TokenizerThread} takes as input an {@link TMModel} and continuously
+	 * runs tokenizing in background on the lines found in {@link TMModel#lines}.
+	 * The {@link TMModel#lines} are expected to be accessed through {@link TMModel#getLines()}
+	 * and manipulated by the UI part to inform of needs to (re)tokenize area, then the {@link TokenizerThread}
+	 * processes them and emits events through the model. UI elements are supposed to subscribe and react to the events with
+	 * {@link TMModel#addModelTokensChangedListener(IModelTokensChangedListener)}.
+	 *
+	 */
+	static class TokenizerThread extends Thread {
+		private final TMModel model;
+		private TMState lastState;
+
+		/**
+		 * Creates a new background thread. The thread runs with minimal
+		 * priority.
+		 *
+		 * @param name
+		 *            the thread's name
+		 */
+		public TokenizerThread(String name, TMModel model) {
+			super(name);
+			this.model = model;
+			setPriority(Thread.MIN_PRIORITY);
+			setDaemon(true);
+		}
+
+		@Override
+		public void run() {
+			if (isInterrupted()) {
+				return;
+			}
+
+			do {
+				try {
+					Integer toProcess = model.invalidLines.take();
+					if (model.lines.get(toProcess).isInvalid) {
+						try {
+							this.revalidateTokensNow(toProcess, null);
+						} catch (Exception t) {
+							LOGGER.severe(t.getMessage());
+							if (toProcess < model.lines.getNumberOfLines()) {
+								model.invalidateLine(toProcess);
+							}
+						}
+					}
+				} catch (InterruptedException e) {
+					interrupt();
+				}
+			} while (!isInterrupted() && model.fThread != null);
+		}
+
+		/**
+		 *
+		 * @param startLine 0-based
+		 * @param toLineIndexOrNull 0-based
+		 */
+		private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) {
+			model.buildEventWithCallback(eventBuilder -> {
+				Integer toLineIndex = toLineIndexOrNull;
+				if (toLineIndex == null || toLineIndex >= model.lines.getNumberOfLines()) {
+					toLineIndex = model.lines.getNumberOfLines() - 1;
+				}
+
+				long tokenizedChars = 0;
+				long currentCharsToTokenize = 0;
+				final long MAX_ALLOWED_TIME = 20;
+				long currentEstimatedTimeToTokenize = 0;
+				long elapsedTime;
+				long startTime = System.currentTimeMillis();
+				// Tokenize at most 1000 lines. Estimate the tokenization speed per
+				// character and stop when:
+				// - MAX_ALLOWED_TIME is reached
+				// - tokenizing the next line would go above MAX_ALLOWED_TIME
+
+				int lineIndex = startLine;
+				while (lineIndex <= toLineIndex && lineIndex < model.getLines().getNumberOfLines()) {
+					elapsedTime = System.currentTimeMillis() - startTime;
+					if (elapsedTime > MAX_ALLOWED_TIME) {
+						// Stop if MAX_ALLOWED_TIME is reached
+						model.invalidateLine(lineIndex);
+						return;
+					}
+
+					// Compute how many characters will be tokenized for this line
+					try {
+						currentCharsToTokenize = model.lines.getLineLength(lineIndex);
+					} catch (Exception e) {
+						LOGGER.severe(e.getMessage());
+					}
+
+					if (tokenizedChars > 0) {
+						// If we have enough history, estimate how long tokenizing this line would take
+						currentEstimatedTimeToTokenize = (long) ((double)elapsedTime / tokenizedChars) * currentCharsToTokenize;
+						if (elapsedTime + currentEstimatedTimeToTokenize > MAX_ALLOWED_TIME) {
+							// Tokenizing this line will go above MAX_ALLOWED_TIME
+							model.invalidateLine(lineIndex);
+							return;
+						}
+					}
+
+					lineIndex = this.updateTokensInRange(eventBuilder, lineIndex, lineIndex) + 1;
+					tokenizedChars += currentCharsToTokenize;
+				}
+			});
+
+		}
+
+		/**
+		 *
+		 * @param eventBuilder
+		 * @param startIndex 0-based
+		 * @param endLineIndex 0-based
+		 * @param emitEvents
+		 * @return the first line index (0-based) that was NOT processed by this operation
+		 */
+		private int updateTokensInRange(ModelTokensChangedEventBuilder eventBuilder, int startIndex, int endLineIndex) {
+			int stopLineTokenizationAfter = 1000000000; // 1 billion, if a line is
+														// so long, you have other
+														// trouble :).
+			// Validate all states up to and including endLineIndex
+			int nextInvalidLineIndex = startIndex;
+			int lineIndex = startIndex;
+			while (lineIndex <= endLineIndex && lineIndex < model.lines.getNumberOfLines()) {
+				int endStateIndex = lineIndex + 1;
+				LineTokens r = null;
+				String text = null;
+				ModelLine modeLine = model.lines.get(lineIndex);
+				try {
+					text = model.lines.getLineText(lineIndex);
+					// Tokenize only the first X characters
+					r = model.tokenizer.tokenize(text, modeLine.getState(), 0, stopLineTokenizationAfter);
+				} catch (Exception e) {
+					LOGGER.severe(e.getMessage());
+				}
+
+				if (r != null && r.tokens != null && !r.tokens.isEmpty()) {
+					// Cannot have a stop offset before the last token
+					r.actualStopOffset = Math.max(r.actualStopOffset, r.tokens.get(r.tokens.size() - 1).startIndex + 1);
+				}
+
+				if (r != null && r.actualStopOffset < text.length()) {
+					// Treat the rest of the line (if above limit) as one default token
+					r.tokens.add(new TMToken(r.actualStopOffset, ""));
+					// Use as end state the starting state
+					r.endState = modeLine.getState();
+				}
+
+				if (r == null) {
+					r = new LineTokens(Collections.singletonList(new TMToken(0, "")), text.length(), modeLine.getState());
+				}
+				modeLine.setTokens(r.tokens);
+				eventBuilder.registerChangedTokens(lineIndex + 1);
+				modeLine.isInvalid = false;
+
+				if (endStateIndex < model.lines.getNumberOfLines()) {
+					ModelLine endStateLine = model.lines.get(endStateIndex);
+					if (endStateLine.getState() != null && r.endState.equals(endStateLine.getState())) {
+						// The end state of this line remains the same
+						nextInvalidLineIndex = lineIndex + 1;
+						while (nextInvalidLineIndex < model.lines.getNumberOfLines()) {
+							boolean isLastLine = nextInvalidLineIndex + 1 >= model.lines.getNumberOfLines();
+							if (model.lines.get(nextInvalidLineIndex).isInvalid
+								|| (!isLastLine && model.lines.get(nextInvalidLineIndex + 1).getState() == null)
+								|| (isLastLine && this.lastState == null)) {
+								break;
+							}
+							nextInvalidLineIndex++;
+						}
+						lineIndex = nextInvalidLineIndex;
+					} else {
+						endStateLine.setState(r.endState);
+						lineIndex++;
+					}
+				} else {
+					this.lastState = r.endState;
+					lineIndex++;
+				}
+			}
+			return nextInvalidLineIndex;
+		}
+
+	}
+
+	@Override
+	public IGrammar getGrammar() {
+		return grammar;
+	}
+
+	@Override
+	public void setGrammar(IGrammar grammar) {
+		if (!Objects.equals(grammar, this.grammar)) {
+			this.grammar = grammar;
+			this.tokenizer = new Tokenizer(grammar);
+			lines.get(0).setState(tokenizer.getInitialState());
+		}
+	}
+
+	@Override
+	public void addModelTokensChangedListener(IModelTokensChangedListener listener) {
+		if (this.fThread == null || this.fThread.isInterrupted()) {
+			this.fThread = new TokenizerThread(getClass().getName(), this);
+		}
+		if (!this.fThread.isAlive()) {
+			this.fThread.start();
+		}
+		if (!listeners.contains(listener)) {
+			listeners.add(listener);
+		}
+	}
+
+	@Override
+	public void removeModelTokensChangedListener(IModelTokensChangedListener listener) {
+		listeners.remove(listener);
+		if (listeners.isEmpty()) {
+			// no need to keep tokenizing if no-one cares
+			stop();
+		}
+	}
+
+	@Override
+	public void dispose() {
+		stop();
+		getLines().dispose();
+	}
+
+	/**
+	 * Interrupt the thread.
+	 */
+	private void stop() {
+		if (fThread == null) {
+			return;
+		}
+		this.fThread.interrupt();
+		this.fThread = null;
+	}
+
+	private void buildEventWithCallback(Consumer callback) {
+		ModelTokensChangedEventBuilder eventBuilder = new ModelTokensChangedEventBuilder(this);
+
+		callback.accept(eventBuilder);
+
+		ModelTokensChangedEvent e = eventBuilder.build();
+		if (e != null) {
+			this.emit(e);
+		}
+	}
+
+	private void emit(ModelTokensChangedEvent e) {
+		for (IModelTokensChangedListener listener : listeners) {
+			listener.modelTokensChanged(e);
+		}
+	}
+
+	@Override
+	public void forceTokenization(int lineNumber) {
+		this.buildEventWithCallback(eventBuilder ->
+			this.fThread.updateTokensInRange(eventBuilder, lineNumber, lineNumber)
+		);
+	}
+
+	@Override
+	public List getLineTokens(int lineNumber) {
+		return lines.get(lineNumber).tokens;
+	}
+
+	public boolean isLineInvalid(int lineNumber) {
+		return lines.get(lineNumber).isInvalid;
+	}
+
+	void invalidateLine(int lineIndex) {
+		this.lines.get(lineIndex).isInvalid = true;
+		this.invalidLines.add(lineIndex);
+	}
+
+	public IModelLines getLines() {
+		return this.lines;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java
index 0e20b0cfc..3d957ce6d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java
@@ -13,50 +13,50 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
+ */
+package org.eclipse.tm4e.core.model;
+
 import java.util.Objects;
 
-import org.eclipse.tm4e.core.grammar.StackElement;
-
-public class TMState {
-
-	private final TMState parentEmbedderState;
-	private StackElement ruleStack;
-
-	public TMState(TMState parentEmbedderState, StackElement ruleStatck) {
-		this.parentEmbedderState = parentEmbedderState;
-		this.ruleStack = ruleStatck;
-	}
-
-	public void setRuleStack(StackElement ruleStack) {
-		this.ruleStack = ruleStack;
-	}
-
-	public StackElement getRuleStack() {
-		return ruleStack;
-	}
-
-	@Override
-	public TMState clone() {
-		TMState parentEmbedderStateClone = this.parentEmbedderState != null ? this.parentEmbedderState.clone() : null;
-		return new TMState(parentEmbedderStateClone, this.ruleStack);
-	}
-
-	@Override
-	public boolean equals(Object other) {
-		if (!(other instanceof TMState)) {
-			return false;
-		}
-		TMState otherState = (TMState) other;
+import org.eclipse.tm4e.core.grammar.StackElement;
+
+public class TMState {
+
+	private final TMState parentEmbedderState;
+	private StackElement ruleStack;
+
+	public TMState(TMState parentEmbedderState, StackElement ruleStatck) {
+		this.parentEmbedderState = parentEmbedderState;
+		this.ruleStack = ruleStatck;
+	}
+
+	public void setRuleStack(StackElement ruleStack) {
+		this.ruleStack = ruleStack;
+	}
+
+	public StackElement getRuleStack() {
+		return ruleStack;
+	}
+
+	@Override
+	public TMState clone() {
+		TMState parentEmbedderStateClone = this.parentEmbedderState != null ? this.parentEmbedderState.clone() : null;
+		return new TMState(parentEmbedderStateClone, this.ruleStack);
+	}
+
+	@Override
+	public boolean equals(Object other) {
+		if (!(other instanceof TMState)) {
+			return false;
+		}
+		TMState otherState = (TMState) other;
 		return Objects.equals(this.parentEmbedderState, otherState.parentEmbedderState) &&
-				Objects.equals(this.ruleStack, otherState.ruleStack);
+				Objects.equals(this.ruleStack, otherState.ruleStack);
 	}
 
 	@Override
 	public int hashCode() {
 		return Objects.hash(this.parentEmbedderState, this.ruleStack);
-	}
-
-}
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java
index b08d212f2..d93796e29 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java
@@ -13,16 +13,16 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
-public class TMToken {
-
-	public final int startIndex;
-	public final String type;
-
-	public TMToken(int startIndex, String type) {
-		this.startIndex = startIndex;
-		this.type = type;
-	}
-}
+ */
+package org.eclipse.tm4e.core.model;
+
+public class TMToken {
+
+	public final int startIndex;
+	public final String type;
+
+	public TMToken(int startIndex, String type) {
+		this.startIndex = startIndex;
+		this.type = type;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java
index 8009f583f..f6879d290 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java
@@ -13,19 +13,19 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
-import java.util.Map;
-
-public class TMTokenDecodeData {
-
-	public final String[] scopes;
-	public final Map> scopeTokensMaps;
-
-	TMTokenDecodeData(String[] scopes, Map> scopeTokensMaps) {
-		this.scopes = scopes;
-		this.scopeTokensMaps = scopeTokensMaps;
-	}
-
-}
+ */
+package org.eclipse.tm4e.core.model;
+
+import java.util.Map;
+
+public class TMTokenDecodeData {
+
+	public final String[] scopes;
+	public final Map> scopeTokensMaps;
+
+	TMTokenDecodeData(String[] scopes, Map> scopeTokensMaps) {
+		this.scopes = scopes;
+		this.scopeTokensMaps = scopeTokensMaps;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java
index 89e4eb802..355e9e1fd 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java
@@ -13,9 +13,9 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.model;
-
+ */
+package org.eclipse.tm4e.core.model;
+
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -23,96 +23,96 @@
 
 import org.eclipse.tm4e.core.grammar.IGrammar;
 import org.eclipse.tm4e.core.grammar.IToken;
-import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
-
-public class Tokenizer implements ITokenizationSupport {
-
-	private final IGrammar grammar;
-	private final DecodeMap decodeMap;
-
-	public Tokenizer(IGrammar grammar) {
-		this.grammar = grammar;
-		this.decodeMap = new DecodeMap();
-	}
-
-	@Override
-	public TMState getInitialState() {
-		return new TMState(null, null);
-	}
-
-	@Override
-	public LineTokens tokenize(String line, TMState state) {
-		return tokenize(line, state, null, null);
-	}
-
-	@Override
-	public LineTokens tokenize(String line, TMState state, Integer offsetDelta, Integer stopAtOffset) {
-		if (offsetDelta == null) {
-			offsetDelta = 0;
-		}
-		// Do not attempt to tokenize if a line has over 20k
-		// or if the rule stack contains more than 100 rules (indicator of
-		// broken grammar that forgets to pop rules)
-		// if (line.length >= 20000 || depth(state.ruleStack) > 100) {
-		// return new RawLineTokens(
-		// [new Token(offsetDelta, '')],
-		// [new ModeTransition(offsetDelta, this._modeId)],
-		// offsetDelta,
-		// state
-		// );
-		// }
-		TMState freshState = state != null ? state.clone() : getInitialState();
-		ITokenizeLineResult textMateResult = grammar.tokenizeLine(line, freshState.getRuleStack());
-		freshState.setRuleStack(textMateResult.getRuleStack());
-
-		// Create the result early and fill in the tokens later
-		List tokens = new ArrayList<>();
-		String lastTokenType = null;
-		for (int tokenIndex = 0, len = textMateResult.getTokens().length; tokenIndex < len; tokenIndex++) {
-			IToken token = textMateResult.getTokens()[tokenIndex];
-			int tokenStartIndex = token.getStartIndex();
-			String tokenType = decodeTextMateToken(this.decodeMap, token.getScopes().toArray(new String[0]));
-
-			// do not push a new token if the type is exactly the same (also
-			// helps with ligatures)
-			if (!tokenType.equals(lastTokenType)) {
-				tokens.add(new TMToken(tokenStartIndex + offsetDelta, tokenType));
-				lastTokenType = tokenType;
-			}
-		}
-		return new LineTokens(tokens, offsetDelta + line.length(), freshState);
-
-	}
-
-	private String decodeTextMateToken(DecodeMap decodeMap, String[] scopes) {
-		String[] prevTokenScopes = decodeMap.prevToken.scopes;
-		int prevTokenScopesLength = prevTokenScopes.length;
-		Map> prevTokenScopeTokensMaps = decodeMap.prevToken.scopeTokensMaps;
-
-		Map> scopeTokensMaps = new LinkedHashMap<>();
-		Map prevScopeTokensMaps = new LinkedHashMap<>();
-		boolean sameAsPrev = true;
-		for (int level = 1/* deliberately skip scope 0 */; level < scopes.length; level++) {
-			String scope = scopes[level];
-
-			if (sameAsPrev) {
-				if (level < prevTokenScopesLength && prevTokenScopes[level].equals(scope)) {
-					prevScopeTokensMaps = prevTokenScopeTokensMaps.get(level);
-					scopeTokensMaps.put(level, prevScopeTokensMaps);
-					continue;
-				}
-				sameAsPrev = false;
-			}
-
-			int[] tokens = decodeMap.getTokenIds(scope);
-			prevScopeTokensMaps = new LinkedHashMap<>(prevScopeTokensMaps);
-			for (int token : tokens) {
-				prevScopeTokensMaps.put(token, true);
-			}
-			scopeTokensMaps.put(level, prevScopeTokensMaps);
-		}
-
-		decodeMap.prevToken = new TMTokenDecodeData(scopes, scopeTokensMaps);
-		return decodeMap.getToken(prevScopeTokensMaps);
-	}
-}
+import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
+
+public class Tokenizer implements ITokenizationSupport {
+
+	private final IGrammar grammar;
+	private final DecodeMap decodeMap;
+
+	public Tokenizer(IGrammar grammar) {
+		this.grammar = grammar;
+		this.decodeMap = new DecodeMap();
+	}
+
+	@Override
+	public TMState getInitialState() {
+		return new TMState(null, null);
+	}
+
+	@Override
+	public LineTokens tokenize(String line, TMState state) {
+		return tokenize(line, state, null, null);
+	}
+
+	@Override
+	public LineTokens tokenize(String line, TMState state, Integer offsetDelta, Integer stopAtOffset) {
+		if (offsetDelta == null) {
+			offsetDelta = 0;
+		}
+		// Do not attempt to tokenize if a line has over 20k
+		// or if the rule stack contains more than 100 rules (indicator of
+		// broken grammar that forgets to pop rules)
+		// if (line.length >= 20000 || depth(state.ruleStack) > 100) {
+		// return new RawLineTokens(
+		// [new Token(offsetDelta, '')],
+		// [new ModeTransition(offsetDelta, this._modeId)],
+		// offsetDelta,
+		// state
+		// );
+		// }
+		TMState freshState = state != null ? state.clone() : getInitialState();
+		ITokenizeLineResult textMateResult = grammar.tokenizeLine(line, freshState.getRuleStack());
+		freshState.setRuleStack(textMateResult.getRuleStack());
+
+		// Create the result early and fill in the tokens later
+		List tokens = new ArrayList<>();
+		String lastTokenType = null;
+		for (int tokenIndex = 0, len = textMateResult.getTokens().length; tokenIndex < len; tokenIndex++) {
+			IToken token = textMateResult.getTokens()[tokenIndex];
+			int tokenStartIndex = token.getStartIndex();
+			String tokenType = decodeTextMateToken(this.decodeMap, token.getScopes().toArray(new String[0]));
+
+			// do not push a new token if the type is exactly the same (also
+			// helps with ligatures)
+			if (!tokenType.equals(lastTokenType)) {
+				tokens.add(new TMToken(tokenStartIndex + offsetDelta, tokenType));
+				lastTokenType = tokenType;
+			}
+		}
+		return new LineTokens(tokens, offsetDelta + line.length(), freshState);
+
+	}
+
+	private String decodeTextMateToken(DecodeMap decodeMap, String[] scopes) {
+		String[] prevTokenScopes = decodeMap.prevToken.scopes;
+		int prevTokenScopesLength = prevTokenScopes.length;
+		Map> prevTokenScopeTokensMaps = decodeMap.prevToken.scopeTokensMaps;
+
+		Map> scopeTokensMaps = new LinkedHashMap<>();
+		Map prevScopeTokensMaps = new LinkedHashMap<>();
+		boolean sameAsPrev = true;
+		for (int level = 1/* deliberately skip scope 0 */; level < scopes.length; level++) {
+			String scope = scopes[level];
+
+			if (sameAsPrev) {
+				if (level < prevTokenScopesLength && prevTokenScopes[level].equals(scope)) {
+					prevScopeTokensMaps = prevTokenScopeTokensMaps.get(level);
+					scopeTokensMaps.put(level, prevScopeTokensMaps);
+					continue;
+				}
+				sameAsPrev = false;
+			}
+
+			int[] tokens = decodeMap.getTokenIds(scope);
+			prevScopeTokensMaps = new LinkedHashMap<>(prevScopeTokensMaps);
+			for (int token : tokens) {
+				prevScopeTokensMaps.put(token, true);
+			}
+			scopeTokensMaps.put(level, prevScopeTokensMaps);
+		}
+
+		decodeMap.prevToken = new TMTokenDecodeData(scopes, scopeTokensMaps);
+		return decodeMap.getToken(prevScopeTokensMaps);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java
index dc7276d7c..61b4180ef 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java
@@ -13,44 +13,44 @@
  * Contributors:
  *  - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
  *  - Angelo Zerr  - translation and adaptation to Java
- */
-package org.eclipse.tm4e.core.registry;
-
+ */
+package org.eclipse.tm4e.core.registry;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 
-import org.eclipse.tm4e.core.theme.IRawTheme;
-
-public interface IRegistryOptions {
-
-	IRegistryOptions DEFAULT_LOCATOR = new IRegistryOptions() {
-
-		@Override
-		public String getFilePath(String scopeName) {
-			return null;
-		}
-		
-		@Override
-		public InputStream getInputStream(String scopeName) {
-			return null;
-		}
-
-		@Override
-		public Collection getInjections(String scopeName) {
-			return null;
+import org.eclipse.tm4e.core.theme.IRawTheme;
+
+public interface IRegistryOptions {
+
+	IRegistryOptions DEFAULT_LOCATOR = new IRegistryOptions() {
+
+		@Override
+		public String getFilePath(String scopeName) {
+			return null;
+		}
+		
+		@Override
+		public InputStream getInputStream(String scopeName) {
+			return null;
 		}
-		
-	};
+
+		@Override
+		public Collection getInjections(String scopeName) {
+			return null;
+		}
+		
+	};
 	
 	default IRawTheme getTheme() {
 		return null;
 	}
-	
-	String getFilePath(String scopeName);
-
-	InputStream getInputStream(String scopeName) throws IOException;
-	
-	Collection getInjections(String scopeName);
-	
-}
+	
+	String getFilePath(String scopeName);
+
+	InputStream getInputStream(String scopeName) throws IOException;
+	
+	Collection getInjections(String scopeName);
+	
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java
index 78130ce44..5e1f60577 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java
@@ -9,70 +9,70 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.theme;
-
+package org.eclipse.tm4e.core.theme;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
-import java.util.Set;
-
-public class ColorMap {
-
-	private int lastColorId;
-	private final Map color2id;
-
-	public ColorMap() {
-		this.lastColorId = 0;
-		this.color2id = new HashMap<>();
-	}
-
-	public int getId(String color) {
-		if (color == null) {
-			return 0;
-		}
-		color = color.toUpperCase();
-		Integer value = this.color2id.get(color);
-		if (value != null) {
-			return value;
-		}
-		value = ++this.lastColorId;
-		this.color2id.put(color, value);
-		return value;
-	}
-
-	public String getColor(int id) {
-		for (Entry entry : color2id.entrySet()) {
-			if (id == entry.getValue()) {
-				return entry.getKey();
-			}
-		}
-		return null;
-	}
-
-	public Set getColorMap() {
-		return this.color2id.keySet();
-	}
-
-	@Override
+import java.util.Set;
+
+public class ColorMap {
+
+	private int lastColorId;
+	private final Map color2id;
+
+	public ColorMap() {
+		this.lastColorId = 0;
+		this.color2id = new HashMap<>();
+	}
+
+	public int getId(String color) {
+		if (color == null) {
+			return 0;
+		}
+		color = color.toUpperCase();
+		Integer value = this.color2id.get(color);
+		if (value != null) {
+			return value;
+		}
+		value = ++this.lastColorId;
+		this.color2id.put(color, value);
+		return value;
+	}
+
+	public String getColor(int id) {
+		for (Entry entry : color2id.entrySet()) {
+			if (id == entry.getValue()) {
+				return entry.getKey();
+			}
+		}
+		return null;
+	}
+
+	public Set getColorMap() {
+		return this.color2id.keySet();
+	}
+
+	@Override
 	public int hashCode() {
-		return Objects.hash(color2id, lastColorId);
-	}
-
-	@Override
+		return Objects.hash(color2id, lastColorId);
+	}
+
+	@Override
 	public boolean equals(Object obj) {
 		if (this == obj) {
 			return true;
-		}
+		}
 		if (obj == null) {
 			return false;
-		}
+		}
 		if (getClass() != obj.getClass()) {
 			return false;
-		}
+		}
 		ColorMap other = (ColorMap) obj;
-		return Objects.equals(color2id, other.color2id) && lastColorId == other.lastColorId;
-	}
-
-
-}
+		return Objects.equals(color2id, other.color2id) && lastColorId == other.lastColorId;
+	}
+
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java
index a8664763f..0a2c70965 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java
@@ -1,30 +1,30 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-/**
- * Font style definitions.
- *
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts
- *
- */
-public class FontStyle {
-
-	public static final int NotSet = -1;
-
-	// This can are bit-flags, so it can be `Italic | Bold`
-	public static final int None = 0;
-	public static final int Italic = 1;
-	public static final int Bold = 2;
-	public static final int Underline = 4;
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+/**
+ * Font style definitions.
+ *
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts
+ *
+ */
+public class FontStyle {
+
+	public static final int NotSet = -1;
+
+	// This can are bit-flags, so it can be `Italic | Bold`
+	public static final int None = 0;
+	public static final int Italic = 1;
+	public static final int Bold = 2;
+	public static final int Underline = 4;
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java
index f345cf3a2..72dfec225 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java
@@ -9,14 +9,14 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.theme;
-
-import java.util.Collection;
-
-public interface IRawTheme {
-
-	String getName();
-
-	Collection getSettings();
-
-}
+package org.eclipse.tm4e.core.theme;
+
+import java.util.Collection;
+
+public interface IRawTheme {
+
+	String getName();
+
+	Collection getSettings();
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java
index 587912c9e..095813d4a 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java
@@ -1,27 +1,27 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-/**
- * A single theme setting.
- * 
- * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts
- */
-public interface IRawThemeSetting {
-
-	String getName();
-
-	Object getScope();
-
-	IThemeSetting getSetting();
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+/**
+ * A single theme setting.
+ * 
+ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts
+ */
+public interface IRawThemeSetting {
+
+	String getName();
+
+	Object getScope();
+
+	IThemeSetting getSetting();
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java
index 3700a98ec..e9c84b1ec 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java
@@ -1,28 +1,28 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-public interface IStyle {
-
-	RGB getColor();
-
-	RGB getBackgroundColor();
-
-	boolean isBold();
-
-	boolean isItalic();
-
-	boolean isUnderline();
-
-	boolean isStrikeThrough();
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+public interface IStyle {
+
+	RGB getColor();
+
+	RGB getBackgroundColor();
+
+	boolean isBold();
+
+	boolean isItalic();
+
+	boolean isUnderline();
+
+	boolean isStrikeThrough();
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java
index 1c61e6537..b26c341d3 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java
@@ -9,14 +9,14 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.theme;
-
-import java.util.List;
-
-public interface IThemeProvider {
-
-	List themeMatch(String scopeName);
-
-	ThemeTrieElementRule getDefaults();
-
-}
+package org.eclipse.tm4e.core.theme;
+
+import java.util.List;
+
+public interface IThemeProvider {
+
+	List themeMatch(String scopeName);
+
+	ThemeTrieElementRule getDefaults();
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java
index b2129f03e..e16f96976 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java
@@ -9,13 +9,13 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.theme;
-
-public interface IThemeSetting {
-
-	Object getFontStyle();
-	
-	String getBackground();
-	
-	String getForeground();
-}
+package org.eclipse.tm4e.core.theme;
+
+public interface IThemeSetting {
+
+	Object getFontStyle();
+	
+	String getBackground();
+	
+	String getForeground();
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java
index 6df2ee9d8..91fdd5920 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java
@@ -9,82 +9,82 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.core.theme;
-
-import java.util.List;
-
-public class ParsedThemeRule {
-
-	// _parsedThemeRuleBrand: void;
-	
-	public final String scope;
-	public final List parentScopes;
-	public final int index;
-
-	/**
-	 * -1 if not set. An or mask of `FontStyle` otherwise.
-	 */
-	public final int fontStyle;
-	public final String foreground;
-	public final String background;
-
-	public ParsedThemeRule(String scope, List parentScopes, int index, int fontStyle, String foreground,
-			String background) {
-		this.scope = scope;
-		this.parentScopes = parentScopes;
-		this.index = index;
-		this.fontStyle = fontStyle;
-		this.foreground = foreground;
-		this.background = background;
-	}
-
-	@Override
-	public int hashCode() {
-		final int prime = 31;
-		int result = 1;
-		result = prime * result + ((background == null) ? 0 : background.hashCode());
-		result = prime * result + fontStyle;
-		result = prime * result + ((foreground == null) ? 0 : foreground.hashCode());
-		result = prime * result + index;
-		result = prime * result + ((parentScopes == null) ? 0 : parentScopes.hashCode());
-		result = prime * result + ((scope == null) ? 0 : scope.hashCode());
-		return result;
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (this == obj)
-			return true;
-		if (obj == null)
-			return false;
-		if (getClass() != obj.getClass())
-			return false;
-		ParsedThemeRule other = (ParsedThemeRule) obj;
-		if (background == null) {
-			if (other.background != null)
-				return false;
-		} else if (!background.equals(other.background))
-			return false;
-		if (fontStyle != other.fontStyle)
-			return false;
-		if (foreground == null) {
-			if (other.foreground != null)
-				return false;
-		} else if (!foreground.equals(other.foreground))
-			return false;
-		if (index != other.index)
-			return false;
-		if (parentScopes == null) {
-			if (other.parentScopes != null)
-				return false;
-		} else if (!parentScopes.equals(other.parentScopes))
-			return false;
-		if (scope == null) {
-			if (other.scope != null)
-				return false;
-		} else if (!scope.equals(other.scope))
-			return false;
-		return true;
-	}
-	
-}
+package org.eclipse.tm4e.core.theme;
+
+import java.util.List;
+
+public class ParsedThemeRule {
+
+	// _parsedThemeRuleBrand: void;
+	
+	public final String scope;
+	public final List parentScopes;
+	public final int index;
+
+	/**
+	 * -1 if not set. An or mask of `FontStyle` otherwise.
+	 */
+	public final int fontStyle;
+	public final String foreground;
+	public final String background;
+
+	public ParsedThemeRule(String scope, List parentScopes, int index, int fontStyle, String foreground,
+			String background) {
+		this.scope = scope;
+		this.parentScopes = parentScopes;
+		this.index = index;
+		this.fontStyle = fontStyle;
+		this.foreground = foreground;
+		this.background = background;
+	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((background == null) ? 0 : background.hashCode());
+		result = prime * result + fontStyle;
+		result = prime * result + ((foreground == null) ? 0 : foreground.hashCode());
+		result = prime * result + index;
+		result = prime * result + ((parentScopes == null) ? 0 : parentScopes.hashCode());
+		result = prime * result + ((scope == null) ? 0 : scope.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		ParsedThemeRule other = (ParsedThemeRule) obj;
+		if (background == null) {
+			if (other.background != null)
+				return false;
+		} else if (!background.equals(other.background))
+			return false;
+		if (fontStyle != other.fontStyle)
+			return false;
+		if (foreground == null) {
+			if (other.foreground != null)
+				return false;
+		} else if (!foreground.equals(other.foreground))
+			return false;
+		if (index != other.index)
+			return false;
+		if (parentScopes == null) {
+			if (other.parentScopes != null)
+				return false;
+		} else if (!parentScopes.equals(other.parentScopes))
+			return false;
+		if (scope == null) {
+			if (other.scope != null)
+				return false;
+		} else if (!scope.equals(other.scope))
+			return false;
+		return true;
+	}
+	
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java
index be3926ec1..d544d6e2d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java
@@ -1,25 +1,25 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-public class RGB {
-
-	public final int red;
-	public final int green;
-	public final int blue;
-
-	public RGB(int red, int green, int blue) {
-		this.red = red;
-		this.green = green;
-		this.blue = blue;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+public class RGB {
+
+	public final int red;
+	public final int green;
+	public final int blue;
+
+	public RGB(int red, int green, int blue) {
+		this.red = red;
+		this.green = green;
+		this.blue = blue;
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java
index 1f0e857d3..312f8e2c1 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java
@@ -1,259 +1,259 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import org.eclipse.tm4e.core.internal.utils.CompareUtils;
-
-/**
- * TextMate theme.
- *
- */
-public class Theme {
-
-	private static final Pattern rrggbb = Pattern.compile("^#[0-9a-f]{6}", Pattern.CASE_INSENSITIVE);
-	private static final Pattern rrggbbaa = Pattern.compile("^#[0-9a-f]{8}", Pattern.CASE_INSENSITIVE);
-	private static final Pattern rgb = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE);
-	private static final Pattern rgba = Pattern.compile("^#[0-9a-f]{4}", Pattern.CASE_INSENSITIVE);
-
-	private final ColorMap colorMap;
-	private final ThemeTrieElement root;
-	private final ThemeTrieElementRule defaults;
-	private final Map> cache;
-
-	public static Theme createFromRawTheme(IRawTheme source) {
-		return createFromParsedTheme(parseTheme(source));
-	}
-
-	public static List parseTheme(IRawTheme source) {
-		if (source == null || source.getSettings() == null) {
-			return Collections.emptyList();
-		}
-		// if (!source.settings || !Array.isArray(source.settings)) {
-		// return [];
-		// }
-		Collection settings = source.getSettings();
-		List result = new ArrayList<>();
-		int i = 0;
-		for (IRawThemeSetting entry : settings) {
-
-			if (entry.getSetting() == null) {
-				continue;
-			}
-
-			Object settingScope = entry.getScope();
-			List scopes = new ArrayList<>();
-			if (settingScope instanceof String) {
-				String scope = (String) settingScope;
-
-				// remove leading commas
-				scope = scope.replaceAll("^[,]+", "");
-
-				// remove trailing commans
-				scope = scope.replaceAll("[,]+$", "");
-
-				scopes = Arrays.asList(scope.split(","));
-			} else if (settingScope instanceof List) {
-				scopes = (List) settingScope;
-			} else {
-				scopes.add("");
-			}
-
-			int fontStyle = FontStyle.NotSet;
-			Object settingsFontStyle = entry.getSetting().getFontStyle();
-			if (settingsFontStyle instanceof String) {
-				fontStyle = FontStyle.None;
-
-				String[] segments = ((String) settingsFontStyle).split(" ");
-				for (String segment : segments) {
-					if ("italic".equals(segment)) {
-						fontStyle = fontStyle | FontStyle.Italic;
-					} else if ("bold".equals(segment)) {
-						fontStyle = fontStyle | FontStyle.Bold;
-					} else if ("underline".equals(segment)) {
-						fontStyle = fontStyle | FontStyle.Underline;
-					}
-				}
-			}
-
-			String foreground = null;
-			Object settingsForeground = entry.getSetting().getForeground();
-			if (settingsForeground instanceof String && isValidHexColor((String) settingsForeground)) {
-				foreground = (String) settingsForeground;
-			}
-
-			String background = null;
-			Object settingsBackground = entry.getSetting().getBackground();
-			if (settingsBackground instanceof String && isValidHexColor((String) settingsBackground)) {
-				background = (String) settingsBackground;
-			}
-			for (int j = 0, lenJ = scopes.size(); j < lenJ; j++) {
-				String _scope = scopes.get(j).trim();
-
-				List segments = Arrays.asList(_scope.split(" "));
-
-				String scope = segments.get(segments.size() - 1);
-				List parentScopes = null;
-				if (segments.size() > 1) {
-					parentScopes = segments.subList(0, segments.size() - 1);// slice(0,
-																			// segments.length
-																			// -
-																			// 1);
-					Collections.reverse(parentScopes); // parentScopes.reverse();
-				}
-
-				ParsedThemeRule t = new ParsedThemeRule(scope, parentScopes, i, fontStyle, foreground, background);
-				result.add(t);
-			}
-			i++;
-		}
-
-		return result;
-	}
-
-	private static boolean isValidHexColor(String hex) {
-		if (hex == null || hex.length() < 1) {
-			return false;
-		}
-
-		if (rrggbb.matcher(hex).matches()) {
-			// #rrggbb
-			return true;
-		}
-
-		if (rrggbbaa.matcher(hex).matches()) {
-			// #rrggbbaa
-			return true;
-		}
-
-		if (rgb.matcher(hex).matches()) {
-			// #rgb
-			return true;
-		}
-
-		if (rgba.matcher(hex).matches()) {
-			// #rgba
-			return true;
-		}
-
-		return false;
-	}
-
-	public static Theme createFromParsedTheme(List source) {
-		return resolveParsedThemeRules(source);
-	}
-
-	/**
-	 * Resolve rules (i.e. inheritance).
-	 */
-	public static Theme resolveParsedThemeRules(List parsedThemeRules) {
-		// Sort rules lexicographically, and then by index if necessary
-		parsedThemeRules.sort((a, b) -> {
-			int r = CompareUtils.strcmp(a.scope, b.scope);
-			if (r != 0) {
-				return r;
-			}
-			r = CompareUtils.strArrCmp(a.parentScopes, b.parentScopes);
-			if (r != 0) {
-				return r;
-			}
-			return a.index - b.index;
-		});
-
-		// Determine defaults
-		int defaultFontStyle = FontStyle.None;
-		String defaultForeground = "#000000";
-		String defaultBackground = "#ffffff";
-		while (parsedThemeRules.size() >= 1 && "".equals(parsedThemeRules.get(0).scope)) {
-			ParsedThemeRule incomingDefaults = parsedThemeRules.remove(0); // shift();
-			if (incomingDefaults.fontStyle != FontStyle.NotSet) {
-				defaultFontStyle = incomingDefaults.fontStyle;
-			}
-			if (incomingDefaults.foreground != null) {
-				defaultForeground = incomingDefaults.foreground;
-			}
-			if (incomingDefaults.background != null) {
-				defaultBackground = incomingDefaults.background;
-			}
-		}
-		ColorMap colorMap = new ColorMap();
-		ThemeTrieElementRule defaults = new ThemeTrieElementRule(0, null, defaultFontStyle,
-				colorMap.getId(defaultForeground), colorMap.getId(defaultBackground));
-
-		ThemeTrieElement root = new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0),
-				Collections.emptyList());
-		for (ParsedThemeRule rule : parsedThemeRules) {
-			root.insert(0, rule.scope, rule.parentScopes, rule.fontStyle, colorMap.getId(rule.foreground),
-					colorMap.getId(rule.background));
-		}
-
-		return new Theme(colorMap, defaults, root);
-	}
-
-	public Theme(ColorMap colorMap, ThemeTrieElementRule defaults, ThemeTrieElement root) {
-		this.colorMap = colorMap;
-		this.root = root;
-		this.defaults = defaults;
-		this.cache = new HashMap<>();
-	}
-
-	public Set getColorMap() {
-		return this.colorMap.getColorMap();
-	}
-
-	public String getColor(int id) {
-		return this.colorMap.getColor(id);
-	}
-
-	public ThemeTrieElementRule getDefaults() {
-		return this.defaults;
-	}
-
-	public List match(String scopeName) {
-		if (!this.cache.containsKey(scopeName)) {
-			this.cache.put(scopeName, this.root.match(scopeName));
-		}
-		return this.cache.get(scopeName);
-	}
-
-	@Override
-	public int hashCode() {
-		return Objects.hash(cache, colorMap, defaults, root);
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (this == obj) {
-			return true;
-		}
-		if (obj == null) {
-			return false;
-		}
-		if (getClass() != obj.getClass()) {
-			return false;
-		}
-		Theme other = (Theme) obj;
-		return Objects.equals(cache, other.cache) && Objects.equals(colorMap, other.colorMap) &&
-				Objects.equals(defaults, other.defaults) && Objects.equals(root, other.root);
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.eclipse.tm4e.core.internal.utils.CompareUtils;
+
+/**
+ * TextMate theme.
+ *
+ */
+public class Theme {
+
+	private static final Pattern rrggbb = Pattern.compile("^#[0-9a-f]{6}", Pattern.CASE_INSENSITIVE);
+	private static final Pattern rrggbbaa = Pattern.compile("^#[0-9a-f]{8}", Pattern.CASE_INSENSITIVE);
+	private static final Pattern rgb = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE);
+	private static final Pattern rgba = Pattern.compile("^#[0-9a-f]{4}", Pattern.CASE_INSENSITIVE);
+
+	private final ColorMap colorMap;
+	private final ThemeTrieElement root;
+	private final ThemeTrieElementRule defaults;
+	private final Map> cache;
+
+	public static Theme createFromRawTheme(IRawTheme source) {
+		return createFromParsedTheme(parseTheme(source));
+	}
+
+	public static List parseTheme(IRawTheme source) {
+		if (source == null || source.getSettings() == null) {
+			return Collections.emptyList();
+		}
+		// if (!source.settings || !Array.isArray(source.settings)) {
+		// return [];
+		// }
+		Collection settings = source.getSettings();
+		List result = new ArrayList<>();
+		int i = 0;
+		for (IRawThemeSetting entry : settings) {
+
+			if (entry.getSetting() == null) {
+				continue;
+			}
+
+			Object settingScope = entry.getScope();
+			List scopes = new ArrayList<>();
+			if (settingScope instanceof String) {
+				String scope = (String) settingScope;
+
+				// remove leading commas
+				scope = scope.replaceAll("^[,]+", "");
+
+				// remove trailing commans
+				scope = scope.replaceAll("[,]+$", "");
+
+				scopes = Arrays.asList(scope.split(","));
+			} else if (settingScope instanceof List) {
+				scopes = (List) settingScope;
+			} else {
+				scopes.add("");
+			}
+
+			int fontStyle = FontStyle.NotSet;
+			Object settingsFontStyle = entry.getSetting().getFontStyle();
+			if (settingsFontStyle instanceof String) {
+				fontStyle = FontStyle.None;
+
+				String[] segments = ((String) settingsFontStyle).split(" ");
+				for (String segment : segments) {
+					if ("italic".equals(segment)) {
+						fontStyle = fontStyle | FontStyle.Italic;
+					} else if ("bold".equals(segment)) {
+						fontStyle = fontStyle | FontStyle.Bold;
+					} else if ("underline".equals(segment)) {
+						fontStyle = fontStyle | FontStyle.Underline;
+					}
+				}
+			}
+
+			String foreground = null;
+			Object settingsForeground = entry.getSetting().getForeground();
+			if (settingsForeground instanceof String && isValidHexColor((String) settingsForeground)) {
+				foreground = (String) settingsForeground;
+			}
+
+			String background = null;
+			Object settingsBackground = entry.getSetting().getBackground();
+			if (settingsBackground instanceof String && isValidHexColor((String) settingsBackground)) {
+				background = (String) settingsBackground;
+			}
+			for (int j = 0, lenJ = scopes.size(); j < lenJ; j++) {
+				String _scope = scopes.get(j).trim();
+
+				List segments = Arrays.asList(_scope.split(" "));
+
+				String scope = segments.get(segments.size() - 1);
+				List parentScopes = null;
+				if (segments.size() > 1) {
+					parentScopes = segments.subList(0, segments.size() - 1);// slice(0,
+																			// segments.length
+																			// -
+																			// 1);
+					Collections.reverse(parentScopes); // parentScopes.reverse();
+				}
+
+				ParsedThemeRule t = new ParsedThemeRule(scope, parentScopes, i, fontStyle, foreground, background);
+				result.add(t);
+			}
+			i++;
+		}
+
+		return result;
+	}
+
+	private static boolean isValidHexColor(String hex) {
+		if (hex == null || hex.length() < 1) {
+			return false;
+		}
+
+		if (rrggbb.matcher(hex).matches()) {
+			// #rrggbb
+			return true;
+		}
+
+		if (rrggbbaa.matcher(hex).matches()) {
+			// #rrggbbaa
+			return true;
+		}
+
+		if (rgb.matcher(hex).matches()) {
+			// #rgb
+			return true;
+		}
+
+		if (rgba.matcher(hex).matches()) {
+			// #rgba
+			return true;
+		}
+
+		return false;
+	}
+
+	public static Theme createFromParsedTheme(List source) {
+		return resolveParsedThemeRules(source);
+	}
+
+	/**
+	 * Resolve rules (i.e. inheritance).
+	 */
+	public static Theme resolveParsedThemeRules(List parsedThemeRules) {
+		// Sort rules lexicographically, and then by index if necessary
+		parsedThemeRules.sort((a, b) -> {
+			int r = CompareUtils.strcmp(a.scope, b.scope);
+			if (r != 0) {
+				return r;
+			}
+			r = CompareUtils.strArrCmp(a.parentScopes, b.parentScopes);
+			if (r != 0) {
+				return r;
+			}
+			return a.index - b.index;
+		});
+
+		// Determine defaults
+		int defaultFontStyle = FontStyle.None;
+		String defaultForeground = "#000000";
+		String defaultBackground = "#ffffff";
+		while (parsedThemeRules.size() >= 1 && "".equals(parsedThemeRules.get(0).scope)) {
+			ParsedThemeRule incomingDefaults = parsedThemeRules.remove(0); // shift();
+			if (incomingDefaults.fontStyle != FontStyle.NotSet) {
+				defaultFontStyle = incomingDefaults.fontStyle;
+			}
+			if (incomingDefaults.foreground != null) {
+				defaultForeground = incomingDefaults.foreground;
+			}
+			if (incomingDefaults.background != null) {
+				defaultBackground = incomingDefaults.background;
+			}
+		}
+		ColorMap colorMap = new ColorMap();
+		ThemeTrieElementRule defaults = new ThemeTrieElementRule(0, null, defaultFontStyle,
+				colorMap.getId(defaultForeground), colorMap.getId(defaultBackground));
+
+		ThemeTrieElement root = new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0),
+				Collections.emptyList());
+		for (ParsedThemeRule rule : parsedThemeRules) {
+			root.insert(0, rule.scope, rule.parentScopes, rule.fontStyle, colorMap.getId(rule.foreground),
+					colorMap.getId(rule.background));
+		}
+
+		return new Theme(colorMap, defaults, root);
+	}
+
+	public Theme(ColorMap colorMap, ThemeTrieElementRule defaults, ThemeTrieElement root) {
+		this.colorMap = colorMap;
+		this.root = root;
+		this.defaults = defaults;
+		this.cache = new HashMap<>();
+	}
+
+	public Set getColorMap() {
+		return this.colorMap.getColorMap();
+	}
+
+	public String getColor(int id) {
+		return this.colorMap.getColor(id);
+	}
+
+	public ThemeTrieElementRule getDefaults() {
+		return this.defaults;
+	}
+
+	public List match(String scopeName) {
+		if (!this.cache.containsKey(scopeName)) {
+			this.cache.put(scopeName, this.root.match(scopeName));
+		}
+		return this.cache.get(scopeName);
+	}
+
+	@Override
+	public int hashCode() {
+		return Objects.hash(cache, colorMap, defaults, root);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj) {
+			return true;
+		}
+		if (obj == null) {
+			return false;
+		}
+		if (getClass() != obj.getClass()) {
+			return false;
+		}
+		Theme other = (Theme) obj;
+		return Objects.equals(cache, other.cache) && Objects.equals(colorMap, other.colorMap) &&
+				Objects.equals(defaults, other.defaults) && Objects.equals(root, other.root);
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java
index 286a4aaec..293823fc4 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java
@@ -1,187 +1,187 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import org.eclipse.tm4e.core.internal.utils.CompareUtils;
-
-public class ThemeTrieElement {
-
-	// _themeTrieElementBrand: void;
-
-	private final ThemeTrieElementRule mainRule;
-	private final List rulesWithParentScopes;
-	private final Map children;
-
-	public ThemeTrieElement(ThemeTrieElementRule mainRule) {
-		this(mainRule, new ArrayList<>(), new HashMap<>());
-	}
-
-	public ThemeTrieElement(ThemeTrieElementRule mainRule, List rulesWithParentScopes) {
-		this(mainRule, rulesWithParentScopes, new HashMap<>());
-	}
-
-	public ThemeTrieElement(ThemeTrieElementRule mainRule, List rulesWithParentScopes,
-			Map children) {
-		this.mainRule = mainRule;
-		this.rulesWithParentScopes = rulesWithParentScopes;
-		this.children = children;
-	}
-
-	private static List sortBySpecificity(List arr) {
-		if (arr.size() == 1) {
-			return arr;
-		}
-		arr.sort(ThemeTrieElement::cmpBySpecificity);
-		return arr;
-	}
-
-	private static int cmpBySpecificity(ThemeTrieElementRule a, ThemeTrieElementRule b) {
-		if (a.scopeDepth == b.scopeDepth) {
-			List aParentScopes = a.parentScopes;
-			List bParentScopes = b.parentScopes;
-			int aParentScopesLen = aParentScopes == null ? 0 : aParentScopes.size();
-			int bParentScopesLen = bParentScopes == null ? 0 : bParentScopes.size();
-			if (aParentScopesLen == bParentScopesLen) {
-				for (int i = 0; i < aParentScopesLen; i++) {
-					int aLen = aParentScopes.get(i).length();
-					int bLen = bParentScopes.get(i).length();
-					if (aLen != bLen) {
-						return bLen - aLen;
-					}
-				}
-			}
-			return bParentScopesLen - aParentScopesLen;
-		}
-		return b.scopeDepth - a.scopeDepth;
-	}
-
-	public List match(String scope) {
-		if ("".equals(scope)) {
-			List arr = new ArrayList<>();
-			arr.add(this.mainRule);
-			arr.addAll(this.rulesWithParentScopes);
-			return ThemeTrieElement.sortBySpecificity(arr);
-		}
-
-		int dotIndex = scope.indexOf('.');
-		String head;
-		String tail;
-		if (dotIndex == -1) {
-			head = scope;
-			tail = "";
-		} else {
-			head = scope.substring(0, dotIndex);
-			tail = scope.substring(dotIndex + 1);
-		}
-
-		if (this.children.containsKey(head)) {
-			return this.children.get(head).match(tail);
-		}
-
-		List arr = new ArrayList<>();
-		arr.add(this.mainRule);
-		arr.addAll(this.rulesWithParentScopes);
-		return ThemeTrieElement.sortBySpecificity(arr);
-	}
-
-	public void insert(int scopeDepth, String scope, List parentScopes, int fontStyle, int foreground,
-			int background) {
-		if ("".equals(scope)) {
-			this.doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background);
-			return;
-		}
-
-		int dotIndex = scope.indexOf('.');
-		String head;
-		String tail;
-		if (dotIndex == -1) {
-			head = scope;
-			tail = "";
-		} else {
-			head = scope.substring(0, dotIndex);
-			tail = scope.substring(dotIndex + 1);
-		}
-
-		ThemeTrieElement child;
-		if (this.children.containsKey(head)) {
-			child = this.children.get(head);
-		} else {
-			child = new ThemeTrieElement(this.mainRule.clone(),
-					ThemeTrieElementRule.cloneArr(this.rulesWithParentScopes));
-			this.children.put(head, child);
-		}
-
-		child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background);
-	}
-
-	private void doInsertHere(int scopeDepth, List parentScopes, int fontStyle, int foreground,
-			int background) {
-
-		if (parentScopes == null) {
-			// Merge into the main rule
-			this.mainRule.acceptOverwrite(scopeDepth, fontStyle, foreground, background);
-			return;
-		}
-
-		// Try to merge into existing rule
-		for (ThemeTrieElementRule rule : this.rulesWithParentScopes) {
-			if (CompareUtils.strArrCmp(rule.parentScopes, parentScopes) == 0) {
-				// bingo! => we get to merge this into an existing one
-				rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background);
-				return;
-			}
-		}
-
-		// Must add a new rule
-
-		// Inherit from main rule
-		if (fontStyle == FontStyle.NotSet) {
-			fontStyle = this.mainRule.fontStyle;
-		}
-		if (foreground == 0) {
-			foreground = this.mainRule.foreground;
-		}
-		if (background == 0) {
-			background = this.mainRule.background;
-		}
-
-		this.rulesWithParentScopes
-				.add(new ThemeTrieElementRule(scopeDepth, parentScopes, fontStyle, foreground, background));
-	}
-
-	@Override
-	public int hashCode() {
-	  return Objects.hash(children, mainRule, rulesWithParentScopes);
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (this == obj) {
-			return true;
-		}
-		if (obj == null) {
-			return false;
-		}
-		if (getClass() != obj.getClass()) {
-			return false;
-		}
-		ThemeTrieElement other = (ThemeTrieElement) obj;
-		return Objects.equals(children, other.children) && Objects.equals(mainRule, other.mainRule) && Objects.equals(rulesWithParentScopes, other.rulesWithParentScopes);
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.eclipse.tm4e.core.internal.utils.CompareUtils;
+
+public class ThemeTrieElement {
+
+	// _themeTrieElementBrand: void;
+
+	private final ThemeTrieElementRule mainRule;
+	private final List rulesWithParentScopes;
+	private final Map children;
+
+	public ThemeTrieElement(ThemeTrieElementRule mainRule) {
+		this(mainRule, new ArrayList<>(), new HashMap<>());
+	}
+
+	public ThemeTrieElement(ThemeTrieElementRule mainRule, List rulesWithParentScopes) {
+		this(mainRule, rulesWithParentScopes, new HashMap<>());
+	}
+
+	public ThemeTrieElement(ThemeTrieElementRule mainRule, List rulesWithParentScopes,
+			Map children) {
+		this.mainRule = mainRule;
+		this.rulesWithParentScopes = rulesWithParentScopes;
+		this.children = children;
+	}
+
+	private static List sortBySpecificity(List arr) {
+		if (arr.size() == 1) {
+			return arr;
+		}
+		arr.sort(ThemeTrieElement::cmpBySpecificity);
+		return arr;
+	}
+
+	private static int cmpBySpecificity(ThemeTrieElementRule a, ThemeTrieElementRule b) {
+		if (a.scopeDepth == b.scopeDepth) {
+			List aParentScopes = a.parentScopes;
+			List bParentScopes = b.parentScopes;
+			int aParentScopesLen = aParentScopes == null ? 0 : aParentScopes.size();
+			int bParentScopesLen = bParentScopes == null ? 0 : bParentScopes.size();
+			if (aParentScopesLen == bParentScopesLen) {
+				for (int i = 0; i < aParentScopesLen; i++) {
+					int aLen = aParentScopes.get(i).length();
+					int bLen = bParentScopes.get(i).length();
+					if (aLen != bLen) {
+						return bLen - aLen;
+					}
+				}
+			}
+			return bParentScopesLen - aParentScopesLen;
+		}
+		return b.scopeDepth - a.scopeDepth;
+	}
+
+	public List match(String scope) {
+		if ("".equals(scope)) {
+			List arr = new ArrayList<>();
+			arr.add(this.mainRule);
+			arr.addAll(this.rulesWithParentScopes);
+			return ThemeTrieElement.sortBySpecificity(arr);
+		}
+
+		int dotIndex = scope.indexOf('.');
+		String head;
+		String tail;
+		if (dotIndex == -1) {
+			head = scope;
+			tail = "";
+		} else {
+			head = scope.substring(0, dotIndex);
+			tail = scope.substring(dotIndex + 1);
+		}
+
+		if (this.children.containsKey(head)) {
+			return this.children.get(head).match(tail);
+		}
+
+		List arr = new ArrayList<>();
+		arr.add(this.mainRule);
+		arr.addAll(this.rulesWithParentScopes);
+		return ThemeTrieElement.sortBySpecificity(arr);
+	}
+
+	public void insert(int scopeDepth, String scope, List parentScopes, int fontStyle, int foreground,
+			int background) {
+		if ("".equals(scope)) {
+			this.doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background);
+			return;
+		}
+
+		int dotIndex = scope.indexOf('.');
+		String head;
+		String tail;
+		if (dotIndex == -1) {
+			head = scope;
+			tail = "";
+		} else {
+			head = scope.substring(0, dotIndex);
+			tail = scope.substring(dotIndex + 1);
+		}
+
+		ThemeTrieElement child;
+		if (this.children.containsKey(head)) {
+			child = this.children.get(head);
+		} else {
+			child = new ThemeTrieElement(this.mainRule.clone(),
+					ThemeTrieElementRule.cloneArr(this.rulesWithParentScopes));
+			this.children.put(head, child);
+		}
+
+		child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background);
+	}
+
+	private void doInsertHere(int scopeDepth, List parentScopes, int fontStyle, int foreground,
+			int background) {
+
+		if (parentScopes == null) {
+			// Merge into the main rule
+			this.mainRule.acceptOverwrite(scopeDepth, fontStyle, foreground, background);
+			return;
+		}
+
+		// Try to merge into existing rule
+		for (ThemeTrieElementRule rule : this.rulesWithParentScopes) {
+			if (CompareUtils.strArrCmp(rule.parentScopes, parentScopes) == 0) {
+				// bingo! => we get to merge this into an existing one
+				rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background);
+				return;
+			}
+		}
+
+		// Must add a new rule
+
+		// Inherit from main rule
+		if (fontStyle == FontStyle.NotSet) {
+			fontStyle = this.mainRule.fontStyle;
+		}
+		if (foreground == 0) {
+			foreground = this.mainRule.foreground;
+		}
+		if (background == 0) {
+			background = this.mainRule.background;
+		}
+
+		this.rulesWithParentScopes
+				.add(new ThemeTrieElementRule(scopeDepth, parentScopes, fontStyle, foreground, background));
+	}
+
+	@Override
+	public int hashCode() {
+	  return Objects.hash(children, mainRule, rulesWithParentScopes);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj) {
+			return true;
+		}
+		if (obj == null) {
+			return false;
+		}
+		if (getClass() != obj.getClass()) {
+			return false;
+		}
+		ThemeTrieElement other = (ThemeTrieElement) obj;
+		return Objects.equals(children, other.children) && Objects.equals(mainRule, other.mainRule) && Objects.equals(rulesWithParentScopes, other.rulesWithParentScopes);
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java
index e527f38cf..f810fadfc 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java
@@ -1,93 +1,93 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-public class ThemeTrieElementRule {
-
-	// _themeTrieElementRuleBrand: void;
-
-	public int scopeDepth;
-	public final List parentScopes;
-	public int fontStyle;
-	public int foreground;
-	public int background;
-
-	public ThemeTrieElementRule(int scopeDepth, List parentScopes, int fontStyle, int foreground,
-			int background) {
-		this.scopeDepth = scopeDepth;
-		this.parentScopes = parentScopes;
-		this.fontStyle = fontStyle;
-		this.foreground = foreground;
-		this.background = background;
-	}
-
-	@Override
-	public ThemeTrieElementRule clone() {
-		return new ThemeTrieElementRule(this.scopeDepth, this.parentScopes, this.fontStyle, this.foreground,
-				this.background);
-	}
-
-	public static List cloneArr(List arr) {
-		List r = new ArrayList<>();
-		for (int i = 0, len = arr.size(); i < len; i++) {
-			r.add(arr.get(i).clone());
-		}
-		return r;
-	}
-
-	public void acceptOverwrite(int scopeDepth, int fontStyle, int foreground, int background) {
-		if (this.scopeDepth > scopeDepth) {
-			// TODO!!!
-			// console.log('how did this happen?');
-		} else {
-			this.scopeDepth = scopeDepth;
-		}
-		// console.log('TODO -> my depth: ' + this.scopeDepth + ', overwriting
-		// depth: ' + scopeDepth);
-		if (fontStyle != FontStyle.NotSet) {
-			this.fontStyle = fontStyle;
-		}
-		if (foreground != 0) {
-			this.foreground = foreground;
-		}
-		if (background != 0) {
-			this.background = background;
-		}
-	}
-
-	@Override
-	public int hashCode() {
-	  return Objects.hash(background, fontStyle, foreground, parentScopes, scopeDepth);
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (this == obj) {
-			return true;
-		}
-		if (obj == null) {
-			return false;
-		}
-		if (getClass() != obj.getClass()) {
-			return false;
-		}
-		ThemeTrieElementRule other = (ThemeTrieElementRule) obj;
-		return background == other.background && fontStyle == other.fontStyle && foreground == other.foreground &&
-		    Objects.equals(parentScopes, other.parentScopes) && scopeDepth == other.scopeDepth;
-	}
-
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+public class ThemeTrieElementRule {
+
+	// _themeTrieElementRuleBrand: void;
+
+	public int scopeDepth;
+	public final List parentScopes;
+	public int fontStyle;
+	public int foreground;
+	public int background;
+
+	public ThemeTrieElementRule(int scopeDepth, List parentScopes, int fontStyle, int foreground,
+			int background) {
+		this.scopeDepth = scopeDepth;
+		this.parentScopes = parentScopes;
+		this.fontStyle = fontStyle;
+		this.foreground = foreground;
+		this.background = background;
+	}
+
+	@Override
+	public ThemeTrieElementRule clone() {
+		return new ThemeTrieElementRule(this.scopeDepth, this.parentScopes, this.fontStyle, this.foreground,
+				this.background);
+	}
+
+	public static List cloneArr(List arr) {
+		List r = new ArrayList<>();
+		for (int i = 0, len = arr.size(); i < len; i++) {
+			r.add(arr.get(i).clone());
+		}
+		return r;
+	}
+
+	public void acceptOverwrite(int scopeDepth, int fontStyle, int foreground, int background) {
+		if (this.scopeDepth > scopeDepth) {
+			// TODO!!!
+			// console.log('how did this happen?');
+		} else {
+			this.scopeDepth = scopeDepth;
+		}
+		// console.log('TODO -> my depth: ' + this.scopeDepth + ', overwriting
+		// depth: ' + scopeDepth);
+		if (fontStyle != FontStyle.NotSet) {
+			this.fontStyle = fontStyle;
+		}
+		if (foreground != 0) {
+			this.foreground = foreground;
+		}
+		if (background != 0) {
+			this.background = background;
+		}
+	}
+
+	@Override
+	public int hashCode() {
+	  return Objects.hash(background, fontStyle, foreground, parentScopes, scopeDepth);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj) {
+			return true;
+		}
+		if (obj == null) {
+			return false;
+		}
+		if (getClass() != obj.getClass()) {
+			return false;
+		}
+		ThemeTrieElementRule other = (ThemeTrieElementRule) obj;
+		return background == other.background && fontStyle == other.fontStyle && foreground == other.foreground &&
+		    Objects.equals(parentScopes, other.parentScopes) && scopeDepth == other.scopeDepth;
+	}
+
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java
index 31d98232a..c7829250d 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java
@@ -1,90 +1,90 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme.css;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.util.List;
-
-import org.eclipse.tm4e.core.internal.css.CSSConditionFactory;
-import org.eclipse.tm4e.core.internal.css.CSSDocumentHandler;
-import org.eclipse.tm4e.core.internal.css.CSSSelectorFactory;
-import org.eclipse.tm4e.core.internal.css.ExtendedSelector;
-import org.eclipse.tm4e.core.theme.IStyle;
-import org.w3c.css.sac.CSSException;
-import org.w3c.css.sac.InputSource;
-import org.w3c.css.sac.Parser;
-import org.w3c.css.sac.Selector;
-import org.w3c.css.sac.SelectorList;
-
-/**
- * CSS Parser to parse style for TextMate syntax coloration.
- *
- */
-public class CSSParser {
-
-	private final CSSDocumentHandler handler;
-
-	public CSSParser(InputStream source) throws Exception {
-		this(toSource(source));
-	}
-
-	private static InputSource toSource(InputStream source) {
-		InputSource in = new InputSource();
-		in.setByteStream(source);
-		return in;
-	}
-
-	public CSSParser(InputSource source) throws Exception {
-		this(source, SACParserFactory.newInstance().makeParser());
-	}
-
-	public CSSParser(String source) throws Exception {
-		this(new InputSource(new StringReader(source)));
-	}
-
-	public CSSParser(InputSource source, Parser parser) throws CSSException, IOException {
-		this.handler = new CSSDocumentHandler();
-		parser.setDocumentHandler(handler);
-		parser.setConditionFactory(CSSConditionFactory.INSTANCE);
-		parser.setSelectorFactory(CSSSelectorFactory.INSTANCE);
-		parser.parseStyleSheet(source);
-	}
-
-	public IStyle getBestStyle(String... names) {
-		int bestSpecificity = 0;
-		IStyle bestStyle = null;
-		for (IStyle style : handler.getList()) {
-			SelectorList list = ((CSSStyle) style).getSelectorList();
-			for (int i = 0; i < list.getLength(); i++) {
-				Selector selector = list.item(i);
-				if (selector instanceof ExtendedSelector) {
-					ExtendedSelector s = ((ExtendedSelector) selector);
-					int nbMatch = s.nbMatch(names);
-					if (nbMatch > 0 && nbMatch == s.nbClass()) {
-						if (bestStyle == null || (nbMatch >= bestSpecificity)) {
-							bestStyle = style;
-							bestSpecificity = nbMatch;
-						}
-					}
-				}
-			}
-		}
-		return bestStyle;
-	}
-
-	public List getStyles() {
-		return handler.getList();
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme.css;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.List;
+
+import org.eclipse.tm4e.core.internal.css.CSSConditionFactory;
+import org.eclipse.tm4e.core.internal.css.CSSDocumentHandler;
+import org.eclipse.tm4e.core.internal.css.CSSSelectorFactory;
+import org.eclipse.tm4e.core.internal.css.ExtendedSelector;
+import org.eclipse.tm4e.core.theme.IStyle;
+import org.w3c.css.sac.CSSException;
+import org.w3c.css.sac.InputSource;
+import org.w3c.css.sac.Parser;
+import org.w3c.css.sac.Selector;
+import org.w3c.css.sac.SelectorList;
+
+/**
+ * CSS Parser to parse style for TextMate syntax coloration.
+ *
+ */
+public class CSSParser {
+
+	private final CSSDocumentHandler handler;
+
+	public CSSParser(InputStream source) throws Exception {
+		this(toSource(source));
+	}
+
+	private static InputSource toSource(InputStream source) {
+		InputSource in = new InputSource();
+		in.setByteStream(source);
+		return in;
+	}
+
+	public CSSParser(InputSource source) throws Exception {
+		this(source, SACParserFactory.newInstance().makeParser());
+	}
+
+	public CSSParser(String source) throws Exception {
+		this(new InputSource(new StringReader(source)));
+	}
+
+	public CSSParser(InputSource source, Parser parser) throws CSSException, IOException {
+		this.handler = new CSSDocumentHandler();
+		parser.setDocumentHandler(handler);
+		parser.setConditionFactory(CSSConditionFactory.INSTANCE);
+		parser.setSelectorFactory(CSSSelectorFactory.INSTANCE);
+		parser.parseStyleSheet(source);
+	}
+
+	public IStyle getBestStyle(String... names) {
+		int bestSpecificity = 0;
+		IStyle bestStyle = null;
+		for (IStyle style : handler.getList()) {
+			SelectorList list = ((CSSStyle) style).getSelectorList();
+			for (int i = 0; i < list.getLength(); i++) {
+				Selector selector = list.item(i);
+				if (selector instanceof ExtendedSelector) {
+					ExtendedSelector s = ((ExtendedSelector) selector);
+					int nbMatch = s.nbMatch(names);
+					if (nbMatch > 0 && nbMatch == s.nbClass()) {
+						if (bestStyle == null || (nbMatch >= bestSpecificity)) {
+							bestStyle = style;
+							bestSpecificity = nbMatch;
+						}
+					}
+				}
+			}
+		}
+		return bestStyle;
+	}
+
+	public List getStyles() {
+		return handler.getList();
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java
index 25e30d67d..81162d5bc 100644
--- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java
+++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java
@@ -1,91 +1,91 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.theme.css;
-
-import org.eclipse.tm4e.core.theme.IStyle;
-import org.eclipse.tm4e.core.theme.RGB;
-import org.w3c.css.sac.SelectorList;
-
-public class CSSStyle implements IStyle {
-
-	private final SelectorList selector;
-	private RGB color;
-	private RGB backgroundColor;
-	
-	private boolean bold;
-	private boolean italic;
-	private boolean underline;
-	private boolean strikeThrough;
-
-	public CSSStyle(SelectorList selector) {
-		this.selector = selector;
-	}
-
-	public void setColor(RGB color) {
-		this.color = color;
-	}
-
-	@Override
-	public RGB getColor() {
-		return color;
-	}
-
-	@Override
-	public RGB getBackgroundColor() {
-		return backgroundColor;
-	}
-	
-	public void setBackgroundColor(RGB backgroundColor) {
-		this.backgroundColor = backgroundColor;		
-	}
-	
-	public SelectorList getSelectorList() {
-		return selector;
-	}
-
-	public void setBold(boolean bold) {
-		this.bold = bold;
-	}
-
-	@Override
-	public boolean isBold() {
-		return bold;
-	}
-
-	public void setItalic(boolean italic) {
-		this.italic = italic;
-	}
-
-	@Override
-	public boolean isItalic() {
-		return italic;
-	}
-
-	@Override
-	public boolean isUnderline() {
-		return underline;
-	}
-
-	public void setUnderline(boolean underline) {
-		this.underline = underline;
-	}
-
-	@Override
-	public boolean isStrikeThrough() {
-		return strikeThrough;
-	}
-	
-	public void setStrikeThrough(boolean strikeThrough) {
-		this.strikeThrough = strikeThrough;
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.theme.css;
+
+import org.eclipse.tm4e.core.theme.IStyle;
+import org.eclipse.tm4e.core.theme.RGB;
+import org.w3c.css.sac.SelectorList;
+
+public class CSSStyle implements IStyle {
+
+	private final SelectorList selector;
+	private RGB color;
+	private RGB backgroundColor;
+	
+	private boolean bold;
+	private boolean italic;
+	private boolean underline;
+	private boolean strikeThrough;
+
+	public CSSStyle(SelectorList selector) {
+		this.selector = selector;
+	}
+
+	public void setColor(RGB color) {
+		this.color = color;
+	}
+
+	@Override
+	public RGB getColor() {
+		return color;
+	}
+
+	@Override
+	public RGB getBackgroundColor() {
+		return backgroundColor;
+	}
+	
+	public void setBackgroundColor(RGB backgroundColor) {
+		this.backgroundColor = backgroundColor;		
+	}
+	
+	public SelectorList getSelectorList() {
+		return selector;
+	}
+
+	public void setBold(boolean bold) {
+		this.bold = bold;
+	}
+
+	@Override
+	public boolean isBold() {
+		return bold;
+	}
+
+	public void setItalic(boolean italic) {
+		this.italic = italic;
+	}
+
+	@Override
+	public boolean isItalic() {
+		return italic;
+	}
+
+	@Override
+	public boolean isUnderline() {
+		return underline;
+	}
+
+	public void setUnderline(boolean underline) {
+		this.underline = underline;
+	}
+
+	@Override
+	public boolean isStrikeThrough() {
+		return strikeThrough;
+	}
+	
+	public void setStrikeThrough(boolean strikeThrough) {
+		this.strikeThrough = strikeThrough;
+	}
+
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/Data.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/Data.java
index 7eb0ddfa8..66d2bb555 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/Data.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/Data.java
@@ -1,16 +1,16 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core;
-
-public class Data {
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core;
+
+public class Data {
+
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java
index d30bbef31..f0b78972f 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java
@@ -1,31 +1,31 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core;
-
-import org.eclipse.tm4e.core.grammar.IGrammar;
-import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
-import org.eclipse.tm4e.core.registry.Registry;
-
-public class TestGrammar {
-
-	public static void main(String[] args) throws Exception {
-
-		Registry registry = new Registry();
-		IGrammar grammar = registry.loadGrammarFromPathSync("Angular2TypeScript.tmLanguage",
-				TestGrammar.class.getResourceAsStream("Angular2TypeScript.tmLanguage"));
-
-		ITokenizeLineResult result = grammar.tokenizeLine("/** **/");
-		for (int i = 0; i < result.getTokens().length; i++) {
-			System.err.println(result.getTokens()[i]);
-		}
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core;
+
+import org.eclipse.tm4e.core.grammar.IGrammar;
+import org.eclipse.tm4e.core.grammar.ITokenizeLineResult;
+import org.eclipse.tm4e.core.registry.Registry;
+
+public class TestGrammar {
+
+	public static void main(String[] args) throws Exception {
+
+		Registry registry = new Registry();
+		IGrammar grammar = registry.loadGrammarFromPathSync("Angular2TypeScript.tmLanguage",
+				TestGrammar.class.getResourceAsStream("Angular2TypeScript.tmLanguage"));
+
+		ITokenizeLineResult result = grammar.tokenizeLine("/** **/");
+		for (int i = 0; i < result.getTokens().length; i++) {
+			System.err.println(result.getTokens()[i]);
+		}
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestOngurama.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestOngurama.java
index de601a35b..b63b6ada4 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestOngurama.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestOngurama.java
@@ -1,29 +1,29 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core;
-
-import org.eclipse.tm4e.core.internal.oniguruma.IOnigNextMatchResult;
-import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner;
-
-public class TestOngurama {
-
-	public static void main(String[] args) {
-
-		OnigScanner scanner = new OnigScanner(new String[] { "c", "a(b)?" });
-		IOnigNextMatchResult result = scanner.findNextMatchSync("abc", 0);
-		System.err.println(result);
-
-		scanner = new OnigScanner(new String[] { "a([b-d])c" });
-		result = scanner.findNextMatchSync("!abcdef", 0);
-		System.err.println(result);
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core;
+
+import org.eclipse.tm4e.core.internal.oniguruma.IOnigNextMatchResult;
+import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner;
+
+public class TestOngurama {
+
+	public static void main(String[] args) {
+
+		OnigScanner scanner = new OnigScanner(new String[] { "c", "a(b)?" });
+		IOnigNextMatchResult result = scanner.findNextMatchSync("abc", 0);
+		System.err.println(result);
+
+		scanner = new OnigScanner(new String[] { "a([b-d])c" });
+		result = scanner.findNextMatchSync("!abcdef", 0);
+		System.err.println(result);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/css/CSSParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/css/CSSParserTest.java
index ea47b0513..cf25dd4cc 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/css/CSSParserTest.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/css/CSSParserTest.java
@@ -1,29 +1,29 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.css;
-
-import org.eclipse.tm4e.core.theme.IStyle;
-import org.eclipse.tm4e.core.theme.css.CSSParser;
-
-public class CSSParserTest {
-
-	public static void main(String[] args) throws Exception {
-		CSSParser parser = new CSSParser(".comment {color:rgb(0,1,2)} .comment.ts {color:rgb(0,1,2)}");
-		String[] names = "comment".split("[.]");
-		parser.getBestStyle(names);
-		
-		names = "comment.ts".split("[.]");
-		IStyle style = parser.getBestStyle(names);
-		
-		System.err.println(style.getColor().red);
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.css;
+
+import org.eclipse.tm4e.core.theme.IStyle;
+import org.eclipse.tm4e.core.theme.css.CSSParser;
+
+public class CSSParserTest {
+
+	public static void main(String[] args) throws Exception {
+		CSSParser parser = new CSSParser(".comment {color:rgb(0,1,2)} .comment.ts {color:rgb(0,1,2)}");
+		String[] names = "comment".split("[.]");
+		parser.getBestStyle(names);
+		
+		names = "comment.ts".split("[.]");
+		IStyle style = parser.getBestStyle(names);
+		
+		System.err.println(style.getColor().red);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java
index 69885692b..41b6a2cad 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java
@@ -1,85 +1,85 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.eclipse.tm4e.core.Data;
-import org.eclipse.tm4e.core.registry.IRegistryOptions;
-import org.eclipse.tm4e.core.registry.Registry;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for grammar tokenizer.
- *
- */
-public class GrammarInjectionTest {
-
-	private static final String[] EXPECTED_TOKENS = {
-			"Token from 0 to 1 with scopes [source.ts, meta.decorator.ts, punctuation.decorator.ts]",
-			"Token from 1 to 10 with scopes [source.ts, meta.decorator.ts, entity.name.function.ts]",
-			"Token from 10 to 11 with scopes [source.ts, meta.decorator.ts, meta.brace.round.ts]",
-			"Token from 11 to 12 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, punctuation.definition.block.ts]",
-			"Token from 12 to 20 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, meta.object-literal.key.ts]",
-			"Token from 20 to 21 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, meta.object-literal.key.ts, punctuation.separator.key-value.ts]",
-			"Token from 21 to 22 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, string.template.ts, punctuation.definition.string.template.begin.ts]",
-			"Token from 22 to 38 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, string.template.ts]",
-			"Token from 38 to 39 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, string.template.ts, punctuation.definition.string.template.end.ts]",
-			"Token from 39 to 40 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, punctuation.definition.block.ts]",
-			"Token from 40 to 41 with scopes [source.ts, meta.decorator.ts, meta.brace.round.ts]" };
-
-
-	@Test
-	public void angular2TokenizeLine() throws Exception {
-		Registry registry = new Registry(new IRegistryOptions() {
-
-			@Override
-			public InputStream getInputStream(String scopeName) throws IOException {
-				return Data.class.getResourceAsStream(getFilePath(scopeName));
-			}
-
-			@Override
-			public Collection getInjections(String scopeName) {
-				return Arrays.asList("template.ng", "styles.ng");
-			}
-
-			@Override
-			public String getFilePath(String scopeName) {
-				if ("source.js".equals(scopeName)) {
-					return "JavaScript.tmLanguage.json";
-				} else if ("text.html.basic".equals(scopeName)) {
-					return "html.json";
-				} else if ("source.ts".equals(scopeName)) {
-					return "TypeScript.tmLanguage.json";
-				} else if ("template.ng".equals(scopeName)) {
-					return "template.ng.json";
-				} else if ("styles.ng".equals(scopeName)) {
-					return "styles.ng.json";
-				}
-				return null;
-			}
-		});
-		IGrammar grammar = registry.loadGrammar("source.ts");
-		ITokenizeLineResult lineTokens = grammar.tokenizeLine("@Component({template:``})");
-		for (int i = 0; i < lineTokens.getTokens().length; i++) {
-			IToken token = lineTokens.getTokens()[i];
-			String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
-					+ token.getScopes();
-			System.err.println(s);
-			Assertions.assertEquals(EXPECTED_TOKENS[i], s);
-		}
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.eclipse.tm4e.core.Data;
+import org.eclipse.tm4e.core.registry.IRegistryOptions;
+import org.eclipse.tm4e.core.registry.Registry;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for grammar tokenizer.
+ *
+ */
+public class GrammarInjectionTest {
+
+	private static final String[] EXPECTED_TOKENS = {
+			"Token from 0 to 1 with scopes [source.ts, meta.decorator.ts, punctuation.decorator.ts]",
+			"Token from 1 to 10 with scopes [source.ts, meta.decorator.ts, entity.name.function.ts]",
+			"Token from 10 to 11 with scopes [source.ts, meta.decorator.ts, meta.brace.round.ts]",
+			"Token from 11 to 12 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, punctuation.definition.block.ts]",
+			"Token from 12 to 20 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, meta.object-literal.key.ts]",
+			"Token from 20 to 21 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, meta.object-literal.key.ts, punctuation.separator.key-value.ts]",
+			"Token from 21 to 22 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, string.template.ts, punctuation.definition.string.template.begin.ts]",
+			"Token from 22 to 38 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, string.template.ts]",
+			"Token from 38 to 39 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, meta.object.member.ts, string.template.ts, punctuation.definition.string.template.end.ts]",
+			"Token from 39 to 40 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, punctuation.definition.block.ts]",
+			"Token from 40 to 41 with scopes [source.ts, meta.decorator.ts, meta.brace.round.ts]" };
+
+
+	@Test
+	public void angular2TokenizeLine() throws Exception {
+		Registry registry = new Registry(new IRegistryOptions() {
+
+			@Override
+			public InputStream getInputStream(String scopeName) throws IOException {
+				return Data.class.getResourceAsStream(getFilePath(scopeName));
+			}
+
+			@Override
+			public Collection getInjections(String scopeName) {
+				return Arrays.asList("template.ng", "styles.ng");
+			}
+
+			@Override
+			public String getFilePath(String scopeName) {
+				if ("source.js".equals(scopeName)) {
+					return "JavaScript.tmLanguage.json";
+				} else if ("text.html.basic".equals(scopeName)) {
+					return "html.json";
+				} else if ("source.ts".equals(scopeName)) {
+					return "TypeScript.tmLanguage.json";
+				} else if ("template.ng".equals(scopeName)) {
+					return "template.ng.json";
+				} else if ("styles.ng".equals(scopeName)) {
+					return "styles.ng.json";
+				}
+				return null;
+			}
+		});
+		IGrammar grammar = registry.loadGrammar("source.ts");
+		ITokenizeLineResult lineTokens = grammar.tokenizeLine("@Component({template:``})");
+		for (int i = 0; i < lineTokens.getTokens().length; i++) {
+			IToken token = lineTokens.getTokens()[i];
+			String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
+					+ token.getScopes();
+			System.err.println(s);
+			Assertions.assertEquals(EXPECTED_TOKENS[i], s);
+		}
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java
index 8dc2fcb38..44ca2ffec 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java
@@ -1,97 +1,97 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar;
-
-import org.eclipse.tm4e.core.Data;
-import org.eclipse.tm4e.core.registry.Registry;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for grammar tokenizer.
- *
- */
-public class GrammarTest {
-
-	private static final String[] EXPECTED_TOKENS = {
-			"Token from 0 to 8 with scopes [source.js, meta.function.js, storage.type.function.js]",
-			"Token from 8 to 9 with scopes [source.js, meta.function.js]",
-			"Token from 9 to 12 with scopes [source.js, meta.function.js, entity.name.function.js]",
-			"Token from 12 to 13 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
-			"Token from 13 to 14 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
-			"Token from 14 to 15 with scopes [source.js, meta.function.js, meta.function.type.parameter.js]",
-			"Token from 15 to 16 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
-			"Token from 16 to 17 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
-			"Token from 17 to 18 with scopes [source.js, meta.function.js]",
-			"Token from 18 to 19 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]",
-			"Token from 19 to 20 with scopes [source.js, meta.function.js, meta.decl.block.js]",
-			"Token from 20 to 26 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.control.js]",
-			"Token from 26 to 28 with scopes [source.js, meta.function.js, meta.decl.block.js]",
-			"Token from 28 to 29 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.operator.arithmetic.js]",
-			"Token from 29 to 32 with scopes [source.js, meta.function.js, meta.decl.block.js]",
-			"Token from 32 to 33 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]" };
-
-	private static final String[] EXPECTED_MULTI_LINE_TOKENS = {
-			"Token from 0 to 8 with scopes [source.js, meta.function.js, storage.type.function.js]",
-			"Token from 8 to 9 with scopes [source.js, meta.function.js]",
-			"Token from 9 to 12 with scopes [source.js, meta.function.js, entity.name.function.js]",
-			"Token from 12 to 13 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
-			"Token from 13 to 14 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
-			"Token from 14 to 15 with scopes [source.js, meta.function.js, meta.function.type.parameter.js]",
-			"Token from 15 to 16 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
-			"Token from 16 to 17 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
-			"Token from 0 to 1 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]",
-			"Token from 1 to 2 with scopes [source.js, meta.function.js, meta.decl.block.js]",
-			"Token from 2 to 8 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.control.js]",
-			"Token from 8 to 10 with scopes [source.js, meta.function.js, meta.decl.block.js]",
-			"Token from 10 to 11 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.operator.arithmetic.js]",
-			"Token from 11 to 14 with scopes [source.js, meta.function.js, meta.decl.block.js]",
-			"Token from 14 to 15 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]" };
-
-	@Test
-	public void tokenizeLine() throws Exception {
-		Registry registry = new Registry();
-		String path = "JavaScript.tmLanguage";
-		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
-		ITokenizeLineResult lineTokens = grammar.tokenizeLine("function add(a,b) { return a+b; }");
-		for (int i = 0; i < lineTokens.getTokens().length; i++) {
-			IToken token = lineTokens.getTokens()[i];
-			String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
-					+ token.getScopes();
-			Assertions.assertEquals(EXPECTED_TOKENS[i], s);
-		}
-	}
-
-	@Test
-	public void tokenizeLines() throws Exception {
-		Registry registry = new Registry();
-		String path = "JavaScript.tmLanguage";
-		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
-
-		StackElement ruleStack = null;
-		int i = 0;
-		int j = 0;
-		String[] lines = { "function add(a,b)", "{ return a+b; }" };
-		for (int l = 0; l < lines.length; l++) {
-			ITokenizeLineResult lineTokens = grammar.tokenizeLine(lines[l], ruleStack);
-			ruleStack = lineTokens.getRuleStack();
-			for (i = 0; i < lineTokens.getTokens().length; i++) {
-				IToken token = lineTokens.getTokens()[i];
-				String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
-						+ token.getScopes();
-				Assertions.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s);
-			}
-			j = i;
-		}
-
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar;
+
+import org.eclipse.tm4e.core.Data;
+import org.eclipse.tm4e.core.registry.Registry;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for grammar tokenizer.
+ *
+ */
+public class GrammarTest {
+
+	private static final String[] EXPECTED_TOKENS = {
+			"Token from 0 to 8 with scopes [source.js, meta.function.js, storage.type.function.js]",
+			"Token from 8 to 9 with scopes [source.js, meta.function.js]",
+			"Token from 9 to 12 with scopes [source.js, meta.function.js, entity.name.function.js]",
+			"Token from 12 to 13 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
+			"Token from 13 to 14 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
+			"Token from 14 to 15 with scopes [source.js, meta.function.js, meta.function.type.parameter.js]",
+			"Token from 15 to 16 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
+			"Token from 16 to 17 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
+			"Token from 17 to 18 with scopes [source.js, meta.function.js]",
+			"Token from 18 to 19 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]",
+			"Token from 19 to 20 with scopes [source.js, meta.function.js, meta.decl.block.js]",
+			"Token from 20 to 26 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.control.js]",
+			"Token from 26 to 28 with scopes [source.js, meta.function.js, meta.decl.block.js]",
+			"Token from 28 to 29 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.operator.arithmetic.js]",
+			"Token from 29 to 32 with scopes [source.js, meta.function.js, meta.decl.block.js]",
+			"Token from 32 to 33 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]" };
+
+	private static final String[] EXPECTED_MULTI_LINE_TOKENS = {
+			"Token from 0 to 8 with scopes [source.js, meta.function.js, storage.type.function.js]",
+			"Token from 8 to 9 with scopes [source.js, meta.function.js]",
+			"Token from 9 to 12 with scopes [source.js, meta.function.js, entity.name.function.js]",
+			"Token from 12 to 13 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
+			"Token from 13 to 14 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
+			"Token from 14 to 15 with scopes [source.js, meta.function.js, meta.function.type.parameter.js]",
+			"Token from 15 to 16 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, parameter.name.js, variable.parameter.js]",
+			"Token from 16 to 17 with scopes [source.js, meta.function.js, meta.function.type.parameter.js, meta.brace.round.js]",
+			"Token from 0 to 1 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]",
+			"Token from 1 to 2 with scopes [source.js, meta.function.js, meta.decl.block.js]",
+			"Token from 2 to 8 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.control.js]",
+			"Token from 8 to 10 with scopes [source.js, meta.function.js, meta.decl.block.js]",
+			"Token from 10 to 11 with scopes [source.js, meta.function.js, meta.decl.block.js, keyword.operator.arithmetic.js]",
+			"Token from 11 to 14 with scopes [source.js, meta.function.js, meta.decl.block.js]",
+			"Token from 14 to 15 with scopes [source.js, meta.function.js, meta.decl.block.js, meta.brace.curly.js]" };
+
+	@Test
+	public void tokenizeLine() throws Exception {
+		Registry registry = new Registry();
+		String path = "JavaScript.tmLanguage";
+		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
+		ITokenizeLineResult lineTokens = grammar.tokenizeLine("function add(a,b) { return a+b; }");
+		for (int i = 0; i < lineTokens.getTokens().length; i++) {
+			IToken token = lineTokens.getTokens()[i];
+			String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
+					+ token.getScopes();
+			Assertions.assertEquals(EXPECTED_TOKENS[i], s);
+		}
+	}
+
+	@Test
+	public void tokenizeLines() throws Exception {
+		Registry registry = new Registry();
+		String path = "JavaScript.tmLanguage";
+		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
+
+		StackElement ruleStack = null;
+		int i = 0;
+		int j = 0;
+		String[] lines = { "function add(a,b)", "{ return a+b; }" };
+		for (int l = 0; l < lines.length; l++) {
+			ITokenizeLineResult lineTokens = grammar.tokenizeLine(lines[l], ruleStack);
+			ruleStack = lineTokens.getRuleStack();
+			for (i = 0; i < lineTokens.getTokens().length; i++) {
+				IToken token = lineTokens.getTokens()[i];
+				String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
+						+ token.getScopes();
+				Assertions.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s);
+			}
+			j = i;
+		}
+
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java
index a69fd5f73..c527140ec 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java
@@ -1,69 +1,69 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tm4e.core.Data;
-import org.eclipse.tm4e.core.registry.Registry;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for grammar tokenizer.
- *
- */
-class GrammarTest2 {
-
-	@Test
-	void tokenizeLines() throws Exception {
-		Registry registry = new Registry();
-		String path = "JavaScript.tmLanguage";
-		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
-
-		StackElement ruleStack = null;
-		int i = 0;
-
-		List lines = new ArrayList<>();
-		try (BufferedReader reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("raytracer.ts")));){
-			String line = null;
-			while ((line = reader.readLine()) != null) {
-				lines.add(line);
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-
-		int t = 0;
-		boolean stop = false;
-		long start = System.currentTimeMillis();
-		for (String line : lines) {
-			ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack);
-			if (stop) {
-				t = 1000;
-				Thread.sleep(t);
-				stop = false;
-			}
-			ruleStack = lineTokens.getRuleStack();
-			for (i = 0; i < lineTokens.getTokens().length; i++) {
-				IToken token = lineTokens.getTokens()[i];
-				String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
-						+ token.getScopes();
-				System.err.println(s);
-				// Assert.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s);
-			}
-		}
-		System.out.println(System.currentTimeMillis() - start - t);
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tm4e.core.Data;
+import org.eclipse.tm4e.core.registry.Registry;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for grammar tokenizer.
+ *
+ */
+class GrammarTest2 {
+
+	@Test
+	void tokenizeLines() throws Exception {
+		Registry registry = new Registry();
+		String path = "JavaScript.tmLanguage";
+		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
+
+		StackElement ruleStack = null;
+		int i = 0;
+
+		List lines = new ArrayList<>();
+		try (BufferedReader reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("raytracer.ts")));){
+			String line = null;
+			while ((line = reader.readLine()) != null) {
+				lines.add(line);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		int t = 0;
+		boolean stop = false;
+		long start = System.currentTimeMillis();
+		for (String line : lines) {
+			ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack);
+			if (stop) {
+				t = 1000;
+				Thread.sleep(t);
+				stop = false;
+			}
+			ruleStack = lineTokens.getRuleStack();
+			for (i = 0; i < lineTokens.getTokens().length; i++) {
+				IToken token = lineTokens.getTokens()[i];
+				String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
+						+ token.getScopes();
+				System.err.println(s);
+				// Assert.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s);
+			}
+		}
+		System.out.println(System.currentTimeMillis() - start - t);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java
index 8a67876fa..8e0b59d32 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java
@@ -1,63 +1,63 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.grammar;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tm4e.core.Data;
-import org.eclipse.tm4e.core.registry.Registry;
-
-public class MarkDown {
-
-	public static void main(String[] args) throws Exception {
-		Registry registry = new Registry();
-		String path = "Markdown.tmLanguage";
-		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
-		
-		List lines = new ArrayList<>();
-		try (BufferedReader reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("test.md.txt")))) {
-			String line = null;
-			while ((line = reader.readLine()) != null) {
-				lines.add(line);
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-
-		
-		long start = System.currentTimeMillis();
-		
-		StackElement ruleStack = null;
-		int i = 0;
-		for (String line : lines) {
-			ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack);			
-			ruleStack = lineTokens.getRuleStack();
-			for (i = 0; i < lineTokens.getTokens().length; i++) {
-//				IToken token = lineTokens.getTokens()[i];
-//				String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
-//						+ token.getScopes();
-				//System.err.println(s);
-				// Assert.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s);
-			}
-		}	
-		System.err.println(System.currentTimeMillis() - start);
-	}
-	
-	static String convertStreamToString(java.io.InputStream is) {
-	    try (java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A")) {
-	    	return s.hasNext() ? s.next() : "";
-	    }
-	}
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.grammar;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tm4e.core.Data;
+import org.eclipse.tm4e.core.registry.Registry;
+
+public class MarkDown {
+
+	public static void main(String[] args) throws Exception {
+		Registry registry = new Registry();
+		String path = "Markdown.tmLanguage";
+		IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path));
+		
+		List lines = new ArrayList<>();
+		try (BufferedReader reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("test.md.txt")))) {
+			String line = null;
+			while ((line = reader.readLine()) != null) {
+				lines.add(line);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		
+		long start = System.currentTimeMillis();
+		
+		StackElement ruleStack = null;
+		int i = 0;
+		for (String line : lines) {
+			ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack);			
+			ruleStack = lineTokens.getRuleStack();
+			for (i = 0; i < lineTokens.getTokens().length; i++) {
+//				IToken token = lineTokens.getTokens()[i];
+//				String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes "
+//						+ token.getScopes();
+				//System.err.println(s);
+				// Assert.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s);
+			}
+		}	
+		System.err.println(System.currentTimeMillis() - start);
+	}
+	
+	static String convertStreamToString(java.io.InputStream is) {
+	    try (java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A")) {
+	    	return s.hasNext() ? s.next() : "";
+	    }
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java
index ef5ee3ded..3fd2f5e4e 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java
@@ -1,27 +1,27 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.grammar.parser.json;
-
-import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader;
-import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser;
-import org.eclipse.tm4e.core.internal.types.IRawGrammar;
-import org.junit.jupiter.api.Test;
-
-public class JSONPListParserTest {
-
-	@Test
-	public void testCsharp() throws Exception {
-		IGrammarParser parser = GrammarReader.JSON_PARSER;
-		IRawGrammar grammar = parser.parse(JSONPListParserTest.class.getResourceAsStream("csharp.json"));
-		System.err.println(grammar);
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.grammar.parser.json;
+
+import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader;
+import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser;
+import org.eclipse.tm4e.core.internal.types.IRawGrammar;
+import org.junit.jupiter.api.Test;
+
+public class JSONPListParserTest {
+
+	@Test
+	public void testCsharp() throws Exception {
+		IGrammarParser parser = GrammarReader.JSON_PARSER;
+		IRawGrammar grammar = parser.parse(JSONPListParserTest.class.getResourceAsStream("csharp.json"));
+		System.err.println(grammar);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java
index ea39eeae2..6f3ccc4a1 100644
--- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java
+++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java
@@ -1,27 +1,27 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.core.internal.grammar.parser.xml;
-
-import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader;
-import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser;
-import org.eclipse.tm4e.core.internal.types.IRawGrammar;
-import org.junit.jupiter.api.Test;
-
-public class XMLPlistParserTest {
-
-	@Test
-	public void testCsharp() throws Exception {
-		IGrammarParser parser = GrammarReader.XML_PARSER;
-		IRawGrammar grammar = parser.parse(XMLPlistParserTest.class.getResourceAsStream("JavaScript.tmLanguage"));
-		System.err.println(grammar);
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.core.internal.grammar.parser.xml;
+
+import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader;
+import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser;
+import org.eclipse.tm4e.core.internal.types.IRawGrammar;
+import org.junit.jupiter.api.Test;
+
+public class XMLPlistParserTest {
+
+	@Test
+	public void testCsharp() throws Exception {
+		IGrammarParser parser = GrammarReader.XML_PARSER;
+		IRawGrammar grammar = parser.parse(XMLPlistParserTest.class.getResourceAsStream("JavaScript.tmLanguage"));
+		System.err.println(grammar);
+	}
+}
diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Angular2TypeScript.tmLanguage b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Angular2TypeScript.tmLanguage
index 4befb89a2..ecfdca5ab 100644
--- a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Angular2TypeScript.tmLanguage
+++ b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Angular2TypeScript.tmLanguage
@@ -1,2003 +1,2003 @@
-
-
-
-
-	fileTypes
-	
-		ts
-	
-	name
-	TypeScript
-	patterns
-	
-		
-			include
-			#expression
-		
-	
-	repository
-	
-		access-modifier
-		
-			match
-			\b(public|protected|private)\b
-			name
-			storage.modifier.ts
-		
-		arithmetic-operator
-		
-			match
-			\*|/|\-\-|\-|\+\+|\+|%
-			name
-			keyword.operator.arithmetic.ts
-		
-		array-literal
-		
-			begin
-			\[
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.square.ts
-				
-			
-			end
-			\]
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.square.ts
-				
-			
-			name
-			meta.array.literal.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		assignment-operator
-		
-			match
-			<<=|>>=|>>>=|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=
-			name
-			keyword.operator.assignment.ts
-		
-		block
-		
-			begin
-			\{
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			end
-			\}
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			name
-			meta.block.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-				
-					include
-					#object-member
-				
-			
-		
-		boolean-literal
-		
-			match
-			\b(false|true)\b
-			name
-			constant.language.boolean.ts
-		
-		cast
-		
-			begin
-			(?:(?<=return|throw|yield|[=(,:>]))\s*(<)(?!<?\=)
-			beginCaptures
-			
-				1
-				
-					name
-					meta.brace.angle.ts
-				
-			
-			end
-			>
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.angle.ts
-				
-			
-			name
-			cast.expr.ts
-			patterns
-			
-				
-					include
-					#type
-				
-			
-		
-		comment
-		
-			name
-			comment.ts
-			patterns
-			
-				
-					include
-					#comment-block-doc
-				
-				
-					include
-					#comment-block
-				
-				
-					include
-					#comment-line
-				
-			
-		
-		comment-block
-		
-			begin
-			/\*
-			end
-			\*/
-			name
-			comment.block.ts
-		
-		comment-block-doc
-		
-			begin
-			/\*\*(?!/)
-			end
-			\*/
-			name
-			comment.block.documentation.ts
-		
-		comment-line
-		
-			match
-			(//).*$\n?
-			name
-			comment.line.ts
-		
-		control-statement
-		
-			match
-			(?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default)\b
-			name
-			keyword.control.ts
-		
-		decl-block
-		
-			begin
-			\{
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			end
-			\}
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			name
-			meta.decl.block.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		declaration
-		
-			name
-			meta.declaration.ts
-			patterns
-			
-				
-					include
-					#function-declaration
-				
-				
-					include
-					#object-declaration
-				
-				
-					include
-					#type-declaration
-				
-				
-					include
-					#enum-declaration
-				
-			
-		
-		enum-declaration
-		
-			captures
-			
-				1
-				
-					name
-					storage.modifier.ts
-				
-				2
-				
-					name
-					storage.type.ts
-				
-				3
-				
-					name
-					entity.name.class.ts
-				
-			
-			match
-			(?:\b(const)\s+)?\b(enum)\s+([a-zA-Z_$][\w$]*)
-			name
-			meta.enum.declaration.ts
-		
-		expression
-		
-			name
-			meta.expression.ts
-			patterns
-			
-				
-					include
-					#ngTemplate
-				
-				
-					include
-					#for-in-simple
-				
-				
-					include
-					#string
-				
-				
-					include
-					#regex
-				
-				
-					include
-					#template
-				
-				
-					include
-					#comment
-				
-				
-					include
-					#literal
-				
-				
-					include
-					#paren-expression
-				
-				
-					include
-					#var-expr
-				
-				
-					include
-					#declaration
-				
-				
-					include
-					#cast
-				
-				
-					include
-					#new-expr
-				
-				
-					include
-					#block
-				
-				
-					include
-					#expression-operator
-				
-				
-					include
-					#relational-operator
-				
-				
-					include
-					#arithmetic-operator
-				
-				
-					include
-					#logic-operator
-				
-				
-					include
-					#assignment-operator
-				
-				
-					include
-					#storage-keyword
-				
-				
-					include
-					#function-call
-				
-				
-					include
-					#switch-case
-				
-				
-					include
-					#control-statement
-				
-			
-		
-		expression-operator
-		
-			match
-			=>|\b(delete|export|import|in|instanceof|module|namespace|new|typeof|void)\b
-			name
-			keyword.operator.ts
-		
-		field-declaration
-		
-			begin
-			(?<!\()\s*\b([a-zA-Z_$][\w$]*)\s*(\?\s*)?(?=(=|:))
-			beginCaptures
-			
-				1
-				
-					name
-					variable.ts
-				
-				2
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			(?=\}|;|,)|(?<=\})
-			name
-			meta.field.declaration.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		for-in-simple
-		
-			captures
-			
-				1
-				
-					name
-					storage.type.ts
-				
-				3
-				
-					name
-					keyword.operator.ts
-				
-			
-			match
-			(?<=\()\s*\b(var|let|const)\s+([a-zA-Z_$][\w$]*)\s+(in|of)\b
-			name
-			forin.expr.ts
-		
-		function-call
-		
-			name
-			functioncall.expr.ts
-			patterns
-			
-				
-					include
-					#type-parameters
-				
-				
-					include
-					#paren-expression
-				
-			
-		
-		function-declaration
-		
-			begin
-			\b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s*
-			beginCaptures
-			
-				1
-				
-					name
-					storage.modifier.ts
-				
-				2
-				
-					name
-					storage.type.function.ts
-				
-				3
-				
-					name
-					entity.name.function.ts
-				
-			
-			end
-			(?=;|\})|(?<=\})
-			name
-			meta.function.ts
-			patterns
-			
-				
-					include
-					#comment
-				
-				
-					include
-					#type-parameters
-				
-				
-					include
-					#function-type-parameters
-				
-				
-					include
-					#return-type
-				
-				
-					include
-					#function-overload-declaration
-				
-				
-					include
-					#decl-block
-				
-			
-		
-		function-overload-declaration
-		
-			captures
-			
-				1
-				
-					name
-					storage.modifier.ts
-				
-				2
-				
-					name
-					storage.type.function.ts
-				
-				3
-				
-					name
-					entity.name.function.ts
-				
-			
-			match
-			\b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s*
-			name
-			meta.function.overload.ts
-		
-		function-type-parameters
-		
-			begin
-			\(
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.round.ts
-				
-			
-			end
-			\)
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.round.ts
-				
-			
-			name
-			meta.function.type.parameter.ts
-			patterns
-			
-				
-					include
-					#comment
-				
-				
-					include
-					#parameter-name
-				
-				
-					include
-					#type-annotation
-				
-				
-					include
-					#variable-initializer
-				
-			
-		
-		htmlComment
-		
-			begin
-			<!--
-			end
-			-->
-			name
-			comment.block.ts
-		
-		htmlText
-		
-			match
-			.*?(?=({{)|(\$\{)|<|$)
-			name
-			string.ts
-		
-		indexer-declaration
-		
-			begin
-			\[
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.square.ts
-				
-			
-			end
-			(\])\s*(\?\s*)?|$
-			endCaptures
-			
-				1
-				
-					name
-					meta.brace.square.ts
-				
-				2
-				
-					name
-					keyword.operator.ts
-				
-			
-			name
-			meta.indexer.declaration.ts
-			patterns
-			
-				
-					include
-					#type-annotation
-				
-				
-					include
-					#indexer-parameter
-				
-				
-					include
-					#expression
-				
-			
-		
-		indexer-parameter
-		
-			captures
-			
-				1
-				
-					name
-					variable.parameter.ts
-				
-			
-			match
-			([a-zA-Z_$][\w$]*)(?=\:)
-			name
-			meta.indexer.parameter.ts
-		
-		literal
-		
-			name
-			literal.ts
-			patterns
-			
-				
-					include
-					#numeric-literal
-				
-				
-					include
-					#boolean-literal
-				
-				
-					include
-					#null-literal
-				
-				
-					include
-					#undefined-literal
-				
-				
-					include
-					#array-literal
-				
-				
-					include
-					#this-literal
-				
-			
-		
-		logic-operator
-		
-			match
-			\!|&|~|\||&&|\|\|
-			name
-			keyword.operator.arithmetic.ts
-		
-		method-declaration
-		
-			begin
-			\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?(?:(get|set)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)
-			beginCaptures
-			
-				1
-				
-					name
-					storage.modifier.ts
-				
-				2
-				
-					name
-					storage.modifier.ts
-				
-				3
-				
-					name
-					storage.type.property.ts
-				
-				4
-				
-					name
-					keyword.operator.ts
-				
-				5
-				
-					name
-					entity.name.function.ts
-				
-				6
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			(?=\}|;|,)|(?<=\})
-			name
-			meta.method.declaration.ts
-			patterns
-			
-				
-					include
-					#comment
-				
-				
-					include
-					#type-parameters
-				
-				
-					include
-					#function-type-parameters
-				
-				
-					include
-					#type-annotation
-				
-				
-					include
-					#method-overload-declaration
-				
-				
-					include
-					#decl-block
-				
-			
-		
-		method-overload-declaration
-		
-			captures
-			
-				1
-				
-					name
-					storage.modifier.ts
-				
-				2
-				
-					name
-					keyword.operator.ts
-				
-				3
-				
-					name
-					entity.name.function.ts
-				
-				4
-				
-					name
-					keyword.operator.ts
-				
-			
-			match
-			\b(?:(public|private|protected)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)
-			name
-			meta.method.overload.declaration.ts
-		
-		new-expr
-		
-			begin
-			\b(new)\b
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			(?=[(;]|$)
-			name
-			new.expr.ts
-			patterns
-			
-				
-					include
-					#type
-				
-				
-					include
-					#comment
-				
-			
-		
-		ngAttrib
-		
-			begin
-			([a-zA-Z\$][a-zA-Z0-9\$\-]*)
-			beginCaptures
-			
-				1
-				
-					name
-					entity.name.class.ts
-				
-			
-			end
-			(?=[^'=])
-			name
-			meta.attribute.ts
-			patterns
-			
-				
-					include
-					#ngAttribValue
-				
-			
-		
-		ngAttribValue
-		
-			begin
-			=
-			beginCaptures
-			
-				0
-				
-					name
-					punctuation.separator.key-value.ts
-				
-			
-			end
-			(?<=')
-			name
-			meta.attribute.ts
-			patterns
-			
-				
-					include
-					#qstring-single
-				
-			
-		
-		ngBinding
-		
-			begin
-			(?:\(|\[|(?:\[\())([a-zA-Z\$][a-zA-Z0-9\$\-]*)(?:(?:\)\])|\)|\])
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.control.ts
-				
-			
-			end
-			(?=[^'=])
-			name
-			meta.binding-name.ts
-			patterns
-			
-				
-					include
-					#ngAttribValue
-				
-			
-		
-		ngDirective
-		
-			begin
-			\*([a-zA-Z\$][a-zA-Z0-9\$\-]*)
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.control.ts
-				
-			
-			end
-			(?=[^'=])
-			name
-			meta.directive-name.ts
-			patterns
-			
-				
-					include
-					#ngAttribValue
-				
-			
-		
-		ngExpr
-		
-			begin
-			{{
-			beginCaptures
-			
-				0
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			}}
-			endCaptures
-			
-				0
-				
-					name
-					keyword.operator.ts
-				
-			
-			name
-			meta.expression.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		ngTag
-		
-			begin
-			(<)([a-zA-Z\$][a-zA-Z0-9\$\-]*)
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.operator.ts
-				
-				2
-				
-					name
-					entity.name.tag.ts
-				
-			
-			end
-			(/>)|(?:(</)([a-zA-Z\$][a-zA-Z0-9\$\-]*)(>))
-			endCaptures
-			
-				1
-				
-					name
-					keyword.operator.ts
-				
-				2
-				
-					name
-					keyword.operator.ts
-				
-				3
-				
-					name
-					entity.name.tag.ts
-				
-				4
-				
-					name
-					keyword.operator.ts
-				
-			
-			name
-			meta.tag.ts
-			patterns
-			
-				
-					include
-					#ngAttrib
-				
-				
-					include
-					#ngDirective
-				
-				
-					include
-					#ngBinding
-				
-				
-					include
-					#ngTagEnd
-				
-			
-		
-		ngTagEnd
-		
-			begin
-			>
-			beginCaptures
-			
-				0
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			(?=</)
-			name
-			meta.tagend.ts
-			patterns
-			
-				
-					include
-					#ngml
-				
-			
-		
-		ngTemplate
-		
-			begin
-			(?:(?<=^|\stemplate:)|(?<=/\*\* @html \*/))\s*(`)
-			beginCaptures
-			
-				1
-				
-					name
-					string.template.ts
-				
-			
-			end
-			`
-			endCaptures
-			
-				0
-				
-					name
-					string.template.ts
-				
-			
-			name
-			meta.ngTemplate.ts
-			patterns
-			
-				
-					include
-					#ngml
-				
-			
-		
-		ngml
-		
-			name
-			meta.ngml.ts
-			patterns
-			
-				
-					include
-					#ngTag
-				
-				
-					include
-					#ngExpr
-				
-				
-					include
-					#htmlComment
-				
-				
-					include
-					#template-substitution-element
-				
-				
-					include
-					#htmlText
-				
-			
-		
-		null-literal
-		
-			match
-			\b(null)\b
-			name
-			constant.language.null.ts
-		
-		numeric-literal
-		
-			match
-			\b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b
-			name
-			constant.numeric.ts
-		
-		object-body
-		
-			begin
-			\{
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			end
-			\}
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			name
-			meta.object.body.ts
-			patterns
-			
-				
-					include
-					#string
-				
-				
-					include
-					#comment
-				
-				
-					include
-					#field-declaration
-				
-				
-					include
-					#method-declaration
-				
-				
-					include
-					#indexer-declaration
-				
-				
-					include
-					#type-annotation
-				
-				
-					include
-					#variable-initializer
-				
-				
-					include
-					#access-modifier
-				
-				
-					include
-					#static-modifier
-				
-				
-					include
-					#property-accessor
-				
-			
-		
-		object-declaration
-		
-			begin
-			\b(?:(export)\s+)?\b(?:(abstract)\s+)?\b(?<!\.)(class|interface)\b
-			beginCaptures
-			
-				1
-				
-					name
-					storage.modifier.ts
-				
-				2
-				
-					name
-					storage.modifier.ts
-				
-				3
-				
-					name
-					storage.type.ts
-				
-			
-			end
-			(?<=\})
-			endCaptures
-			
-				1
-				
-					name
-					brace.curly.ts
-				
-			
-			name
-			meta.declaration.object.ts
-			patterns
-			
-				
-					include
-					#comment
-				
-				
-					include
-					#object-heritage
-				
-				
-					include
-					#object-name
-				
-				
-					include
-					#type-parameters
-				
-				
-					include
-					#object-body
-				
-			
-		
-		object-heritage
-		
-			begin
-			(?:\b(extends|implements))
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.other.ts
-				
-			
-			end
-			(?=\{)
-			endCaptures
-			
-				1
-				
-					name
-					brace.curly.ts
-				
-			
-			name
-			meta.object.heritage.ts
-			patterns
-			
-				
-					include
-					#comment
-				
-				
-					include
-					#type-parameters
-				
-				
-					include
-					#object-heritage-parent
-				
-			
-		
-		object-heritage-parent
-		
-			captures
-			
-				1
-				
-					name
-					storage.type.ts
-				
-			
-			match
-			(?:\s*([a-zA-Z_$][\w$]*))
-			name
-			meta.object.heritage.parent.ts
-		
-		object-member
-		
-			begin
-			[a-zA-Z_$][\w$]*\s*:
-			end
-			(?=,|\})
-			name
-			meta.object.member.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		object-name
-		
-			captures
-			
-				0
-				
-					name
-					entity.name.class.ts
-				
-			
-			match
-			[a-zA-Z_$][\w$]*
-			name
-			meta.object.name.ts
-		
-		parameter-name
-		
-			captures
-			
-				1
-				
-					name
-					storage.modifier.ts
-				
-				2
-				
-					name
-					keyword.operator.ts
-				
-				3
-				
-					name
-					variable.parameter.ts
-				
-				4
-				
-					name
-					keyword.operator.ts
-				
-			
-			match
-			(?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\??)
-			name
-			parameter.name.ts
-		
-		paren-expression
-		
-			begin
-			\(
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.paren.ts
-				
-			
-			end
-			\)
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.paren.ts
-				
-			
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		property-accessor
-		
-			match
-			\b(get|set)\b
-			name
-			storage.type.property.ts
-		
-		qstring-double
-		
-			begin
-			"
-			end
-			"|(?=$)
-			name
-			string.double.ts
-			patterns
-			
-				
-					include
-					#string-character-escape
-				
-			
-		
-		qstring-single
-		
-			begin
-			'
-			end
-			'|(?=$)
-			name
-			string.single.ts
-			patterns
-			
-				
-					include
-					#string-character-escape
-				
-			
-		
-		regex
-		
-			begin
-			(?<=[=(:,\[]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?])
-			end
-			$|(/)[igm]*
-			name
-			string.regex.ts
-			patterns
-			
-				
-					match
-					\\.
-					name
-					constant.character.escape.ts
-				
-				
-					match
-					\[(\\\]|[^\]])*\]
-					name
-					constant.character.class.ts
-				
-			
-		
-		relational-operator
-		
-			match
-			===|==|=|!=|!==|<=|>=|<>|<|>
-			name
-			keyword.operator.comparison.ts
-		
-		return-type
-		
-			begin
-			(?<=\))\s*:
-			end
-			(?=$)|(?=\{|;|//)
-			name
-			meta.return.type.ts
-			patterns
-			
-				
-					include
-					#type
-				
-			
-		
-		static-modifier
-		
-			match
-			\b(static)\b
-			name
-			keyword.other.ts
-		
-		storage-keyword
-		
-			match
-			\b(number|boolean|string|any|var|let|function|const)\b
-			name
-			storage.type.ts
-		
-		string
-		
-			name
-			string.ts
-			patterns
-			
-				
-					include
-					#qstring-single
-				
-				
-					include
-					#qstring-double
-				
-			
-		
-		string-character-escape
-		
-			match
-			\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)
-			name
-			constant.character.escape
-		
-		switch-case
-		
-			begin
-			(?<!\.)\b(case|default)\b
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.control.ts
-				
-			
-			end
-			:
-			name
-			case.expr.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		template
-		
-			begin
-			`
-			beginCaptures
-			
-				0
-				
-					name
-					string.template.ts
-				
-			
-			end
-			`
-			endCaptures
-			
-				0
-				
-					name
-					string.template.ts
-				
-			
-			name
-			meta.template.ts
-			patterns
-			
-				
-					include
-					#template-substitution-element
-				
-				
-					include
-					#template-string-contents
-				
-			
-		
-		template-string-contents
-		
-			begin
-			.*?
-			end
-			(?=(\$\{|`))
-			name
-			string.template.ts
-			patterns
-			
-				
-					include
-					#string-character-escape
-				
-			
-		
-		template-substitution-element
-		
-			begin
-			\$\{
-			beginCaptures
-			
-				0
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			\}
-			endCaptures
-			
-				0
-				
-					name
-					keyword.operator.ts
-				
-			
-			name
-			template.element.ts
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-		this-literal
-		
-			match
-			\b(this)\b
-			name
-			constant.language.this.ts
-		
-		type
-		
-			name
-			meta.type.ts
-			patterns
-			
-				
-					include
-					#type-primitive
-				
-				
-					include
-					#type-parameters
-				
-				
-					include
-					#type-tuple
-				
-				
-					include
-					#type-object
-				
-				
-					include
-					#type-operator
-				
-				
-					include
-					#type-paren-or-function-type-parameters
-				
-				
-					include
-					#type-function-return-type
-				
-				
-					include
-					#type-name
-				
-			
-		
-		type-annotation
-		
-			begin
-			:
-			end
-			(?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[a-zA-Z_$])\s*(?=\{)
-			name
-			meta.type.annotation.ts
-			patterns
-			
-				
-					include
-					#type
-				
-				
-					include
-					#string
-				
-				
-					include
-					#comment
-				
-			
-		
-		type-declaration
-		
-			begin
-			\b(type)\b\s+([a-zA-Z_$][\w$]*)\s*=\s*
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.other.ts
-				
-				2
-				
-					name
-					storage.type.ts
-				
-			
-			end
-			(?=[,);>]|var|type|function|class|interface)
-			name
-			meta.type.declaration.ts
-			patterns
-			
-				
-					include
-					#type
-				
-			
-		
-		type-function-return-type
-		
-			begin
-			=>
-			beginCaptures
-			
-				0
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			(?=\s*[,\)\{=;>]|//|$)
-			name
-			meta.type.function.return.ts
-			patterns
-			
-				
-					include
-					#type
-				
-			
-		
-		type-name
-		
-			captures
-			
-				1
-				
-					name
-					entity.name.type.ts
-				
-			
-			match
-			[a-zA-Z_$][.\w$]*
-			name
-			meta.type.name.ts
-		
-		type-object
-		
-			begin
-			\{
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			end
-			\}
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.curly.ts
-				
-			
-			name
-			meta.object.type.ts
-			patterns
-			
-				
-					include
-					#comment
-				
-				
-					include
-					#field-declaration
-				
-				
-					include
-					#method-declaration
-				
-				
-					include
-					#indexer-declaration
-				
-				
-					include
-					#type-annotation
-				
-			
-		
-		type-operator
-		
-			match
-			[.|]
-			name
-			keyword.operator.type.ts
-		
-		type-parameters
-		
-			begin
-			([a-zA-Z_$][\w$]*)?(<)
-			beginCaptures
-			
-				1
-				
-					name
-					entity.name.type.ts
-				
-				2
-				
-					name
-					meta.brace.angle.ts
-				
-			
-			end
-			(?=$)|(>)
-			endCaptures
-			
-				2
-				
-					name
-					meta.brace.angle.ts
-				
-			
-			name
-			meta.type.parameters.ts
-			patterns
-			
-				
-					match
-					\b(extends)\b
-					name
-					keyword.other.ts
-				
-				
-					include
-					#comment
-				
-				
-					include
-					#type
-				
-			
-		
-		type-paren-or-function-type-parameters
-		
-			begin
-			(?:\b(new)\b)?\s*\(
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.control.ts
-				
-			
-			end
-			\)
-			name
-			meta.type.paren.cover.ts
-			patterns
-			
-				
-					include
-					#comment
-				
-				
-					include
-					#type
-				
-				
-					include
-					#function-type-parameters
-				
-			
-		
-		type-primitive
-		
-			captures
-			
-				1
-				
-					name
-					storage.type.ts
-				
-			
-			match
-			\b(string|number|boolean|symbol|any|void)\b
-			name
-			meta.type.primitive.ts
-		
-		type-tuple
-		
-			begin
-			\[
-			beginCaptures
-			
-				0
-				
-					name
-					meta.brace.square.ts
-				
-			
-			end
-			\]
-			endCaptures
-			
-				0
-				
-					name
-					meta.brace.square.ts
-				
-			
-			name
-			meta.type.tuple.ts
-			patterns
-			
-				
-					include
-					#type
-				
-				
-					include
-					#comment
-				
-			
-		
-		undefined-literal
-		
-			match
-			\b(undefined)\b
-			name
-			constant.language.ts
-		
-		var-expr
-		
-			begin
-			(?<!\()\s*\b(var|let|const(?!\s+enum))\s+([a-zA-Z_$][\w$]*)
-			beginCaptures
-			
-				1
-				
-					name
-					storage.type.ts
-				
-				2
-				
-					name
-					variable.ts
-				
-			
-			end
-			(?=$|[;=\}\{])|(?<=\})
-			name
-			meta.var.expr.ts
-			patterns
-			
-				
-					include
-					#type-annotation
-				
-				
-					include
-					#string
-				
-				
-					include
-					#comment
-				
-			
-		
-		variable-initializer
-		
-			begin
-			(=)
-			beginCaptures
-			
-				1
-				
-					name
-					keyword.operator.ts
-				
-			
-			end
-			(?=$|[,);=])
-			patterns
-			
-				
-					include
-					#expression
-				
-			
-		
-	
-	scopeName
-	source.ts
-	uuid
-	ef98eb90-bf9b-11e4-bb52-0800200c9a66
-
+
+
+
+
+	fileTypes
+	
+		ts
+	
+	name
+	TypeScript
+	patterns
+	
+		
+			include
+			#expression
+		
+	
+	repository
+	
+		access-modifier
+		
+			match
+			\b(public|protected|private)\b
+			name
+			storage.modifier.ts
+		
+		arithmetic-operator
+		
+			match
+			\*|/|\-\-|\-|\+\+|\+|%
+			name
+			keyword.operator.arithmetic.ts
+		
+		array-literal
+		
+			begin
+			\[
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.square.ts
+				
+			
+			end
+			\]
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.square.ts
+				
+			
+			name
+			meta.array.literal.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		assignment-operator
+		
+			match
+			<<=|>>=|>>>=|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=
+			name
+			keyword.operator.assignment.ts
+		
+		block
+		
+			begin
+			\{
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			end
+			\}
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			name
+			meta.block.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+				
+					include
+					#object-member
+				
+			
+		
+		boolean-literal
+		
+			match
+			\b(false|true)\b
+			name
+			constant.language.boolean.ts
+		
+		cast
+		
+			begin
+			(?:(?<=return|throw|yield|[=(,:>]))\s*(<)(?!<?\=)
+			beginCaptures
+			
+				1
+				
+					name
+					meta.brace.angle.ts
+				
+			
+			end
+			>
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.angle.ts
+				
+			
+			name
+			cast.expr.ts
+			patterns
+			
+				
+					include
+					#type
+				
+			
+		
+		comment
+		
+			name
+			comment.ts
+			patterns
+			
+				
+					include
+					#comment-block-doc
+				
+				
+					include
+					#comment-block
+				
+				
+					include
+					#comment-line
+				
+			
+		
+		comment-block
+		
+			begin
+			/\*
+			end
+			\*/
+			name
+			comment.block.ts
+		
+		comment-block-doc
+		
+			begin
+			/\*\*(?!/)
+			end
+			\*/
+			name
+			comment.block.documentation.ts
+		
+		comment-line
+		
+			match
+			(//).*$\n?
+			name
+			comment.line.ts
+		
+		control-statement
+		
+			match
+			(?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default)\b
+			name
+			keyword.control.ts
+		
+		decl-block
+		
+			begin
+			\{
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			end
+			\}
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			name
+			meta.decl.block.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		declaration
+		
+			name
+			meta.declaration.ts
+			patterns
+			
+				
+					include
+					#function-declaration
+				
+				
+					include
+					#object-declaration
+				
+				
+					include
+					#type-declaration
+				
+				
+					include
+					#enum-declaration
+				
+			
+		
+		enum-declaration
+		
+			captures
+			
+				1
+				
+					name
+					storage.modifier.ts
+				
+				2
+				
+					name
+					storage.type.ts
+				
+				3
+				
+					name
+					entity.name.class.ts
+				
+			
+			match
+			(?:\b(const)\s+)?\b(enum)\s+([a-zA-Z_$][\w$]*)
+			name
+			meta.enum.declaration.ts
+		
+		expression
+		
+			name
+			meta.expression.ts
+			patterns
+			
+				
+					include
+					#ngTemplate
+				
+				
+					include
+					#for-in-simple
+				
+				
+					include
+					#string
+				
+				
+					include
+					#regex
+				
+				
+					include
+					#template
+				
+				
+					include
+					#comment
+				
+				
+					include
+					#literal
+				
+				
+					include
+					#paren-expression
+				
+				
+					include
+					#var-expr
+				
+				
+					include
+					#declaration
+				
+				
+					include
+					#cast
+				
+				
+					include
+					#new-expr
+				
+				
+					include
+					#block
+				
+				
+					include
+					#expression-operator
+				
+				
+					include
+					#relational-operator
+				
+				
+					include
+					#arithmetic-operator
+				
+				
+					include
+					#logic-operator
+				
+				
+					include
+					#assignment-operator
+				
+				
+					include
+					#storage-keyword
+				
+				
+					include
+					#function-call
+				
+				
+					include
+					#switch-case
+				
+				
+					include
+					#control-statement
+				
+			
+		
+		expression-operator
+		
+			match
+			=>|\b(delete|export|import|in|instanceof|module|namespace|new|typeof|void)\b
+			name
+			keyword.operator.ts
+		
+		field-declaration
+		
+			begin
+			(?<!\()\s*\b([a-zA-Z_$][\w$]*)\s*(\?\s*)?(?=(=|:))
+			beginCaptures
+			
+				1
+				
+					name
+					variable.ts
+				
+				2
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			(?=\}|;|,)|(?<=\})
+			name
+			meta.field.declaration.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		for-in-simple
+		
+			captures
+			
+				1
+				
+					name
+					storage.type.ts
+				
+				3
+				
+					name
+					keyword.operator.ts
+				
+			
+			match
+			(?<=\()\s*\b(var|let|const)\s+([a-zA-Z_$][\w$]*)\s+(in|of)\b
+			name
+			forin.expr.ts
+		
+		function-call
+		
+			name
+			functioncall.expr.ts
+			patterns
+			
+				
+					include
+					#type-parameters
+				
+				
+					include
+					#paren-expression
+				
+			
+		
+		function-declaration
+		
+			begin
+			\b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s*
+			beginCaptures
+			
+				1
+				
+					name
+					storage.modifier.ts
+				
+				2
+				
+					name
+					storage.type.function.ts
+				
+				3
+				
+					name
+					entity.name.function.ts
+				
+			
+			end
+			(?=;|\})|(?<=\})
+			name
+			meta.function.ts
+			patterns
+			
+				
+					include
+					#comment
+				
+				
+					include
+					#type-parameters
+				
+				
+					include
+					#function-type-parameters
+				
+				
+					include
+					#return-type
+				
+				
+					include
+					#function-overload-declaration
+				
+				
+					include
+					#decl-block
+				
+			
+		
+		function-overload-declaration
+		
+			captures
+			
+				1
+				
+					name
+					storage.modifier.ts
+				
+				2
+				
+					name
+					storage.type.function.ts
+				
+				3
+				
+					name
+					entity.name.function.ts
+				
+			
+			match
+			\b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s*
+			name
+			meta.function.overload.ts
+		
+		function-type-parameters
+		
+			begin
+			\(
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.round.ts
+				
+			
+			end
+			\)
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.round.ts
+				
+			
+			name
+			meta.function.type.parameter.ts
+			patterns
+			
+				
+					include
+					#comment
+				
+				
+					include
+					#parameter-name
+				
+				
+					include
+					#type-annotation
+				
+				
+					include
+					#variable-initializer
+				
+			
+		
+		htmlComment
+		
+			begin
+			<!--
+			end
+			-->
+			name
+			comment.block.ts
+		
+		htmlText
+		
+			match
+			.*?(?=({{)|(\$\{)|<|$)
+			name
+			string.ts
+		
+		indexer-declaration
+		
+			begin
+			\[
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.square.ts
+				
+			
+			end
+			(\])\s*(\?\s*)?|$
+			endCaptures
+			
+				1
+				
+					name
+					meta.brace.square.ts
+				
+				2
+				
+					name
+					keyword.operator.ts
+				
+			
+			name
+			meta.indexer.declaration.ts
+			patterns
+			
+				
+					include
+					#type-annotation
+				
+				
+					include
+					#indexer-parameter
+				
+				
+					include
+					#expression
+				
+			
+		
+		indexer-parameter
+		
+			captures
+			
+				1
+				
+					name
+					variable.parameter.ts
+				
+			
+			match
+			([a-zA-Z_$][\w$]*)(?=\:)
+			name
+			meta.indexer.parameter.ts
+		
+		literal
+		
+			name
+			literal.ts
+			patterns
+			
+				
+					include
+					#numeric-literal
+				
+				
+					include
+					#boolean-literal
+				
+				
+					include
+					#null-literal
+				
+				
+					include
+					#undefined-literal
+				
+				
+					include
+					#array-literal
+				
+				
+					include
+					#this-literal
+				
+			
+		
+		logic-operator
+		
+			match
+			\!|&|~|\||&&|\|\|
+			name
+			keyword.operator.arithmetic.ts
+		
+		method-declaration
+		
+			begin
+			\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?(?:(get|set)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)
+			beginCaptures
+			
+				1
+				
+					name
+					storage.modifier.ts
+				
+				2
+				
+					name
+					storage.modifier.ts
+				
+				3
+				
+					name
+					storage.type.property.ts
+				
+				4
+				
+					name
+					keyword.operator.ts
+				
+				5
+				
+					name
+					entity.name.function.ts
+				
+				6
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			(?=\}|;|,)|(?<=\})
+			name
+			meta.method.declaration.ts
+			patterns
+			
+				
+					include
+					#comment
+				
+				
+					include
+					#type-parameters
+				
+				
+					include
+					#function-type-parameters
+				
+				
+					include
+					#type-annotation
+				
+				
+					include
+					#method-overload-declaration
+				
+				
+					include
+					#decl-block
+				
+			
+		
+		method-overload-declaration
+		
+			captures
+			
+				1
+				
+					name
+					storage.modifier.ts
+				
+				2
+				
+					name
+					keyword.operator.ts
+				
+				3
+				
+					name
+					entity.name.function.ts
+				
+				4
+				
+					name
+					keyword.operator.ts
+				
+			
+			match
+			\b(?:(public|private|protected)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)
+			name
+			meta.method.overload.declaration.ts
+		
+		new-expr
+		
+			begin
+			\b(new)\b
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			(?=[(;]|$)
+			name
+			new.expr.ts
+			patterns
+			
+				
+					include
+					#type
+				
+				
+					include
+					#comment
+				
+			
+		
+		ngAttrib
+		
+			begin
+			([a-zA-Z\$][a-zA-Z0-9\$\-]*)
+			beginCaptures
+			
+				1
+				
+					name
+					entity.name.class.ts
+				
+			
+			end
+			(?=[^'=])
+			name
+			meta.attribute.ts
+			patterns
+			
+				
+					include
+					#ngAttribValue
+				
+			
+		
+		ngAttribValue
+		
+			begin
+			=
+			beginCaptures
+			
+				0
+				
+					name
+					punctuation.separator.key-value.ts
+				
+			
+			end
+			(?<=')
+			name
+			meta.attribute.ts
+			patterns
+			
+				
+					include
+					#qstring-single
+				
+			
+		
+		ngBinding
+		
+			begin
+			(?:\(|\[|(?:\[\())([a-zA-Z\$][a-zA-Z0-9\$\-]*)(?:(?:\)\])|\)|\])
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.control.ts
+				
+			
+			end
+			(?=[^'=])
+			name
+			meta.binding-name.ts
+			patterns
+			
+				
+					include
+					#ngAttribValue
+				
+			
+		
+		ngDirective
+		
+			begin
+			\*([a-zA-Z\$][a-zA-Z0-9\$\-]*)
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.control.ts
+				
+			
+			end
+			(?=[^'=])
+			name
+			meta.directive-name.ts
+			patterns
+			
+				
+					include
+					#ngAttribValue
+				
+			
+		
+		ngExpr
+		
+			begin
+			{{
+			beginCaptures
+			
+				0
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			}}
+			endCaptures
+			
+				0
+				
+					name
+					keyword.operator.ts
+				
+			
+			name
+			meta.expression.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		ngTag
+		
+			begin
+			(<)([a-zA-Z\$][a-zA-Z0-9\$\-]*)
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.operator.ts
+				
+				2
+				
+					name
+					entity.name.tag.ts
+				
+			
+			end
+			(/>)|(?:(</)([a-zA-Z\$][a-zA-Z0-9\$\-]*)(>))
+			endCaptures
+			
+				1
+				
+					name
+					keyword.operator.ts
+				
+				2
+				
+					name
+					keyword.operator.ts
+				
+				3
+				
+					name
+					entity.name.tag.ts
+				
+				4
+				
+					name
+					keyword.operator.ts
+				
+			
+			name
+			meta.tag.ts
+			patterns
+			
+				
+					include
+					#ngAttrib
+				
+				
+					include
+					#ngDirective
+				
+				
+					include
+					#ngBinding
+				
+				
+					include
+					#ngTagEnd
+				
+			
+		
+		ngTagEnd
+		
+			begin
+			>
+			beginCaptures
+			
+				0
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			(?=</)
+			name
+			meta.tagend.ts
+			patterns
+			
+				
+					include
+					#ngml
+				
+			
+		
+		ngTemplate
+		
+			begin
+			(?:(?<=^|\stemplate:)|(?<=/\*\* @html \*/))\s*(`)
+			beginCaptures
+			
+				1
+				
+					name
+					string.template.ts
+				
+			
+			end
+			`
+			endCaptures
+			
+				0
+				
+					name
+					string.template.ts
+				
+			
+			name
+			meta.ngTemplate.ts
+			patterns
+			
+				
+					include
+					#ngml
+				
+			
+		
+		ngml
+		
+			name
+			meta.ngml.ts
+			patterns
+			
+				
+					include
+					#ngTag
+				
+				
+					include
+					#ngExpr
+				
+				
+					include
+					#htmlComment
+				
+				
+					include
+					#template-substitution-element
+				
+				
+					include
+					#htmlText
+				
+			
+		
+		null-literal
+		
+			match
+			\b(null)\b
+			name
+			constant.language.null.ts
+		
+		numeric-literal
+		
+			match
+			\b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b
+			name
+			constant.numeric.ts
+		
+		object-body
+		
+			begin
+			\{
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			end
+			\}
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			name
+			meta.object.body.ts
+			patterns
+			
+				
+					include
+					#string
+				
+				
+					include
+					#comment
+				
+				
+					include
+					#field-declaration
+				
+				
+					include
+					#method-declaration
+				
+				
+					include
+					#indexer-declaration
+				
+				
+					include
+					#type-annotation
+				
+				
+					include
+					#variable-initializer
+				
+				
+					include
+					#access-modifier
+				
+				
+					include
+					#static-modifier
+				
+				
+					include
+					#property-accessor
+				
+			
+		
+		object-declaration
+		
+			begin
+			\b(?:(export)\s+)?\b(?:(abstract)\s+)?\b(?<!\.)(class|interface)\b
+			beginCaptures
+			
+				1
+				
+					name
+					storage.modifier.ts
+				
+				2
+				
+					name
+					storage.modifier.ts
+				
+				3
+				
+					name
+					storage.type.ts
+				
+			
+			end
+			(?<=\})
+			endCaptures
+			
+				1
+				
+					name
+					brace.curly.ts
+				
+			
+			name
+			meta.declaration.object.ts
+			patterns
+			
+				
+					include
+					#comment
+				
+				
+					include
+					#object-heritage
+				
+				
+					include
+					#object-name
+				
+				
+					include
+					#type-parameters
+				
+				
+					include
+					#object-body
+				
+			
+		
+		object-heritage
+		
+			begin
+			(?:\b(extends|implements))
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.other.ts
+				
+			
+			end
+			(?=\{)
+			endCaptures
+			
+				1
+				
+					name
+					brace.curly.ts
+				
+			
+			name
+			meta.object.heritage.ts
+			patterns
+			
+				
+					include
+					#comment
+				
+				
+					include
+					#type-parameters
+				
+				
+					include
+					#object-heritage-parent
+				
+			
+		
+		object-heritage-parent
+		
+			captures
+			
+				1
+				
+					name
+					storage.type.ts
+				
+			
+			match
+			(?:\s*([a-zA-Z_$][\w$]*))
+			name
+			meta.object.heritage.parent.ts
+		
+		object-member
+		
+			begin
+			[a-zA-Z_$][\w$]*\s*:
+			end
+			(?=,|\})
+			name
+			meta.object.member.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		object-name
+		
+			captures
+			
+				0
+				
+					name
+					entity.name.class.ts
+				
+			
+			match
+			[a-zA-Z_$][\w$]*
+			name
+			meta.object.name.ts
+		
+		parameter-name
+		
+			captures
+			
+				1
+				
+					name
+					storage.modifier.ts
+				
+				2
+				
+					name
+					keyword.operator.ts
+				
+				3
+				
+					name
+					variable.parameter.ts
+				
+				4
+				
+					name
+					keyword.operator.ts
+				
+			
+			match
+			(?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\??)
+			name
+			parameter.name.ts
+		
+		paren-expression
+		
+			begin
+			\(
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.paren.ts
+				
+			
+			end
+			\)
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.paren.ts
+				
+			
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		property-accessor
+		
+			match
+			\b(get|set)\b
+			name
+			storage.type.property.ts
+		
+		qstring-double
+		
+			begin
+			"
+			end
+			"|(?=$)
+			name
+			string.double.ts
+			patterns
+			
+				
+					include
+					#string-character-escape
+				
+			
+		
+		qstring-single
+		
+			begin
+			'
+			end
+			'|(?=$)
+			name
+			string.single.ts
+			patterns
+			
+				
+					include
+					#string-character-escape
+				
+			
+		
+		regex
+		
+			begin
+			(?<=[=(:,\[]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?])
+			end
+			$|(/)[igm]*
+			name
+			string.regex.ts
+			patterns
+			
+				
+					match
+					\\.
+					name
+					constant.character.escape.ts
+				
+				
+					match
+					\[(\\\]|[^\]])*\]
+					name
+					constant.character.class.ts
+				
+			
+		
+		relational-operator
+		
+			match
+			===|==|=|!=|!==|<=|>=|<>|<|>
+			name
+			keyword.operator.comparison.ts
+		
+		return-type
+		
+			begin
+			(?<=\))\s*:
+			end
+			(?=$)|(?=\{|;|//)
+			name
+			meta.return.type.ts
+			patterns
+			
+				
+					include
+					#type
+				
+			
+		
+		static-modifier
+		
+			match
+			\b(static)\b
+			name
+			keyword.other.ts
+		
+		storage-keyword
+		
+			match
+			\b(number|boolean|string|any|var|let|function|const)\b
+			name
+			storage.type.ts
+		
+		string
+		
+			name
+			string.ts
+			patterns
+			
+				
+					include
+					#qstring-single
+				
+				
+					include
+					#qstring-double
+				
+			
+		
+		string-character-escape
+		
+			match
+			\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)
+			name
+			constant.character.escape
+		
+		switch-case
+		
+			begin
+			(?<!\.)\b(case|default)\b
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.control.ts
+				
+			
+			end
+			:
+			name
+			case.expr.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		template
+		
+			begin
+			`
+			beginCaptures
+			
+				0
+				
+					name
+					string.template.ts
+				
+			
+			end
+			`
+			endCaptures
+			
+				0
+				
+					name
+					string.template.ts
+				
+			
+			name
+			meta.template.ts
+			patterns
+			
+				
+					include
+					#template-substitution-element
+				
+				
+					include
+					#template-string-contents
+				
+			
+		
+		template-string-contents
+		
+			begin
+			.*?
+			end
+			(?=(\$\{|`))
+			name
+			string.template.ts
+			patterns
+			
+				
+					include
+					#string-character-escape
+				
+			
+		
+		template-substitution-element
+		
+			begin
+			\$\{
+			beginCaptures
+			
+				0
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			\}
+			endCaptures
+			
+				0
+				
+					name
+					keyword.operator.ts
+				
+			
+			name
+			template.element.ts
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+		this-literal
+		
+			match
+			\b(this)\b
+			name
+			constant.language.this.ts
+		
+		type
+		
+			name
+			meta.type.ts
+			patterns
+			
+				
+					include
+					#type-primitive
+				
+				
+					include
+					#type-parameters
+				
+				
+					include
+					#type-tuple
+				
+				
+					include
+					#type-object
+				
+				
+					include
+					#type-operator
+				
+				
+					include
+					#type-paren-or-function-type-parameters
+				
+				
+					include
+					#type-function-return-type
+				
+				
+					include
+					#type-name
+				
+			
+		
+		type-annotation
+		
+			begin
+			:
+			end
+			(?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[a-zA-Z_$])\s*(?=\{)
+			name
+			meta.type.annotation.ts
+			patterns
+			
+				
+					include
+					#type
+				
+				
+					include
+					#string
+				
+				
+					include
+					#comment
+				
+			
+		
+		type-declaration
+		
+			begin
+			\b(type)\b\s+([a-zA-Z_$][\w$]*)\s*=\s*
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.other.ts
+				
+				2
+				
+					name
+					storage.type.ts
+				
+			
+			end
+			(?=[,);>]|var|type|function|class|interface)
+			name
+			meta.type.declaration.ts
+			patterns
+			
+				
+					include
+					#type
+				
+			
+		
+		type-function-return-type
+		
+			begin
+			=>
+			beginCaptures
+			
+				0
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			(?=\s*[,\)\{=;>]|//|$)
+			name
+			meta.type.function.return.ts
+			patterns
+			
+				
+					include
+					#type
+				
+			
+		
+		type-name
+		
+			captures
+			
+				1
+				
+					name
+					entity.name.type.ts
+				
+			
+			match
+			[a-zA-Z_$][.\w$]*
+			name
+			meta.type.name.ts
+		
+		type-object
+		
+			begin
+			\{
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			end
+			\}
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.curly.ts
+				
+			
+			name
+			meta.object.type.ts
+			patterns
+			
+				
+					include
+					#comment
+				
+				
+					include
+					#field-declaration
+				
+				
+					include
+					#method-declaration
+				
+				
+					include
+					#indexer-declaration
+				
+				
+					include
+					#type-annotation
+				
+			
+		
+		type-operator
+		
+			match
+			[.|]
+			name
+			keyword.operator.type.ts
+		
+		type-parameters
+		
+			begin
+			([a-zA-Z_$][\w$]*)?(<)
+			beginCaptures
+			
+				1
+				
+					name
+					entity.name.type.ts
+				
+				2
+				
+					name
+					meta.brace.angle.ts
+				
+			
+			end
+			(?=$)|(>)
+			endCaptures
+			
+				2
+				
+					name
+					meta.brace.angle.ts
+				
+			
+			name
+			meta.type.parameters.ts
+			patterns
+			
+				
+					match
+					\b(extends)\b
+					name
+					keyword.other.ts
+				
+				
+					include
+					#comment
+				
+				
+					include
+					#type
+				
+			
+		
+		type-paren-or-function-type-parameters
+		
+			begin
+			(?:\b(new)\b)?\s*\(
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.control.ts
+				
+			
+			end
+			\)
+			name
+			meta.type.paren.cover.ts
+			patterns
+			
+				
+					include
+					#comment
+				
+				
+					include
+					#type
+				
+				
+					include
+					#function-type-parameters
+				
+			
+		
+		type-primitive
+		
+			captures
+			
+				1
+				
+					name
+					storage.type.ts
+				
+			
+			match
+			\b(string|number|boolean|symbol|any|void)\b
+			name
+			meta.type.primitive.ts
+		
+		type-tuple
+		
+			begin
+			\[
+			beginCaptures
+			
+				0
+				
+					name
+					meta.brace.square.ts
+				
+			
+			end
+			\]
+			endCaptures
+			
+				0
+				
+					name
+					meta.brace.square.ts
+				
+			
+			name
+			meta.type.tuple.ts
+			patterns
+			
+				
+					include
+					#type
+				
+				
+					include
+					#comment
+				
+			
+		
+		undefined-literal
+		
+			match
+			\b(undefined)\b
+			name
+			constant.language.ts
+		
+		var-expr
+		
+			begin
+			(?<!\()\s*\b(var|let|const(?!\s+enum))\s+([a-zA-Z_$][\w$]*)
+			beginCaptures
+			
+				1
+				
+					name
+					storage.type.ts
+				
+				2
+				
+					name
+					variable.ts
+				
+			
+			end
+			(?=$|[;=\}\{])|(?<=\})
+			name
+			meta.var.expr.ts
+			patterns
+			
+				
+					include
+					#type-annotation
+				
+				
+					include
+					#string
+				
+				
+					include
+					#comment
+				
+			
+		
+		variable-initializer
+		
+			begin
+			(=)
+			beginCaptures
+			
+				1
+				
+					name
+					keyword.operator.ts
+				
+			
+			end
+			(?=$|[,);=])
+			patterns
+			
+				
+					include
+					#expression
+				
+			
+		
+	
+	scopeName
+	source.ts
+	uuid
+	ef98eb90-bf9b-11e4-bb52-0800200c9a66
+
 
\ No newline at end of file
diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Markdown.tmLanguage b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Markdown.tmLanguage
index f7be0df46..26f838238 100644
--- a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Markdown.tmLanguage
+++ b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/Markdown.tmLanguage
@@ -1,1108 +1,1108 @@
-
-
-
-
-	fileTypes
-	
-		md
-		mdown
-		markdown
-		markdn
-	
-	keyEquivalent
-	^~M
-	name
-	Markdown
-	patterns
-	
-		
-			include
-			#block
-		
-	
-	repository
-	
-		block
-		
-			patterns
-			
-				
-					include
-					#separator
-				
-				
-					include
-					#heading
-				
-				
-					include
-					#blockquote
-				
-				
-					include
-					#lists
-				
-				
-					include
-					#raw_block
-				
-				
-					include
-					#link-def
-				
-				
-					include
-					#html
-				
-				
-					include
-					#paragraph
-				
-			
-			repository
-			
-				blockquote
-				
-					begin
-					(^|\G)(>) ?
-					captures
-					
-						2
-						
-							name
-							punctuation.definition.quote.markdown
-						
-					
-					name
-					markup.quote.markdown
-					patterns
-					
-						
-							include
-							#block
-						
-					
-					while
-					(^|\G)(>) ?
-				
-				heading
-				
-					begin
-					(?:^|\G)(#{1,6})\s*(?=[\S[^#]])
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.heading.markdown
-						
-					
-					contentName
-					entity.name.section.markdown
-					end
-					\s*(#{1,6})?$\n?
-					name
-					markup.heading.${1/(#)(#)?(#)?(#)?(#)?(#)?/${6:?6:${5:?5:${4:?4:${3:?3:${2:?2:1}}}}}/}.markdown
-					patterns
-					
-						
-							include
-							#inline
-						
-					
-				
-				heading-setext
-				
-					patterns
-					
-						
-							match
-							^(={3,})(?=[ \t]*$\n?)
-							name
-							markup.heading.setext.1.markdown
-						
-						
-							match
-							^(-{3,})(?=[ \t]*$\n?)
-							name
-							markup.heading.setext.2.markdown
-						
-					
-				
-				html
-				
-					patterns
-					
-						
-							begin
-							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del).*</\2\s*>\s*$)
-							end
-							$
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-						
-						
-							begin
-							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del))
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-							while
-							\G(?!</\2\s*>)
-						
-					
-				
-				link-def
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.constant.markdown
-						
-						10
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						11
-						
-							name
-							string.other.link.description.title.markdown
-						
-						12
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						13
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						2
-						
-							name
-							constant.other.reference.link.markdown
-						
-						3
-						
-							name
-							punctuation.definition.constant.markdown
-						
-						4
-						
-							name
-							punctuation.separator.key-value.markdown
-						
-						5
-						
-							name
-							punctuation.definition.link.markdown
-						
-						6
-						
-							name
-							markup.underline.link.markdown
-						
-						7
-						
-							name
-							punctuation.definition.link.markdown
-						
-						8
-						
-							name
-							string.other.link.description.title.markdown
-						
-						9
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-					
-					match
-					^(?x:
-									\s*						# Leading whitespace
-									(\[)(.+?)(\])(:)		# Reference name
-									[ \t]*					# Optional whitespace
-									(<?)(\S+?)(>?)			# The url
-									[ \t]*					# Optional whitespace
-									(?:
-										  ((\().+?(\)))		# Match title in quotes…
-										| ((").+?("))		# or in parens.
-									)?						# Title is optional
-									\s*						# Optional whitespace
-									$
-								)
-					name
-					meta.link.reference.def.markdown
-				
-				list_paragraph
-				
-					begin
-					(^|\G)(?=\S)(?![*+-]\s|[0-9]+\.\s)
-					name
-					meta.paragraph.markdown
-					patterns
-					
-						
-							include
-							#inline
-						
-						
-							include
-							text.html.basic
-						
-						
-							include
-							#heading-setext
-						
-					
-					while
-					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|>|[ ]{0,3}[*+-]|[ ]{0,3}[0-9]+\.)
-				
-				lists
-				
-					patterns
-					
-						
-							begin
-							(^|\G)([ ]{0,3})([*+-])([ ]{1,3}|\t)
-							beginCaptures
-							
-								3
-								
-									name
-									punctuation.definition.list.markdown
-								
-							
-							comment
-							Currently does not support un-indented second lines.
-							name
-							markup.list.unnumbered.markdown
-							patterns
-							
-								
-									include
-									#list_paragraph
-								
-								
-									include
-									#block
-								
-							
-							while
-							\G([ ]{4}|\t|$)
-						
-						
-							begin
-							(^|\G)([ ]{0,3})([0-9]+\.)([ ]{1,3}|\t)
-							beginCaptures
-							
-								3
-								
-									name
-									punctuation.definition.list.markdown
-								
-							
-							name
-							markup.list.numbered.markdown
-							patterns
-							
-								
-									include
-									#list_paragraph
-								
-								
-									include
-									#block
-								
-							
-							while
-							\G([ ]{4}|\t|$)
-						
-					
-				
-				paragraph
-				
-					begin
-					(^|\G)(?=\S)
-					name
-					meta.paragraph.markdown
-					patterns
-					
-						
-							include
-							#inline
-						
-						
-							include
-							text.html.basic
-						
-						
-							include
-							#heading-setext
-						
-					
-					while
-					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|\s*\[.+?\]:|>)
-				
-				raw_block
-				
-					begin
-					(^|\G)([ ]{4}|\t)
-					name
-					markup.raw.block.markdown
-					while
-					(^|\G)([ ]{4}|\t)
-				
-				separator
-				
-					match
-					(^|\G)[ ]{0,3}([-*_])([ ]{0,2}\2){2,}[ \t]*$\n?
-					name
-					meta.separator.markdown
-				
-			
-		
-		inline
-		
-			patterns
-			
-				
-					include
-					#ampersand
-				
-				
-					include
-					#bracket
-				
-				
-					include
-					#bold
-				
-				
-					include
-					#italic
-				
-				
-					include
-					#raw
-				
-				
-					include
-					#escape
-				
-				
-					include
-					#image-inline
-				
-				
-					include
-					#image-ref
-				
-				
-					include
-					#link-email
-				
-				
-					include
-					#link-inet
-				
-				
-					include
-					#link-inline
-				
-				
-					include
-					#link-ref
-				
-				
-					include
-					#link-ref-literal
-				
-			
-			repository
-			
-				ampersand
-				
-					comment
-					
-						Markdown will convert this for us. We match it so that the
-						HTML grammar will not mark it up as invalid.
-					
-					match
-					&(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);)
-					name
-					meta.other.valid-ampersand.markdown
-				
-				bold
-				
-					begin
-					(?x)
-								(\*\*|__)(?=\S)								# Open
-								(?=
-									(
-									    <[^>]*+>							# HTML tags
-									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
-																			# Raw
-									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
-									  | \[
-										(				
-										        (?<square>					# Named group
-													[^\[\]\\]				# Match most chars
-										          | \\.						# Escaped chars
-										          | \[ \g<square>*+ \]		# Nested brackets
-										        )*+
-											\]
-											(
-												(							# Reference Link
-													[ ]?					# Optional space
-													\[[^\]]*+\]				# Ref name
-												)
-											  | (							# Inline Link
-													\(						# Opening paren
-														[ \t]*+				# Optional whtiespace
-														<?(.*?)>?			# URL
-														[ \t]*+				# Optional whtiespace
-														(					# Optional Title
-															(?<title>['"])
-															(.*?)
-															\k<title>
-														)?
-													\)
-												)
-											)
-										)
-									  | (?!(?<=\S)\1).						# Everything besides
-																			# style closer
-									)++
-									(?<=\S)\1								# Close
-								)
-							
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.bold.markdown
-						
-					
-					end
-					(?<=\S)(\1)
-					name
-					markup.bold.markdown
-					patterns
-					
-						
-							applyEndPatternLast
-							1
-							begin
-							(?=<[^>]*?>)
-							end
-							(?<=>)
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-						
-						
-							include
-							#escape
-						
-						
-							include
-							#ampersand
-						
-						
-							include
-							#bracket
-						
-						
-							include
-							#raw
-						
-						
-							include
-							#italic
-						
-						
-							include
-							#image-inline
-						
-						
-							include
-							#link-inline
-						
-						
-							include
-							#link-inet
-						
-						
-							include
-							#link-email
-						
-						
-							include
-							#image-ref
-						
-						
-							include
-							#link-ref-literal
-						
-						
-							include
-							#link-ref
-						
-					
-				
-				bracket
-				
-					comment
-					
-						Markdown will convert this for us. We match it so that the
-						HTML grammar will not mark it up as invalid.
-					
-					match
-					<(?![a-z/?\$!])
-					name
-					meta.other.valid-bracket.markdown
-				
-				escape
-				
-					match
-					\\[-`*_#+.!(){}\[\]\\>]
-					name
-					constant.character.escape.markdown
-				
-				image-inline
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						10
-						
-							name
-							string.other.link.description.title.markdown
-						
-						11
-						
-							name
-							punctuation.definition.string.markdown
-						
-						12
-						
-							name
-							punctuation.definition.string.markdown
-						
-						13
-						
-							name
-							string.other.link.description.title.markdown
-						
-						14
-						
-							name
-							punctuation.definition.string.markdown
-						
-						15
-						
-							name
-							punctuation.definition.string.markdown
-						
-						16
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						2
-						
-							name
-							string.other.link.description.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							invalid.illegal.whitespace.markdown
-						
-						6
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						7
-						
-							name
-							punctuation.definition.link.markdown
-						
-						8
-						
-							name
-							markup.underline.link.image.markdown
-						
-						9
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(?x:
-						\!							# Images start with !
-						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])	
-													# Match the link text.
-						([ ])?						# Space not allowed
-						(\()						# Opening paren for url
-							(<?)(\S+?)(>?)			# The url
-							[ \t]*					# Optional whitespace
-							(?:
-								  ((\().+?(\)))		# Match title in parens…
-								| ((").+?("))		# or in quotes.
-							)?						# Title is optional
-							\s*						# Optional whitespace
-						(\))
-					 )
-					name
-					meta.image.inline.markdown
-				
-				image-ref
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						2
-						
-							name
-							string.other.link.description.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						5
-						
-							name
-							punctuation.definition.constant.markdown
-						
-						6
-						
-							name
-							constant.other.reference.link.markdown
-						
-						7
-						
-							name
-							punctuation.definition.constant.markdown
-						
-					
-					match
-					\!(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(.*?)(\])
-					name
-					meta.image.reference.markdown
-				
-				italic
-				
-					begin
-					(?x)
-								(\*|_)(?=\S)								# Open
-								(?=
-									(
-									    <[^>]*+>							# HTML tags
-									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
-																			# Raw
-									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
-									  | \[
-										(				
-										        (?<square>					# Named group
-													[^\[\]\\]				# Match most chars
-										          | \\.						# Escaped chars
-										          | \[ \g<square>*+ \]		# Nested brackets
-										        )*+
-											\]
-											(
-												(							# Reference Link
-													[ ]?					# Optional space
-													\[[^\]]*+\]				# Ref name
-												)
-											  | (							# Inline Link
-													\(						# Opening paren
-														[ \t]*+				# Optional whtiespace
-														<?(.*?)>?			# URL
-														[ \t]*+				# Optional whtiespace
-														(					# Optional Title
-															(?<title>['"])
-															(.*?)
-															\k<title>
-														)?
-													\)
-												)
-											)
-										)
-									  | \1\1								# Must be bold closer
-									  | (?!(?<=\S)\1).						# Everything besides
-																			# style closer
-									)++
-									(?<=\S)\1								# Close
-								)
-							
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.italic.markdown
-						
-					
-					end
-					(?<=\S)(\1)((?!\1)|(?=\1\1))
-					name
-					markup.italic.markdown
-					patterns
-					
-						
-							applyEndPatternLast
-							1
-							begin
-							(?=<[^>]*?>)
-							end
-							(?<=>)
-							patterns
-							
-								
-									include
-									text.html.basic
-								
-							
-						
-						
-							include
-							#escape
-						
-						
-							include
-							#ampersand
-						
-						
-							include
-							#bracket
-						
-						
-							include
-							#raw
-						
-						
-							include
-							#bold
-						
-						
-							include
-							#image-inline
-						
-						
-							include
-							#link-inline
-						
-						
-							include
-							#link-inet
-						
-						
-							include
-							#link-email
-						
-						
-							include
-							#image-ref
-						
-						
-							include
-							#link-ref-literal
-						
-						
-							include
-							#link-ref
-						
-					
-				
-				link-email
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.link.markdown
-						
-						2
-						
-							name
-							markup.underline.link.markdown
-						
-						4
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(<)((?:mailto:)?[-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(>)
-					name
-					meta.link.email.lt-gt.markdown
-				
-				link-inet
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.link.markdown
-						
-						2
-						
-							name
-							markup.underline.link.markdown
-						
-						3
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(<)((?:https?|ftp)://.*?)(>)
-					name
-					meta.link.inet.markdown
-				
-				link-inline
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						10
-						
-							name
-							string.other.link.description.title.markdown
-						
-						11
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						12
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						13
-						
-							name
-							string.other.link.description.title.markdown
-						
-						14
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						15
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						16
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						2
-						
-							name
-							string.other.link.title.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							invalid.illegal.whitespace.markdown
-						
-						6
-						
-							name
-							punctuation.definition.metadata.markdown
-						
-						7
-						
-							name
-							punctuation.definition.link.markdown
-						
-						8
-						
-							name
-							markup.underline.link.markdown
-						
-						9
-						
-							name
-							punctuation.definition.link.markdown
-						
-					
-					match
-					(?x:
-						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])	
-													# Match the link text.
-						([ ])?						# Space not allowed
-						(\()						# Opening paren for url
-							(<?)(.*?)(>?)			# The url
-							[ \t]*					# Optional whitespace
-							(?:
-								  ((\().+?(\)))		# Match title in parens…
-								| ((").+?("))		# or in quotes.
-							)?						# Title is optional
-							\s*						# Optional whitespace
-						(\))
-					 )
-					name
-					meta.link.inline.markdown
-				
-				link-ref
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						2
-						
-							name
-							string.other.link.title.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							punctuation.definition.constant.begin.markdown
-						
-						6
-						
-							name
-							constant.other.reference.link.markdown
-						
-						7
-						
-							name
-							punctuation.definition.constant.end.markdown
-						
-					
-					match
-					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)([^\]]*+)(\])
-					name
-					meta.link.reference.markdown
-				
-				link-ref-literal
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.string.begin.markdown
-						
-						2
-						
-							name
-							string.other.link.title.markdown
-						
-						4
-						
-							name
-							punctuation.definition.string.end.markdown
-						
-						5
-						
-							name
-							punctuation.definition.constant.begin.markdown
-						
-						6
-						
-							name
-							punctuation.definition.constant.end.markdown
-						
-					
-					match
-					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(\])
-					name
-					meta.link.reference.literal.markdown
-				
-				raw
-				
-					captures
-					
-						1
-						
-							name
-							punctuation.definition.raw.markdown
-						
-						2
-						
-						3
-						
-							name
-							punctuation.definition.raw.markdown
-						
-					
-					match
-					(`+)([^`]|(?!(?<!`)\1(?!`))`)*+(\1)
-					name
-					markup.raw.inline.markdown
-				
-			
-		
-	
-	scopeName
-	text.html.markdown
-	uuid
-	0A1D9874-B448-11D9-BD50-000D93B6E43C
-
+
+
+
+
+	fileTypes
+	
+		md
+		mdown
+		markdown
+		markdn
+	
+	keyEquivalent
+	^~M
+	name
+	Markdown
+	patterns
+	
+		
+			include
+			#block
+		
+	
+	repository
+	
+		block
+		
+			patterns
+			
+				
+					include
+					#separator
+				
+				
+					include
+					#heading
+				
+				
+					include
+					#blockquote
+				
+				
+					include
+					#lists
+				
+				
+					include
+					#raw_block
+				
+				
+					include
+					#link-def
+				
+				
+					include
+					#html
+				
+				
+					include
+					#paragraph
+				
+			
+			repository
+			
+				blockquote
+				
+					begin
+					(^|\G)(>) ?
+					captures
+					
+						2
+						
+							name
+							punctuation.definition.quote.markdown
+						
+					
+					name
+					markup.quote.markdown
+					patterns
+					
+						
+							include
+							#block
+						
+					
+					while
+					(^|\G)(>) ?
+				
+				heading
+				
+					begin
+					(?:^|\G)(#{1,6})\s*(?=[\S[^#]])
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.heading.markdown
+						
+					
+					contentName
+					entity.name.section.markdown
+					end
+					\s*(#{1,6})?$\n?
+					name
+					markup.heading.${1/(#)(#)?(#)?(#)?(#)?(#)?/${6:?6:${5:?5:${4:?4:${3:?3:${2:?2:1}}}}}/}.markdown
+					patterns
+					
+						
+							include
+							#inline
+						
+					
+				
+				heading-setext
+				
+					patterns
+					
+						
+							match
+							^(={3,})(?=[ \t]*$\n?)
+							name
+							markup.heading.setext.1.markdown
+						
+						
+							match
+							^(-{3,})(?=[ \t]*$\n?)
+							name
+							markup.heading.setext.2.markdown
+						
+					
+				
+				html
+				
+					patterns
+					
+						
+							begin
+							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del).*</\2\s*>\s*$)
+							end
+							$
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+						
+						
+							begin
+							(?i)(^|\G)(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del))
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+							while
+							\G(?!</\2\s*>)
+						
+					
+				
+				link-def
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.constant.markdown
+						
+						10
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						11
+						
+							name
+							string.other.link.description.title.markdown
+						
+						12
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						13
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						2
+						
+							name
+							constant.other.reference.link.markdown
+						
+						3
+						
+							name
+							punctuation.definition.constant.markdown
+						
+						4
+						
+							name
+							punctuation.separator.key-value.markdown
+						
+						5
+						
+							name
+							punctuation.definition.link.markdown
+						
+						6
+						
+							name
+							markup.underline.link.markdown
+						
+						7
+						
+							name
+							punctuation.definition.link.markdown
+						
+						8
+						
+							name
+							string.other.link.description.title.markdown
+						
+						9
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+					
+					match
+					^(?x:
+									\s*						# Leading whitespace
+									(\[)(.+?)(\])(:)		# Reference name
+									[ \t]*					# Optional whitespace
+									(<?)(\S+?)(>?)			# The url
+									[ \t]*					# Optional whitespace
+									(?:
+										  ((\().+?(\)))		# Match title in quotes…
+										| ((").+?("))		# or in parens.
+									)?						# Title is optional
+									\s*						# Optional whitespace
+									$
+								)
+					name
+					meta.link.reference.def.markdown
+				
+				list_paragraph
+				
+					begin
+					(^|\G)(?=\S)(?![*+-]\s|[0-9]+\.\s)
+					name
+					meta.paragraph.markdown
+					patterns
+					
+						
+							include
+							#inline
+						
+						
+							include
+							text.html.basic
+						
+						
+							include
+							#heading-setext
+						
+					
+					while
+					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|>|[ ]{0,3}[*+-]|[ ]{0,3}[0-9]+\.)
+				
+				lists
+				
+					patterns
+					
+						
+							begin
+							(^|\G)([ ]{0,3})([*+-])([ ]{1,3}|\t)
+							beginCaptures
+							
+								3
+								
+									name
+									punctuation.definition.list.markdown
+								
+							
+							comment
+							Currently does not support un-indented second lines.
+							name
+							markup.list.unnumbered.markdown
+							patterns
+							
+								
+									include
+									#list_paragraph
+								
+								
+									include
+									#block
+								
+							
+							while
+							\G([ ]{4}|\t|$)
+						
+						
+							begin
+							(^|\G)([ ]{0,3})([0-9]+\.)([ ]{1,3}|\t)
+							beginCaptures
+							
+								3
+								
+									name
+									punctuation.definition.list.markdown
+								
+							
+							name
+							markup.list.numbered.markdown
+							patterns
+							
+								
+									include
+									#list_paragraph
+								
+								
+									include
+									#block
+								
+							
+							while
+							\G([ ]{4}|\t|$)
+						
+					
+				
+				paragraph
+				
+					begin
+					(^|\G)(?=\S)
+					name
+					meta.paragraph.markdown
+					patterns
+					
+						
+							include
+							#inline
+						
+						
+							include
+							text.html.basic
+						
+						
+							include
+							#heading-setext
+						
+					
+					while
+					(^|\G)(?!\s*$|#|[ ]{0,3}([-*_][ ]{2,}){3,}[ \t]*$\n?|\s*\[.+?\]:|>)
+				
+				raw_block
+				
+					begin
+					(^|\G)([ ]{4}|\t)
+					name
+					markup.raw.block.markdown
+					while
+					(^|\G)([ ]{4}|\t)
+				
+				separator
+				
+					match
+					(^|\G)[ ]{0,3}([-*_])([ ]{0,2}\2){2,}[ \t]*$\n?
+					name
+					meta.separator.markdown
+				
+			
+		
+		inline
+		
+			patterns
+			
+				
+					include
+					#ampersand
+				
+				
+					include
+					#bracket
+				
+				
+					include
+					#bold
+				
+				
+					include
+					#italic
+				
+				
+					include
+					#raw
+				
+				
+					include
+					#escape
+				
+				
+					include
+					#image-inline
+				
+				
+					include
+					#image-ref
+				
+				
+					include
+					#link-email
+				
+				
+					include
+					#link-inet
+				
+				
+					include
+					#link-inline
+				
+				
+					include
+					#link-ref
+				
+				
+					include
+					#link-ref-literal
+				
+			
+			repository
+			
+				ampersand
+				
+					comment
+					
+						Markdown will convert this for us. We match it so that the
+						HTML grammar will not mark it up as invalid.
+					
+					match
+					&(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);)
+					name
+					meta.other.valid-ampersand.markdown
+				
+				bold
+				
+					begin
+					(?x)
+								(\*\*|__)(?=\S)								# Open
+								(?=
+									(
+									    <[^>]*+>							# HTML tags
+									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
+																			# Raw
+									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
+									  | \[
+										(				
+										        (?<square>					# Named group
+													[^\[\]\\]				# Match most chars
+										          | \\.						# Escaped chars
+										          | \[ \g<square>*+ \]		# Nested brackets
+										        )*+
+											\]
+											(
+												(							# Reference Link
+													[ ]?					# Optional space
+													\[[^\]]*+\]				# Ref name
+												)
+											  | (							# Inline Link
+													\(						# Opening paren
+														[ \t]*+				# Optional whtiespace
+														<?(.*?)>?			# URL
+														[ \t]*+				# Optional whtiespace
+														(					# Optional Title
+															(?<title>['"])
+															(.*?)
+															\k<title>
+														)?
+													\)
+												)
+											)
+										)
+									  | (?!(?<=\S)\1).						# Everything besides
+																			# style closer
+									)++
+									(?<=\S)\1								# Close
+								)
+							
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.bold.markdown
+						
+					
+					end
+					(?<=\S)(\1)
+					name
+					markup.bold.markdown
+					patterns
+					
+						
+							applyEndPatternLast
+							1
+							begin
+							(?=<[^>]*?>)
+							end
+							(?<=>)
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+						
+						
+							include
+							#escape
+						
+						
+							include
+							#ampersand
+						
+						
+							include
+							#bracket
+						
+						
+							include
+							#raw
+						
+						
+							include
+							#italic
+						
+						
+							include
+							#image-inline
+						
+						
+							include
+							#link-inline
+						
+						
+							include
+							#link-inet
+						
+						
+							include
+							#link-email
+						
+						
+							include
+							#image-ref
+						
+						
+							include
+							#link-ref-literal
+						
+						
+							include
+							#link-ref
+						
+					
+				
+				bracket
+				
+					comment
+					
+						Markdown will convert this for us. We match it so that the
+						HTML grammar will not mark it up as invalid.
+					
+					match
+					<(?![a-z/?\$!])
+					name
+					meta.other.valid-bracket.markdown
+				
+				escape
+				
+					match
+					\\[-`*_#+.!(){}\[\]\\>]
+					name
+					constant.character.escape.markdown
+				
+				image-inline
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						10
+						
+							name
+							string.other.link.description.title.markdown
+						
+						11
+						
+							name
+							punctuation.definition.string.markdown
+						
+						12
+						
+							name
+							punctuation.definition.string.markdown
+						
+						13
+						
+							name
+							string.other.link.description.title.markdown
+						
+						14
+						
+							name
+							punctuation.definition.string.markdown
+						
+						15
+						
+							name
+							punctuation.definition.string.markdown
+						
+						16
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						2
+						
+							name
+							string.other.link.description.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							invalid.illegal.whitespace.markdown
+						
+						6
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						7
+						
+							name
+							punctuation.definition.link.markdown
+						
+						8
+						
+							name
+							markup.underline.link.image.markdown
+						
+						9
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(?x:
+						\!							# Images start with !
+						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])	
+													# Match the link text.
+						([ ])?						# Space not allowed
+						(\()						# Opening paren for url
+							(<?)(\S+?)(>?)			# The url
+							[ \t]*					# Optional whitespace
+							(?:
+								  ((\().+?(\)))		# Match title in parens…
+								| ((").+?("))		# or in quotes.
+							)?						# Title is optional
+							\s*						# Optional whitespace
+						(\))
+					 )
+					name
+					meta.image.inline.markdown
+				
+				image-ref
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						2
+						
+							name
+							string.other.link.description.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						5
+						
+							name
+							punctuation.definition.constant.markdown
+						
+						6
+						
+							name
+							constant.other.reference.link.markdown
+						
+						7
+						
+							name
+							punctuation.definition.constant.markdown
+						
+					
+					match
+					\!(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(.*?)(\])
+					name
+					meta.image.reference.markdown
+				
+				italic
+				
+					begin
+					(?x)
+								(\*|_)(?=\S)								# Open
+								(?=
+									(
+									    <[^>]*+>							# HTML tags
+									  | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw>
+																			# Raw
+									  | \\[\\`*_{}\[\]()#.!+\->]?+			# Escapes
+									  | \[
+										(				
+										        (?<square>					# Named group
+													[^\[\]\\]				# Match most chars
+										          | \\.						# Escaped chars
+										          | \[ \g<square>*+ \]		# Nested brackets
+										        )*+
+											\]
+											(
+												(							# Reference Link
+													[ ]?					# Optional space
+													\[[^\]]*+\]				# Ref name
+												)
+											  | (							# Inline Link
+													\(						# Opening paren
+														[ \t]*+				# Optional whtiespace
+														<?(.*?)>?			# URL
+														[ \t]*+				# Optional whtiespace
+														(					# Optional Title
+															(?<title>['"])
+															(.*?)
+															\k<title>
+														)?
+													\)
+												)
+											)
+										)
+									  | \1\1								# Must be bold closer
+									  | (?!(?<=\S)\1).						# Everything besides
+																			# style closer
+									)++
+									(?<=\S)\1								# Close
+								)
+							
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.italic.markdown
+						
+					
+					end
+					(?<=\S)(\1)((?!\1)|(?=\1\1))
+					name
+					markup.italic.markdown
+					patterns
+					
+						
+							applyEndPatternLast
+							1
+							begin
+							(?=<[^>]*?>)
+							end
+							(?<=>)
+							patterns
+							
+								
+									include
+									text.html.basic
+								
+							
+						
+						
+							include
+							#escape
+						
+						
+							include
+							#ampersand
+						
+						
+							include
+							#bracket
+						
+						
+							include
+							#raw
+						
+						
+							include
+							#bold
+						
+						
+							include
+							#image-inline
+						
+						
+							include
+							#link-inline
+						
+						
+							include
+							#link-inet
+						
+						
+							include
+							#link-email
+						
+						
+							include
+							#image-ref
+						
+						
+							include
+							#link-ref-literal
+						
+						
+							include
+							#link-ref
+						
+					
+				
+				link-email
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.link.markdown
+						
+						2
+						
+							name
+							markup.underline.link.markdown
+						
+						4
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(<)((?:mailto:)?[-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(>)
+					name
+					meta.link.email.lt-gt.markdown
+				
+				link-inet
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.link.markdown
+						
+						2
+						
+							name
+							markup.underline.link.markdown
+						
+						3
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(<)((?:https?|ftp)://.*?)(>)
+					name
+					meta.link.inet.markdown
+				
+				link-inline
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						10
+						
+							name
+							string.other.link.description.title.markdown
+						
+						11
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						12
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						13
+						
+							name
+							string.other.link.description.title.markdown
+						
+						14
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						15
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						16
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						2
+						
+							name
+							string.other.link.title.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							invalid.illegal.whitespace.markdown
+						
+						6
+						
+							name
+							punctuation.definition.metadata.markdown
+						
+						7
+						
+							name
+							punctuation.definition.link.markdown
+						
+						8
+						
+							name
+							markup.underline.link.markdown
+						
+						9
+						
+							name
+							punctuation.definition.link.markdown
+						
+					
+					match
+					(?x:
+						(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])	
+													# Match the link text.
+						([ ])?						# Space not allowed
+						(\()						# Opening paren for url
+							(<?)(.*?)(>?)			# The url
+							[ \t]*					# Optional whitespace
+							(?:
+								  ((\().+?(\)))		# Match title in parens…
+								| ((").+?("))		# or in quotes.
+							)?						# Title is optional
+							\s*						# Optional whitespace
+						(\))
+					 )
+					name
+					meta.link.inline.markdown
+				
+				link-ref
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						2
+						
+							name
+							string.other.link.title.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							punctuation.definition.constant.begin.markdown
+						
+						6
+						
+							name
+							constant.other.reference.link.markdown
+						
+						7
+						
+							name
+							punctuation.definition.constant.end.markdown
+						
+					
+					match
+					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)([^\]]*+)(\])
+					name
+					meta.link.reference.markdown
+				
+				link-ref-literal
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.string.begin.markdown
+						
+						2
+						
+							name
+							string.other.link.title.markdown
+						
+						4
+						
+							name
+							punctuation.definition.string.end.markdown
+						
+						5
+						
+							name
+							punctuation.definition.constant.begin.markdown
+						
+						6
+						
+							name
+							punctuation.definition.constant.end.markdown
+						
+					
+					match
+					(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(\])
+					name
+					meta.link.reference.literal.markdown
+				
+				raw
+				
+					captures
+					
+						1
+						
+							name
+							punctuation.definition.raw.markdown
+						
+						2
+						
+						3
+						
+							name
+							punctuation.definition.raw.markdown
+						
+					
+					match
+					(`+)([^`]|(?!(?<!`)\1(?!`))`)*+(\1)
+					name
+					markup.raw.inline.markdown
+				
+			
+		
+	
+	scopeName
+	text.html.markdown
+	uuid
+	0A1D9874-B448-11D9-BD50-000D93B6E43C
+
 
\ No newline at end of file
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java
index c8743a7f3..25cfcb37f 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java
@@ -1,85 +1,85 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration;
-
-import java.util.List;
-
-import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.Folding;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
-
-public interface ILanguageConfiguration {
-	/**
-	 * Returns the language's comments. The comments are used by
-	 * {@link AutoClosingPairConditional} when notIn contains
-	 * comment
-	 *
-	 * @return the language's comments or null if not set
-	 */
-	Comments getComments();
-
-	/**
-	 * Returns the language's brackets. This configuration implicitly affects
-	 * pressing Enter around these brackets.
-	 *
-	 * @return the language's brackets. This configuration implicitly affects
-	 *         pressing Enter around these brackets.
-	 */
-	List getBrackets();
-
-	/**
-	 * Returns the language's auto closing pairs. The 'close' character is
-	 * automatically inserted with the 'open' character is typed. If not set, the
-	 * configured brackets will be used.
-	 *
-	 * @return the language's auto closing pairs. The 'close' character is
-	 *         autautomatically inserted with the 'open' character is typed. If not
-	 *         set, the configured brackets will be used.
-	 */
-	List getAutoClosingPairs();
-
-	/**
-	 * Returns the language's rules to be evaluated when pressing Enter.
-	 *
-	 * @return the language's rules to be evaluated when pressing Enter.
-	 */
-	List getOnEnterRules();
-
-	/**
-	 * Returns the language's surrounding pairs. When the 'open' character is typed
-	 * on a selection, the selected string is surrounded by the open and close
-	 * characters. If not set, the autoclosing pairs settings will be used.
-	 *
-	 * @return the language's surrounding pairs. When the 'open' character is typed
-	 *         on a selection, the selected string is surrounded by the open and
-	 *         close characters. If not set, the autoclosing pairs settings will be
-	 *         used.
-	 */
-	List getSurroundingPairs();
-
-	/**
-	 * Returns the language's folding rules.
-	 *
-	 * @return the language's folding or null if not set
-	 */
-	Folding getFolding();
-
-	/**
-	 * Returns the language's definition of a word. This is the regex used when
-	 * refering to a word.
-	 *
-	 * @return the language's word pattern or null if not set
-	 */
-	String getWordPattern();
-}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration;
+
+import java.util.List;
+
+import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.Folding;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
+
+public interface ILanguageConfiguration {
+	/**
+	 * Returns the language's comments. The comments are used by
+	 * {@link AutoClosingPairConditional} when notIn contains
+	 * comment
+	 *
+	 * @return the language's comments or null if not set
+	 */
+	Comments getComments();
+
+	/**
+	 * Returns the language's brackets. This configuration implicitly affects
+	 * pressing Enter around these brackets.
+	 *
+	 * @return the language's brackets. This configuration implicitly affects
+	 *         pressing Enter around these brackets.
+	 */
+	List getBrackets();
+
+	/**
+	 * Returns the language's auto closing pairs. The 'close' character is
+	 * automatically inserted with the 'open' character is typed. If not set, the
+	 * configured brackets will be used.
+	 *
+	 * @return the language's auto closing pairs. The 'close' character is
+	 *         autautomatically inserted with the 'open' character is typed. If not
+	 *         set, the configured brackets will be used.
+	 */
+	List getAutoClosingPairs();
+
+	/**
+	 * Returns the language's rules to be evaluated when pressing Enter.
+	 *
+	 * @return the language's rules to be evaluated when pressing Enter.
+	 */
+	List getOnEnterRules();
+
+	/**
+	 * Returns the language's surrounding pairs. When the 'open' character is typed
+	 * on a selection, the selected string is surrounded by the open and close
+	 * characters. If not set, the autoclosing pairs settings will be used.
+	 *
+	 * @return the language's surrounding pairs. When the 'open' character is typed
+	 *         on a selection, the selected string is surrounded by the open and
+	 *         close characters. If not set, the autoclosing pairs settings will be
+	 *         used.
+	 */
+	List getSurroundingPairs();
+
+	/**
+	 * Returns the language's folding rules.
+	 *
+	 * @return the language's folding or null if not set
+	 */
+	Folding getFolding();
+
+	/**
+	 * Returns the language's definition of a word. This is the regex used when
+	 * refering to a word.
+	 *
+	 * @return the language's word pattern or null if not set
+	 */
+	String getWordPattern();
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java
index 1f3efa758..7a2cc468b 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java
@@ -1,238 +1,238 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration;
-
-import java.util.Arrays;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
-import org.eclipse.jface.text.DocumentCommand;
-import org.eclipse.jface.text.IAutoEditStrategy;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterActionAndIndent;
-import org.eclipse.tm4e.languageconfiguration.internal.utils.TabSpacesInfo;
-import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils;
-import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
-import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * {@link IAutoEditStrategy} which uses VSCode language-configuration.json.
- *
- */
-public class LanguageConfigurationAutoEditStrategy implements IAutoEditStrategy {
-
-	private IDocument document;
-	private IContentType[] contentTypes;
-
-	private TabSpacesInfo tabSpacesInfo;
-	private ITextViewer viewer;
-
-	@Override
-	public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
-		IContentType[] contentTypes = findContentTypes(document);
-		if (contentTypes == null || command.text.isEmpty()) {
-			return;
-		}
-		installViewer();
-
-		if (TextUtils.isEnter(document, command)) {
-			// key enter pressed
-			onEnter(document, command);
-			return;
-		}
-
-		// Auto close pair
-		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
-		for (IContentType contentType : contentTypes) {
-			CharacterPair autoClosingPair = registry.getAutoClosePair(document.get(), command.offset, command.text,
-					contentType);
-			if (autoClosingPair == null) {
-				continue;
-			}
-			command.caretOffset = command.offset + command.text.length();
-			command.shiftsCaret = false;
-			if (command.text.equals(autoClosingPair.getKey()) && isFollowedBy(document, command.offset, autoClosingPair.getKey())) {
-				command.text = "";
-			} else if (command.text.equals(autoClosingPair.getValue()) && isFollowedBy(document, command.offset, autoClosingPair.getValue())) {
-				command.text = "";
-			} else {
-				command.text += autoClosingPair.getValue();
-			}
-			return;
-		}
-
-		Arrays.stream(contentTypes)
-			.flatMap(contentType -> registry.getEnabledAutoClosingPairs(contentType).stream())
-			.map(CharacterPair::getValue)
-			.filter(command.text::equals)
-			.filter(closing -> isFollowedBy(document, command.offset, closing))
-			.findFirst()
-			.ifPresent(closing -> {
-				command.caretOffset = command.offset + command.text.length();
-				command.shiftsCaret = false;
-				command.text = "";
-			});
-
-	}
-
-	/**
-	 * Returns true if the content after the given offset is followed
-	 * by the given value and false otherwise.
-	 *
-	 * @param document the document
-	 * @param offset   the offset
-	 * @param value    the content value to check
-	 * @return true if the content after the given offset is followed
-	 *         by the given value and false otherwise.
-	 */
-	private static boolean isFollowedBy(IDocument document, int offset, String value) {
-		for (int i = 0; i < value.length(); i++) {
-			if (document.getLength() <= offset) {
-				return false;
-			}
-			try {
-				if (document.getChar(offset) != value.charAt(i)) {
-					return false;
-				}
-			} catch (BadLocationException e) {
-				return false;
-			}
-			offset++;
-		}
-		return true;
-	}
-
-	private void onEnter(IDocument document, DocumentCommand command) {
-		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
-		for (IContentType contentType : contentTypes) {
-			if (!registry.shouldEnterAction(document, command.offset, contentType)) {
-				continue;
-			}
-			EnterActionAndIndent r = registry.getEnterAction(document, command.offset, contentType);
-			if (r != null) {
-				EnterAction enterAction = r.getEnterAction();
-				String indentation = TextUtils.getIndentationFromWhitespace(r.getIndentation(), getTabSpaces());
-				String delim = command.text;
-				switch (enterAction.getIndentAction()) {
-				case None: {
-					// Nothing special
-					String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText());
-					String typeText = delim + increasedIndent;
-
-					command.text = typeText;
-					command.shiftsCaret = false;
-					command.caretOffset = command.offset + (delim + increasedIndent).length();
-					break;
-				}
-				case Indent: {
-					// Indent once
-					String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText());
-					String typeText = delim + increasedIndent;
-
-					command.text = typeText;
-					command.shiftsCaret = false;
-					command.caretOffset = command.offset + (delim + increasedIndent).length();
-					break;
-				}
-				case IndentOutdent: {
-					// Ultra special
-					String normalIndent = normalizeIndentation(indentation);
-					String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText());
-
-					String typeText = delim + increasedIndent + delim + normalIndent;
-					command.text = typeText;
-					command.shiftsCaret = false;
-					command.caretOffset = command.offset + (delim + increasedIndent).length();
-					break;
-				}
-				case Outdent:
-					String outdentedText = outdentString(
-							normalizeIndentation(indentation + enterAction.getAppendText()));
-					command.text = delim + outdentedText;
-					command.shiftsCaret = false;
-					command.caretOffset = command.offset + (delim + outdentedText).length();
-					break;
-				}
-				return;
-			}
-		}
-
-		// fail back to default for indentation
-		new DefaultIndentLineAutoEditStrategy().customizeDocumentCommand(document, command);
-	}
-
-	private IContentType[] findContentTypes(IDocument document) {
-		if (this.document != null && this.document.equals(document)) {
-			return contentTypes;
-		}
-		try {
-			ContentTypeInfo info = ContentTypeHelper.findContentTypes(document);
-			this.contentTypes = info.getContentTypes();
-			this.document = document;
-		} catch (CoreException e) {
-			e.printStackTrace();
-		}
-		return contentTypes;
-	}
-
-	private String outdentString(String str) {
-		if (str.startsWith("\t")) {//$NON-NLS-1$
-			return str.substring(1);
-		}
-		TabSpacesInfo tabSpaces = getTabSpaces();
-		if (tabSpaces.isInsertSpaces()) {
-			char[] chars = new char[tabSpaces.getTabSize()];
-			Arrays.fill(chars, ' ');
-			String spaces = new String(chars);
-			if (str.startsWith(spaces)) {
-				return str.substring(spaces.length());
-			}
-		}
-		return str;
-	}
-
-	private String normalizeIndentation(String str) {
-		TabSpacesInfo tabSpaces = getTabSpaces();
-		return TextUtils.normalizeIndentation(str, tabSpaces.getTabSize(), tabSpaces.isInsertSpaces());
-	}
-
-	private TabSpacesInfo getTabSpaces() {
-		// For performance reason, tab spaces info are cached.
-		// If user change preferences (tab size, insert spaces), he must close the
-		// editor
-		// FIXME : how to detect changes of (tab size, insert spaces) with a generic
-		// mean?
-		if (tabSpacesInfo != null) {
-			return tabSpacesInfo;
-		}
-		tabSpacesInfo = TextUtils.getTabSpaces(viewer);
-		return tabSpacesInfo;
-	}
-
-	private void installViewer() {
-		if (viewer == null) {
-			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-			IEditorPart editorPart = page.getActiveEditor();
-			viewer = editorPart.getAdapter(ITextViewer.class);
-		}
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration;
+
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterActionAndIndent;
+import org.eclipse.tm4e.languageconfiguration.internal.utils.TabSpacesInfo;
+import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils;
+import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
+import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * {@link IAutoEditStrategy} which uses VSCode language-configuration.json.
+ *
+ */
+public class LanguageConfigurationAutoEditStrategy implements IAutoEditStrategy {
+
+	private IDocument document;
+	private IContentType[] contentTypes;
+
+	private TabSpacesInfo tabSpacesInfo;
+	private ITextViewer viewer;
+
+	@Override
+	public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
+		IContentType[] contentTypes = findContentTypes(document);
+		if (contentTypes == null || command.text.isEmpty()) {
+			return;
+		}
+		installViewer();
+
+		if (TextUtils.isEnter(document, command)) {
+			// key enter pressed
+			onEnter(document, command);
+			return;
+		}
+
+		// Auto close pair
+		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
+		for (IContentType contentType : contentTypes) {
+			CharacterPair autoClosingPair = registry.getAutoClosePair(document.get(), command.offset, command.text,
+					contentType);
+			if (autoClosingPair == null) {
+				continue;
+			}
+			command.caretOffset = command.offset + command.text.length();
+			command.shiftsCaret = false;
+			if (command.text.equals(autoClosingPair.getKey()) && isFollowedBy(document, command.offset, autoClosingPair.getKey())) {
+				command.text = "";
+			} else if (command.text.equals(autoClosingPair.getValue()) && isFollowedBy(document, command.offset, autoClosingPair.getValue())) {
+				command.text = "";
+			} else {
+				command.text += autoClosingPair.getValue();
+			}
+			return;
+		}
+
+		Arrays.stream(contentTypes)
+			.flatMap(contentType -> registry.getEnabledAutoClosingPairs(contentType).stream())
+			.map(CharacterPair::getValue)
+			.filter(command.text::equals)
+			.filter(closing -> isFollowedBy(document, command.offset, closing))
+			.findFirst()
+			.ifPresent(closing -> {
+				command.caretOffset = command.offset + command.text.length();
+				command.shiftsCaret = false;
+				command.text = "";
+			});
+
+	}
+
+	/**
+	 * Returns true if the content after the given offset is followed
+	 * by the given value and false otherwise.
+	 *
+	 * @param document the document
+	 * @param offset   the offset
+	 * @param value    the content value to check
+	 * @return true if the content after the given offset is followed
+	 *         by the given value and false otherwise.
+	 */
+	private static boolean isFollowedBy(IDocument document, int offset, String value) {
+		for (int i = 0; i < value.length(); i++) {
+			if (document.getLength() <= offset) {
+				return false;
+			}
+			try {
+				if (document.getChar(offset) != value.charAt(i)) {
+					return false;
+				}
+			} catch (BadLocationException e) {
+				return false;
+			}
+			offset++;
+		}
+		return true;
+	}
+
+	private void onEnter(IDocument document, DocumentCommand command) {
+		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
+		for (IContentType contentType : contentTypes) {
+			if (!registry.shouldEnterAction(document, command.offset, contentType)) {
+				continue;
+			}
+			EnterActionAndIndent r = registry.getEnterAction(document, command.offset, contentType);
+			if (r != null) {
+				EnterAction enterAction = r.getEnterAction();
+				String indentation = TextUtils.getIndentationFromWhitespace(r.getIndentation(), getTabSpaces());
+				String delim = command.text;
+				switch (enterAction.getIndentAction()) {
+				case None: {
+					// Nothing special
+					String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText());
+					String typeText = delim + increasedIndent;
+
+					command.text = typeText;
+					command.shiftsCaret = false;
+					command.caretOffset = command.offset + (delim + increasedIndent).length();
+					break;
+				}
+				case Indent: {
+					// Indent once
+					String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText());
+					String typeText = delim + increasedIndent;
+
+					command.text = typeText;
+					command.shiftsCaret = false;
+					command.caretOffset = command.offset + (delim + increasedIndent).length();
+					break;
+				}
+				case IndentOutdent: {
+					// Ultra special
+					String normalIndent = normalizeIndentation(indentation);
+					String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText());
+
+					String typeText = delim + increasedIndent + delim + normalIndent;
+					command.text = typeText;
+					command.shiftsCaret = false;
+					command.caretOffset = command.offset + (delim + increasedIndent).length();
+					break;
+				}
+				case Outdent:
+					String outdentedText = outdentString(
+							normalizeIndentation(indentation + enterAction.getAppendText()));
+					command.text = delim + outdentedText;
+					command.shiftsCaret = false;
+					command.caretOffset = command.offset + (delim + outdentedText).length();
+					break;
+				}
+				return;
+			}
+		}
+
+		// fail back to default for indentation
+		new DefaultIndentLineAutoEditStrategy().customizeDocumentCommand(document, command);
+	}
+
+	private IContentType[] findContentTypes(IDocument document) {
+		if (this.document != null && this.document.equals(document)) {
+			return contentTypes;
+		}
+		try {
+			ContentTypeInfo info = ContentTypeHelper.findContentTypes(document);
+			this.contentTypes = info.getContentTypes();
+			this.document = document;
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+		return contentTypes;
+	}
+
+	private String outdentString(String str) {
+		if (str.startsWith("\t")) {//$NON-NLS-1$
+			return str.substring(1);
+		}
+		TabSpacesInfo tabSpaces = getTabSpaces();
+		if (tabSpaces.isInsertSpaces()) {
+			char[] chars = new char[tabSpaces.getTabSize()];
+			Arrays.fill(chars, ' ');
+			String spaces = new String(chars);
+			if (str.startsWith(spaces)) {
+				return str.substring(spaces.length());
+			}
+		}
+		return str;
+	}
+
+	private String normalizeIndentation(String str) {
+		TabSpacesInfo tabSpaces = getTabSpaces();
+		return TextUtils.normalizeIndentation(str, tabSpaces.getTabSize(), tabSpaces.isInsertSpaces());
+	}
+
+	private TabSpacesInfo getTabSpaces() {
+		// For performance reason, tab spaces info are cached.
+		// If user change preferences (tab size, insert spaces), he must close the
+		// editor
+		// FIXME : how to detect changes of (tab size, insert spaces) with a generic
+		// mean?
+		if (tabSpacesInfo != null) {
+			return tabSpacesInfo;
+		}
+		tabSpacesInfo = TextUtils.getTabSpaces(viewer);
+		return tabSpacesInfo;
+	}
+
+	private void installViewer() {
+		if (viewer == null) {
+			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+			IEditorPart editorPart = page.getActiveEditor();
+			viewer = editorPart.getAdapter(ITextViewer.class);
+		}
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java
index 0eab91090..74bdf13cb 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java
@@ -1,143 +1,143 @@
-/**
- *  Copyright (c) 2018 Angelo ZERR.
+/**
+ *  Copyright (c) 2018 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
-import org.eclipse.jface.text.source.ICharacterPairMatcher;
-import org.eclipse.jface.text.source.ICharacterPairMatcherExtension;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
-import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
-
-/**
- * Support of matching bracket with language configuration.
- *
- */
-public class LanguageConfigurationCharacterPairMatcher
-		implements ICharacterPairMatcher, ICharacterPairMatcherExtension {
-
-	private DefaultCharacterPairMatcher matcher;
-
-	private IDocument document;
-
-	@Override
-	public IRegion match(IDocument document, int offset) {
-		DefaultCharacterPairMatcher matcher = getMatcher(document);
-		return matcher != null ? matcher.match(document, offset) : null;
-	}
-
-	@Override
-	public IRegion match(IDocument document, int offset, int length) {
-		DefaultCharacterPairMatcher matcher = getMatcher(document);
-		return matcher != null ? matcher.match(document, offset, length) : null;
-	}
-
-	@Override
-	public int getAnchor() {
-		return matcher != null ? matcher.getAnchor() : -1;
-	}
-
-	@Override
-	public IRegion findEnclosingPeerCharacters(IDocument document, int offset, int length) {
-		DefaultCharacterPairMatcher matcher = getMatcher(document);
-		return matcher != null ? matcher.findEnclosingPeerCharacters(document, offset, length) : null;
-	}
-
-	@Override
-	public boolean isMatchedChar(char ch) {
-		DefaultCharacterPairMatcher matcher = getMatcher(document);
-		return matcher != null ? matcher.isMatchedChar(ch) : false;
-	}
-
-	@Override
-	public boolean isMatchedChar(char ch, IDocument document, int offset) {
-		DefaultCharacterPairMatcher matcher = getMatcher(document);
-		return matcher != null ? matcher.isMatchedChar(ch, document, offset) : false;
-	}
-
-	@Override
-	public boolean isRecomputationOfEnclosingPairRequired(IDocument document, IRegion currentSelection,
-			IRegion previousSelection) {
-		DefaultCharacterPairMatcher matcher = getMatcher(document);
-		return matcher != null
-				? matcher.isRecomputationOfEnclosingPairRequired(document, currentSelection, previousSelection)
-				: false;
-	}
-
-	@Override
-	public void dispose() {
-		if (matcher != null) {
-			matcher.dispose();
-		}
-		matcher = null;
-	}
-
-	@Override
-	public void clear() {
-		if (matcher != null) {
-			matcher.clear();
-		}
-	}
-
-	/**
-	 * Returns the matcher from the document.
-	 * 
-	 * @param document
-	 * @return
-	 */
-	private DefaultCharacterPairMatcher getMatcher(IDocument document) {
-		if (!document.equals(this.document)) {
-			matcher = null;
-		}
-		if (matcher == null) {
-			// initizalize a DefaultCharacterPairMatcher by using character pairs of the
-			// language configuration.
-			StringBuilder chars = new StringBuilder();
-			this.document = document;
-			IContentType[] contentTypes = findContentTypes(document);
-			if (contentTypes != null) {
-				LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
-				for (IContentType contentType : contentTypes) {
-					if (!registry.shouldSurroundingPairs(document, -1, contentType)) {
-						continue;
-					}
-					List surroundingPairs = registry.getSurroundingPairs(contentType);
-					for (CharacterPair surroundingPair : surroundingPairs) {
-						chars.append(surroundingPair.getKey());
-						chars.append(surroundingPair.getValue());
-					}
-				}
-			}
-			matcher = new DefaultCharacterPairMatcher(chars.toString().toCharArray());
-		}
-		return matcher;
-	}
-
-	private IContentType[] findContentTypes(IDocument document) {
-		try {
-			ContentTypeInfo info = ContentTypeHelper.findContentTypes(document);
-			if(info != null) {
-				return info.getContentTypes();
-			}
-		} catch (CoreException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ICharacterPairMatcherExtension;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
+import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
+
+/**
+ * Support of matching bracket with language configuration.
+ *
+ */
+public class LanguageConfigurationCharacterPairMatcher
+		implements ICharacterPairMatcher, ICharacterPairMatcherExtension {
+
+	private DefaultCharacterPairMatcher matcher;
+
+	private IDocument document;
+
+	@Override
+	public IRegion match(IDocument document, int offset) {
+		DefaultCharacterPairMatcher matcher = getMatcher(document);
+		return matcher != null ? matcher.match(document, offset) : null;
+	}
+
+	@Override
+	public IRegion match(IDocument document, int offset, int length) {
+		DefaultCharacterPairMatcher matcher = getMatcher(document);
+		return matcher != null ? matcher.match(document, offset, length) : null;
+	}
+
+	@Override
+	public int getAnchor() {
+		return matcher != null ? matcher.getAnchor() : -1;
+	}
+
+	@Override
+	public IRegion findEnclosingPeerCharacters(IDocument document, int offset, int length) {
+		DefaultCharacterPairMatcher matcher = getMatcher(document);
+		return matcher != null ? matcher.findEnclosingPeerCharacters(document, offset, length) : null;
+	}
+
+	@Override
+	public boolean isMatchedChar(char ch) {
+		DefaultCharacterPairMatcher matcher = getMatcher(document);
+		return matcher != null ? matcher.isMatchedChar(ch) : false;
+	}
+
+	@Override
+	public boolean isMatchedChar(char ch, IDocument document, int offset) {
+		DefaultCharacterPairMatcher matcher = getMatcher(document);
+		return matcher != null ? matcher.isMatchedChar(ch, document, offset) : false;
+	}
+
+	@Override
+	public boolean isRecomputationOfEnclosingPairRequired(IDocument document, IRegion currentSelection,
+			IRegion previousSelection) {
+		DefaultCharacterPairMatcher matcher = getMatcher(document);
+		return matcher != null
+				? matcher.isRecomputationOfEnclosingPairRequired(document, currentSelection, previousSelection)
+				: false;
+	}
+
+	@Override
+	public void dispose() {
+		if (matcher != null) {
+			matcher.dispose();
+		}
+		matcher = null;
+	}
+
+	@Override
+	public void clear() {
+		if (matcher != null) {
+			matcher.clear();
+		}
+	}
+
+	/**
+	 * Returns the matcher from the document.
+	 * 
+	 * @param document
+	 * @return
+	 */
+	private DefaultCharacterPairMatcher getMatcher(IDocument document) {
+		if (!document.equals(this.document)) {
+			matcher = null;
+		}
+		if (matcher == null) {
+			// initizalize a DefaultCharacterPairMatcher by using character pairs of the
+			// language configuration.
+			StringBuilder chars = new StringBuilder();
+			this.document = document;
+			IContentType[] contentTypes = findContentTypes(document);
+			if (contentTypes != null) {
+				LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
+				for (IContentType contentType : contentTypes) {
+					if (!registry.shouldSurroundingPairs(document, -1, contentType)) {
+						continue;
+					}
+					List surroundingPairs = registry.getSurroundingPairs(contentType);
+					for (CharacterPair surroundingPair : surroundingPairs) {
+						chars.append(surroundingPair.getKey());
+						chars.append(surroundingPair.getValue());
+					}
+				}
+			}
+			matcher = new DefaultCharacterPairMatcher(chars.toString().toCharArray());
+		}
+		return matcher;
+	}
+
+	private IContentType[] findContentTypes(IDocument document) {
+		try {
+			ContentTypeInfo info = ContentTypeHelper.findContentTypes(document);
+			if(info != null) {
+				return info.getContentTypes();
+			}
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java
index 90c0910ce..5d1a91110 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java
@@ -1,291 +1,291 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.IRewriteTarget;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport;
-import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils;
-import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
-import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-public class ToggleLineCommentHandler extends AbstractHandler {
-	public static final String TOGGLE_LINE_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.togglelinecommentcommand";
-	public static final String ADD_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.addblockcommentcommand";
-	public static final String REMOVE_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.removeblockcommentcommand";
-
-	@Override
-	public Object execute(ExecutionEvent event) throws ExecutionException {
-		IEditorPart part = HandlerUtil.getActiveEditor(event);
-		if (!(part instanceof ITextEditor)) {
-			return null;
-		}
-		ITextEditor editor = (ITextEditor) part;
-		ISelection selection = editor.getSelectionProvider().getSelection();
-		if (!(selection instanceof ITextSelection)) {
-			return null;
-		}
-		ITextSelection textSelection = (ITextSelection) selection;
-		IEditorInput input = editor.getEditorInput();
-		IDocumentProvider docProvider = editor.getDocumentProvider();
-		if (docProvider == null || input == null) {
-			return null;
-		}
-
-		IDocument document = docProvider.getDocument(input);
-		if (document == null) {
-			return null;
-		}
-
-		ContentTypeInfo info;
-		try {
-			info = ContentTypeHelper.findContentTypes(document);
-		} catch (CoreException e) {
-			return null;
-		}
-		IContentType[] contentTypes = info.getContentTypes();
-		Command command = event.getCommand();
-		CommentSupport commentSupport = getCommentSupport(contentTypes);
-		if (commentSupport == null) {
-			return null;
-		}
-		// Check if comment support is valid according the command to do.
-		if (!isValid(commentSupport, command)) {
-			return null;
-		}
-
-		IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
-		if (target != null) {
-			target.beginCompoundChange();
-		}
-		try {
-			if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && commentSupport.getLineComment() != null) {
-				updateLineComment(document, textSelection, commentSupport.getLineComment(), editor);
-			} else {
-				IRegion existingBlock = getBlockComment(document, textSelection, commentSupport);
-				if (ADD_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock == null) {
-					addBlockComment(document, textSelection, commentSupport.getBlockComment(), editor);
-				} else if (REMOVE_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock != null) {
-					removeBlockComment(document, textSelection, existingBlock, commentSupport.getBlockComment(),
-							editor);
-				}
-			}
-		} catch (BadLocationException e) {
-			// Caught by making no changes
-		} finally {
-			if (target != null) {
-				target.endCompoundChange();
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * Returns true if comment support is valid according the command to do and
-	 * false otherwise.
-	 * 
-	 * @param commentSupport
-	 * @param command
-	 * @return true if comment support is valid according the command to do and
-	 *         false otherwise.
-	 */
-	private boolean isValid(CommentSupport commentSupport, Command command) {
-		if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId())) {
-			// check if line comment is valid.
-			return commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty();
-		}
-		// check if block comment is valid
-		CharacterPair characterPair = commentSupport.getBlockComment();
-		return characterPair != null && characterPair.getKey() != null && !characterPair.getKey().isEmpty()
-				&& characterPair.getValue() != null && !characterPair.getValue().isEmpty();
-	}
-
-	/**
-	 * Returns the comment support from the given list of content types and null
-	 * otherwise.
-	 * 
-	 * @param contentTypes
-	 * @return the comment support from the given list of content types and null
-	 *         otherwise.
-	 */
-	private CommentSupport getCommentSupport(IContentType[] contentTypes) {
-		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
-		for (IContentType contentType : contentTypes) {
-			if (!registry.shouldComment(contentType)) {
-				continue;
-			}
-			CommentSupport commentSupport = registry.getCommentSupport(contentType);
-			if (commentSupport != null) {
-				return commentSupport;
-			}
-		}
-		return null;
-	}
-
-	private void updateLineComment(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
-			throws BadLocationException {
-		if (areLinesCommented(document, selection, comment)) {
-			removeLineComments(document, selection, comment, editor);
-		} else {
-			addLineComments(document, selection, comment, editor);
-		}
-	}
-
-	private boolean areLinesCommented(IDocument document, ITextSelection selection, String comment)
-			throws BadLocationException {
-		int lineNumber = selection.getStartLine();
-		while (lineNumber <= selection.getEndLine()) {
-			IRegion lineRegion = document.getLineInformation(lineNumber);
-			if (!document.get(lineRegion.getOffset(), lineRegion.getLength()).trim().startsWith(comment)) {
-				return false;
-			}
-			lineNumber++;
-		}
-		return true;
-	}
-
-	private IRegion getBlockComment(IDocument document, ITextSelection selection, CommentSupport commentSupport)
-			throws BadLocationException {
-		if (selection.getText() == null) {
-			return null;
-		}
-		String text = document.get();
-		String open = commentSupport.getBlockComment().getKey();
-		String close = commentSupport.getBlockComment().getValue();
-		int selectionStart = selection.getOffset();
-		int selectionEnd = selectionStart + selection.getLength();
-		int openOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionStart, open);
-		if (openOffset == -1) {
-			openOffset = text.lastIndexOf(open, selectionStart);
-			if (openOffset == -1 || openOffset < document.getLineOffset(selection.getStartLine())) {
-				return null;
-			}
-		}
-
-		int closeOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionEnd, close);
-		if (closeOffset == -1 || closeOffset < openOffset + open.length()) {
-			closeOffset = text.indexOf(close, selectionEnd);
-			IRegion endLineRegion = document.getLineInformation(document.getLineOfOffset(selectionEnd));
-			if (openOffset == -1 || closeOffset < openOffset + open.length()
-					|| closeOffset > endLineRegion.getOffset() + endLineRegion.getLength()) {
-				return null;
-			}
-		}
-
-		// Make sure there isn't a different block closer before the one we found
-		int othercloseOffset = text.indexOf(close, openOffset + open.length());
-		while (othercloseOffset != -1 && othercloseOffset < closeOffset) {
-			int startOfLineOffset = document.getLineOffset(document.getLineOfOffset(othercloseOffset));
-			if (commentSupport.getLineComment() != null && text.substring(startOfLineOffset, othercloseOffset)
-					.indexOf(commentSupport.getLineComment()) != -1) {
-				return null;
-			}
-			othercloseOffset = text.indexOf(close, othercloseOffset + close.length());
-		}
-		return new Region(openOffset, closeOffset - openOffset);
-	}
-
-	private void removeLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
-			throws BadLocationException {
-		int lineNumber = selection.getStartLine();
-		int endLineNumber = selection.getEndLine();
-		String oldText = document.get();
-		int deletedChars = 0;
-		boolean isStartBeforeComment = false;
-
-		while (lineNumber <= endLineNumber) {
-			int commentOffset = oldText.indexOf(comment, document.getLineOffset(lineNumber) + deletedChars);
-			document.replace(commentOffset - deletedChars, comment.length(), "");
-			if (deletedChars == 0) {
-				isStartBeforeComment = commentOffset > selection.getOffset();
-			}
-			if (lineNumber != endLineNumber) {
-				deletedChars += comment.length();
-			}
-			lineNumber++;
-		}
-		ITextSelection newSelection = new TextSelection(
-				selection.getOffset() - (isStartBeforeComment ? 0 : comment.length()),
-				selection.getLength() - deletedChars);
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
-
-	private void addLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
-			throws BadLocationException {
-		int lineNumber = selection.getStartLine();
-		int endLineNumber = selection.getEndLine();
-		int insertedChars = 0;
-
-		while (lineNumber <= endLineNumber) {
-			document.replace(document.getLineOffset(lineNumber), 0, comment);
-			if (lineNumber != endLineNumber) {
-				insertedChars += comment.length();
-			}
-			lineNumber++;
-		}
-		ITextSelection newSelection = new TextSelection(selection.getOffset() + comment.length(),
-				selection.getLength() + insertedChars);
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
-
-	private void removeBlockComment(IDocument document, ITextSelection selection, IRegion existingBlock,
-			CharacterPair blockComment, ITextEditor editor) throws BadLocationException {
-		int openOffset = existingBlock.getOffset();
-		int openLength = blockComment.getKey().length();
-		int closeOffset = existingBlock.getOffset() + existingBlock.getLength();
-		int closeLength = blockComment.getValue().length();
-		document.replace(openOffset, openLength, "");
-		document.replace(closeOffset - openLength, closeLength, "");
-
-		int offsetFix = openLength;
-		int lengthFix = 0;
-		if (selection.getOffset() < openOffset + openLength) {
-			offsetFix = selection.getOffset() - openOffset;
-			lengthFix = openLength - offsetFix;
-		}
-		if (selection.getOffset() + selection.getLength() > closeOffset) {
-			lengthFix += selection.getOffset() + selection.getLength() - closeOffset;
-		}
-		ITextSelection newSelection = new TextSelection(selection.getOffset() - offsetFix,
-				selection.getLength() - lengthFix);
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
-
-	private void addBlockComment(IDocument document, ITextSelection selection, CharacterPair blockComment,
-			ITextEditor editor) throws BadLocationException {
-		document.replace(selection.getOffset(), 0, blockComment.getKey());
-		document.replace(selection.getOffset() + selection.getLength() + blockComment.getKey().length(), 0,
-				blockComment.getValue());
-		ITextSelection newSelection = new TextSelection(selection.getOffset() + blockComment.getKey().length(),
-				selection.getLength());
-		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
-	}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.IRewriteTarget;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport;
+import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils;
+import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
+import org.eclipse.tm4e.ui.utils.ContentTypeInfo;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class ToggleLineCommentHandler extends AbstractHandler {
+	public static final String TOGGLE_LINE_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.togglelinecommentcommand";
+	public static final String ADD_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.addblockcommentcommand";
+	public static final String REMOVE_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.removeblockcommentcommand";
+
+	@Override
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		IEditorPart part = HandlerUtil.getActiveEditor(event);
+		if (!(part instanceof ITextEditor)) {
+			return null;
+		}
+		ITextEditor editor = (ITextEditor) part;
+		ISelection selection = editor.getSelectionProvider().getSelection();
+		if (!(selection instanceof ITextSelection)) {
+			return null;
+		}
+		ITextSelection textSelection = (ITextSelection) selection;
+		IEditorInput input = editor.getEditorInput();
+		IDocumentProvider docProvider = editor.getDocumentProvider();
+		if (docProvider == null || input == null) {
+			return null;
+		}
+
+		IDocument document = docProvider.getDocument(input);
+		if (document == null) {
+			return null;
+		}
+
+		ContentTypeInfo info;
+		try {
+			info = ContentTypeHelper.findContentTypes(document);
+		} catch (CoreException e) {
+			return null;
+		}
+		IContentType[] contentTypes = info.getContentTypes();
+		Command command = event.getCommand();
+		CommentSupport commentSupport = getCommentSupport(contentTypes);
+		if (commentSupport == null) {
+			return null;
+		}
+		// Check if comment support is valid according the command to do.
+		if (!isValid(commentSupport, command)) {
+			return null;
+		}
+
+		IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
+		if (target != null) {
+			target.beginCompoundChange();
+		}
+		try {
+			if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && commentSupport.getLineComment() != null) {
+				updateLineComment(document, textSelection, commentSupport.getLineComment(), editor);
+			} else {
+				IRegion existingBlock = getBlockComment(document, textSelection, commentSupport);
+				if (ADD_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock == null) {
+					addBlockComment(document, textSelection, commentSupport.getBlockComment(), editor);
+				} else if (REMOVE_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock != null) {
+					removeBlockComment(document, textSelection, existingBlock, commentSupport.getBlockComment(),
+							editor);
+				}
+			}
+		} catch (BadLocationException e) {
+			// Caught by making no changes
+		} finally {
+			if (target != null) {
+				target.endCompoundChange();
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Returns true if comment support is valid according the command to do and
+	 * false otherwise.
+	 * 
+	 * @param commentSupport
+	 * @param command
+	 * @return true if comment support is valid according the command to do and
+	 *         false otherwise.
+	 */
+	private boolean isValid(CommentSupport commentSupport, Command command) {
+		if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId())) {
+			// check if line comment is valid.
+			return commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty();
+		}
+		// check if block comment is valid
+		CharacterPair characterPair = commentSupport.getBlockComment();
+		return characterPair != null && characterPair.getKey() != null && !characterPair.getKey().isEmpty()
+				&& characterPair.getValue() != null && !characterPair.getValue().isEmpty();
+	}
+
+	/**
+	 * Returns the comment support from the given list of content types and null
+	 * otherwise.
+	 * 
+	 * @param contentTypes
+	 * @return the comment support from the given list of content types and null
+	 *         otherwise.
+	 */
+	private CommentSupport getCommentSupport(IContentType[] contentTypes) {
+		LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
+		for (IContentType contentType : contentTypes) {
+			if (!registry.shouldComment(contentType)) {
+				continue;
+			}
+			CommentSupport commentSupport = registry.getCommentSupport(contentType);
+			if (commentSupport != null) {
+				return commentSupport;
+			}
+		}
+		return null;
+	}
+
+	private void updateLineComment(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
+			throws BadLocationException {
+		if (areLinesCommented(document, selection, comment)) {
+			removeLineComments(document, selection, comment, editor);
+		} else {
+			addLineComments(document, selection, comment, editor);
+		}
+	}
+
+	private boolean areLinesCommented(IDocument document, ITextSelection selection, String comment)
+			throws BadLocationException {
+		int lineNumber = selection.getStartLine();
+		while (lineNumber <= selection.getEndLine()) {
+			IRegion lineRegion = document.getLineInformation(lineNumber);
+			if (!document.get(lineRegion.getOffset(), lineRegion.getLength()).trim().startsWith(comment)) {
+				return false;
+			}
+			lineNumber++;
+		}
+		return true;
+	}
+
+	private IRegion getBlockComment(IDocument document, ITextSelection selection, CommentSupport commentSupport)
+			throws BadLocationException {
+		if (selection.getText() == null) {
+			return null;
+		}
+		String text = document.get();
+		String open = commentSupport.getBlockComment().getKey();
+		String close = commentSupport.getBlockComment().getValue();
+		int selectionStart = selection.getOffset();
+		int selectionEnd = selectionStart + selection.getLength();
+		int openOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionStart, open);
+		if (openOffset == -1) {
+			openOffset = text.lastIndexOf(open, selectionStart);
+			if (openOffset == -1 || openOffset < document.getLineOffset(selection.getStartLine())) {
+				return null;
+			}
+		}
+
+		int closeOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionEnd, close);
+		if (closeOffset == -1 || closeOffset < openOffset + open.length()) {
+			closeOffset = text.indexOf(close, selectionEnd);
+			IRegion endLineRegion = document.getLineInformation(document.getLineOfOffset(selectionEnd));
+			if (openOffset == -1 || closeOffset < openOffset + open.length()
+					|| closeOffset > endLineRegion.getOffset() + endLineRegion.getLength()) {
+				return null;
+			}
+		}
+
+		// Make sure there isn't a different block closer before the one we found
+		int othercloseOffset = text.indexOf(close, openOffset + open.length());
+		while (othercloseOffset != -1 && othercloseOffset < closeOffset) {
+			int startOfLineOffset = document.getLineOffset(document.getLineOfOffset(othercloseOffset));
+			if (commentSupport.getLineComment() != null && text.substring(startOfLineOffset, othercloseOffset)
+					.indexOf(commentSupport.getLineComment()) != -1) {
+				return null;
+			}
+			othercloseOffset = text.indexOf(close, othercloseOffset + close.length());
+		}
+		return new Region(openOffset, closeOffset - openOffset);
+	}
+
+	private void removeLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
+			throws BadLocationException {
+		int lineNumber = selection.getStartLine();
+		int endLineNumber = selection.getEndLine();
+		String oldText = document.get();
+		int deletedChars = 0;
+		boolean isStartBeforeComment = false;
+
+		while (lineNumber <= endLineNumber) {
+			int commentOffset = oldText.indexOf(comment, document.getLineOffset(lineNumber) + deletedChars);
+			document.replace(commentOffset - deletedChars, comment.length(), "");
+			if (deletedChars == 0) {
+				isStartBeforeComment = commentOffset > selection.getOffset();
+			}
+			if (lineNumber != endLineNumber) {
+				deletedChars += comment.length();
+			}
+			lineNumber++;
+		}
+		ITextSelection newSelection = new TextSelection(
+				selection.getOffset() - (isStartBeforeComment ? 0 : comment.length()),
+				selection.getLength() - deletedChars);
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
+
+	private void addLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor)
+			throws BadLocationException {
+		int lineNumber = selection.getStartLine();
+		int endLineNumber = selection.getEndLine();
+		int insertedChars = 0;
+
+		while (lineNumber <= endLineNumber) {
+			document.replace(document.getLineOffset(lineNumber), 0, comment);
+			if (lineNumber != endLineNumber) {
+				insertedChars += comment.length();
+			}
+			lineNumber++;
+		}
+		ITextSelection newSelection = new TextSelection(selection.getOffset() + comment.length(),
+				selection.getLength() + insertedChars);
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
+
+	private void removeBlockComment(IDocument document, ITextSelection selection, IRegion existingBlock,
+			CharacterPair blockComment, ITextEditor editor) throws BadLocationException {
+		int openOffset = existingBlock.getOffset();
+		int openLength = blockComment.getKey().length();
+		int closeOffset = existingBlock.getOffset() + existingBlock.getLength();
+		int closeLength = blockComment.getValue().length();
+		document.replace(openOffset, openLength, "");
+		document.replace(closeOffset - openLength, closeLength, "");
+
+		int offsetFix = openLength;
+		int lengthFix = 0;
+		if (selection.getOffset() < openOffset + openLength) {
+			offsetFix = selection.getOffset() - openOffset;
+			lengthFix = openLength - offsetFix;
+		}
+		if (selection.getOffset() + selection.getLength() > closeOffset) {
+			lengthFix += selection.getOffset() + selection.getLength() - closeOffset;
+		}
+		ITextSelection newSelection = new TextSelection(selection.getOffset() - offsetFix,
+				selection.getLength() - lengthFix);
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
+
+	private void addBlockComment(IDocument document, ITextSelection selection, CharacterPair blockComment,
+			ITextEditor editor) throws BadLocationException {
+		document.replace(selection.getOffset(), 0, blockComment.getKey());
+		document.replace(selection.getOffset() + selection.getLength() + blockComment.getKey().length(), 0,
+				blockComment.getValue());
+		ITextSelection newSelection = new TextSelection(selection.getOffset() + blockComment.getKey().length(),
+				selection.getLength());
+		editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength());
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java
index f816df086..acd02ea40 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java
@@ -1,279 +1,279 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal;
-
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.Folding;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
-
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
-/**
- * VSCode language-configuration.json
- *
- * @see https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages
- */
-public class LanguageConfiguration implements ILanguageConfiguration {
-
-	/**
-	 * Returns an instance of {@link LanguageConfiguration} loaded from the VSCode
-	 * language-configuration.json file reader.
-	 *
-	 * @param reader
-	 * @return an instance of {@link LanguageConfiguration} loaded from the VSCode
-	 *         language-configuration.json file reader.
-	 */
-	public static LanguageConfiguration load(Reader reader) {
-		return new GsonBuilder()
-				.registerTypeAdapter(OnEnterRule.class, (JsonDeserializer) (json, typeOfT, context) -> {
-					String beforeText = null;
-					String afterText = null;
-					EnterAction action = null;
-					if (json.isJsonObject()) {
-						JsonObject object = json.getAsJsonObject();
-						beforeText = getAsString(object.get("beforeText")); //$NON-NLS-1$
-						afterText = getAsString(object.get("afterText")); //$NON-NLS-1$
-						JsonElement actionElement = object.get("action"); //$NON-NLS-1$
-						if (actionElement != null && actionElement.isJsonObject()) {
-							JsonObject actionObject = actionElement.getAsJsonObject();
-							IndentAction indentAction = IndentAction
-									.valueOf(getAsString(actionObject.get("indentAction"))); //$NON-NLS-1$
-							Integer removeText = getAsInt(actionObject.get("removeText")); //$NON-NLS-1$
-							String appendText = getAsString(actionObject.get("appendText")); //$NON-NLS-1$
-							if (indentAction != null) {
-								action = new EnterAction(indentAction);
-								action.setAppendText(appendText);
-								action.setRemoveText(removeText);
-							}
-						}
-					}
-					if (beforeText == null || action == null) {
-						return null;
-					}
-					return new OnEnterRule(beforeText, afterText, action);
-				}).registerTypeAdapter(Comments.class, (JsonDeserializer) (json, typeOfT, context) -> {
-					// ex: {"lineComment": "//","blockComment": [ "/*", "*/" ]}
-					String lineComment = null;
-					CharacterPair blockComment = null;
-					if (json.isJsonObject()) {
-						JsonObject object = json.getAsJsonObject();
-						lineComment = getAsString(object.get("lineComment")); //$NON-NLS-1$
-						JsonElement blockCommentElement = object.get("blockComment"); //$NON-NLS-1$
-						if (blockCommentElement != null && blockCommentElement.isJsonArray()) {
-							JsonArray blockCommentArray = blockCommentElement.getAsJsonArray();
-							if (blockCommentArray.size() == 2) {
-								String blockCommentStart = getAsString(blockCommentArray.get(0));
-								String blockCommentEnd = getAsString(blockCommentArray.get(1));
-								if (blockCommentStart != null && blockCommentEnd != null) {
-									blockComment = new CharacterPair(blockCommentStart, blockCommentEnd);
-								}
-							}
-						}
-					}
-					if (lineComment == null && blockComment == null) {
-						return null;
-					}
-					return new Comments(lineComment, blockComment);
-				}).registerTypeAdapter(CharacterPair.class,
-						(JsonDeserializer) (json, typeOfT, context) -> {
-							String open = null;
-							String close = null;
-							if (json.isJsonArray()) {
-								// ex: ["{","}"]
-								JsonArray characterPairs = json.getAsJsonArray();
-								if (characterPairs.size() == 2) {
-									open = getAsString(characterPairs.get(0));
-									close = getAsString(characterPairs.get(1));
-								}
-							}
-							if (open == null || close == null) {
-								return null;
-							}
-							return new CharacterPair(open, close);
-						})
-				.registerTypeAdapter(AutoClosingPairConditional.class,
-						(JsonDeserializer) (json, typeOfT, context) -> {
-							List notInList = new ArrayList<>();
-							String open = null;
-							String close = null;
-							if (json.isJsonArray()) {
-								// ex: ["{","}"]
-								JsonArray characterPairs = json.getAsJsonArray();
-								if (characterPairs.size() == 2) {
-									open = getAsString(characterPairs.get(0));
-									close = getAsString(characterPairs.get(1));
-								}
-							} else if (json.isJsonObject()) {
-								// ex: {"open":"'","close":"'", "notIn": ["string", "comment"]}
-								JsonObject object = json.getAsJsonObject();
-								open = getAsString(object.get("open")); //$NON-NLS-1$
-								close = getAsString(object.get("close")); //$NON-NLS-1$
-								JsonElement notInElement = object.get("notIn"); //$NON-NLS-1$
-								if (notInElement != null && notInElement.isJsonArray()) {
-									JsonArray notInArray = notInElement.getAsJsonArray();
-									notInArray.forEach(element -> {
-										String string = getAsString(element);
-										if (string != null) {
-											notInList.add(string);
-										}
-									});
-								}
-							}
-							if (open == null || close == null) {
-								return null;
-							}
-							return new AutoClosingPairConditional(open, close, notInList);
-						})
-				.registerTypeAdapter(Folding.class, (JsonDeserializer) (json, typeOfT, context) -> {
-					// ex: {"offSide": true, "markers": {"start": "^\\s*/", "end": "^\\s*"}}
-					boolean offSide = false;
-					String startMarker = null;
-					String endMarker = null;
-					if (json.isJsonObject()) {
-						JsonObject object = json.getAsJsonObject();
-						offSide = getAsBoolean(object.get("offSide"), offSide); //$NON-NLS-1$
-						JsonElement markersElement = object.get("markers"); //$NON-NLS-1$
-						if (markersElement != null && markersElement.isJsonObject()) {
-							JsonObject markersObject = markersElement.getAsJsonObject();
-							startMarker = getAsString(markersObject.get("start")); //$NON-NLS-1$
-							endMarker = getAsString(markersObject.get("end")); //$NON-NLS-1$
-						}
-					}
-					if (startMarker == null || endMarker == null) {
-						return null;
-					}
-					return new Folding(offSide, startMarker, endMarker);
-				}).create().fromJson(reader, LanguageConfiguration.class);
-	}
-
-	private static String getAsString(JsonElement element) {
-		if (element == null) {
-			return null;
-		}
-		try {
-			return element.getAsString();
-		} catch (Exception e) {
-			return null;
-		}
-	}
-
-	private static Boolean getAsBoolean(JsonElement element, Boolean defaultValue) {
-		if (element == null) {
-			return defaultValue;
-		}
-		try {
-			return element.getAsBoolean();
-		} catch (Exception e) {
-			return defaultValue;
-		}
-	}
-
-	private static Integer getAsInt(JsonElement element) {
-		if (element == null) {
-			return null;
-		}
-		try {
-			return element.getAsInt();
-		} catch (Exception e) {
-			return null;
-		}
-	}
-
-	/**
-	 * Defines the comment symbols
-	 */
-	private Comments comments;
-
-	/**
-	 * The language's brackets. This configuration implicitly affects pressing Enter
-	 * around these brackets.
-	 */
-	private List brackets;
-
-	/**
-	 * The language's rules to be evaluated when pressing Enter.
-	 */
-	private List onEnterRules;
-
-	/**
-	 * The language's auto closing pairs. The 'close' character is automatically
-	 * inserted with the 'open' character is typed. If not set, the configured
-	 * brackets will be used.
-	 */
-	private List autoClosingPairs;
-
-	/**
-	 * The language's surrounding pairs. When the 'open' character is typed on a
-	 * selection, the selected string is surrounded by the open and close
-	 * characters. If not set, the autoclosing pairs settings will be used.
-	 */
-	private List surroundingPairs;
-
-	/**
-	 * Defines when and how code should be folded in the editor
-	 */
-	private Folding folding;
-
-	/**
-	 * Regex which defines what is considered to be a word in the programming
-	 * language.
-	 */
-	private String wordPattern;
-
-	@Override
-	public Comments getComments() {
-		return comments;
-	}
-
-	@Override
-	public List getBrackets() {
-		return brackets;
-	}
-
-	@Override
-	public List getAutoClosingPairs() {
-		return autoClosingPairs;
-	}
-
-	@Override
-	public List getOnEnterRules() {
-		return onEnterRules;
-	}
-
-	@Override
-	public List getSurroundingPairs() {
-		return surroundingPairs;
-	}
-
-	@Override
-	public Folding getFolding() {
-		return folding;
-	}
-
-	@Override
-	public String getWordPattern() {
-		return wordPattern;
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.Folding;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+/**
+ * VSCode language-configuration.json
+ *
+ * @see https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages
+ */
+public class LanguageConfiguration implements ILanguageConfiguration {
+
+	/**
+	 * Returns an instance of {@link LanguageConfiguration} loaded from the VSCode
+	 * language-configuration.json file reader.
+	 *
+	 * @param reader
+	 * @return an instance of {@link LanguageConfiguration} loaded from the VSCode
+	 *         language-configuration.json file reader.
+	 */
+	public static LanguageConfiguration load(Reader reader) {
+		return new GsonBuilder()
+				.registerTypeAdapter(OnEnterRule.class, (JsonDeserializer) (json, typeOfT, context) -> {
+					String beforeText = null;
+					String afterText = null;
+					EnterAction action = null;
+					if (json.isJsonObject()) {
+						JsonObject object = json.getAsJsonObject();
+						beforeText = getAsString(object.get("beforeText")); //$NON-NLS-1$
+						afterText = getAsString(object.get("afterText")); //$NON-NLS-1$
+						JsonElement actionElement = object.get("action"); //$NON-NLS-1$
+						if (actionElement != null && actionElement.isJsonObject()) {
+							JsonObject actionObject = actionElement.getAsJsonObject();
+							IndentAction indentAction = IndentAction
+									.valueOf(getAsString(actionObject.get("indentAction"))); //$NON-NLS-1$
+							Integer removeText = getAsInt(actionObject.get("removeText")); //$NON-NLS-1$
+							String appendText = getAsString(actionObject.get("appendText")); //$NON-NLS-1$
+							if (indentAction != null) {
+								action = new EnterAction(indentAction);
+								action.setAppendText(appendText);
+								action.setRemoveText(removeText);
+							}
+						}
+					}
+					if (beforeText == null || action == null) {
+						return null;
+					}
+					return new OnEnterRule(beforeText, afterText, action);
+				}).registerTypeAdapter(Comments.class, (JsonDeserializer) (json, typeOfT, context) -> {
+					// ex: {"lineComment": "//","blockComment": [ "/*", "*/" ]}
+					String lineComment = null;
+					CharacterPair blockComment = null;
+					if (json.isJsonObject()) {
+						JsonObject object = json.getAsJsonObject();
+						lineComment = getAsString(object.get("lineComment")); //$NON-NLS-1$
+						JsonElement blockCommentElement = object.get("blockComment"); //$NON-NLS-1$
+						if (blockCommentElement != null && blockCommentElement.isJsonArray()) {
+							JsonArray blockCommentArray = blockCommentElement.getAsJsonArray();
+							if (blockCommentArray.size() == 2) {
+								String blockCommentStart = getAsString(blockCommentArray.get(0));
+								String blockCommentEnd = getAsString(blockCommentArray.get(1));
+								if (blockCommentStart != null && blockCommentEnd != null) {
+									blockComment = new CharacterPair(blockCommentStart, blockCommentEnd);
+								}
+							}
+						}
+					}
+					if (lineComment == null && blockComment == null) {
+						return null;
+					}
+					return new Comments(lineComment, blockComment);
+				}).registerTypeAdapter(CharacterPair.class,
+						(JsonDeserializer) (json, typeOfT, context) -> {
+							String open = null;
+							String close = null;
+							if (json.isJsonArray()) {
+								// ex: ["{","}"]
+								JsonArray characterPairs = json.getAsJsonArray();
+								if (characterPairs.size() == 2) {
+									open = getAsString(characterPairs.get(0));
+									close = getAsString(characterPairs.get(1));
+								}
+							}
+							if (open == null || close == null) {
+								return null;
+							}
+							return new CharacterPair(open, close);
+						})
+				.registerTypeAdapter(AutoClosingPairConditional.class,
+						(JsonDeserializer) (json, typeOfT, context) -> {
+							List notInList = new ArrayList<>();
+							String open = null;
+							String close = null;
+							if (json.isJsonArray()) {
+								// ex: ["{","}"]
+								JsonArray characterPairs = json.getAsJsonArray();
+								if (characterPairs.size() == 2) {
+									open = getAsString(characterPairs.get(0));
+									close = getAsString(characterPairs.get(1));
+								}
+							} else if (json.isJsonObject()) {
+								// ex: {"open":"'","close":"'", "notIn": ["string", "comment"]}
+								JsonObject object = json.getAsJsonObject();
+								open = getAsString(object.get("open")); //$NON-NLS-1$
+								close = getAsString(object.get("close")); //$NON-NLS-1$
+								JsonElement notInElement = object.get("notIn"); //$NON-NLS-1$
+								if (notInElement != null && notInElement.isJsonArray()) {
+									JsonArray notInArray = notInElement.getAsJsonArray();
+									notInArray.forEach(element -> {
+										String string = getAsString(element);
+										if (string != null) {
+											notInList.add(string);
+										}
+									});
+								}
+							}
+							if (open == null || close == null) {
+								return null;
+							}
+							return new AutoClosingPairConditional(open, close, notInList);
+						})
+				.registerTypeAdapter(Folding.class, (JsonDeserializer) (json, typeOfT, context) -> {
+					// ex: {"offSide": true, "markers": {"start": "^\\s*/", "end": "^\\s*"}}
+					boolean offSide = false;
+					String startMarker = null;
+					String endMarker = null;
+					if (json.isJsonObject()) {
+						JsonObject object = json.getAsJsonObject();
+						offSide = getAsBoolean(object.get("offSide"), offSide); //$NON-NLS-1$
+						JsonElement markersElement = object.get("markers"); //$NON-NLS-1$
+						if (markersElement != null && markersElement.isJsonObject()) {
+							JsonObject markersObject = markersElement.getAsJsonObject();
+							startMarker = getAsString(markersObject.get("start")); //$NON-NLS-1$
+							endMarker = getAsString(markersObject.get("end")); //$NON-NLS-1$
+						}
+					}
+					if (startMarker == null || endMarker == null) {
+						return null;
+					}
+					return new Folding(offSide, startMarker, endMarker);
+				}).create().fromJson(reader, LanguageConfiguration.class);
+	}
+
+	private static String getAsString(JsonElement element) {
+		if (element == null) {
+			return null;
+		}
+		try {
+			return element.getAsString();
+		} catch (Exception e) {
+			return null;
+		}
+	}
+
+	private static Boolean getAsBoolean(JsonElement element, Boolean defaultValue) {
+		if (element == null) {
+			return defaultValue;
+		}
+		try {
+			return element.getAsBoolean();
+		} catch (Exception e) {
+			return defaultValue;
+		}
+	}
+
+	private static Integer getAsInt(JsonElement element) {
+		if (element == null) {
+			return null;
+		}
+		try {
+			return element.getAsInt();
+		} catch (Exception e) {
+			return null;
+		}
+	}
+
+	/**
+	 * Defines the comment symbols
+	 */
+	private Comments comments;
+
+	/**
+	 * The language's brackets. This configuration implicitly affects pressing Enter
+	 * around these brackets.
+	 */
+	private List brackets;
+
+	/**
+	 * The language's rules to be evaluated when pressing Enter.
+	 */
+	private List onEnterRules;
+
+	/**
+	 * The language's auto closing pairs. The 'close' character is automatically
+	 * inserted with the 'open' character is typed. If not set, the configured
+	 * brackets will be used.
+	 */
+	private List autoClosingPairs;
+
+	/**
+	 * The language's surrounding pairs. When the 'open' character is typed on a
+	 * selection, the selected string is surrounded by the open and close
+	 * characters. If not set, the autoclosing pairs settings will be used.
+	 */
+	private List surroundingPairs;
+
+	/**
+	 * Defines when and how code should be folded in the editor
+	 */
+	private Folding folding;
+
+	/**
+	 * Regex which defines what is considered to be a word in the programming
+	 * language.
+	 */
+	private String wordPattern;
+
+	@Override
+	public Comments getComments() {
+		return comments;
+	}
+
+	@Override
+	public List getBrackets() {
+		return brackets;
+	}
+
+	@Override
+	public List getAutoClosingPairs() {
+		return autoClosingPairs;
+	}
+
+	@Override
+	public List getOnEnterRules() {
+		return onEnterRules;
+	}
+
+	@Override
+	public List getSurroundingPairs() {
+		return surroundingPairs;
+	}
+
+	@Override
+	public Folding getFolding() {
+		return folding;
+	}
+
+	@Override
+	public String getWordPattern() {
+		return wordPattern;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java
index 5dc7c6e63..582cb42c6 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java
@@ -1,159 +1,159 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration;
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPairSupport;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport;
-import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterSupport;
-import org.eclipse.tm4e.registry.TMResource;
-import org.eclipse.tm4e.registry.XMLConstants;
-import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
-
-/**
- * Language configuration definition.
- *
- */
-public class LanguageConfigurationDefinition extends TMResource implements ILanguageConfigurationDefinition {
-
-	private final IContentType contentType;
-	private boolean onEnterEnabled = true;
-	private boolean bracketAutoClosingEnabled = true;
-	private boolean matchingPairsEnabled = true;
-
-	private CharacterPairSupport characterPair;
-	private OnEnterSupport onEnter;
-	private CommentSupport comment;
-
-	public LanguageConfigurationDefinition(IContentType contentType, String path) {
-		super(path);
-		this.contentType = contentType;
-	}
-
-	public LanguageConfigurationDefinition(IConfigurationElement ce) {
-		super(ce);
-		this.contentType = ContentTypeHelper.getContentTypeById(ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR));
-	}
-
-	/**
-	 * Constructor for user preferences (loaded from Json with Gson).
-	 */
-	public LanguageConfigurationDefinition(IContentType contentType, String path, String pluginId,
-			boolean onEnterEnabled, boolean bracketAutoClosingEnabled, boolean matchingPairsEnabled) {
-		super(path, pluginId);
-		this.contentType = contentType;
-		this.onEnterEnabled = onEnterEnabled;
-		this.bracketAutoClosingEnabled = bracketAutoClosingEnabled;
-		this.matchingPairsEnabled = matchingPairsEnabled;
-	}
-
-	/**
-	 * Returns the "character pair" support and null otherwise.
-	 *
-	 * @return the "character pair" support and null otherwise.
-	 */
-	public CharacterPairSupport getCharacterPair() {
-		if (this.characterPair == null) {
-			ILanguageConfiguration conf = getLanguageConfiguration();
-			if (conf != null) {
-				this.characterPair = new CharacterPairSupport(conf.getBrackets(), conf.getAutoClosingPairs(),
-						conf.getSurroundingPairs());
-			}
-		}
-		return characterPair;
-	}
-
-	/**
-	 * Returns the "on enter" support and null otherwise.
-	 *
-	 * @return the "on enter" support and null otherwise.
-	 */
-	public OnEnterSupport getOnEnter() {
-		if (this.onEnter == null) {
-			ILanguageConfiguration conf = getLanguageConfiguration();
-			if (conf != null && (conf.getBrackets() != null || conf.getOnEnterRules() != null)) {
-				this.onEnter = new OnEnterSupport(conf.getBrackets(), conf.getOnEnterRules());
-			}
-		}
-		return onEnter;
-	}
-
-	/**
-	 * Returns the "commment" support and null otherwise.
-	 *
-	 * @return the "commment" support and null otherwise.
-	 */
-	public CommentSupport getCommentSupport() {
-		if (this.comment == null) {
-			ILanguageConfiguration conf = getLanguageConfiguration();
-			if (conf != null) {
-				this.comment = new CommentSupport(conf.getComments());
-			}
-		}
-		return comment;
-	}
-
-	@Override
-	public IContentType getContentType() {
-		return contentType;
-	}
-
-	@Override
-	public ILanguageConfiguration getLanguageConfiguration() {
-		try {
-			return LanguageConfiguration.load(new InputStreamReader(getInputStream(), Charset.defaultCharset()));
-		} catch (IOException e) {
-			LanguageConfigurationPlugin.getInstance().getLog().log(new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, e.getMessage(), e));
-			return null;
-		}
-	}
-
-	@Override
-	public Boolean isOnEnterEnabled() {
-		return onEnterEnabled;
-	}
-
-	@Override
-	public void setOnEnterEnabled(boolean onEnterEnabled) {
-		this.onEnterEnabled = onEnterEnabled;
-	}
-
-	@Override
-	public Boolean isBracketAutoClosingEnabled() {
-		return bracketAutoClosingEnabled;
-	}
-
-	@Override
-	public void setBracketAutoClosingEnabled(boolean bracketAutoClosingEnabled) {
-		this.bracketAutoClosingEnabled = bracketAutoClosingEnabled;
-	}
-
-	@Override
-	public Boolean isMatchingPairsEnabled() {
-		return matchingPairsEnabled;
-	}
-
-	@Override
-	public void setMatchingPairsEnabled(boolean matchingPairsEnabled) {
-		this.matchingPairsEnabled = matchingPairsEnabled;
-	}
-
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration;
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPairSupport;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport;
+import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterSupport;
+import org.eclipse.tm4e.registry.TMResource;
+import org.eclipse.tm4e.registry.XMLConstants;
+import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
+
+/**
+ * Language configuration definition.
+ *
+ */
+public class LanguageConfigurationDefinition extends TMResource implements ILanguageConfigurationDefinition {
+
+	private final IContentType contentType;
+	private boolean onEnterEnabled = true;
+	private boolean bracketAutoClosingEnabled = true;
+	private boolean matchingPairsEnabled = true;
+
+	private CharacterPairSupport characterPair;
+	private OnEnterSupport onEnter;
+	private CommentSupport comment;
+
+	public LanguageConfigurationDefinition(IContentType contentType, String path) {
+		super(path);
+		this.contentType = contentType;
+	}
+
+	public LanguageConfigurationDefinition(IConfigurationElement ce) {
+		super(ce);
+		this.contentType = ContentTypeHelper.getContentTypeById(ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR));
+	}
+
+	/**
+	 * Constructor for user preferences (loaded from Json with Gson).
+	 */
+	public LanguageConfigurationDefinition(IContentType contentType, String path, String pluginId,
+			boolean onEnterEnabled, boolean bracketAutoClosingEnabled, boolean matchingPairsEnabled) {
+		super(path, pluginId);
+		this.contentType = contentType;
+		this.onEnterEnabled = onEnterEnabled;
+		this.bracketAutoClosingEnabled = bracketAutoClosingEnabled;
+		this.matchingPairsEnabled = matchingPairsEnabled;
+	}
+
+	/**
+	 * Returns the "character pair" support and null otherwise.
+	 *
+	 * @return the "character pair" support and null otherwise.
+	 */
+	public CharacterPairSupport getCharacterPair() {
+		if (this.characterPair == null) {
+			ILanguageConfiguration conf = getLanguageConfiguration();
+			if (conf != null) {
+				this.characterPair = new CharacterPairSupport(conf.getBrackets(), conf.getAutoClosingPairs(),
+						conf.getSurroundingPairs());
+			}
+		}
+		return characterPair;
+	}
+
+	/**
+	 * Returns the "on enter" support and null otherwise.
+	 *
+	 * @return the "on enter" support and null otherwise.
+	 */
+	public OnEnterSupport getOnEnter() {
+		if (this.onEnter == null) {
+			ILanguageConfiguration conf = getLanguageConfiguration();
+			if (conf != null && (conf.getBrackets() != null || conf.getOnEnterRules() != null)) {
+				this.onEnter = new OnEnterSupport(conf.getBrackets(), conf.getOnEnterRules());
+			}
+		}
+		return onEnter;
+	}
+
+	/**
+	 * Returns the "commment" support and null otherwise.
+	 *
+	 * @return the "commment" support and null otherwise.
+	 */
+	public CommentSupport getCommentSupport() {
+		if (this.comment == null) {
+			ILanguageConfiguration conf = getLanguageConfiguration();
+			if (conf != null) {
+				this.comment = new CommentSupport(conf.getComments());
+			}
+		}
+		return comment;
+	}
+
+	@Override
+	public IContentType getContentType() {
+		return contentType;
+	}
+
+	@Override
+	public ILanguageConfiguration getLanguageConfiguration() {
+		try {
+			return LanguageConfiguration.load(new InputStreamReader(getInputStream(), Charset.defaultCharset()));
+		} catch (IOException e) {
+			LanguageConfigurationPlugin.getInstance().getLog().log(new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, e.getMessage(), e));
+			return null;
+		}
+	}
+
+	@Override
+	public Boolean isOnEnterEnabled() {
+		return onEnterEnabled;
+	}
+
+	@Override
+	public void setOnEnterEnabled(boolean onEnterEnabled) {
+		this.onEnterEnabled = onEnterEnabled;
+	}
+
+	@Override
+	public Boolean isBracketAutoClosingEnabled() {
+		return bracketAutoClosingEnabled;
+	}
+
+	@Override
+	public void setBracketAutoClosingEnabled(boolean bracketAutoClosingEnabled) {
+		this.bracketAutoClosingEnabled = bracketAutoClosingEnabled;
+	}
+
+	@Override
+	public Boolean isMatchingPairsEnabled() {
+		return matchingPairsEnabled;
+	}
+
+	@Override
+	public void setMatchingPairsEnabled(boolean matchingPairsEnabled) {
+		this.matchingPairsEnabled = matchingPairsEnabled;
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java
index ddee01773..b536acaec 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java
@@ -1,75 +1,75 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Helper class to get NLSed messages.
- *
- */
-public class LanguageConfigurationMessages extends NLS {
-
-	private static final String BUNDLE_NAME = "org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages"; //$NON-NLS-1$
-
-	public static String AutoClosingPairConditionalTableWidget_notIn;
-	public static String CharacterPairsTableWidget_end;
-	public static String CharacterPairsTableWidget_start;
-	public static String LanguageConfigurationInfoWidget_autoClosingPairs;
-	public static String LanguageConfigurationInfoWidget_blockCommentsEnd;
-	public static String LanguageConfigurationInfoWidget_blockCommentsStart;
-	public static String LanguageConfigurationInfoWidget_brackets;
-	public static String LanguageConfigurationInfoWidget_comments;
-	public static String LanguageConfigurationInfoWidget_end;
-	public static String LanguageConfigurationInfoWidget_folding_title;
-	public static String LanguageConfigurationInfoWidget_lineComments;
-	public static String LanguageConfigurationInfoWidget_markers;
-	public static String LanguageConfigurationInfoWidget_offSide;
-	public static String LanguageConfigurationInfoWidget_offSide_tooltip;
-	public static String LanguageConfigurationInfoWidget_onEnterRules;
-	public static String LanguageConfigurationInfoWidget_start;
-	public static String LanguageConfigurationInfoWidget_surroundingPairs;
-	public static String LanguageConfigurationInfoWidget_wordPattern_message;
-	public static String LanguageConfigurationInfoWidget_wordPattern_title;
-	public static String LanguageConfigurationPreferencePage_contentType;
-	public static String LanguageConfigurationPreferencePage_title;
-	public static String LanguageConfigurationPreferencePage_description;
-	public static String LanguageConfigurationPreferencePage_description2;
-	public static String LanguageConfigurationPreferencePage_new;
-	public static String LanguageConfigurationPreferencePage_path;
-	public static String LanguageConfigurationPreferencePage_pluginId;
-	public static String LanguageConfigurationPreferencePage_remove;
-	public static String OnEnterRuleTableWidget_beforeText;
-	public static String OnEnterRuleTableWidget_afterText;
-	public static String OnEnterRuleTableWidget_indentAction;
-	public static String OnEnterRuleTableWidget_appendText;
-	public static String OnEnterRuleTableWidget_removeText;
-	public static String SelectLanguageConfigurationWizardPage_browse_fileSystem;
-	public static String SelectLanguageConfigurationWizardPage_browse_workspace;
-	public static String SelectLanguageConfigurationWizardPage_contentType;
-	public static String SelectLanguageConfigurationWizardPage_file;
-	public static String SelectLanguageConfigurationWizardPage_fileError_error;
-	public static String SelectLanguageConfigurationWizardPage_fileError_invalid;
-	public static String SelectLanguageConfigurationWizardPage_fileError_noSelection;
-	public static String SelectLanguageConfigurationWizardPage_contentTypeError_noSelection;
-	public static String SelectLanguageConfigurationWizardPage_contentTypeError_invalid;
-	public static String SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate;
-	public static String SelectLanguageConfigurationWizardPage_page_description;
-	public static String SelectLanguageConfigurationWizardPage_page_title;
-	public static String SelectLanguageConfigurationWizardPage_workspace_description;
-	public static String SelectLanguageConfigurationWizardPage_workspace_title;
-
-	static {
-		NLS.initializeMessages(BUNDLE_NAME, LanguageConfigurationMessages.class);
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Helper class to get NLSed messages.
+ *
+ */
+public class LanguageConfigurationMessages extends NLS {
+
+	private static final String BUNDLE_NAME = "org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages"; //$NON-NLS-1$
+
+	public static String AutoClosingPairConditionalTableWidget_notIn;
+	public static String CharacterPairsTableWidget_end;
+	public static String CharacterPairsTableWidget_start;
+	public static String LanguageConfigurationInfoWidget_autoClosingPairs;
+	public static String LanguageConfigurationInfoWidget_blockCommentsEnd;
+	public static String LanguageConfigurationInfoWidget_blockCommentsStart;
+	public static String LanguageConfigurationInfoWidget_brackets;
+	public static String LanguageConfigurationInfoWidget_comments;
+	public static String LanguageConfigurationInfoWidget_end;
+	public static String LanguageConfigurationInfoWidget_folding_title;
+	public static String LanguageConfigurationInfoWidget_lineComments;
+	public static String LanguageConfigurationInfoWidget_markers;
+	public static String LanguageConfigurationInfoWidget_offSide;
+	public static String LanguageConfigurationInfoWidget_offSide_tooltip;
+	public static String LanguageConfigurationInfoWidget_onEnterRules;
+	public static String LanguageConfigurationInfoWidget_start;
+	public static String LanguageConfigurationInfoWidget_surroundingPairs;
+	public static String LanguageConfigurationInfoWidget_wordPattern_message;
+	public static String LanguageConfigurationInfoWidget_wordPattern_title;
+	public static String LanguageConfigurationPreferencePage_contentType;
+	public static String LanguageConfigurationPreferencePage_title;
+	public static String LanguageConfigurationPreferencePage_description;
+	public static String LanguageConfigurationPreferencePage_description2;
+	public static String LanguageConfigurationPreferencePage_new;
+	public static String LanguageConfigurationPreferencePage_path;
+	public static String LanguageConfigurationPreferencePage_pluginId;
+	public static String LanguageConfigurationPreferencePage_remove;
+	public static String OnEnterRuleTableWidget_beforeText;
+	public static String OnEnterRuleTableWidget_afterText;
+	public static String OnEnterRuleTableWidget_indentAction;
+	public static String OnEnterRuleTableWidget_appendText;
+	public static String OnEnterRuleTableWidget_removeText;
+	public static String SelectLanguageConfigurationWizardPage_browse_fileSystem;
+	public static String SelectLanguageConfigurationWizardPage_browse_workspace;
+	public static String SelectLanguageConfigurationWizardPage_contentType;
+	public static String SelectLanguageConfigurationWizardPage_file;
+	public static String SelectLanguageConfigurationWizardPage_fileError_error;
+	public static String SelectLanguageConfigurationWizardPage_fileError_invalid;
+	public static String SelectLanguageConfigurationWizardPage_fileError_noSelection;
+	public static String SelectLanguageConfigurationWizardPage_contentTypeError_noSelection;
+	public static String SelectLanguageConfigurationWizardPage_contentTypeError_invalid;
+	public static String SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate;
+	public static String SelectLanguageConfigurationWizardPage_page_description;
+	public static String SelectLanguageConfigurationWizardPage_page_title;
+	public static String SelectLanguageConfigurationWizardPage_workspace_description;
+	public static String SelectLanguageConfigurationWizardPage_workspace_title;
+
+	static {
+		NLS.initializeMessages(BUNDLE_NAME, LanguageConfigurationMessages.class);
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java
index 5945760fc..dcf44e9b8 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java
@@ -1,41 +1,41 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal;
-
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * OSGi Activator for Language Configuration (VSCode
- * language-configuration.json) Eclipse bundle.
- *
- */
-public class LanguageConfigurationPlugin extends AbstractUIPlugin {
-
-	public static final String PLUGIN_ID = "org.eclipse.tm4e.languageconfiguration"; //$NON-NLS-1$
-
-	private static LanguageConfigurationPlugin INSTANCE = null;
-
-	public static LanguageConfigurationPlugin getInstance() {
-		return INSTANCE;
-	}
-
-	@Override public void start(BundleContext context) throws Exception {
-		super.start(context);
-		INSTANCE = this;
-	}
-
-	@Override public void stop(BundleContext context) throws Exception {
-		INSTANCE = null;
-		super.stop(context);
-	}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * OSGi Activator for Language Configuration (VSCode
+ * language-configuration.json) Eclipse bundle.
+ *
+ */
+public class LanguageConfigurationPlugin extends AbstractUIPlugin {
+
+	public static final String PLUGIN_ID = "org.eclipse.tm4e.languageconfiguration"; //$NON-NLS-1$
+
+	private static LanguageConfigurationPlugin INSTANCE = null;
+
+	public static LanguageConfigurationPlugin getInstance() {
+		return INSTANCE;
+	}
+
+	@Override public void start(BundleContext context) throws Exception {
+		super.start(context);
+		INSTANCE = this;
+	}
+
+	@Override public void stop(BundleContext context) throws Exception {
+		INSTANCE = null;
+		super.stop(context);
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java
index b01768526..dc5a7dd8d 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java
@@ -1,292 +1,292 @@
-/**
- *  Copyright (c) 2015-2018 Angelo ZERR and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- *  Lucas Bullen (Red Hat Inc.) - configuration viewing and editing
- */
-package org.eclipse.tm4e.languageconfiguration.internal.preferences;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Collectors;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.util.BidiUtils;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.WorkingCopyLanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
-import org.eclipse.tm4e.languageconfiguration.internal.widgets.ColumnSelectionAdapter;
-import org.eclipse.tm4e.languageconfiguration.internal.widgets.ColumnViewerComparator;
-import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationPreferencesWidget;
-import org.eclipse.tm4e.languageconfiguration.internal.wizards.LanguageConfigurationImportWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.osgi.service.prefs.BackingStoreException;
-
-/**
- * A language configuration preference page allows configuration of the language
- * configuration It provides controls for adding, removing and changing language
- * configuration as well as enablement, default management.
- */
-public class LanguageConfigurationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
-
-	public final static String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$
-
-	private final ILanguageConfigurationRegistryManager manager;
-
-	private TableViewer definitionViewer;
-
-	private Button definitionNewButton;
-	private Button definitionRemoveButton;
-	private LanguageConfigurationPreferencesWidget infoWidget;
-
-	public LanguageConfigurationPreferencePage() {
-		super();
-		setDescription(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_description);
-		manager = new WorkingCopyLanguageConfigurationRegistryManager(
-				LanguageConfigurationRegistryManager.getInstance());
-	}
-
-	@Override
-	protected Control createContents(Composite ancestor) {
-		Composite parent = new Composite(ancestor, SWT.NONE);
-		GridLayout layout = new GridLayout();
-		layout.numColumns = 2;
-		layout.marginHeight = 0;
-		layout.marginWidth = 0;
-		parent.setLayout(layout);
-
-		Composite innerParent = new Composite(parent, SWT.NONE);
-		GridLayout innerLayout = new GridLayout();
-		innerLayout.numColumns = 2;
-		innerLayout.marginHeight = 0;
-		innerLayout.marginWidth = 0;
-		innerParent.setLayout(innerLayout);
-		GridData gd = new GridData(GridData.FILL_BOTH);
-		gd.horizontalSpan = 2;
-		innerParent.setLayoutData(gd);
-
-		createDefinitionsListContent(parent);
-
-		definitionViewer.setInput(manager);
-
-		infoWidget = new LanguageConfigurationPreferencesWidget(parent, SWT.NONE);
-		GridData data = new GridData(GridData.FILL_HORIZONTAL);
-		data.horizontalSpan = 2;
-		infoWidget.setLayoutData(data);
-
-		Dialog.applyDialogFont(parent);
-		innerParent.layout();
-
-		return parent;
-
-	}
-
-	/**
-	 * Create grammar list content.
-	 *
-	 * @param parent
-	 */
-	private void createDefinitionsListContent(Composite parent) {
-		Label description = new Label(parent, SWT.NONE);
-		description.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_description2);
-		description.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
-		Composite tableComposite = new Composite(parent, SWT.NONE);
-		GridData data = new GridData(GridData.FILL_BOTH);
-		data.widthHint = 360;
-		data.heightHint = convertHeightInCharsToPixels(10);
-		tableComposite.setLayoutData(data);
-
-		TableColumnLayout columnLayout = new TableColumnLayout();
-		tableComposite.setLayout(columnLayout);
-		Table table = new Table(tableComposite,
-				SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
-
-		table.setHeaderVisible(true);
-		table.setLinesVisible(true);
-
-		GC gc = new GC(getShell());
-		gc.setFont(JFaceResources.getDialogFont());
-
-		ColumnViewerComparator viewerComparator = new ColumnViewerComparator();
-
-		definitionViewer = new TableViewer(table);
-
-		TableColumn column1 = new TableColumn(table, SWT.NONE);
-		column1.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_contentType);
-		int minWidth = computeMinimumColumnWidth(gc,
-				LanguageConfigurationMessages.LanguageConfigurationPreferencePage_contentType);
-		columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true));
-		column1.addSelectionListener(new ColumnSelectionAdapter(column1, definitionViewer, 0, viewerComparator));
-
-		TableColumn column2 = new TableColumn(table, SWT.NONE);
-		column2.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_path);
-		minWidth = computeMinimumColumnWidth(gc,
-				LanguageConfigurationMessages.LanguageConfigurationPreferencePage_path);
-		columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true));
-		column2.addSelectionListener(new ColumnSelectionAdapter(column2, definitionViewer, 1, viewerComparator));
-
-		TableColumn column3 = new TableColumn(table, SWT.NONE);
-		column3.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_pluginId);
-		minWidth = computeMinimumColumnWidth(gc,
-				LanguageConfigurationMessages.LanguageConfigurationPreferencePage_pluginId);
-		columnLayout.setColumnData(column3, new ColumnWeightData(2, minWidth, true));
-		column3.addSelectionListener(new ColumnSelectionAdapter(column3, definitionViewer, 2, viewerComparator));
-
-		gc.dispose();
-
-		definitionViewer.setLabelProvider(new LanguageConfigurationLabelProvider());
-		definitionViewer.setContentProvider(new LanguageConfigurationContentProvider());
-		definitionViewer.setComparator(viewerComparator);
-
-		definitionViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
-			@Override
-			public void selectionChanged(SelectionChangedEvent e) {
-				IStructuredSelection selection = definitionViewer.getStructuredSelection();
-				infoWidget.refresh(null, manager);
-				if (selection.isEmpty()) {
-					return;
-				}
-				ILanguageConfigurationDefinition definition = (ILanguageConfigurationDefinition) (selection)
-						.getFirstElement();
-				// Update button
-				definitionRemoveButton.setEnabled(definition.getPluginId() == null);
-				selectDefinition(definition);
-			}
-
-			private void selectDefinition(ILanguageConfigurationDefinition definition) {
-				infoWidget.refresh(definition, manager);
-			}
-		});
-
-		// Specify default sorting
-		table.setSortColumn(column1);
-		table.setSortDirection(viewerComparator.getDirection());
-
-		BidiUtils.applyTextDirection(definitionViewer.getControl(), BidiUtils.BTD_DEFAULT);
-
-		Composite buttons = new Composite(parent, SWT.NONE);
-		buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
-		GridLayout layout = new GridLayout();
-		layout.marginHeight = 0;
-		layout.marginWidth = 0;
-		buttons.setLayout(layout);
-
-		definitionNewButton = new Button(buttons, SWT.PUSH);
-		definitionNewButton.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_new);
-		definitionNewButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		definitionNewButton.addListener(SWT.Selection, new Listener() {
-
-			@Override
-			public void handleEvent(Event e) {
-				add();
-			}
-
-			private void add() {
-				// Open import wizard for language configurations.
-				LanguageConfigurationImportWizard wizard = new LanguageConfigurationImportWizard(false);
-				wizard.setRegistryManager(manager);
-				WizardDialog dialog = new WizardDialog(getShell(), wizard);
-				if (dialog.open() == Window.OK) {
-					ILanguageConfigurationDefinition created = wizard.getCreatedDefinition();
-					definitionViewer.refresh();
-					definitionViewer.setSelection(new StructuredSelection(created));
-				}
-			}
-		});
-
-		definitionRemoveButton = new Button(buttons, SWT.PUSH);
-		definitionRemoveButton.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_remove);
-		definitionRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		definitionRemoveButton.addListener(SWT.Selection, new Listener() {
-
-			@Override
-			public void handleEvent(Event e) {
-				remove();
-			}
-
-			private void remove() {
-				Collection definitions = getSelectedUserDefinitions();
-				if (!definitions.isEmpty()) {
-					for (ILanguageConfigurationDefinition definition : definitions) {
-						manager.unregisterLanguageConfigurationDefinition(definition);
-					}
-					definitionViewer.refresh();
-				}
-			}
-		});
-	}
-
-	private int computeMinimumColumnWidth(GC gc, String string) {
-		return gc.stringExtent(string).x + 10; // pad 10 to accommodate table header trimmings
-	}
-
-	/**
-	 * Returns list of selected definitions which was created by the user.
-	 *
-	 * @return list of selected definitions which was created by the user.
-	 */
-	private Collection getSelectedUserDefinitions() {
-		IStructuredSelection selection = definitionViewer.getStructuredSelection();
-		if (selection.isEmpty()) {
-			return Collections.emptyList();
-		}
-		return ((Collection) selection.toList()).stream()
-				.filter(definition -> definition.getPluginId() == null).collect(Collectors.toList());
-	}
-
-	@Override
-	public void setVisible(boolean visible) {
-		super.setVisible(visible);
-		if (visible) {
-			setTitle(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_title);
-		}
-	}
-
-	@Override
-	public boolean performOk() {
-		try {
-			manager.save();
-		} catch (BackingStoreException e) {
-			// TODO: Log
-		}
-		return super.performOk();
-	}
-
-	@Override
-	public void init(IWorkbench workbench) {
-
-	}
-}
+/**
+ *  Copyright (c) 2015-2018 Angelo ZERR and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ *  Lucas Bullen (Red Hat Inc.) - configuration viewing and editing
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.preferences;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.stream.Collectors;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.BidiUtils;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.WorkingCopyLanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager;
+import org.eclipse.tm4e.languageconfiguration.internal.widgets.ColumnSelectionAdapter;
+import org.eclipse.tm4e.languageconfiguration.internal.widgets.ColumnViewerComparator;
+import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationPreferencesWidget;
+import org.eclipse.tm4e.languageconfiguration.internal.wizards.LanguageConfigurationImportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * A language configuration preference page allows configuration of the language
+ * configuration It provides controls for adding, removing and changing language
+ * configuration as well as enablement, default management.
+ */
+public class LanguageConfigurationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+	public final static String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$
+
+	private final ILanguageConfigurationRegistryManager manager;
+
+	private TableViewer definitionViewer;
+
+	private Button definitionNewButton;
+	private Button definitionRemoveButton;
+	private LanguageConfigurationPreferencesWidget infoWidget;
+
+	public LanguageConfigurationPreferencePage() {
+		super();
+		setDescription(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_description);
+		manager = new WorkingCopyLanguageConfigurationRegistryManager(
+				LanguageConfigurationRegistryManager.getInstance());
+	}
+
+	@Override
+	protected Control createContents(Composite ancestor) {
+		Composite parent = new Composite(ancestor, SWT.NONE);
+		GridLayout layout = new GridLayout();
+		layout.numColumns = 2;
+		layout.marginHeight = 0;
+		layout.marginWidth = 0;
+		parent.setLayout(layout);
+
+		Composite innerParent = new Composite(parent, SWT.NONE);
+		GridLayout innerLayout = new GridLayout();
+		innerLayout.numColumns = 2;
+		innerLayout.marginHeight = 0;
+		innerLayout.marginWidth = 0;
+		innerParent.setLayout(innerLayout);
+		GridData gd = new GridData(GridData.FILL_BOTH);
+		gd.horizontalSpan = 2;
+		innerParent.setLayoutData(gd);
+
+		createDefinitionsListContent(parent);
+
+		definitionViewer.setInput(manager);
+
+		infoWidget = new LanguageConfigurationPreferencesWidget(parent, SWT.NONE);
+		GridData data = new GridData(GridData.FILL_HORIZONTAL);
+		data.horizontalSpan = 2;
+		infoWidget.setLayoutData(data);
+
+		Dialog.applyDialogFont(parent);
+		innerParent.layout();
+
+		return parent;
+
+	}
+
+	/**
+	 * Create grammar list content.
+	 *
+	 * @param parent
+	 */
+	private void createDefinitionsListContent(Composite parent) {
+		Label description = new Label(parent, SWT.NONE);
+		description.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_description2);
+		description.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
+		Composite tableComposite = new Composite(parent, SWT.NONE);
+		GridData data = new GridData(GridData.FILL_BOTH);
+		data.widthHint = 360;
+		data.heightHint = convertHeightInCharsToPixels(10);
+		tableComposite.setLayoutData(data);
+
+		TableColumnLayout columnLayout = new TableColumnLayout();
+		tableComposite.setLayout(columnLayout);
+		Table table = new Table(tableComposite,
+				SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+
+		table.setHeaderVisible(true);
+		table.setLinesVisible(true);
+
+		GC gc = new GC(getShell());
+		gc.setFont(JFaceResources.getDialogFont());
+
+		ColumnViewerComparator viewerComparator = new ColumnViewerComparator();
+
+		definitionViewer = new TableViewer(table);
+
+		TableColumn column1 = new TableColumn(table, SWT.NONE);
+		column1.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_contentType);
+		int minWidth = computeMinimumColumnWidth(gc,
+				LanguageConfigurationMessages.LanguageConfigurationPreferencePage_contentType);
+		columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true));
+		column1.addSelectionListener(new ColumnSelectionAdapter(column1, definitionViewer, 0, viewerComparator));
+
+		TableColumn column2 = new TableColumn(table, SWT.NONE);
+		column2.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_path);
+		minWidth = computeMinimumColumnWidth(gc,
+				LanguageConfigurationMessages.LanguageConfigurationPreferencePage_path);
+		columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true));
+		column2.addSelectionListener(new ColumnSelectionAdapter(column2, definitionViewer, 1, viewerComparator));
+
+		TableColumn column3 = new TableColumn(table, SWT.NONE);
+		column3.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_pluginId);
+		minWidth = computeMinimumColumnWidth(gc,
+				LanguageConfigurationMessages.LanguageConfigurationPreferencePage_pluginId);
+		columnLayout.setColumnData(column3, new ColumnWeightData(2, minWidth, true));
+		column3.addSelectionListener(new ColumnSelectionAdapter(column3, definitionViewer, 2, viewerComparator));
+
+		gc.dispose();
+
+		definitionViewer.setLabelProvider(new LanguageConfigurationLabelProvider());
+		definitionViewer.setContentProvider(new LanguageConfigurationContentProvider());
+		definitionViewer.setComparator(viewerComparator);
+
+		definitionViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+			@Override
+			public void selectionChanged(SelectionChangedEvent e) {
+				IStructuredSelection selection = definitionViewer.getStructuredSelection();
+				infoWidget.refresh(null, manager);
+				if (selection.isEmpty()) {
+					return;
+				}
+				ILanguageConfigurationDefinition definition = (ILanguageConfigurationDefinition) (selection)
+						.getFirstElement();
+				// Update button
+				definitionRemoveButton.setEnabled(definition.getPluginId() == null);
+				selectDefinition(definition);
+			}
+
+			private void selectDefinition(ILanguageConfigurationDefinition definition) {
+				infoWidget.refresh(definition, manager);
+			}
+		});
+
+		// Specify default sorting
+		table.setSortColumn(column1);
+		table.setSortDirection(viewerComparator.getDirection());
+
+		BidiUtils.applyTextDirection(definitionViewer.getControl(), BidiUtils.BTD_DEFAULT);
+
+		Composite buttons = new Composite(parent, SWT.NONE);
+		buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+		GridLayout layout = new GridLayout();
+		layout.marginHeight = 0;
+		layout.marginWidth = 0;
+		buttons.setLayout(layout);
+
+		definitionNewButton = new Button(buttons, SWT.PUSH);
+		definitionNewButton.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_new);
+		definitionNewButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		definitionNewButton.addListener(SWT.Selection, new Listener() {
+
+			@Override
+			public void handleEvent(Event e) {
+				add();
+			}
+
+			private void add() {
+				// Open import wizard for language configurations.
+				LanguageConfigurationImportWizard wizard = new LanguageConfigurationImportWizard(false);
+				wizard.setRegistryManager(manager);
+				WizardDialog dialog = new WizardDialog(getShell(), wizard);
+				if (dialog.open() == Window.OK) {
+					ILanguageConfigurationDefinition created = wizard.getCreatedDefinition();
+					definitionViewer.refresh();
+					definitionViewer.setSelection(new StructuredSelection(created));
+				}
+			}
+		});
+
+		definitionRemoveButton = new Button(buttons, SWT.PUSH);
+		definitionRemoveButton.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_remove);
+		definitionRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		definitionRemoveButton.addListener(SWT.Selection, new Listener() {
+
+			@Override
+			public void handleEvent(Event e) {
+				remove();
+			}
+
+			private void remove() {
+				Collection definitions = getSelectedUserDefinitions();
+				if (!definitions.isEmpty()) {
+					for (ILanguageConfigurationDefinition definition : definitions) {
+						manager.unregisterLanguageConfigurationDefinition(definition);
+					}
+					definitionViewer.refresh();
+				}
+			}
+		});
+	}
+
+	private int computeMinimumColumnWidth(GC gc, String string) {
+		return gc.stringExtent(string).x + 10; // pad 10 to accommodate table header trimmings
+	}
+
+	/**
+	 * Returns list of selected definitions which was created by the user.
+	 *
+	 * @return list of selected definitions which was created by the user.
+	 */
+	private Collection getSelectedUserDefinitions() {
+		IStructuredSelection selection = definitionViewer.getStructuredSelection();
+		if (selection.isEmpty()) {
+			return Collections.emptyList();
+		}
+		return ((Collection) selection.toList()).stream()
+				.filter(definition -> definition.getPluginId() == null).collect(Collectors.toList());
+	}
+
+	@Override
+	public void setVisible(boolean visible) {
+		super.setVisible(visible);
+		if (visible) {
+			setTitle(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_title);
+		}
+	}
+
+	@Override
+	public boolean performOk() {
+		try {
+			manager.save();
+		} catch (BackingStoreException e) {
+			// TODO: Log
+		}
+		return super.performOk();
+	}
+
+	@Override
+	public void init(IWorkbench workbench) {
+
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java
index ecad6d1eb..fd5ff7218 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java
@@ -1,22 +1,22 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.preferences;
-
-/**
- * Preferences constants for language configurations.
- *
- */
-public class PreferenceConstants {
-
-	public static final String LANGUAGE_CONFIGURATIONS = "org.eclipse.tm4e.languageConfigurations"; //$NON-NLS-1$
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.preferences;
+
+/**
+ * Preferences constants for language configurations.
+ *
+ */
+public class PreferenceConstants {
+
+	public static final String LANGUAGE_CONFIGURATIONS = "org.eclipse.tm4e.languageConfigurations"; //$NON-NLS-1$
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java
index 90e1f22f2..1646d870f 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java
@@ -1,69 +1,69 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.preferences;
-
-import java.util.Collection;
-
-import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
-import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition;
-import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSerializer;
-
-/**
- * Helper class load, save language configuration preferences with Json format.
- *
- */
-public class PreferenceHelper {
-
-	private static final Gson DEFAULT_GSON;
-
-	static {
-		DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(LanguageConfigurationDefinition.class,
-				(JsonDeserializer) (json, typeOfT, context) -> {
-					JsonObject object = json.getAsJsonObject();
-					JsonElement pluginId = object.get("pluginId");
-					return new LanguageConfigurationDefinition(
-							ContentTypeHelper.getContentTypeById(object.get("contentTypeId").getAsString()), //$NON-NLS-1$
-							object.get("path").getAsString(), //$NON-NLS-1$
-							pluginId == null ? null : pluginId.getAsString(),
-							object.get("onEnterEnabled").getAsBoolean(), //$NON-NLS-1$
-							object.get("bracketAutoClosingEnabled").getAsBoolean(), //$NON-NLS-1$
-							object.get("matchingPairsEnabled").getAsBoolean()); //$NON-NLS-1$
-				}).registerTypeAdapter(LanguageConfigurationDefinition.class,
-						(JsonSerializer) (definition, typeOfT, context) -> {
-							JsonObject object = new JsonObject();
-							object.addProperty("path", definition.getPath()); //$NON-NLS-1$
-							object.addProperty("pluginId", definition.getPluginId()); //$NON-NLS-1$
-							object.addProperty("contentTypeId", definition.getContentType().getId()); //$NON-NLS-1$
-							object.addProperty("onEnterEnabled", definition.isOnEnterEnabled()); //$NON-NLS-1$
-							object.addProperty("bracketAutoClosingEnabled", definition.isBracketAutoClosingEnabled()); //$NON-NLS-1$
-							object.addProperty("matchingPairsEnabled", definition.isMatchingPairsEnabled()); //$NON-NLS-1$
-							return object;
-						})
-				.create();
-	}
-
-	public static ILanguageConfigurationDefinition[] loadLanguageConfigurationDefinitions(String json) {
-		return DEFAULT_GSON.fromJson(json, LanguageConfigurationDefinition[].class);
-	}
-
-	public static String toJson(Collection definitions) {
-		return DEFAULT_GSON.toJson(definitions);
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.preferences;
+
+import java.util.Collection;
+
+import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition;
+import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition;
+import org.eclipse.tm4e.ui.utils.ContentTypeHelper;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonSerializer;
+
+/**
+ * Helper class load, save language configuration preferences with Json format.
+ *
+ */
+public class PreferenceHelper {
+
+	private static final Gson DEFAULT_GSON;
+
+	static {
+		DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(LanguageConfigurationDefinition.class,
+				(JsonDeserializer) (json, typeOfT, context) -> {
+					JsonObject object = json.getAsJsonObject();
+					JsonElement pluginId = object.get("pluginId");
+					return new LanguageConfigurationDefinition(
+							ContentTypeHelper.getContentTypeById(object.get("contentTypeId").getAsString()), //$NON-NLS-1$
+							object.get("path").getAsString(), //$NON-NLS-1$
+							pluginId == null ? null : pluginId.getAsString(),
+							object.get("onEnterEnabled").getAsBoolean(), //$NON-NLS-1$
+							object.get("bracketAutoClosingEnabled").getAsBoolean(), //$NON-NLS-1$
+							object.get("matchingPairsEnabled").getAsBoolean()); //$NON-NLS-1$
+				}).registerTypeAdapter(LanguageConfigurationDefinition.class,
+						(JsonSerializer) (definition, typeOfT, context) -> {
+							JsonObject object = new JsonObject();
+							object.addProperty("path", definition.getPath()); //$NON-NLS-1$
+							object.addProperty("pluginId", definition.getPluginId()); //$NON-NLS-1$
+							object.addProperty("contentTypeId", definition.getContentType().getId()); //$NON-NLS-1$
+							object.addProperty("onEnterEnabled", definition.isOnEnterEnabled()); //$NON-NLS-1$
+							object.addProperty("bracketAutoClosingEnabled", definition.isBracketAutoClosingEnabled()); //$NON-NLS-1$
+							object.addProperty("matchingPairsEnabled", definition.isMatchingPairsEnabled()); //$NON-NLS-1$
+							return object;
+						})
+				.create();
+	}
+
+	public static ILanguageConfigurationDefinition[] loadLanguageConfigurationDefinitions(String json) {
+		return DEFAULT_GSON.fromJson(json, LanguageConfigurationDefinition[].class);
+	}
+
+	public static String toJson(Collection definitions) {
+		return DEFAULT_GSON.toJson(definitions);
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java
index 8395bd522..f2b5dd9b2 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java
@@ -1,29 +1,29 @@
-/**
- * Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-import java.util.List;
-
-@SuppressWarnings("serial")
-public class AutoClosingPairConditional extends CharacterPair {
-
-	private final List notIn;
-
-	public AutoClosingPairConditional(String open, String close, List notIn) {
-		super(open, close);
-		this.notIn = notIn;
-	}
-
-	public List getNotIn() {
-		return notIn;
-	}
-}
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+import java.util.List;
+
+@SuppressWarnings("serial")
+public class AutoClosingPairConditional extends CharacterPair {
+
+	private final List notIn;
+
+	public AutoClosingPairConditional(String open, String close, List notIn) {
+		super(open, close);
+		this.notIn = notIn;
+	}
+
+	public List getNotIn() {
+		return notIn;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java
index 28c3f536a..286cc5179 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java
@@ -1,26 +1,26 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-import java.util.AbstractMap.SimpleEntry;
-
-/**
- * A tuple of two characters, like a pair of opening and closing brackets.
- */
-@SuppressWarnings("serial")
-public class CharacterPair extends SimpleEntry {
-
-	public CharacterPair(String key, String value) {
-		super(key, value);
-	}
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+import java.util.AbstractMap.SimpleEntry;
+
+/**
+ * A tuple of two characters, like a pair of opening and closing brackets.
+ */
+@SuppressWarnings("serial")
+public class CharacterPair extends SimpleEntry {
+
+	public CharacterPair(String key, String value) {
+		super(key, value);
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java
index c9b920bc6..bc624d655 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java
@@ -1,74 +1,74 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * The "character pair" support.
- *
- */
-public class CharacterPairSupport {
-
-	private List autoClosingPairs;
-	private final List surroundingPairs;
-
-	public CharacterPairSupport(List brackets, List autoClosingPairs,
-			List surroundingPairs) {
-		if (autoClosingPairs != null) {
-			this.autoClosingPairs = autoClosingPairs.stream().filter(el -> el != null)
-					.map(el -> new AutoClosingPairConditional(el.getKey(), el.getValue(), el.getNotIn()))
-					.collect(Collectors.toList());
-		} else if (brackets != null) {
-			this.autoClosingPairs = brackets.stream().filter(el -> el != null)
-					.map(el -> new AutoClosingPairConditional(el.getKey(), el.getValue(), null))
-					.collect(Collectors.toList());
-		} else {
-			this.autoClosingPairs = new ArrayList<>();
-		}
-
-		this.surroundingPairs = surroundingPairs != null
-				? surroundingPairs.stream().filter(el -> el != null).collect(Collectors.toList())
-				: this.autoClosingPairs;
-	}
-
-	public CharacterPair getAutoClosePair(String text, Integer offset,
-			String newCharacter/* : string, context: ScopedLineTokens, column: number */) {
-		if (newCharacter.isEmpty()) {
-			return null;
-		}
-		for (CharacterPair autoClosingPair : autoClosingPairs) {
-			String openning = autoClosingPair.getKey();
-			if (!openning.endsWith(newCharacter)) {
-				continue;
-			}
-			if (openning.length() > 1) {
-				String offsetPrefix = text.substring(0, offset);
-				if (!offsetPrefix.endsWith(openning.substring(0, openning.length() - 1))) {
-					continue;
-				}
-			}
-			return autoClosingPair;
-		}
-		return null;
-	}
-
-	public List getAutoClosingPairs() {
-		return autoClosingPairs;
-	}
-
-	public List getSurroundingPairs() {
-		return surroundingPairs;
-	}
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * The "character pair" support.
+ *
+ */
+public class CharacterPairSupport {
+
+	private List autoClosingPairs;
+	private final List surroundingPairs;
+
+	public CharacterPairSupport(List brackets, List autoClosingPairs,
+			List surroundingPairs) {
+		if (autoClosingPairs != null) {
+			this.autoClosingPairs = autoClosingPairs.stream().filter(el -> el != null)
+					.map(el -> new AutoClosingPairConditional(el.getKey(), el.getValue(), el.getNotIn()))
+					.collect(Collectors.toList());
+		} else if (brackets != null) {
+			this.autoClosingPairs = brackets.stream().filter(el -> el != null)
+					.map(el -> new AutoClosingPairConditional(el.getKey(), el.getValue(), null))
+					.collect(Collectors.toList());
+		} else {
+			this.autoClosingPairs = new ArrayList<>();
+		}
+
+		this.surroundingPairs = surroundingPairs != null
+				? surroundingPairs.stream().filter(el -> el != null).collect(Collectors.toList())
+				: this.autoClosingPairs;
+	}
+
+	public CharacterPair getAutoClosePair(String text, Integer offset,
+			String newCharacter/* : string, context: ScopedLineTokens, column: number */) {
+		if (newCharacter.isEmpty()) {
+			return null;
+		}
+		for (CharacterPair autoClosingPair : autoClosingPairs) {
+			String openning = autoClosingPair.getKey();
+			if (!openning.endsWith(newCharacter)) {
+				continue;
+			}
+			if (openning.length() > 1) {
+				String offsetPrefix = text.substring(0, offset);
+				if (!offsetPrefix.endsWith(openning.substring(0, openning.length() - 1))) {
+					continue;
+				}
+			}
+			return autoClosingPair;
+		}
+		return null;
+	}
+
+	public List getAutoClosingPairs() {
+		return autoClosingPairs;
+	}
+
+	public List getSurroundingPairs() {
+		return surroundingPairs;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java
index 19ce7fbed..b5edf1e3c 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java
@@ -1,63 +1,63 @@
-/**
- *  Copyright (c) 2018 Red Hat Inc. and others.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-
-public class CommentSupport {
-
-	private final Comments comments;
-
-	public CommentSupport(Comments comments) {
-		this.comments = comments;
-	}
-
-	public boolean isInComment(IDocument document, int offset) {
-		try {
-			if (isInBlockComment(document.get(0, offset))) {
-				return true;
-			}
-			int line = document.getLineOfOffset(offset);
-			int lineOffset = document.getLineOffset(line);
-			return isInLineComment(document.get(lineOffset, offset - lineOffset));
-		} catch (BadLocationException e) {
-			return false;
-		}
-	}
-
-	public String getLineComment() {
-		return comments.getLineComment();
-	}
-
-	public CharacterPair getBlockComment() {
-		return comments.getBlockComment();
-	}
-
-	private boolean isInLineComment(String indexLinePrefix) {
-		return indexLinePrefix.indexOf(comments.getLineComment()) != -1;
-	}
-
-	private boolean isInBlockComment(String indexPrefix) {
-		String commentOpen = comments.getBlockComment().getKey();
-		String commentClose = comments.getBlockComment().getValue();
-		int index = indexPrefix.indexOf(commentOpen);
-		while (index != -1 && index < indexPrefix.length()) {
-			int closeIndex = indexPrefix.indexOf(commentClose, index + commentOpen.length());
-			if (closeIndex == -1) {
-				return true;
-			}
-			index = indexPrefix.indexOf(commentOpen, closeIndex + commentClose.length());
-		}
-		return false;
-	}
-}
+/**
+ *  Copyright (c) 2018 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Lucas Bullen (Red Hat Inc.) - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+public class CommentSupport {
+
+	private final Comments comments;
+
+	public CommentSupport(Comments comments) {
+		this.comments = comments;
+	}
+
+	public boolean isInComment(IDocument document, int offset) {
+		try {
+			if (isInBlockComment(document.get(0, offset))) {
+				return true;
+			}
+			int line = document.getLineOfOffset(offset);
+			int lineOffset = document.getLineOffset(line);
+			return isInLineComment(document.get(lineOffset, offset - lineOffset));
+		} catch (BadLocationException e) {
+			return false;
+		}
+	}
+
+	public String getLineComment() {
+		return comments.getLineComment();
+	}
+
+	public CharacterPair getBlockComment() {
+		return comments.getBlockComment();
+	}
+
+	private boolean isInLineComment(String indexLinePrefix) {
+		return indexLinePrefix.indexOf(comments.getLineComment()) != -1;
+	}
+
+	private boolean isInBlockComment(String indexPrefix) {
+		String commentOpen = comments.getBlockComment().getKey();
+		String commentClose = comments.getBlockComment().getValue();
+		int index = indexPrefix.indexOf(commentOpen);
+		while (index != -1 && index < indexPrefix.length()) {
+			int closeIndex = indexPrefix.indexOf(commentClose, index + commentOpen.length());
+			if (closeIndex == -1) {
+				return true;
+			}
+			index = indexPrefix.indexOf(commentOpen, closeIndex + commentClose.length());
+		}
+		return false;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java
index 40bf7ce4b..aea6c899c 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java
@@ -9,110 +9,110 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-/**
- * Describes what to do when pressing Enter.
- */
-public class EnterAction {
-
-	public enum IndentAction {
-		/**
-		 * Insert new line and copy the previous line's indentation.
-		 */
-		None,
-		/**
-		 * Insert new line and indent once (relative to the previous line's
-		 * indentation).
-		 */
-		Indent,
-		/**
-		 * Insert two new lines: - the first one indented which will hold the cursor -
-		 * the second one at the same indentation level
-		 */
-		IndentOutdent,
-		/**
-		 * Insert new line and outdent once (relative to the previous line's
-		 * indentation).
-		 */
-		Outdent;
-	}
-
-	/**
-	 * Describe what to do with the indentation.
-	 */
-	private final IndentAction indentAction;
-
-	/**
-	 * Describe whether to outdent current line.
-	 */
-	private Boolean outdentCurrentLine;
-	/**
-	 * Describes text to be appended after the new line and after the indentation.
-	 */
-	private String appendText;
-	/**
-	 * Describes the number of characters to remove from the new line's indentation.
-	 */
-	private Integer removeText;
-
-	public EnterAction(IndentAction indentAction) {
-		this.indentAction = indentAction;
-	}
-
-	public IndentAction getIndentAction() {
-		return indentAction;
-	}
-
-	/**
-	 * @return the outdentCurrentLine
-	 */
-	public Boolean getOutdentCurrentLine() {
-		return outdentCurrentLine;
-	}
-
-	/**
-	 * @param outdentCurrentLine
-	 *            the outdentCurrentLine to set
-	 * @return
-	 */
-	public EnterAction setOutdentCurrentLine(Boolean outdentCurrentLine) {
-		this.outdentCurrentLine = outdentCurrentLine;
-		return this;
-	}
-
-	/**
-	 * @return the appendText
-	 */
-	public String getAppendText() {
-		return appendText;
-	}
-
-	/**
-	 * @param appendText
-	 *            the appendText to set
-	 * @return
-	 */
-	public EnterAction setAppendText(String appendText) {
-		this.appendText = appendText;
-		return this;
-	}
-
-	/**
-	 * @return the removeText
-	 */
-	public Integer getRemoveText() {
-		return removeText;
-	}
-
-	/**
-	 * @param removeText
-	 *            the removeText to set
-	 * @return
-	 */
-	public EnterAction setRemoveText(Integer removeText) {
-		this.removeText = removeText;
-		return this;
-	}
-
-}
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+/**
+ * Describes what to do when pressing Enter.
+ */
+public class EnterAction {
+
+	public enum IndentAction {
+		/**
+		 * Insert new line and copy the previous line's indentation.
+		 */
+		None,
+		/**
+		 * Insert new line and indent once (relative to the previous line's
+		 * indentation).
+		 */
+		Indent,
+		/**
+		 * Insert two new lines: - the first one indented which will hold the cursor -
+		 * the second one at the same indentation level
+		 */
+		IndentOutdent,
+		/**
+		 * Insert new line and outdent once (relative to the previous line's
+		 * indentation).
+		 */
+		Outdent;
+	}
+
+	/**
+	 * Describe what to do with the indentation.
+	 */
+	private final IndentAction indentAction;
+
+	/**
+	 * Describe whether to outdent current line.
+	 */
+	private Boolean outdentCurrentLine;
+	/**
+	 * Describes text to be appended after the new line and after the indentation.
+	 */
+	private String appendText;
+	/**
+	 * Describes the number of characters to remove from the new line's indentation.
+	 */
+	private Integer removeText;
+
+	public EnterAction(IndentAction indentAction) {
+		this.indentAction = indentAction;
+	}
+
+	public IndentAction getIndentAction() {
+		return indentAction;
+	}
+
+	/**
+	 * @return the outdentCurrentLine
+	 */
+	public Boolean getOutdentCurrentLine() {
+		return outdentCurrentLine;
+	}
+
+	/**
+	 * @param outdentCurrentLine
+	 *            the outdentCurrentLine to set
+	 * @return
+	 */
+	public EnterAction setOutdentCurrentLine(Boolean outdentCurrentLine) {
+		this.outdentCurrentLine = outdentCurrentLine;
+		return this;
+	}
+
+	/**
+	 * @return the appendText
+	 */
+	public String getAppendText() {
+		return appendText;
+	}
+
+	/**
+	 * @param appendText
+	 *            the appendText to set
+	 * @return
+	 */
+	public EnterAction setAppendText(String appendText) {
+		this.appendText = appendText;
+		return this;
+	}
+
+	/**
+	 * @return the removeText
+	 */
+	public Integer getRemoveText() {
+		return removeText;
+	}
+
+	/**
+	 * @param removeText
+	 *            the removeText to set
+	 * @return
+	 */
+	public EnterAction setRemoveText(Integer removeText) {
+		this.removeText = removeText;
+		return this;
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java
index b887f2092..814723144 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java
@@ -9,29 +9,29 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-public class EnterActionAndIndent {
-
-	private final EnterAction enterAction;
-
-	private final String indentation;
-
-	/**
-	 * @param enterAction
-	 * @param indentation
-	 */
-	public EnterActionAndIndent(EnterAction enterAction, String indentation) {
-		super();
-		this.enterAction = enterAction;
-		this.indentation = indentation;
-	}
-
-	public EnterAction getEnterAction() {
-		return enterAction;
-	}
-
-	public String getIndentation() {
-		return indentation;
-	}
-}
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+public class EnterActionAndIndent {
+
+	private final EnterAction enterAction;
+
+	private final String indentation;
+
+	/**
+	 * @param enterAction
+	 * @param indentation
+	 */
+	public EnterActionAndIndent(EnterAction enterAction, String indentation) {
+		super();
+		this.enterAction = enterAction;
+		this.indentation = indentation;
+	}
+
+	public EnterAction getEnterAction() {
+		return enterAction;
+	}
+
+	public String getIndentation() {
+		return indentation;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java
index 740240835..b50545b77 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java
@@ -9,8 +9,8 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-public class IndentationRule {
-
-}
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+public class IndentationRule {
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java
index 84c173004..89666271b 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java
@@ -9,50 +9,50 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-import java.util.regex.Pattern;
-
-import org.eclipse.tm4e.languageconfiguration.internal.utils.RegExpUtils;
-
-/**
- * Describes a rule to be evaluated when pressing Enter.
- */
-public class OnEnterRule {
-
-	/**
-	 * This rule will only execute if the text before the cursor matches this
-	 * regular expression.
-	 */
-	private final Pattern beforeText;
-
-	/**
-	 * This rule will only execute if the text after the cursor matches this regular
-	 * expression.
-	 */
-	private final Pattern afterText;
-
-	/**
-	 * The action to execute.
-	 */
-	private final EnterAction action;
-
-	public OnEnterRule(String beforeText, String afterText, EnterAction action) {
-		this.beforeText = RegExpUtils.create(beforeText);
-		this.afterText = afterText != null ? RegExpUtils.create(afterText) : null;
-		this.action = action;
-	}
-
-	public Pattern getBeforeText() {
-		return beforeText;
-	}
-
-	public Pattern getAfterText() {
-		return afterText;
-	}
-
-	public EnterAction getAction() {
-		return action;
-	}
-
-}
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.tm4e.languageconfiguration.internal.utils.RegExpUtils;
+
+/**
+ * Describes a rule to be evaluated when pressing Enter.
+ */
+public class OnEnterRule {
+
+	/**
+	 * This rule will only execute if the text before the cursor matches this
+	 * regular expression.
+	 */
+	private final Pattern beforeText;
+
+	/**
+	 * This rule will only execute if the text after the cursor matches this regular
+	 * expression.
+	 */
+	private final Pattern afterText;
+
+	/**
+	 * The action to execute.
+	 */
+	private final EnterAction action;
+
+	public OnEnterRule(String beforeText, String afterText, EnterAction action) {
+		this.beforeText = RegExpUtils.create(beforeText);
+		this.afterText = afterText != null ? RegExpUtils.create(afterText) : null;
+		this.action = action;
+	}
+
+	public Pattern getBeforeText() {
+		return beforeText;
+	}
+
+	public Pattern getAfterText() {
+		return afterText;
+	}
+
+	public EnterAction getAction() {
+		return action;
+	}
+
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java
index 4fd1f58bb..df80b97c1 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java
@@ -1,118 +1,118 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License 2.0
- * which is available at https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.supports;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
-import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction;
-import org.eclipse.tm4e.languageconfiguration.internal.utils.RegExpUtils;
-
-/**
- * On enter support.
- *
- */
-public class OnEnterSupport {
-
-	private static final List DEFAULT_BRACKETS = Arrays.asList(new CharacterPair("(", ")"), //$NON-NLS-1$ //$NON-NLS-2$
-			new CharacterPair("{", "}"), new CharacterPair("[", "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
-	private final List brackets;
-
-	private final List regExpRules;
-
-	public OnEnterSupport(List brackets, List regExpRules) {
-		this.brackets = (brackets != null ? brackets : DEFAULT_BRACKETS).stream().filter(el -> el != null)
-				.map((bracket -> new ProcessedBracketPair(bracket.getKey(), bracket.getValue()))).collect(Collectors.toList());
-
-		this.regExpRules = regExpRules != null ? regExpRules : Collections.emptyList();
-	}
-
-	public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, String afterEnterText) {
-		// (1): `regExpRules`
-		for (OnEnterRule rule : regExpRules) {
-			if (rule.getBeforeText().matcher(beforeEnterText).find()) {
-				if (rule.getAfterText() != null) {
-					if (rule.getAfterText().matcher(afterEnterText).find()) {
-						return rule.getAction();
-					}
-				} else {
-					return rule.getAction();
-				}
-			}
-		}
-
-		// (2): Special indent-outdent
-		if (beforeEnterText.length() > 0 && afterEnterText.length() > 0) {
-			for (ProcessedBracketPair bracket : brackets) {
-				if (bracket.matchOpen(beforeEnterText) && bracket.matchClose(afterEnterText)) {
-					return new EnterAction(IndentAction.IndentOutdent);
-				}
-			}
-		}
-
-		// (3): Open bracket based logic
-		if (beforeEnterText.length() > 0) {
-			for (ProcessedBracketPair bracket : brackets) {
-				if (bracket.matchOpen(beforeEnterText)) {
-					return new EnterAction(IndentAction.Indent);
-				}
-			}
-		}
-		return null;
-	}
-
-	private static class ProcessedBracketPair {
-
-		private static final Pattern B_REGEXP = Pattern.compile("\\B"); //$NON-NLS-1$
-
-		private final Pattern openRegExp;
-		private final Pattern closeRegExp;
-
-		public ProcessedBracketPair(String open, String close) {
-			openRegExp = createOpenBracketRegExp(open);
-			closeRegExp = createCloseBracketRegExp(close);
-		}
-
-		public boolean matchOpen(String beforeEnterText) {
-			return openRegExp != null && openRegExp.matcher(beforeEnterText).find();
-		}
-
-		public boolean matchClose(String afterEnterText) {
-			return closeRegExp != null && closeRegExp.matcher(afterEnterText).find();
-		}
-
-		private static Pattern createOpenBracketRegExp(String bracket) {
-			StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket));
-			String c = String.valueOf(str.charAt(0));
-			if (!B_REGEXP.matcher(c).find()) {
-				str.insert(0, "\\b"); //$NON-NLS-1$
-			}
-			str.append("\\s*$"); //$NON-NLS-1$
-			return RegExpUtils.create(str.toString());
-		}
-
-		private static Pattern createCloseBracketRegExp(String bracket) {
-			StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket));
-			String c = String.valueOf(str.charAt(str.length() - 1));
-			if (!B_REGEXP.matcher(c).find()) {
-				str.append("\\b"); //$NON-NLS-1$
-			}
-			str.insert(0, "^\\s*"); //$NON-NLS-1$
-			return RegExpUtils.create(str.toString());
-		}
-
-	}
-}
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.supports;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction;
+import org.eclipse.tm4e.languageconfiguration.internal.utils.RegExpUtils;
+
+/**
+ * On enter support.
+ *
+ */
+public class OnEnterSupport {
+
+	private static final List DEFAULT_BRACKETS = Arrays.asList(new CharacterPair("(", ")"), //$NON-NLS-1$ //$NON-NLS-2$
+			new CharacterPair("{", "}"), new CharacterPair("[", "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+	private final List brackets;
+
+	private final List regExpRules;
+
+	public OnEnterSupport(List brackets, List regExpRules) {
+		this.brackets = (brackets != null ? brackets : DEFAULT_BRACKETS).stream().filter(el -> el != null)
+				.map((bracket -> new ProcessedBracketPair(bracket.getKey(), bracket.getValue()))).collect(Collectors.toList());
+
+		this.regExpRules = regExpRules != null ? regExpRules : Collections.emptyList();
+	}
+
+	public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, String afterEnterText) {
+		// (1): `regExpRules`
+		for (OnEnterRule rule : regExpRules) {
+			if (rule.getBeforeText().matcher(beforeEnterText).find()) {
+				if (rule.getAfterText() != null) {
+					if (rule.getAfterText().matcher(afterEnterText).find()) {
+						return rule.getAction();
+					}
+				} else {
+					return rule.getAction();
+				}
+			}
+		}
+
+		// (2): Special indent-outdent
+		if (beforeEnterText.length() > 0 && afterEnterText.length() > 0) {
+			for (ProcessedBracketPair bracket : brackets) {
+				if (bracket.matchOpen(beforeEnterText) && bracket.matchClose(afterEnterText)) {
+					return new EnterAction(IndentAction.IndentOutdent);
+				}
+			}
+		}
+
+		// (3): Open bracket based logic
+		if (beforeEnterText.length() > 0) {
+			for (ProcessedBracketPair bracket : brackets) {
+				if (bracket.matchOpen(beforeEnterText)) {
+					return new EnterAction(IndentAction.Indent);
+				}
+			}
+		}
+		return null;
+	}
+
+	private static class ProcessedBracketPair {
+
+		private static final Pattern B_REGEXP = Pattern.compile("\\B"); //$NON-NLS-1$
+
+		private final Pattern openRegExp;
+		private final Pattern closeRegExp;
+
+		public ProcessedBracketPair(String open, String close) {
+			openRegExp = createOpenBracketRegExp(open);
+			closeRegExp = createCloseBracketRegExp(close);
+		}
+
+		public boolean matchOpen(String beforeEnterText) {
+			return openRegExp != null && openRegExp.matcher(beforeEnterText).find();
+		}
+
+		public boolean matchClose(String afterEnterText) {
+			return closeRegExp != null && closeRegExp.matcher(afterEnterText).find();
+		}
+
+		private static Pattern createOpenBracketRegExp(String bracket) {
+			StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket));
+			String c = String.valueOf(str.charAt(0));
+			if (!B_REGEXP.matcher(c).find()) {
+				str.insert(0, "\\b"); //$NON-NLS-1$
+			}
+			str.append("\\s*$"); //$NON-NLS-1$
+			return RegExpUtils.create(str.toString());
+		}
+
+		private static Pattern createCloseBracketRegExp(String bracket) {
+			StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket));
+			String c = String.valueOf(str.charAt(str.length() - 1));
+			if (!B_REGEXP.matcher(c).find()) {
+				str.append("\\b"); //$NON-NLS-1$
+			}
+			str.insert(0, "^\\s*"); //$NON-NLS-1$
+			return RegExpUtils.create(str.toString());
+		}
+
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java
index 4da6d5791..22da0ccd5 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java
@@ -1,42 +1,42 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.utils;
-
-import java.util.regex.Pattern;
-
-/**
- * Regex utilities.
- *
- */
-public class RegExpUtils {
-
-	/**
-	 * Escapes regular expression characters in a given string
-	 */
-	public static String escapeRegExpCharacters(String value) {
-		return value.replaceAll("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\[\\]\\(\\)\\#]", "\\\\$0"); //$NON-NLS-1$ //$NON-NLS-2$
-	}
-
-	/**
-	 * Create Java Regexp and null otherwise.
-	 *
-	 * @param regex
-	 * @return Java Regexp and null otherwise.
-	 */
-	public static Pattern create(String regex) {
-		try {
-			return Pattern.compile(regex);
-		} catch (Exception e) {
-			return null;
-		}
-	}
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *  Angelo Zerr  - initial API and implementation
+ */
+package org.eclipse.tm4e.languageconfiguration.internal.utils;
+
+import java.util.regex.Pattern;
+
+/**
+ * Regex utilities.
+ *
+ */
+public class RegExpUtils {
+
+	/**
+	 * Escapes regular expression characters in a given string
+	 */
+	public static String escapeRegExpCharacters(String value) {
+		return value.replaceAll("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\[\\]\\(\\)\\#]", "\\\\$0"); //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	/**
+	 * Create Java Regexp and null otherwise.
+	 *
+	 * @param regex
+	 * @return Java Regexp and null otherwise.
+	 */
+	public static Pattern create(String regex) {
+		try {
+			return Pattern.compile(regex);
+		} catch (Exception e) {
+			return null;
+		}
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java
index 3af880844..f89cad864 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java
@@ -9,23 +9,23 @@
  * Contributors:
  * Angelo Zerr  - initial API and implementation
  */
-package org.eclipse.tm4e.languageconfiguration.internal.utils;
-
-public class TabSpacesInfo {
-
-	private final int tabSize;
-	private final boolean insertSpaces;
-
-	public TabSpacesInfo(int tabSize, boolean insertSpaces) {
-		this.tabSize = tabSize;
-		this.insertSpaces = insertSpaces;
-	}
-	
-	public int getTabSize() {
-		return tabSize;
-	}
-	
-	public boolean isInsertSpaces() {
-		return insertSpaces;
-	}
-}
+package org.eclipse.tm4e.languageconfiguration.internal.utils;
+
+public class TabSpacesInfo {
+
+	private final int tabSize;
+	private final boolean insertSpaces;
+
+	public TabSpacesInfo(int tabSize, boolean insertSpaces) {
+		this.tabSize = tabSize;
+		this.insertSpaces = insertSpaces;
+	}
+	
+	public int getTabSize() {
+		return tabSize;
+	}
+	
+	public boolean isInsertSpaces() {
+		return insertSpaces;
+	}
+}
diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java
index bdb536b42..03efeaacf 100644
--- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java
+++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java
@@ -1,181 +1,181 @@
-/**
- *  Copyright (c) 2015-2017 Angelo ZERR.
+/**
+ *  Copyright (c) 2015-2017 Angelo ZERR.
  * This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License 2.0
  * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
- * SPDX-License-Identifier: EPL-2.0
- *
- *  Contributors:
- *  Angelo Zerr  - initial API and implementation
- */
-package org.eclipse.tm4e.languageconfiguration.internal.utils;
-
-import java.util.Arrays;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentCommand;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TabsToSpacesConverter;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.TextViewer;
-import org.eclipse.tm4e.ui.utils.ClassHelper;
-
-public class TextUtils {
-
-	/**
-	 * Returns true if text of the command is an enter and false otherwise.
-	 *
-	 * @param d
-	 * @param c
-	 * @return true if text of the command is an enter and false otherwise.
-	 */
-	public static boolean isEnter(IDocument d, DocumentCommand c) {
-		return (c.length == 0 && c.text != null && TextUtilities.equals(d.getLegalLineDelimiters(), c.text) != -1);
-	}
-
-	public static String normalizeIndentation(String str, int tabSize, boolean insertSpaces) {
-		int firstNonWhitespaceIndex = TextUtils.firstNonWhitespaceIndex(str);
-		if (firstNonWhitespaceIndex == -1) {
-			firstNonWhitespaceIndex = str.length();
-		}
-		return TextUtils.normalizeIndentationFromWhitespace(str.substring(0, firstNonWhitespaceIndex), tabSize,
-				insertSpaces) + str.substring(firstNonWhitespaceIndex);
-	}
-
-	private static String normalizeIndentationFromWhitespace(String str, int tabSize, boolean insertSpaces) {
-		int spacesCnt = 0;
-		for (int i = 0; i < str.length(); i++) {
-			if (str.charAt(i) == '\t') {
-				spacesCnt += tabSize;
-			} else {
-				spacesCnt++;
-			}
-		}
-
-		StringBuilder result = new StringBuilder();
-		if (!insertSpaces) {
-			long tabsCnt = Math.round(Math.floor(spacesCnt / tabSize));
-			spacesCnt = spacesCnt % tabSize;
-			for (int i = 0; i < tabsCnt; i++) {
-				result.append('\t');
-			}
-		}
-
-		for (int i = 0; i < spacesCnt; i++) {
-			result.append(' ');
-		}
-
-		return result.toString();
-	}
-
-	/**
-	 * Returns the start of the string at the offset in the text. If the string is
-	 * not in the text at the offset, returns -1.
- * Ex:
- * text = "apple banana", offset=8, string="banana" returns=6 - */ - public static int startIndexOfOffsetTouchingString(String text, int offset, String string) { - int start = offset - string.length(); - start = start < 0 ? 0 : start; - int end = offset + string.length(); - end = end >= text.length() ? text.length() : end; - try { - int indexInSubtext = text.substring(start, end).indexOf(string); - return indexInSubtext == -1 ? -1 : start + indexInSubtext; - } catch (IndexOutOfBoundsException e) { - return -1; - } - } - - /** - * Returns first index of the string that is not whitespace. If string is empty - * or contains only whitespaces, returns -1 - */ - public static int firstNonWhitespaceIndex(String str) { - for (int i = 0, len = str.length(); i < len; i++) { - char c = str.charAt(i); - if (c != ' ' && c != '\t') { - return i; - } - } - return -1; - } - - public static String getIndentationFromWhitespace(String whitespace, TabSpacesInfo tabSpaces) { - String tab = "\t"; //$NON-NLS-1$ - String spaces = null; - int indentOffset = 0; - boolean startsWithTab = true; - boolean startsWithSpaces = true; - if (tabSpaces.isInsertSpaces()) { - char[] chars = new char[tabSpaces.getTabSize()]; - Arrays.fill(chars, ' '); - spaces = new String(chars); - } - while (startsWithTab || startsWithSpaces) { - startsWithTab = whitespace.startsWith(tab, indentOffset); - startsWithSpaces = tabSpaces.isInsertSpaces() && whitespace.startsWith(spaces, indentOffset); - if (startsWithTab) { - indentOffset += tab.length(); - } - if (startsWithSpaces) { - indentOffset += spaces.length(); - } - } - return whitespace.substring(0, indentOffset); - } - - public static String getLinePrefixingWhitespaceAtPosition(IDocument d, int offset) { - try { - // find start of line - int p = offset; - IRegion info = d.getLineInformationOfOffset(p); - int start = info.getOffset(); - - // find white spaces - int end = findEndOfWhiteSpace(d, start, offset); - - return d.get(start, end - start); - } catch (BadLocationException excp) { - // stop work - } - return ""; //$NON-NLS-1$ - } - - /** - * Returns the first offset greater than offset and smaller than - * end whose character is not a space or tab character. If no such - * offset is found, end is returned. - * - * @param document the document to search in - * @param offset the offset at which searching start - * @param end the offset at which searching stops - * @return the offset in the specified range whose character is not a space or - * tab - * @exception BadLocationException if position is an invalid range in the given - * document - */ - private static int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException { - while (offset < end) { - char c = document.getChar(offset); - if (c != ' ' && c != '\t') { - return offset; - } - offset++; - } - return end; - } - - public static TabSpacesInfo getTabSpaces(ITextViewer viewer) { - TabsToSpacesConverter converter = ClassHelper.getFieldValue(viewer, "fTabsToSpacesConverter", TextViewer.class); //$NON-NLS-1$ - if (converter != null) { - int tabSize = ClassHelper.getFieldValue(converter, "fTabRatio", TabsToSpacesConverter.class); //$NON-NLS-1$ - return new TabSpacesInfo(tabSize, true); - } - return new TabSpacesInfo(-1, false); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.languageconfiguration.internal.utils; + +import java.util.Arrays; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.TabsToSpacesConverter; +import org.eclipse.jface.text.TextUtilities; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.tm4e.ui.utils.ClassHelper; + +public class TextUtils { + + /** + * Returns true if text of the command is an enter and false otherwise. + * + * @param d + * @param c + * @return true if text of the command is an enter and false otherwise. + */ + public static boolean isEnter(IDocument d, DocumentCommand c) { + return (c.length == 0 && c.text != null && TextUtilities.equals(d.getLegalLineDelimiters(), c.text) != -1); + } + + public static String normalizeIndentation(String str, int tabSize, boolean insertSpaces) { + int firstNonWhitespaceIndex = TextUtils.firstNonWhitespaceIndex(str); + if (firstNonWhitespaceIndex == -1) { + firstNonWhitespaceIndex = str.length(); + } + return TextUtils.normalizeIndentationFromWhitespace(str.substring(0, firstNonWhitespaceIndex), tabSize, + insertSpaces) + str.substring(firstNonWhitespaceIndex); + } + + private static String normalizeIndentationFromWhitespace(String str, int tabSize, boolean insertSpaces) { + int spacesCnt = 0; + for (int i = 0; i < str.length(); i++) { + if (str.charAt(i) == '\t') { + spacesCnt += tabSize; + } else { + spacesCnt++; + } + } + + StringBuilder result = new StringBuilder(); + if (!insertSpaces) { + long tabsCnt = Math.round(Math.floor(spacesCnt / tabSize)); + spacesCnt = spacesCnt % tabSize; + for (int i = 0; i < tabsCnt; i++) { + result.append('\t'); + } + } + + for (int i = 0; i < spacesCnt; i++) { + result.append(' '); + } + + return result.toString(); + } + + /** + * Returns the start of the string at the offset in the text. If the string is + * not in the text at the offset, returns -1.
+ * Ex:
+ * text = "apple banana", offset=8, string="banana" returns=6 + */ + public static int startIndexOfOffsetTouchingString(String text, int offset, String string) { + int start = offset - string.length(); + start = start < 0 ? 0 : start; + int end = offset + string.length(); + end = end >= text.length() ? text.length() : end; + try { + int indexInSubtext = text.substring(start, end).indexOf(string); + return indexInSubtext == -1 ? -1 : start + indexInSubtext; + } catch (IndexOutOfBoundsException e) { + return -1; + } + } + + /** + * Returns first index of the string that is not whitespace. If string is empty + * or contains only whitespaces, returns -1 + */ + public static int firstNonWhitespaceIndex(String str) { + for (int i = 0, len = str.length(); i < len; i++) { + char c = str.charAt(i); + if (c != ' ' && c != '\t') { + return i; + } + } + return -1; + } + + public static String getIndentationFromWhitespace(String whitespace, TabSpacesInfo tabSpaces) { + String tab = "\t"; //$NON-NLS-1$ + String spaces = null; + int indentOffset = 0; + boolean startsWithTab = true; + boolean startsWithSpaces = true; + if (tabSpaces.isInsertSpaces()) { + char[] chars = new char[tabSpaces.getTabSize()]; + Arrays.fill(chars, ' '); + spaces = new String(chars); + } + while (startsWithTab || startsWithSpaces) { + startsWithTab = whitespace.startsWith(tab, indentOffset); + startsWithSpaces = tabSpaces.isInsertSpaces() && whitespace.startsWith(spaces, indentOffset); + if (startsWithTab) { + indentOffset += tab.length(); + } + if (startsWithSpaces) { + indentOffset += spaces.length(); + } + } + return whitespace.substring(0, indentOffset); + } + + public static String getLinePrefixingWhitespaceAtPosition(IDocument d, int offset) { + try { + // find start of line + int p = offset; + IRegion info = d.getLineInformationOfOffset(p); + int start = info.getOffset(); + + // find white spaces + int end = findEndOfWhiteSpace(d, start, offset); + + return d.get(start, end - start); + } catch (BadLocationException excp) { + // stop work + } + return ""; //$NON-NLS-1$ + } + + /** + * Returns the first offset greater than offset and smaller than + * end whose character is not a space or tab character. If no such + * offset is found, end is returned. + * + * @param document the document to search in + * @param offset the offset at which searching start + * @param end the offset at which searching stops + * @return the offset in the specified range whose character is not a space or + * tab + * @exception BadLocationException if position is an invalid range in the given + * document + */ + private static int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException { + while (offset < end) { + char c = document.getChar(offset); + if (c != ' ' && c != '\t') { + return offset; + } + offset++; + } + return end; + } + + public static TabSpacesInfo getTabSpaces(ITextViewer viewer) { + TabsToSpacesConverter converter = ClassHelper.getFieldValue(viewer, "fTabsToSpacesConverter", TextViewer.class); //$NON-NLS-1$ + if (converter != null) { + int tabSize = ClassHelper.getFieldValue(converter, "fTabRatio", TabsToSpacesConverter.class); //$NON-NLS-1$ + return new TabSpacesInfo(tabSize, true); + } + return new TabSpacesInfo(-1, false); + } + +} diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java index f99689248..be45d13f4 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java @@ -1,111 +1,111 @@ -/** - * Copyright (c) 2018 Red Hat Inc. and others. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation - */ -package org.eclipse.tm4e.languageconfiguration.internal.widgets; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.jface.layout.TableColumnLayout; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; -import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; - -public class CharacterPairsTableWidget extends TableViewer { - - public CharacterPairsTableWidget(Table table) { - super(table); - setContentProvider(new CharacterPairContentProvider()); - setLabelProvider(new CharacterPairLabelProvider()); - - GC gc = new GC(table.getShell()); - gc.setFont(JFaceResources.getDialogFont()); - TableColumnLayout columnLayout = new TableColumnLayout(); - - TableColumn column1 = new TableColumn(table, SWT.NONE); - column1.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_start); - int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_start); - columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); - - TableColumn column2 = new TableColumn(table, SWT.NONE); - column2.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_end); - minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_end); - columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); - } - - protected int computeMinimumColumnWidth(GC gc, String string) { - return gc.stringExtent(string).x + 10; - } - - protected static class CharacterPairContentProvider implements IStructuredContentProvider { - - private List characterPairList; - - @Override - public Object[] getElements(Object input) { - return characterPairList.toArray(new CharacterPair[characterPairList.size()]); - } - - @SuppressWarnings("unchecked") - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (newInput == null) { - characterPairList = Collections.EMPTY_LIST; - } else { - characterPairList = (List) newInput; - } - } - - @Override - public void dispose() { - characterPairList = null; - } - } - - protected static class CharacterPairLabelProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getText(Object element) { - return getColumnText(element, 0); - } - - @Override - public String getColumnText(Object element, int columnIndex) { - CharacterPair pair = (CharacterPair) element; - - switch (columnIndex) { - case 0: - return pair.getKey(); - case 1: - return pair.getValue(); - default: - return ""; //$NON-NLS-1$ - } - } - } - -} +/** + * Copyright (c) 2018 Red Hat Inc. and others. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation + */ +package org.eclipse.tm4e.languageconfiguration.internal.widgets; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; +import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; + +public class CharacterPairsTableWidget extends TableViewer { + + public CharacterPairsTableWidget(Table table) { + super(table); + setContentProvider(new CharacterPairContentProvider()); + setLabelProvider(new CharacterPairLabelProvider()); + + GC gc = new GC(table.getShell()); + gc.setFont(JFaceResources.getDialogFont()); + TableColumnLayout columnLayout = new TableColumnLayout(); + + TableColumn column1 = new TableColumn(table, SWT.NONE); + column1.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_start); + int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_start); + columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); + + TableColumn column2 = new TableColumn(table, SWT.NONE); + column2.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_end); + minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_end); + columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); + } + + protected int computeMinimumColumnWidth(GC gc, String string) { + return gc.stringExtent(string).x + 10; + } + + protected static class CharacterPairContentProvider implements IStructuredContentProvider { + + private List characterPairList; + + @Override + public Object[] getElements(Object input) { + return characterPairList.toArray(new CharacterPair[characterPairList.size()]); + } + + @SuppressWarnings("unchecked") + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput == null) { + characterPairList = Collections.EMPTY_LIST; + } else { + characterPairList = (List) newInput; + } + } + + @Override + public void dispose() { + characterPairList = null; + } + } + + protected static class CharacterPairLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getText(Object element) { + return getColumnText(element, 0); + } + + @Override + public String getColumnText(Object element, int columnIndex) { + CharacterPair pair = (CharacterPair) element; + + switch (columnIndex) { + case 0: + return pair.getKey(); + case 1: + return pair.getValue(); + default: + return ""; //$NON-NLS-1$ + } + } + } + +} diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java index 7958babf7..8c380b346 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java @@ -1,133 +1,133 @@ -/** - * Copyright (c) 2018 Red Hat Inc. and others. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation - */ -package org.eclipse.tm4e.languageconfiguration.internal.widgets; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.jface.layout.TableColumnLayout; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; -import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction; -import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule; - -public class OnEnterRuleTableWidget extends TableViewer { - - public OnEnterRuleTableWidget(Table table) { - super(table); - setContentProvider(new OnEnterRuleContentProvider()); - setLabelProvider(new OnEnterRuleLabelProvider()); - - GC gc = new GC(table.getShell()); - gc.setFont(JFaceResources.getDialogFont()); - TableColumnLayout columnLayout = new TableColumnLayout(); - - TableColumn column1 = new TableColumn(table, SWT.NONE); - column1.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText); - int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText); - columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); - - TableColumn column2 = new TableColumn(table, SWT.NONE); - column2.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText); - minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText); - columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); - - TableColumn column3 = new TableColumn(table, SWT.NONE); - column3.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction); - minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction); - columnLayout.setColumnData(column3, new ColumnWeightData(1, minWidth, true)); - - TableColumn column4 = new TableColumn(table, SWT.NONE); - column4.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText); - minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText); - columnLayout.setColumnData(column4, new ColumnWeightData(1, minWidth, true)); - - TableColumn column5 = new TableColumn(table, SWT.NONE); - column5.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); - minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); - columnLayout.setColumnData(column5, new ColumnWeightData(1, minWidth, true)); - } - - protected int computeMinimumColumnWidth(GC gc, String string) { - return gc.stringExtent(string).x + 10; - } - - protected static class OnEnterRuleContentProvider implements IStructuredContentProvider { - - private List onEnterRulesList; - - @Override - public Object[] getElements(Object input) { - return onEnterRulesList.toArray(new OnEnterRule[onEnterRulesList.size()]); - } - - @SuppressWarnings("unchecked") - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (newInput == null) { - onEnterRulesList = Collections.EMPTY_LIST; - } else { - onEnterRulesList = (List) newInput; - } - } - - @Override - public void dispose() { - onEnterRulesList = null; - } - } - - protected static class OnEnterRuleLabelProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getText(Object element) { - return getColumnText(element, 0); - } - - @Override - public String getColumnText(Object element, int columnIndex) { - OnEnterRule rule = (OnEnterRule) element; - EnterAction action = rule.getAction(); - - switch (columnIndex) { - case 0: - return rule.getBeforeText().pattern(); - case 1: - return rule.getAfterText() == null ? "" : rule.getAfterText().pattern(); //$NON-NLS-1$ - case 2: - return action.getIndentAction().toString(); - case 3: - return action.getAppendText() == null ? "" : action.getAppendText(); //$NON-NLS-1$ - case 4: - return action.getRemoveText() == null ? "" : action.getRemoveText().toString(); //$NON-NLS-1$ - default: - return ""; //$NON-NLS-1$ - } - } - } -} +/** + * Copyright (c) 2018 Red Hat Inc. and others. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation + */ +package org.eclipse.tm4e.languageconfiguration.internal.widgets; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; +import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction; +import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule; + +public class OnEnterRuleTableWidget extends TableViewer { + + public OnEnterRuleTableWidget(Table table) { + super(table); + setContentProvider(new OnEnterRuleContentProvider()); + setLabelProvider(new OnEnterRuleLabelProvider()); + + GC gc = new GC(table.getShell()); + gc.setFont(JFaceResources.getDialogFont()); + TableColumnLayout columnLayout = new TableColumnLayout(); + + TableColumn column1 = new TableColumn(table, SWT.NONE); + column1.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText); + int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText); + columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); + + TableColumn column2 = new TableColumn(table, SWT.NONE); + column2.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText); + minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText); + columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); + + TableColumn column3 = new TableColumn(table, SWT.NONE); + column3.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction); + minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction); + columnLayout.setColumnData(column3, new ColumnWeightData(1, minWidth, true)); + + TableColumn column4 = new TableColumn(table, SWT.NONE); + column4.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText); + minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText); + columnLayout.setColumnData(column4, new ColumnWeightData(1, minWidth, true)); + + TableColumn column5 = new TableColumn(table, SWT.NONE); + column5.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); + minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); + columnLayout.setColumnData(column5, new ColumnWeightData(1, minWidth, true)); + } + + protected int computeMinimumColumnWidth(GC gc, String string) { + return gc.stringExtent(string).x + 10; + } + + protected static class OnEnterRuleContentProvider implements IStructuredContentProvider { + + private List onEnterRulesList; + + @Override + public Object[] getElements(Object input) { + return onEnterRulesList.toArray(new OnEnterRule[onEnterRulesList.size()]); + } + + @SuppressWarnings("unchecked") + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput == null) { + onEnterRulesList = Collections.EMPTY_LIST; + } else { + onEnterRulesList = (List) newInput; + } + } + + @Override + public void dispose() { + onEnterRulesList = null; + } + } + + protected static class OnEnterRuleLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getText(Object element) { + return getColumnText(element, 0); + } + + @Override + public String getColumnText(Object element, int columnIndex) { + OnEnterRule rule = (OnEnterRule) element; + EnterAction action = rule.getAction(); + + switch (columnIndex) { + case 0: + return rule.getBeforeText().pattern(); + case 1: + return rule.getAfterText() == null ? "" : rule.getAfterText().pattern(); //$NON-NLS-1$ + case 2: + return action.getIndentAction().toString(); + case 3: + return action.getAppendText() == null ? "" : action.getAppendText(); //$NON-NLS-1$ + case 4: + return action.getRemoveText() == null ? "" : action.getRemoveText().toString(); //$NON-NLS-1$ + default: + return ""; //$NON-NLS-1$ + } + } + } +} diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java index 4d1a216e9..4431de68f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java @@ -1,316 +1,316 @@ -/** - * Copyright (c) 2018 Red Hat Inc. and others. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation - */ -package org.eclipse.tm4e.languageconfiguration.internal.wizards; - -import java.io.FileReader; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.jface.dialogs.DialogPage; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration; -import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; -import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; -import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfiguration; -import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition; -import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; -import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationPlugin; -import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationInfoWidget; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; -import org.eclipse.ui.dialogs.ResourceSelectionDialog; - -public class SelectLanguageConfigurationWizardPage extends WizardPage implements Listener { - private static final String PAGE_NAME = SelectLanguageConfigurationWizardPage.class.getName(); - - protected static final String[] TEXTMATE_EXTENSIONS = { "*language-configuration.json" }; //$NON-NLS-1$ - - private Button browseFileSystemButton; - private Button browseWorkspaceButton; - private Text fileText; - private Text contentTypeText; - private LanguageConfigurationInfoWidget infoWidget; - - private ILanguageConfigurationRegistryManager registryManager; - - protected SelectLanguageConfigurationWizardPage(String pageName) { - super(pageName); - } - - public SelectLanguageConfigurationWizardPage(ILanguageConfigurationRegistryManager registryManager) { - super(PAGE_NAME); - this.registryManager = registryManager; - super.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_title); - super.setDescription(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_description); - } - - @Override - public final void createControl(Composite parent) { - initializeDialogUnits(parent); - Composite topLevel = new Composite(parent, SWT.NONE); - topLevel.setLayout(new GridLayout()); - topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); - topLevel.setFont(parent.getFont()); - - createBody(topLevel); - setPageComplete(false); - setControl(topLevel); - } - - @Override - public void handleEvent(Event event) { - validateAndUpdateStatus(event); - } - - private void validateAndUpdateStatus(Event event) { - IStatus status = validatePage(event); - statusChanged(status == null ? Status.OK_STATUS : status); - } - - public void statusChanged(IStatus status) { - setPageComplete(!status.matches(IStatus.ERROR)); - applyToStatusLine(this, status); - } - - private static void applyToStatusLine(DialogPage page, IStatus status) { - String message = Status.OK_STATUS.equals(status) ? null : status.getMessage(); - switch (status.getSeverity()) { - case IStatus.OK: - page.setMessage(message, IMessageProvider.NONE); - page.setErrorMessage(null); - break; - case IStatus.WARNING: - page.setMessage(message, IMessageProvider.WARNING); - page.setErrorMessage(null); - break; - case IStatus.INFO: - page.setMessage(message, IMessageProvider.INFORMATION); - page.setErrorMessage(null); - break; - default: - if (message != null && message.length() == 0) { - message = null; - } - page.setMessage(null); - page.setErrorMessage(message); - break; - } - } - - protected void createBody(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - parent.setFont(parent.getFont()); - parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - parent.setLayout(new GridLayout(2, false)); - - fileText = createText(parent, LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_file); - fileText.addListener(SWT.Modify, this); - - Composite buttons = new Composite(parent, SWT.NONE); - buttons.setLayout(new GridLayout(2, false)); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 2; - gd.horizontalAlignment = SWT.RIGHT; - buttons.setLayoutData(gd); - - infoWidget = new LanguageConfigurationInfoWidget(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - infoWidget.setLayoutData(data); - - browseFileSystemButton = new Button(buttons, SWT.NONE); - browseFileSystemButton - .setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_fileSystem); - browseFileSystemButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(parent.getShell()); - dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); - dialog.setFilterPath(fileText.getText()); - String result = dialog.open(); - if (result != null && result.length() > 0) { - fileText.setText(result); - } - } - }); - - browseWorkspaceButton = new Button(buttons, SWT.NONE); - browseWorkspaceButton - .setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_workspace); - browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - ResourceSelectionDialog dialog = new ResourceSelectionDialog(browseWorkspaceButton.getShell(), - ResourcesPlugin.getWorkspace().getRoot(), - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_description); - dialog.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_title); - int returnCode = dialog.open(); - Object[] results = dialog.getResult(); - if (returnCode == 0 && results.length > 0) { - fileText.setText(((IResource) results[0]).getFullPath().makeRelative().toString()); - } - } - }); - contentTypeText = createText(parent, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentType); - contentTypeText.addListener(SWT.Modify, this); - createContentTypeTreeViewer(parent); - } - - private void createContentTypeTreeViewer(Composite composite) { - TreeViewer contentTypesViewer = new TreeViewer(composite, - SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - contentTypesViewer.getControl().setFont(composite.getFont()); - contentTypesViewer.setContentProvider(new ContentTypesContentProvider()); - contentTypesViewer.setLabelProvider(new ContentTypesLabelProvider()); - contentTypesViewer.setComparator(new ViewerComparator()); - contentTypesViewer.setInput(Platform.getContentTypeManager()); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - contentTypesViewer.getControl().setLayoutData(data); - - contentTypesViewer.addSelectionChangedListener(event -> contentTypeText - .setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString())); - } - - private static class ContentTypesLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - IContentType contentType = (IContentType) element; - return contentType.getName(); - } - } - - private static class ContentTypesContentProvider implements ITreeContentProvider { - - private IContentTypeManager manager = Platform.getContentTypeManager(); - - @Override - public Object[] getChildren(Object parentElement) { - List elements = new ArrayList<>(); - IContentType baseType = (IContentType) parentElement; - for (IContentType contentType : manager.getAllContentTypes()) { - if ((contentType.getBaseType() == null && baseType == null) - || ((contentType.getBaseType() != null && contentType.getBaseType().equals(baseType)))) { - elements.add(contentType); - } - } - return elements.toArray(); - } - - @Override - public Object getParent(Object element) { - IContentType contentType = (IContentType) element; - return contentType.getBaseType(); - } - - @Override - public boolean hasChildren(Object element) { - return getChildren(element).length > 0; - } - - @Override - public Object[] getElements(Object inputElement) { - return getChildren(null); - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - manager = (IContentTypeManager) newInput; - } - } - - private Text createText(Composite parent, String s) { - Label label = new Label(parent, SWT.NONE); - label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); - label.setText(s); - - Text text = new Text(parent, SWT.BORDER); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return text; - } - - protected IStatus validatePage(Event event) { - infoWidget.refresh(null); - String path = fileText.getText(); - if (path.length() == 0) { - return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_noSelection); - } - IPath p = new Path(path); - if (!p.isAbsolute()) { - p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation(); - } - try { - ILanguageConfiguration configuration = LanguageConfiguration.load(new FileReader(p.toFile())); - if (configuration == null) { - return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_invalid); - } - infoWidget.refresh(configuration); - } catch (Exception e) { - return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_error - + e.getLocalizedMessage()); - } - if (contentTypeText.getText().isEmpty()) { - return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_noSelection); - } - IContentType contentType = ContentTypeHelper.getContentTypeById(contentTypeText.getText()); - if (contentType == null) { - return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_invalid); - } - if (registryManager.getLanguageConfigurationFor(new IContentType[] { contentType }) != null) { - return new Status(IStatus.WARNING, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate); - } - return null; - } - - public ILanguageConfigurationDefinition getDefinition() { - IPath p = new Path(fileText.getText()); - if (!p.isAbsolute()) { - p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation(); - } - return new LanguageConfigurationDefinition(ContentTypeHelper.getContentTypeById(contentTypeText.getText()), - p.toString()); - } - -} +/** + * Copyright (c) 2018 Red Hat Inc. and others. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation + */ +package org.eclipse.tm4e.languageconfiguration.internal.wizards; + +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.jface.dialogs.DialogPage; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration; +import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; +import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; +import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfiguration; +import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition; +import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; +import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationPlugin; +import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationInfoWidget; +import org.eclipse.tm4e.ui.utils.ContentTypeHelper; +import org.eclipse.ui.dialogs.ResourceSelectionDialog; + +public class SelectLanguageConfigurationWizardPage extends WizardPage implements Listener { + private static final String PAGE_NAME = SelectLanguageConfigurationWizardPage.class.getName(); + + protected static final String[] TEXTMATE_EXTENSIONS = { "*language-configuration.json" }; //$NON-NLS-1$ + + private Button browseFileSystemButton; + private Button browseWorkspaceButton; + private Text fileText; + private Text contentTypeText; + private LanguageConfigurationInfoWidget infoWidget; + + private ILanguageConfigurationRegistryManager registryManager; + + protected SelectLanguageConfigurationWizardPage(String pageName) { + super(pageName); + } + + public SelectLanguageConfigurationWizardPage(ILanguageConfigurationRegistryManager registryManager) { + super(PAGE_NAME); + this.registryManager = registryManager; + super.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_title); + super.setDescription(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_description); + } + + @Override + public final void createControl(Composite parent) { + initializeDialogUnits(parent); + Composite topLevel = new Composite(parent, SWT.NONE); + topLevel.setLayout(new GridLayout()); + topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); + topLevel.setFont(parent.getFont()); + + createBody(topLevel); + setPageComplete(false); + setControl(topLevel); + } + + @Override + public void handleEvent(Event event) { + validateAndUpdateStatus(event); + } + + private void validateAndUpdateStatus(Event event) { + IStatus status = validatePage(event); + statusChanged(status == null ? Status.OK_STATUS : status); + } + + public void statusChanged(IStatus status) { + setPageComplete(!status.matches(IStatus.ERROR)); + applyToStatusLine(this, status); + } + + private static void applyToStatusLine(DialogPage page, IStatus status) { + String message = Status.OK_STATUS.equals(status) ? null : status.getMessage(); + switch (status.getSeverity()) { + case IStatus.OK: + page.setMessage(message, IMessageProvider.NONE); + page.setErrorMessage(null); + break; + case IStatus.WARNING: + page.setMessage(message, IMessageProvider.WARNING); + page.setErrorMessage(null); + break; + case IStatus.INFO: + page.setMessage(message, IMessageProvider.INFORMATION); + page.setErrorMessage(null); + break; + default: + if (message != null && message.length() == 0) { + message = null; + } + page.setMessage(null); + page.setErrorMessage(message); + break; + } + } + + protected void createBody(Composite ancestor) { + Composite parent = new Composite(ancestor, SWT.NONE); + parent.setFont(parent.getFont()); + parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + parent.setLayout(new GridLayout(2, false)); + + fileText = createText(parent, LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_file); + fileText.addListener(SWT.Modify, this); + + Composite buttons = new Composite(parent, SWT.NONE); + buttons.setLayout(new GridLayout(2, false)); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + gd.horizontalAlignment = SWT.RIGHT; + buttons.setLayoutData(gd); + + infoWidget = new LanguageConfigurationInfoWidget(parent, SWT.NONE); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + infoWidget.setLayoutData(data); + + browseFileSystemButton = new Button(buttons, SWT.NONE); + browseFileSystemButton + .setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_fileSystem); + browseFileSystemButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(parent.getShell()); + dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); + dialog.setFilterPath(fileText.getText()); + String result = dialog.open(); + if (result != null && result.length() > 0) { + fileText.setText(result); + } + } + }); + + browseWorkspaceButton = new Button(buttons, SWT.NONE); + browseWorkspaceButton + .setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_workspace); + browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ResourceSelectionDialog dialog = new ResourceSelectionDialog(browseWorkspaceButton.getShell(), + ResourcesPlugin.getWorkspace().getRoot(), + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_description); + dialog.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_title); + int returnCode = dialog.open(); + Object[] results = dialog.getResult(); + if (returnCode == 0 && results.length > 0) { + fileText.setText(((IResource) results[0]).getFullPath().makeRelative().toString()); + } + } + }); + contentTypeText = createText(parent, + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentType); + contentTypeText.addListener(SWT.Modify, this); + createContentTypeTreeViewer(parent); + } + + private void createContentTypeTreeViewer(Composite composite) { + TreeViewer contentTypesViewer = new TreeViewer(composite, + SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + contentTypesViewer.getControl().setFont(composite.getFont()); + contentTypesViewer.setContentProvider(new ContentTypesContentProvider()); + contentTypesViewer.setLabelProvider(new ContentTypesLabelProvider()); + contentTypesViewer.setComparator(new ViewerComparator()); + contentTypesViewer.setInput(Platform.getContentTypeManager()); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + contentTypesViewer.getControl().setLayoutData(data); + + contentTypesViewer.addSelectionChangedListener(event -> contentTypeText + .setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString())); + } + + private static class ContentTypesLabelProvider extends LabelProvider { + @Override + public String getText(Object element) { + IContentType contentType = (IContentType) element; + return contentType.getName(); + } + } + + private static class ContentTypesContentProvider implements ITreeContentProvider { + + private IContentTypeManager manager = Platform.getContentTypeManager(); + + @Override + public Object[] getChildren(Object parentElement) { + List elements = new ArrayList<>(); + IContentType baseType = (IContentType) parentElement; + for (IContentType contentType : manager.getAllContentTypes()) { + if ((contentType.getBaseType() == null && baseType == null) + || ((contentType.getBaseType() != null && contentType.getBaseType().equals(baseType)))) { + elements.add(contentType); + } + } + return elements.toArray(); + } + + @Override + public Object getParent(Object element) { + IContentType contentType = (IContentType) element; + return contentType.getBaseType(); + } + + @Override + public boolean hasChildren(Object element) { + return getChildren(element).length > 0; + } + + @Override + public Object[] getElements(Object inputElement) { + return getChildren(null); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + manager = (IContentTypeManager) newInput; + } + } + + private Text createText(Composite parent, String s) { + Label label = new Label(parent, SWT.NONE); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + label.setText(s); + + Text text = new Text(parent, SWT.BORDER); + text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + return text; + } + + protected IStatus validatePage(Event event) { + infoWidget.refresh(null); + String path = fileText.getText(); + if (path.length() == 0) { + return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_noSelection); + } + IPath p = new Path(path); + if (!p.isAbsolute()) { + p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation(); + } + try { + ILanguageConfiguration configuration = LanguageConfiguration.load(new FileReader(p.toFile())); + if (configuration == null) { + return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_invalid); + } + infoWidget.refresh(configuration); + } catch (Exception e) { + return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_error + + e.getLocalizedMessage()); + } + if (contentTypeText.getText().isEmpty()) { + return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_noSelection); + } + IContentType contentType = ContentTypeHelper.getContentTypeById(contentTypeText.getText()); + if (contentType == null) { + return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_invalid); + } + if (registryManager.getLanguageConfigurationFor(new IContentType[] { contentType }) != null) { + return new Status(IStatus.WARNING, LanguageConfigurationPlugin.PLUGIN_ID, + LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate); + } + return null; + } + + public ILanguageConfigurationDefinition getDefinition() { + IPath p = new Path(fileText.getText()); + if (!p.isAbsolute()) { + p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation(); + } + return new LanguageConfigurationDefinition(ContentTypeHelper.getContentTypeById(contentTypeText.getText()), + p.toString()); + } + +} diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java index 98e28a695..9a808bfdd 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java @@ -1,151 +1,151 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.languageconfiguration.internal.supports; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.Arrays; - -import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction; -import org.junit.jupiter.api.Test; - -/** - * {@link OnEnterSupport} tests. - * - */ -public class OnEnterSupportTest { - - @Test - public void useBrackets() { - UseBracketsTest support = new UseBracketsTest(); - - support.testIndentAction("a", "", IndentAction.None); - support.testIndentAction("", "b", IndentAction.None); - support.testIndentAction("(", "b", IndentAction.Indent); - support.testIndentAction("a", ")", IndentAction.None); - support.testIndentAction("begin", "ending", IndentAction.Indent); - support.testIndentAction("abegin", "end", IndentAction.None); - support.testIndentAction("begin", ")", IndentAction.Indent); - support.testIndentAction("begin", "end", IndentAction.IndentOutdent); - support.testIndentAction("begin ", " end", IndentAction.IndentOutdent); - support.testIndentAction(" begin", "end//as", IndentAction.IndentOutdent); - support.testIndentAction("(", ")", IndentAction.IndentOutdent); - support.testIndentAction("( ", ")", IndentAction.IndentOutdent); - support.testIndentAction("a(", ")b", IndentAction.IndentOutdent); - - support.testIndentAction("(", "", IndentAction.Indent); - support.testIndentAction("(", "foo", IndentAction.Indent); - support.testIndentAction("begin", "foo", IndentAction.Indent); - support.testIndentAction("begin", "", IndentAction.Indent); - } - - private class UseBracketsTest extends OnEnterSupport { - - public UseBracketsTest() { - super(Arrays.asList(new CharacterPair("(", ")"), new CharacterPair("begin", "end")), null); - } - - public void testIndentAction(String beforeText, String afterText, IndentAction expected) { - EnterAction actual = super.onEnter("", beforeText, afterText); - if (expected == IndentAction.None) { - assertNull(actual); - } else { - assertEquals(expected, actual.getIndentAction()); - } - } - } - - @Test - public void regExpRules() { - RegExpRulesTest support = new RegExpRulesTest(); - - support.testIndentAction("\t/**", " */", IndentAction.IndentOutdent, " * "); - support.testIndentAction("\t/**", "", IndentAction.None, " * "); - support.testIndentAction("\t/** * / * / * /", "", IndentAction.None, " * "); - support.testIndentAction("\t/** /*", "", IndentAction.None, " * "); - support.testIndentAction("/**", "", IndentAction.None, " * "); - support.testIndentAction("\t/**/", "", null, null); - support.testIndentAction("\t/***/", "", null, null); - support.testIndentAction("\t/*******/", "", null, null); - support.testIndentAction("\t/** * * * * */", "", null, null); - support.testIndentAction("\t/** */", "", null, null); - support.testIndentAction("\t/** asdfg */", "", null, null); - support.testIndentAction("\t/* asdfg */", "", null, null); - support.testIndentAction("\t/* asdfg */", "", null, null); - support.testIndentAction("\t/** asdfg */", "", null, null); - support.testIndentAction("*/", "", null, null); - support.testIndentAction("\t/*", "", null, null); - support.testIndentAction("\t*", "", null, null); - support.testIndentAction("\t *", "", IndentAction.None, "* "); - support.testIndentAction("\t */", "", IndentAction.None, null, 1); - support.testIndentAction("\t * */", "", IndentAction.None, null, 1); - support.testIndentAction("\t * * / * / * / */", "", null, null); - support.testIndentAction("\t * ", "", IndentAction.None, "* "); - support.testIndentAction(" * ", "", IndentAction.None, "* "); - support.testIndentAction(" * asdfsfagadfg", "", IndentAction.None, "* "); - support.testIndentAction(" * asdfsfagadfg * * * ", "", IndentAction.None, "* "); - support.testIndentAction(" * /*", "", IndentAction.None, "* "); - support.testIndentAction(" * asdfsfagadfg * / * / * /", "", IndentAction.None, "* "); - support.testIndentAction(" * asdfsfagadfg * / * / * /*", "", IndentAction.None, "* "); - support.testIndentAction(" */", "", IndentAction.None, null, 1); - support.testIndentAction("\t */", "", IndentAction.None, null, 1); - support.testIndentAction("\t\t */", "", IndentAction.None, null, 1); - support.testIndentAction(" */", "", IndentAction.None, null, 1); - support.testIndentAction(" */", "", IndentAction.None, null, 1); - support.testIndentAction("\t */", "", IndentAction.None, null, 1); - support.testIndentAction( - " *--------------------------------------------------------------------------------------------*/", "", - IndentAction.None, null, 1); - } - - private class RegExpRulesTest extends OnEnterSupport { - - public RegExpRulesTest() { - super(null, - Arrays.asList( - new OnEnterRule("^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", "^\\s*\\*\\/$", - new EnterAction(IndentAction.IndentOutdent).setAppendText(" * ")), - new OnEnterRule("^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", null, - new EnterAction(IndentAction.None).setAppendText(" * ")), - new OnEnterRule("^(\\t|(\\ \\ ))*\\ \\*(\\ ([^\\*]|\\*(?!\\/))*)?$", null, - new EnterAction(IndentAction.None).setAppendText("* ")), - new OnEnterRule("^(\\t|(\\ \\ ))*\\ \\*\\/\\s*$", null, - new EnterAction(IndentAction.None).setRemoveText(1)), - new OnEnterRule("^(\\t|(\\ \\ ))*\\ \\*[^/]*\\*\\/\\s*$", null, - new EnterAction(IndentAction.None).setRemoveText(1)))); - } - - public void testIndentAction(String beforeText, String afterText, IndentAction expectedIndentAction, - String expectedAppendText) { - testIndentAction(beforeText, afterText, expectedIndentAction, expectedAppendText, 0); - } - - public void testIndentAction(String beforeText, String afterText, IndentAction expectedIndentAction, - String expectedAppendText, int removeText) { - EnterAction actual = super.onEnter("", beforeText, afterText); - if (expectedIndentAction == null) { - assertNull(actual, "isNull:" + beforeText); - } else { - assertNotNull(actual, "isNotNull:" + beforeText); - assertEquals(expectedIndentAction, actual.getIndentAction(), "indentAction:" + beforeText); - if (expectedAppendText != null) { - assertEquals(expectedAppendText, actual.getAppendText(), "appendText:" + beforeText); - } - if (removeText != 0) { - assertEquals(removeText, actual.getRemoveText(), "removeText:" + beforeText); - } - } - } - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.languageconfiguration.internal.supports; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.Arrays; + +import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction; +import org.junit.jupiter.api.Test; + +/** + * {@link OnEnterSupport} tests. + * + */ +public class OnEnterSupportTest { + + @Test + public void useBrackets() { + UseBracketsTest support = new UseBracketsTest(); + + support.testIndentAction("a", "", IndentAction.None); + support.testIndentAction("", "b", IndentAction.None); + support.testIndentAction("(", "b", IndentAction.Indent); + support.testIndentAction("a", ")", IndentAction.None); + support.testIndentAction("begin", "ending", IndentAction.Indent); + support.testIndentAction("abegin", "end", IndentAction.None); + support.testIndentAction("begin", ")", IndentAction.Indent); + support.testIndentAction("begin", "end", IndentAction.IndentOutdent); + support.testIndentAction("begin ", " end", IndentAction.IndentOutdent); + support.testIndentAction(" begin", "end//as", IndentAction.IndentOutdent); + support.testIndentAction("(", ")", IndentAction.IndentOutdent); + support.testIndentAction("( ", ")", IndentAction.IndentOutdent); + support.testIndentAction("a(", ")b", IndentAction.IndentOutdent); + + support.testIndentAction("(", "", IndentAction.Indent); + support.testIndentAction("(", "foo", IndentAction.Indent); + support.testIndentAction("begin", "foo", IndentAction.Indent); + support.testIndentAction("begin", "", IndentAction.Indent); + } + + private class UseBracketsTest extends OnEnterSupport { + + public UseBracketsTest() { + super(Arrays.asList(new CharacterPair("(", ")"), new CharacterPair("begin", "end")), null); + } + + public void testIndentAction(String beforeText, String afterText, IndentAction expected) { + EnterAction actual = super.onEnter("", beforeText, afterText); + if (expected == IndentAction.None) { + assertNull(actual); + } else { + assertEquals(expected, actual.getIndentAction()); + } + } + } + + @Test + public void regExpRules() { + RegExpRulesTest support = new RegExpRulesTest(); + + support.testIndentAction("\t/**", " */", IndentAction.IndentOutdent, " * "); + support.testIndentAction("\t/**", "", IndentAction.None, " * "); + support.testIndentAction("\t/** * / * / * /", "", IndentAction.None, " * "); + support.testIndentAction("\t/** /*", "", IndentAction.None, " * "); + support.testIndentAction("/**", "", IndentAction.None, " * "); + support.testIndentAction("\t/**/", "", null, null); + support.testIndentAction("\t/***/", "", null, null); + support.testIndentAction("\t/*******/", "", null, null); + support.testIndentAction("\t/** * * * * */", "", null, null); + support.testIndentAction("\t/** */", "", null, null); + support.testIndentAction("\t/** asdfg */", "", null, null); + support.testIndentAction("\t/* asdfg */", "", null, null); + support.testIndentAction("\t/* asdfg */", "", null, null); + support.testIndentAction("\t/** asdfg */", "", null, null); + support.testIndentAction("*/", "", null, null); + support.testIndentAction("\t/*", "", null, null); + support.testIndentAction("\t*", "", null, null); + support.testIndentAction("\t *", "", IndentAction.None, "* "); + support.testIndentAction("\t */", "", IndentAction.None, null, 1); + support.testIndentAction("\t * */", "", IndentAction.None, null, 1); + support.testIndentAction("\t * * / * / * / */", "", null, null); + support.testIndentAction("\t * ", "", IndentAction.None, "* "); + support.testIndentAction(" * ", "", IndentAction.None, "* "); + support.testIndentAction(" * asdfsfagadfg", "", IndentAction.None, "* "); + support.testIndentAction(" * asdfsfagadfg * * * ", "", IndentAction.None, "* "); + support.testIndentAction(" * /*", "", IndentAction.None, "* "); + support.testIndentAction(" * asdfsfagadfg * / * / * /", "", IndentAction.None, "* "); + support.testIndentAction(" * asdfsfagadfg * / * / * /*", "", IndentAction.None, "* "); + support.testIndentAction(" */", "", IndentAction.None, null, 1); + support.testIndentAction("\t */", "", IndentAction.None, null, 1); + support.testIndentAction("\t\t */", "", IndentAction.None, null, 1); + support.testIndentAction(" */", "", IndentAction.None, null, 1); + support.testIndentAction(" */", "", IndentAction.None, null, 1); + support.testIndentAction("\t */", "", IndentAction.None, null, 1); + support.testIndentAction( + " *--------------------------------------------------------------------------------------------*/", "", + IndentAction.None, null, 1); + } + + private class RegExpRulesTest extends OnEnterSupport { + + public RegExpRulesTest() { + super(null, + Arrays.asList( + new OnEnterRule("^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", "^\\s*\\*\\/$", + new EnterAction(IndentAction.IndentOutdent).setAppendText(" * ")), + new OnEnterRule("^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", null, + new EnterAction(IndentAction.None).setAppendText(" * ")), + new OnEnterRule("^(\\t|(\\ \\ ))*\\ \\*(\\ ([^\\*]|\\*(?!\\/))*)?$", null, + new EnterAction(IndentAction.None).setAppendText("* ")), + new OnEnterRule("^(\\t|(\\ \\ ))*\\ \\*\\/\\s*$", null, + new EnterAction(IndentAction.None).setRemoveText(1)), + new OnEnterRule("^(\\t|(\\ \\ ))*\\ \\*[^/]*\\*\\/\\s*$", null, + new EnterAction(IndentAction.None).setRemoveText(1)))); + } + + public void testIndentAction(String beforeText, String afterText, IndentAction expectedIndentAction, + String expectedAppendText) { + testIndentAction(beforeText, afterText, expectedIndentAction, expectedAppendText, 0); + } + + public void testIndentAction(String beforeText, String afterText, IndentAction expectedIndentAction, + String expectedAppendText, int removeText) { + EnterAction actual = super.onEnter("", beforeText, afterText); + if (expectedIndentAction == null) { + assertNull(actual, "isNull:" + beforeText); + } else { + assertNotNull(actual, "isNotNull:" + beforeText); + assertEquals(expectedIndentAction, actual.getIndentAction(), "indentAction:" + beforeText); + if (expectedAppendText != null) { + assertEquals(expectedAppendText, actual.getAppendText(), "appendText:" + beforeText); + } + if (removeText != 0) { + assertEquals(removeText, actual.getRemoveText(), "removeText:" + beforeText); + } + } + } + } +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java index 42b6b4d94..7e42b57c4 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java @@ -1,116 +1,116 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.markdown; - -import java.util.List; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.model.ITokenizationSupport; -import org.eclipse.tm4e.core.model.LineTokens; -import org.eclipse.tm4e.core.model.TMState; -import org.eclipse.tm4e.core.model.TMToken; -import org.eclipse.tm4e.core.model.Tokenizer; -import org.eclipse.tm4e.markdown.marked.HTMLRenderer; -import org.eclipse.tm4e.markdown.marked.Helpers; -import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; - -public class TMHTMLRenderer extends HTMLRenderer { - - private final String defaultLang; - - public TMHTMLRenderer(String defaultLang) { - this.defaultLang = defaultLang; - } - - @Override - public void code(String code, String lang, boolean escaped) { - IGrammar grammar = lang == null ? getDefaultGrammar() : getGrammar(lang); - if (grammar == null) { - super.code(code, lang, escaped); - } else { - ITokenizationSupport tokenizationSupport = new Tokenizer(grammar); - html.append("
"); - tokenizeLines(code, tokenizationSupport); - html.append("
"); - } - } - - private void tokenizeLines(String text, ITokenizationSupport tokenizationSupport) { - String[] lines = text.split("\r\n|\r|\n"); - TMState currentState = tokenizationSupport.getInitialState(); - for (int i = 0; i < lines.length; i++) { - currentState = tokenizeLine(lines[i], tokenizationSupport, currentState); - - // Keep new lines - if (i < lines.length - 1) { - emitNewLine(); - } - } - } - - private void emitNewLine() { - html.append("
"); - } - - private TMState tokenizeLine(String line, ITokenizationSupport tokenizationSupport, TMState startState) { - LineTokens tokenized = tokenizationSupport.tokenize(line, startState); - TMState endState = tokenized.getEndState(); - List tokens = tokenized.getTokens(); - int offset = 0; - String tokenText; - - // For each token inject spans with proper class names based on token - // type - for (int j = 0; j < tokens.size(); j++) { - TMToken token = tokens.get(j); - - // Tokens only provide a startIndex from where they are valid from. - // As such, we need to - // look ahead the value of the token by advancing until the next - // tokens start inex or the - // end of the line. - if (j < tokens.size() - 1) { - tokenText = line.substring(offset, tokens.get(j + 1).startIndex); - offset = tokens.get(j + 1).startIndex; - } else { - tokenText = line.substring(offset); - } - - String className = "token"; - String safeType = token.type.replaceAll("[^a-z0-9\\-]", " "); - if (safeType.length() > 0) { - className += ' ' + safeType; - } - - html.append(""); - html.append(Helpers.escape(tokenText)); - html.append(""); - // emitToken(className, tokenText); - } - - return endState; - } - - protected IGrammar getDefaultGrammar() { - return getGrammar(defaultLang); - } - - protected IGrammar getGrammar(String lang) { - IContentType[] contentTypes = Platform.getContentTypeManager().findContentTypesFor("x." + lang); - return TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.markdown; + +import java.util.List; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.model.ITokenizationSupport; +import org.eclipse.tm4e.core.model.LineTokens; +import org.eclipse.tm4e.core.model.TMState; +import org.eclipse.tm4e.core.model.TMToken; +import org.eclipse.tm4e.core.model.Tokenizer; +import org.eclipse.tm4e.markdown.marked.HTMLRenderer; +import org.eclipse.tm4e.markdown.marked.Helpers; +import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; + +public class TMHTMLRenderer extends HTMLRenderer { + + private final String defaultLang; + + public TMHTMLRenderer(String defaultLang) { + this.defaultLang = defaultLang; + } + + @Override + public void code(String code, String lang, boolean escaped) { + IGrammar grammar = lang == null ? getDefaultGrammar() : getGrammar(lang); + if (grammar == null) { + super.code(code, lang, escaped); + } else { + ITokenizationSupport tokenizationSupport = new Tokenizer(grammar); + html.append("
"); + tokenizeLines(code, tokenizationSupport); + html.append("
"); + } + } + + private void tokenizeLines(String text, ITokenizationSupport tokenizationSupport) { + String[] lines = text.split("\r\n|\r|\n"); + TMState currentState = tokenizationSupport.getInitialState(); + for (int i = 0; i < lines.length; i++) { + currentState = tokenizeLine(lines[i], tokenizationSupport, currentState); + + // Keep new lines + if (i < lines.length - 1) { + emitNewLine(); + } + } + } + + private void emitNewLine() { + html.append("
"); + } + + private TMState tokenizeLine(String line, ITokenizationSupport tokenizationSupport, TMState startState) { + LineTokens tokenized = tokenizationSupport.tokenize(line, startState); + TMState endState = tokenized.getEndState(); + List tokens = tokenized.getTokens(); + int offset = 0; + String tokenText; + + // For each token inject spans with proper class names based on token + // type + for (int j = 0; j < tokens.size(); j++) { + TMToken token = tokens.get(j); + + // Tokens only provide a startIndex from where they are valid from. + // As such, we need to + // look ahead the value of the token by advancing until the next + // tokens start inex or the + // end of the line. + if (j < tokens.size() - 1) { + tokenText = line.substring(offset, tokens.get(j + 1).startIndex); + offset = tokens.get(j + 1).startIndex; + } else { + tokenText = line.substring(offset); + } + + String className = "token"; + String safeType = token.type.replaceAll("[^a-z0-9\\-]", " "); + if (safeType.length() > 0) { + className += ' ' + safeType; + } + + html.append(""); + html.append(Helpers.escape(tokenText)); + html.append(""); + // emitToken(className, tokenText); + } + + return endState; + } + + protected IGrammar getDefaultGrammar() { + return getGrammar(defaultLang); + } + + protected IGrammar getGrammar(String lang) { + IContentType[] contentTypes = Platform.getContentTypeManager().findContentTypesFor("x." + lang); + return TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); + } +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java index b8dff4ee2..7ca4efd63 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java @@ -1,40 +1,40 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.markdown; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -/** - * OSGi Activator for TextMate Markdown bundle. - * - */ -public class TMMarkdownPlugin implements BundleActivator { - - public static final String PLUGIN_ID = "org.eclipse.tm4e.markdown"; - - private static BundleContext context; - - static BundleContext getContext() { - return context; - } - - @Override - public void start(BundleContext bundleContext) throws Exception { - TMMarkdownPlugin.context = bundleContext; - } - - @Override - public void stop(BundleContext bundleContext) throws Exception { - TMMarkdownPlugin.context = null; - } + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.markdown; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * OSGi Activator for TextMate Markdown bundle. + * + */ +public class TMMarkdownPlugin implements BundleActivator { + + public static final String PLUGIN_ID = "org.eclipse.tm4e.markdown"; + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + @Override + public void start(BundleContext bundleContext) throws Exception { + TMMarkdownPlugin.context = bundleContext; + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + TMMarkdownPlugin.context = null; + } } \ No newline at end of file diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java index a2465b607..c162e6143 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java @@ -13,105 +13,105 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public class BlockRules { - - private static final String _tag = "(?!(?:" + "a|em|strong|small|s|cite|q|dfn|abbr|data|time|code" - + "|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo" - + "|span|br|wbr|ins|del|img)\\b)\\w+(?!:\\/|[^\\w\\s@]*@)\\b"; - - public static BlockRules normal = normal(); - public static BlockRules gfm = gfm(); - public static BlockRules tables = tables(); - - public final RegExp newline; - public final RegExp code; - public final RegExp fences; - public final RegExp hr; - public final RegExp heading; - public final RegExp nptable; - public final RegExp lheading; - public final RegExp blockquote; - public final RegExp list; - public final RegExp html; - public final RegExp def; - public final RegExp table; - public final RegExp paragraph; - public final RegExp text; - public final RegExp bullet; - public final RegExp item; - - public BlockRules(RegExp newline, RegExp code, RegExp fences, RegExp hr, RegExp heading, RegExp nptable, - RegExp lheading, RegExp blockquote, RegExp list, RegExp html, RegExp def, RegExp table, RegExp paragraph, - RegExp text, RegExp bullet, RegExp item) { - this.newline = newline; - this.code = code; - this.fences = fences; - this.hr = hr; - this.heading = heading; - this.nptable = nptable; - this.lheading = lheading; - this.blockquote = blockquote; - this.list = list; - this.html = html; - this.def = def; - this.table = table; - this.paragraph = paragraph; - this.text = text; - this.bullet = bullet; - this.item = item; - } - - private static BlockRules block() { - RegExp newline = new RegExp("^\\n+"); - RegExp code = new RegExp("^( {4}[^\\n]+\\n*)+/"); - RegExp fences = new RegExp(""); - RegExp hr = new RegExp("^( *[-*_]){3,} *(?:\\n+|$)"); - RegExp heading = new RegExp("^ *(#{1,6}) *([^\\n]+?) *#* *(?:\\n+|$)"); - RegExp nptable = new RegExp(""); - RegExp lheading = new RegExp("^([^\\n]+)\\n *(=|-){2,} *(?:\\n+|$)"); - RegExp blockquote = new RegExp("^( *>[^\\n]+(\\n(?!def)[^\\n]+)*\\n*)+"); - RegExp list = new RegExp("^( *)(bull) [\\s\\S]+?(?:hr|def|\\n{2,}(?! )(?!\\1bull )\\n*|\\s*$)"); - RegExp html = new RegExp("^ *(?:comment *(?:\\n|\\s*$)|closed *(?:\\n{2,}|\\s*$)|closing *(?:\\n{2,}|\\s*$))"); - RegExp def = new RegExp("^ *\\[([^\\]]+)\\]: *]+)>?(?: +[\"(]([^\\n]+)[\")])? *(?:\\n+|$)"); - RegExp table = RegExp.noop(); - RegExp paragraph = new RegExp("^((?:[^\\n]+\\n?(?!hr|heading|lheading|blockquote|tag|def))+)\\n*"); - RegExp text = new RegExp("^[^\\n]+"); - RegExp bullet = new RegExp("(?:[*+-]|\\d+\\.)"); - RegExp item = new RegExp("^( *)(bull) [^\\n]*(?:\\n(?!\\1bull )[^\\n]*)*"); - - item.replaceAll("bull", bullet); - list.replaceAll("bull", bullet).replace("hr", "\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))").replace("def", - "\\n+(?=" + def.source + ")"); - blockquote.replace("def", def); - paragraph.replace("hr", hr).replace("heading", heading).replace("lheading", lheading) - .replace("blockquote", blockquote).replace("tag", "<" + _tag).replace("def", def); - return new BlockRules(newline, code, fences, hr, heading, nptable, lheading, blockquote, list, html, def, table, - paragraph, text, bullet, item); - } - - private static BlockRules normal() { - return block(); - } - - private static BlockRules gfm() { - BlockRules gfm = normal(); - gfm.fences.source = "^ *(`{3,}|~{3,})[ \\.]*(\\S+)? *\\n([\\s\\S]*?)\\s*\\1 *(?:\\n+|$)"; - // gfm.paragraph.source = "^"; - gfm.heading.source = "^ *(#{1,6}) +([^\\n]+?) *#* *(?:\\n+|$)"; - String pattern = "(?!" + gfm.fences.source.replaceFirst("\\\\1", "\\\\2") + "|" - + gfm.list.source.replaceFirst("\\\\1", "\\\\3") + "|"; - //pattern = pattern.replaceAll("\\\"", "\\\\\""); - //pattern = pattern.replaceAll("[$]", "\\\\\\$"); - gfm.paragraph.replace("\\(\\?\\!", pattern); - return gfm; - } - - private static BlockRules tables() { - BlockRules tables = gfm(); - - return tables; - } -} + */ +package org.eclipse.tm4e.markdown.marked; + +public class BlockRules { + + private static final String _tag = "(?!(?:" + "a|em|strong|small|s|cite|q|dfn|abbr|data|time|code" + + "|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo" + + "|span|br|wbr|ins|del|img)\\b)\\w+(?!:\\/|[^\\w\\s@]*@)\\b"; + + public static BlockRules normal = normal(); + public static BlockRules gfm = gfm(); + public static BlockRules tables = tables(); + + public final RegExp newline; + public final RegExp code; + public final RegExp fences; + public final RegExp hr; + public final RegExp heading; + public final RegExp nptable; + public final RegExp lheading; + public final RegExp blockquote; + public final RegExp list; + public final RegExp html; + public final RegExp def; + public final RegExp table; + public final RegExp paragraph; + public final RegExp text; + public final RegExp bullet; + public final RegExp item; + + public BlockRules(RegExp newline, RegExp code, RegExp fences, RegExp hr, RegExp heading, RegExp nptable, + RegExp lheading, RegExp blockquote, RegExp list, RegExp html, RegExp def, RegExp table, RegExp paragraph, + RegExp text, RegExp bullet, RegExp item) { + this.newline = newline; + this.code = code; + this.fences = fences; + this.hr = hr; + this.heading = heading; + this.nptable = nptable; + this.lheading = lheading; + this.blockquote = blockquote; + this.list = list; + this.html = html; + this.def = def; + this.table = table; + this.paragraph = paragraph; + this.text = text; + this.bullet = bullet; + this.item = item; + } + + private static BlockRules block() { + RegExp newline = new RegExp("^\\n+"); + RegExp code = new RegExp("^( {4}[^\\n]+\\n*)+/"); + RegExp fences = new RegExp(""); + RegExp hr = new RegExp("^( *[-*_]){3,} *(?:\\n+|$)"); + RegExp heading = new RegExp("^ *(#{1,6}) *([^\\n]+?) *#* *(?:\\n+|$)"); + RegExp nptable = new RegExp(""); + RegExp lheading = new RegExp("^([^\\n]+)\\n *(=|-){2,} *(?:\\n+|$)"); + RegExp blockquote = new RegExp("^( *>[^\\n]+(\\n(?!def)[^\\n]+)*\\n*)+"); + RegExp list = new RegExp("^( *)(bull) [\\s\\S]+?(?:hr|def|\\n{2,}(?! )(?!\\1bull )\\n*|\\s*$)"); + RegExp html = new RegExp("^ *(?:comment *(?:\\n|\\s*$)|closed *(?:\\n{2,}|\\s*$)|closing *(?:\\n{2,}|\\s*$))"); + RegExp def = new RegExp("^ *\\[([^\\]]+)\\]: *]+)>?(?: +[\"(]([^\\n]+)[\")])? *(?:\\n+|$)"); + RegExp table = RegExp.noop(); + RegExp paragraph = new RegExp("^((?:[^\\n]+\\n?(?!hr|heading|lheading|blockquote|tag|def))+)\\n*"); + RegExp text = new RegExp("^[^\\n]+"); + RegExp bullet = new RegExp("(?:[*+-]|\\d+\\.)"); + RegExp item = new RegExp("^( *)(bull) [^\\n]*(?:\\n(?!\\1bull )[^\\n]*)*"); + + item.replaceAll("bull", bullet); + list.replaceAll("bull", bullet).replace("hr", "\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))").replace("def", + "\\n+(?=" + def.source + ")"); + blockquote.replace("def", def); + paragraph.replace("hr", hr).replace("heading", heading).replace("lheading", lheading) + .replace("blockquote", blockquote).replace("tag", "<" + _tag).replace("def", def); + return new BlockRules(newline, code, fences, hr, heading, nptable, lheading, blockquote, list, html, def, table, + paragraph, text, bullet, item); + } + + private static BlockRules normal() { + return block(); + } + + private static BlockRules gfm() { + BlockRules gfm = normal(); + gfm.fences.source = "^ *(`{3,}|~{3,})[ \\.]*(\\S+)? *\\n([\\s\\S]*?)\\s*\\1 *(?:\\n+|$)"; + // gfm.paragraph.source = "^"; + gfm.heading.source = "^ *(#{1,6}) +([^\\n]+?) *#* *(?:\\n+|$)"; + String pattern = "(?!" + gfm.fences.source.replaceFirst("\\\\1", "\\\\2") + "|" + + gfm.list.source.replaceFirst("\\\\1", "\\\\3") + "|"; + //pattern = pattern.replaceAll("\\\"", "\\\\\""); + //pattern = pattern.replaceAll("[$]", "\\\\\\$"); + gfm.paragraph.replace("\\(\\?\\!", pattern); + return gfm; + } + + private static BlockRules tables() { + BlockRules tables = gfm(); + + return tables; + } +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java index ec0f2789d..bda7005d8 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java @@ -13,163 +13,163 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -import static org.eclipse.tm4e.markdown.marked.Helpers.escape; - -public class HTMLRenderer implements IRenderer { - - protected final StringBuilder html; - - public HTMLRenderer() { - this(new StringBuilder()); - } - - public HTMLRenderer(StringBuilder html) { - this.html = html; - } - - @Override - public void code(String code, String lang, boolean escaped) { - if (lang == null) { - html.append("
");
-			html.append(escaped ? code : escape(code, true));
-			html.append("\n
"); - } else { - html.append("
");
-			html.append(escaped ? code : escape(code, true));
-			html.append("\n
"); - } - } - - @Override - public void blockquote(String quote) { - // TODO Auto-generated method stub - - } - - @Override - public void html(String html) { - // TODO Auto-generated method stub - - } - - @Override - public void heading(String text, int level, String raw) { - html.append(""); - html.append(text); - html.append("\n"); - } - - @Override - public void hr() { - html.append("
\n"); - } - - @Override - public void list(String body, boolean ordered) { - // TODO Auto-generated method stub - - } - - @Override - public void listitem(String text) { - // TODO Auto-generated method stub - - } - - @Override - public void startParagraph() { - html.append("

"); - } - - @Override - public void endParagraph() { - html.append("

\n"); - } - - @Override - public void table(String header, String body) { - // TODO Auto-generated method stub - - } - - @Override - public void tablerow(String content) { - // TODO Auto-generated method stub - - } - - @Override - public void tablecell(String content, String flags) { - // TODO Auto-generated method stub - - } - - @Override - public void startEm() { - html.append(""); - } - - @Override - public void endEm() { - html.append(""); - } - - @Override - public void startStrong() { - html.append(""); - } - - @Override - public void endStrong() { - html.append(""); - } - - @Override - public void codespan(String text) { - html.append(""); - html.append(text); - html.append(""); - } - - @Override - public void br() { - // TODO Auto-generated method stub - - } - - @Override - public void del(String text) { - // TODO Auto-generated method stub - - } - - @Override - public void link(String href, String title, String text) { - // TODO Auto-generated method stub - - } - - @Override - public void image(String href, String title, String text) { - // TODO Auto-generated method stub - - } - - @Override - public void text(String text) { - html.append(text); - } - - @Override - public String toString() { - return html.toString(); - } -} + */ +package org.eclipse.tm4e.markdown.marked; + +import static org.eclipse.tm4e.markdown.marked.Helpers.escape; + +public class HTMLRenderer implements IRenderer { + + protected final StringBuilder html; + + public HTMLRenderer() { + this(new StringBuilder()); + } + + public HTMLRenderer(StringBuilder html) { + this.html = html; + } + + @Override + public void code(String code, String lang, boolean escaped) { + if (lang == null) { + html.append("
");
+			html.append(escaped ? code : escape(code, true));
+			html.append("\n
"); + } else { + html.append("
");
+			html.append(escaped ? code : escape(code, true));
+			html.append("\n
"); + } + } + + @Override + public void blockquote(String quote) { + // TODO Auto-generated method stub + + } + + @Override + public void html(String html) { + // TODO Auto-generated method stub + + } + + @Override + public void heading(String text, int level, String raw) { + html.append(""); + html.append(text); + html.append("\n"); + } + + @Override + public void hr() { + html.append("
\n"); + } + + @Override + public void list(String body, boolean ordered) { + // TODO Auto-generated method stub + + } + + @Override + public void listitem(String text) { + // TODO Auto-generated method stub + + } + + @Override + public void startParagraph() { + html.append("

"); + } + + @Override + public void endParagraph() { + html.append("

\n"); + } + + @Override + public void table(String header, String body) { + // TODO Auto-generated method stub + + } + + @Override + public void tablerow(String content) { + // TODO Auto-generated method stub + + } + + @Override + public void tablecell(String content, String flags) { + // TODO Auto-generated method stub + + } + + @Override + public void startEm() { + html.append(""); + } + + @Override + public void endEm() { + html.append(""); + } + + @Override + public void startStrong() { + html.append(""); + } + + @Override + public void endStrong() { + html.append(""); + } + + @Override + public void codespan(String text) { + html.append(""); + html.append(text); + html.append(""); + } + + @Override + public void br() { + // TODO Auto-generated method stub + + } + + @Override + public void del(String text) { + // TODO Auto-generated method stub + + } + + @Override + public void link(String href, String title, String text) { + // TODO Auto-generated method stub + + } + + @Override + public void image(String href, String title, String text) { + // TODO Auto-generated method stub + + } + + @Override + public void text(String text) { + html.append(text); + } + + @Override + public String toString() { + return html.toString(); + } +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java index c6b1c15b2..44aabea84 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java @@ -13,26 +13,26 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public class Helpers { - - public static String escape(String html) { - return escape(html, false); - } - - public static String escape(String html, boolean encode) { - return html - .replaceAll(!encode ? "&(?!#?\\w+;)" : "&", "&") - .replaceAll("<", "<") - .replaceAll(">", ">") - .replaceAll("\"", """) - .replaceAll("'", "'"); - } - - public static boolean isEmpty(String s) { - return s == null || s.length() < 1; - } - -} + */ +package org.eclipse.tm4e.markdown.marked; + +public class Helpers { + + public static String escape(String html) { + return escape(html, false); + } + + public static String escape(String html, boolean encode) { + return html + .replaceAll(!encode ? "&(?!#?\\w+;)" : "&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll("\"", """) + .replaceAll("'", "'"); + } + + public static boolean isEmpty(String s) { + return s == null || s.length() < 1; + } + +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java index b499db8d1..0b51d7092 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java @@ -13,55 +13,55 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public interface IRenderer { - - void code(String code, String lang, boolean escaped); - - void blockquote(String quote); - - void html(String html); - - void heading(String text, int level, String raw); - - void hr(); - - void list(String body, boolean ordered); - - void listitem(String text); - - void startParagraph(); - - void endParagraph(); - - void table(String header, String body); - - void tablerow(String content); - - void tablecell(String content, String flags); - - void startEm(); - - void endEm(); - - void startStrong(); - - void endStrong(); - - void codespan(String text); - - void br(); - - void del(String text); - - void link(String href, String title, String text); - - void image(String href, String title, String text); - - void text(String text); - - - -} + */ +package org.eclipse.tm4e.markdown.marked; + +public interface IRenderer { + + void code(String code, String lang, boolean escaped); + + void blockquote(String quote); + + void html(String html); + + void heading(String text, int level, String raw); + + void hr(); + + void list(String body, boolean ordered); + + void listitem(String text); + + void startParagraph(); + + void endParagraph(); + + void table(String header, String body); + + void tablerow(String content); + + void tablecell(String content, String flags); + + void startEm(); + + void endEm(); + + void startStrong(); + + void endStrong(); + + void codespan(String text); + + void br(); + + void del(String text); + + void link(String href, String title, String text); + + void image(String href, String title, String text); + + void text(String text); + + + +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java index 2c07355c2..428aba000 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java @@ -13,84 +13,84 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -import static org.eclipse.tm4e.markdown.marked.Helpers.escape; -import static org.eclipse.tm4e.markdown.marked.Helpers.isEmpty; - -import java.util.regex.Matcher; - -public class InlineLexer { - - private Options options; - private InlineRules rules; - private final IRenderer renderer; - - public InlineLexer(Object links, Options options, IRenderer renderer) { - this.options = options != null ? options : Options.DEFAULTS; - // this.links = links; - this.rules = InlineRules.normal; - this.renderer = renderer != null ? renderer : new HTMLRenderer(); - // this.renderer = this.options.renderer || new Renderer; - // this.renderer.options = this.options; - - // if (!this.links) { - // throw new - // Error('Tokens array requires a `links` property.'); - // } - - if (this.options.isGfm()) { - if (this.options.isBreaks()) { - this.rules = InlineRules.breaks; - } else { - this.rules = InlineRules.gfm; - } - } else if (this.options.isPedantic()) { - this.rules = InlineRules.pedantic; - } - } - - public void output(String src) { - Matcher cap = null; - while (!isEmpty(src)) { - - // strong - if ((cap = this.rules.strong.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - this.renderer.startStrong(); - this.output(!isEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); - this.renderer.endStrong(); - continue; - } - - // em - if ((cap = this.rules.em.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - this.renderer.startEm(); - this.output(!isEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); - this.renderer.endEm(); - continue; - } - - // code - if ((cap = this.rules.code.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - this.renderer.codespan(escape(cap.group(2), true)); - continue; - } - - // text - if ((cap = this.rules.text.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - this.renderer.text(escape(this.smartypants(cap.group(0)))); - continue; - } - } - } - - private String smartypants(String text) { - return text; - } - -} + */ +package org.eclipse.tm4e.markdown.marked; + +import static org.eclipse.tm4e.markdown.marked.Helpers.escape; +import static org.eclipse.tm4e.markdown.marked.Helpers.isEmpty; + +import java.util.regex.Matcher; + +public class InlineLexer { + + private Options options; + private InlineRules rules; + private final IRenderer renderer; + + public InlineLexer(Object links, Options options, IRenderer renderer) { + this.options = options != null ? options : Options.DEFAULTS; + // this.links = links; + this.rules = InlineRules.normal; + this.renderer = renderer != null ? renderer : new HTMLRenderer(); + // this.renderer = this.options.renderer || new Renderer; + // this.renderer.options = this.options; + + // if (!this.links) { + // throw new + // Error('Tokens array requires a `links` property.'); + // } + + if (this.options.isGfm()) { + if (this.options.isBreaks()) { + this.rules = InlineRules.breaks; + } else { + this.rules = InlineRules.gfm; + } + } else if (this.options.isPedantic()) { + this.rules = InlineRules.pedantic; + } + } + + public void output(String src) { + Matcher cap = null; + while (!isEmpty(src)) { + + // strong + if ((cap = this.rules.strong.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + this.renderer.startStrong(); + this.output(!isEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); + this.renderer.endStrong(); + continue; + } + + // em + if ((cap = this.rules.em.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + this.renderer.startEm(); + this.output(!isEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); + this.renderer.endEm(); + continue; + } + + // code + if ((cap = this.rules.code.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + this.renderer.codespan(escape(cap.group(2), true)); + continue; + } + + // text + if ((cap = this.rules.text.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + this.renderer.text(escape(this.smartypants(cap.group(0)))); + continue; + } + } + } + + private String smartypants(String text) { + return text; + } + +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java index 6cb328c0c..f11a30588 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java @@ -13,98 +13,98 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public class InlineRules { - - private static final String INLINE_INSIDE = "(?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*"; - private static final String INLINE_HREF = "\\s*?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*"; - - public static final InlineRules normal = normal(); - - public static final InlineRules pedantic = pedantic(); - - public static final InlineRules gfm = gfm(); - - public static final InlineRules breaks = breaks(); - - public final RegExp escape; - public final RegExp autolink; - public final RegExp url; - public final RegExp tag; - public final RegExp link; - public final RegExp reflink; - public final RegExp nolink; - public final RegExp strong; - public final RegExp em; - public final RegExp code; - public final RegExp br; - public final RegExp del; - public final RegExp text; - - public InlineRules(RegExp escape, RegExp autolink, RegExp url, RegExp tag, RegExp link, RegExp reflink, - RegExp nolink, RegExp strong, RegExp em, RegExp code, RegExp br, RegExp del, RegExp text) { - this.escape = escape; - this.autolink = autolink; - this.url = url; - this.tag = tag; - this.link = link; - this.reflink = reflink; - this.nolink = nolink; - this.strong = strong; - this.em = em; - this.code = code; - this.br = br; - this.del = del; - this.text = text; - } - - private static InlineRules inline() { - RegExp escape = new RegExp("^\\\\([\\\\`*{}\\[\\]()#+\\-.!_>])"); - RegExp autolink = new RegExp("^<([^ >]+(@|:\\/)[^ >]+)>"); - RegExp url = RegExp.noop(); - RegExp tag = new RegExp("^|^<\\/?\\w+(?:\"[^\"]*\"|'[^']*'|[^'\">])*?>"); - RegExp link = new RegExp("^!?\\[(inside)\\]\\(href\\)"); - RegExp reflink = new RegExp("^!?\\[(inside)\\]\\s*\\[([^\\]]*)\\]"); - RegExp nolink = new RegExp("^!?\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\]"); - RegExp strong = new RegExp("^__([\\s\\S]+?)__(?!_)|^\\*\\*([\\s\\S]+?)\\*\\*(?!\\*)"); - RegExp em = new RegExp("^\\b_((?:[^_]|__)+?)_\\b|^\\*((?:\\*\\*|[\\s\\S])+?)\\*(?!\\*)"); - RegExp code = new RegExp("^(`+)\\s*([\\s\\S]*?[^`])\\s*\\1(?!`)"); - RegExp br = new RegExp("^ {2,}\\n(?!\\s*$)"); - RegExp del = RegExp.noop(); - RegExp text = new RegExp("^[\\s\\S]+?(?=[\\\\?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*"; + + public static final InlineRules normal = normal(); + + public static final InlineRules pedantic = pedantic(); + + public static final InlineRules gfm = gfm(); + + public static final InlineRules breaks = breaks(); + + public final RegExp escape; + public final RegExp autolink; + public final RegExp url; + public final RegExp tag; + public final RegExp link; + public final RegExp reflink; + public final RegExp nolink; + public final RegExp strong; + public final RegExp em; + public final RegExp code; + public final RegExp br; + public final RegExp del; + public final RegExp text; + + public InlineRules(RegExp escape, RegExp autolink, RegExp url, RegExp tag, RegExp link, RegExp reflink, + RegExp nolink, RegExp strong, RegExp em, RegExp code, RegExp br, RegExp del, RegExp text) { + this.escape = escape; + this.autolink = autolink; + this.url = url; + this.tag = tag; + this.link = link; + this.reflink = reflink; + this.nolink = nolink; + this.strong = strong; + this.em = em; + this.code = code; + this.br = br; + this.del = del; + this.text = text; + } + + private static InlineRules inline() { + RegExp escape = new RegExp("^\\\\([\\\\`*{}\\[\\]()#+\\-.!_>])"); + RegExp autolink = new RegExp("^<([^ >]+(@|:\\/)[^ >]+)>"); + RegExp url = RegExp.noop(); + RegExp tag = new RegExp("^|^<\\/?\\w+(?:\"[^\"]*\"|'[^']*'|[^'\">])*?>"); + RegExp link = new RegExp("^!?\\[(inside)\\]\\(href\\)"); + RegExp reflink = new RegExp("^!?\\[(inside)\\]\\s*\\[([^\\]]*)\\]"); + RegExp nolink = new RegExp("^!?\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\]"); + RegExp strong = new RegExp("^__([\\s\\S]+?)__(?!_)|^\\*\\*([\\s\\S]+?)\\*\\*(?!\\*)"); + RegExp em = new RegExp("^\\b_((?:[^_]|__)+?)_\\b|^\\*((?:\\*\\*|[\\s\\S])+?)\\*(?!\\*)"); + RegExp code = new RegExp("^(`+)\\s*([\\s\\S]*?[^`])\\s*\\1(?!`)"); + RegExp br = new RegExp("^ {2,}\\n(?!\\s*$)"); + RegExp del = RegExp.noop(); + RegExp text = new RegExp("^[\\s\\S]+?(?=[\\\\ - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -import static org.eclipse.tm4e.markdown.marked.Helpers.isEmpty; - -import java.util.regex.Matcher; - -public class Lexer { - - private BlockRules rules; - private final Tokens tokens; - private final Options options; - - public Lexer(Options options) { - this.tokens = new Tokens(); - this.options = options != null ? options : Options.DEFAULTS; - this.rules = BlockRules.normal; - - if (this.options.isGfm()) { - if (this.options.isTables()) { - this.rules = BlockRules.tables; - } else { - this.rules = BlockRules.gfm; - } - } - } - - public static Tokens lex(String src, Options options) { - Lexer lexer = new Lexer(options); - return lexer.lex(src); - } - - private Tokens lex(String src) { - src = src.replaceAll("\r\n|\r", "\n").replaceAll("\t", " ").replaceAll("\u00a0", " ").replaceAll("\u2424", - "\n"); - return this.token(src, true); - } - - private Tokens token(String src, boolean top) { - return token(src, top, null); - } - - private Tokens token(String src, boolean top, Object bq) { - src = src.replaceAll("^ +$", ""); - Matcher cap; - while (!isEmpty(src)) { - - // newline - if ((cap = this.rules.newline.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - if (cap.group(0).length() > 1) { - this.tokens.add(new Token(TokenType.space)); - } - } - - // code - // if ((cap = this.rules.code.exec(src)) != null) { - // src = src.substring(cap.group(0).length()); - // cap = cap.group(0).matches("^ {4}", ""); - // String text = !this.options.pedantic - // ? cap.replace(/\n+$/, '') - // : cap; - // this.tokens.add(new Token(TokenType.type)); - // continue; - // } - - // fences (gfm) - if ((cap = this.rules.fences.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - String lang = cap.group(2); - String text = !isEmpty(cap.group(3)) ? cap.group(3) : ""; - this.tokens.add(new Token(TokenType.code, lang, text)); - continue; - } - - // heading - if ((cap = this.rules.heading.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - String text = cap.group(2); - int depth = cap.group(1).length(); - this.tokens.add(new Token(TokenType.heading, text, depth)); - continue; - } - - // table no leading pipe (gfm) - // TODO - - // lheading - if ((cap = this.rules.lheading.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - String text = cap.group(1); - int depth = cap.group(2).equals("=") ? 1 : 2; - this.tokens.add(new Token(TokenType.heading, text, depth)); - continue; - } - - // hr - if ((cap = this.rules.hr.exec(src)) != null) { - src = src.substring(cap.group(0).length()); - this.tokens.add(new Token(TokenType.hr)); - continue; - } - - // top-level paragraph - if (top && ((cap = this.rules.paragraph.exec(src)) != null)) { - src = src.substring(cap.group(0).length()); - String text = cap.group(1).charAt(cap.group(1).length() - 1) == '\n' ? cap.group(1) : cap.group(1); - this.tokens.add(new Token(TokenType.paragraph, text)); - continue; - } - } - return this.tokens; - } - -} + */ +package org.eclipse.tm4e.markdown.marked; + +import static org.eclipse.tm4e.markdown.marked.Helpers.isEmpty; + +import java.util.regex.Matcher; + +public class Lexer { + + private BlockRules rules; + private final Tokens tokens; + private final Options options; + + public Lexer(Options options) { + this.tokens = new Tokens(); + this.options = options != null ? options : Options.DEFAULTS; + this.rules = BlockRules.normal; + + if (this.options.isGfm()) { + if (this.options.isTables()) { + this.rules = BlockRules.tables; + } else { + this.rules = BlockRules.gfm; + } + } + } + + public static Tokens lex(String src, Options options) { + Lexer lexer = new Lexer(options); + return lexer.lex(src); + } + + private Tokens lex(String src) { + src = src.replaceAll("\r\n|\r", "\n").replaceAll("\t", " ").replaceAll("\u00a0", " ").replaceAll("\u2424", + "\n"); + return this.token(src, true); + } + + private Tokens token(String src, boolean top) { + return token(src, top, null); + } + + private Tokens token(String src, boolean top, Object bq) { + src = src.replaceAll("^ +$", ""); + Matcher cap; + while (!isEmpty(src)) { + + // newline + if ((cap = this.rules.newline.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + if (cap.group(0).length() > 1) { + this.tokens.add(new Token(TokenType.space)); + } + } + + // code + // if ((cap = this.rules.code.exec(src)) != null) { + // src = src.substring(cap.group(0).length()); + // cap = cap.group(0).matches("^ {4}", ""); + // String text = !this.options.pedantic + // ? cap.replace(/\n+$/, '') + // : cap; + // this.tokens.add(new Token(TokenType.type)); + // continue; + // } + + // fences (gfm) + if ((cap = this.rules.fences.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + String lang = cap.group(2); + String text = !isEmpty(cap.group(3)) ? cap.group(3) : ""; + this.tokens.add(new Token(TokenType.code, lang, text)); + continue; + } + + // heading + if ((cap = this.rules.heading.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + String text = cap.group(2); + int depth = cap.group(1).length(); + this.tokens.add(new Token(TokenType.heading, text, depth)); + continue; + } + + // table no leading pipe (gfm) + // TODO + + // lheading + if ((cap = this.rules.lheading.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + String text = cap.group(1); + int depth = cap.group(2).equals("=") ? 1 : 2; + this.tokens.add(new Token(TokenType.heading, text, depth)); + continue; + } + + // hr + if ((cap = this.rules.hr.exec(src)) != null) { + src = src.substring(cap.group(0).length()); + this.tokens.add(new Token(TokenType.hr)); + continue; + } + + // top-level paragraph + if (top && ((cap = this.rules.paragraph.exec(src)) != null)) { + src = src.substring(cap.group(0).length()); + String text = cap.group(1).charAt(cap.group(1).length() - 1) == '\n' ? cap.group(1) : cap.group(1); + this.tokens.add(new Token(TokenType.paragraph, text)); + continue; + } + } + return this.tokens; + } + +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java index ee2267bfe..d5c48eaf2 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java @@ -13,25 +13,25 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public class Marked { - - public static IRenderer parse(String src) { - return parse(src, (Options) null); - } - - public static IRenderer parse(String src, IRenderer renderer) { - return parse(src, null, renderer); - } - - public static IRenderer parse(String src, Options opt) { - return parse(src, opt, null); - } - - public static IRenderer parse(String src, Options opt, IRenderer renderer) { - - return Parser.parse(Lexer.lex(src, opt), opt, renderer); - } -} + */ +package org.eclipse.tm4e.markdown.marked; + +public class Marked { + + public static IRenderer parse(String src) { + return parse(src, (Options) null); + } + + public static IRenderer parse(String src, IRenderer renderer) { + return parse(src, null, renderer); + } + + public static IRenderer parse(String src, Options opt) { + return parse(src, opt, null); + } + + public static IRenderer parse(String src, Options opt, IRenderer renderer) { + + return Parser.parse(Lexer.lex(src, opt), opt, renderer); + } +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Options.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Options.java index bf86ef868..1df952592 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Options.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Options.java @@ -13,52 +13,52 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public class Options { - - public static final Options DEFAULTS = new Options(); - - private boolean gfm; - private boolean breaks; - private boolean pedantic; - private boolean tables; - - public Options() { - this.gfm = true; - } - - public boolean isGfm() { - return gfm; - } - - public void setGfm(boolean gfm) { - this.gfm = gfm; - } - - public boolean isBreaks() { - return breaks; - } - - public void setBreaks(boolean breaks) { - this.breaks = breaks; - } - - public boolean isPedantic() { - return pedantic; - } - - public void setPedantic(boolean pedantic) { - this.pedantic = pedantic; - } - - public boolean isTables() { - return tables; - } - - public void setTables(boolean tables) { - this.tables = tables; - } - -} + */ +package org.eclipse.tm4e.markdown.marked; + +public class Options { + + public static final Options DEFAULTS = new Options(); + + private boolean gfm; + private boolean breaks; + private boolean pedantic; + private boolean tables; + + public Options() { + this.gfm = true; + } + + public boolean isGfm() { + return gfm; + } + + public void setGfm(boolean gfm) { + this.gfm = gfm; + } + + public boolean isBreaks() { + return breaks; + } + + public void setBreaks(boolean breaks) { + this.breaks = breaks; + } + + public boolean isPedantic() { + return pedantic; + } + + public void setPedantic(boolean pedantic) { + this.pedantic = pedantic; + } + + public boolean isTables() { + return tables; + } + + public void setTables(boolean tables) { + this.tables = tables; + } + +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java index 6b4b81ea2..f066a947a 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java @@ -13,74 +13,74 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public class Parser { - - private Tokens tokens; - private Token token; - private Options options; - private InlineLexer inline; - private IRenderer renderer; - - public Parser(Options options, IRenderer renderer) { - this.tokens = new Tokens(); - this.token = null; - this.options = options != null ? options : Options.DEFAULTS; - this.renderer = renderer != null ? renderer : new HTMLRenderer(); - } - - public static IRenderer parse(Tokens src, Options options, IRenderer renderer) { - Parser parser = new Parser(options, renderer); - return parser.parse(src); - } - - private IRenderer parse(Tokens src) { - this.inline = new InlineLexer(src.links, this.options, this.renderer); - this.tokens = src.reverse(); - - // var out = ''; - while (this.next()) { - // out += this.tok(); - this.tok(); - } - - return renderer; - } - - /** - * Next Token - */ - private boolean next() { - return ((this.token = this.tokens.pop()) != null); - } - - /** - * Parse Current Token - */ - private void tok() { - switch (this.token.type) { - case space: - break; - case hr: - this.renderer.hr(); - break; - case heading: - // this.renderer.heading(this.inline.output(this.token.text), - // this.token.depth, this.token.text); - this.renderer.heading(this.token.text, this.token.depth, this.token.text); - break; - case code: - this.renderer.code(this.token.text, this.token.lang, this.token.escaped); - break; - case paragraph: - this.renderer.startParagraph(); - this.inline.output(this.token.text); - this.renderer.endParagraph(); - break; - } - - } - -} + */ +package org.eclipse.tm4e.markdown.marked; + +public class Parser { + + private Tokens tokens; + private Token token; + private Options options; + private InlineLexer inline; + private IRenderer renderer; + + public Parser(Options options, IRenderer renderer) { + this.tokens = new Tokens(); + this.token = null; + this.options = options != null ? options : Options.DEFAULTS; + this.renderer = renderer != null ? renderer : new HTMLRenderer(); + } + + public static IRenderer parse(Tokens src, Options options, IRenderer renderer) { + Parser parser = new Parser(options, renderer); + return parser.parse(src); + } + + private IRenderer parse(Tokens src) { + this.inline = new InlineLexer(src.links, this.options, this.renderer); + this.tokens = src.reverse(); + + // var out = ''; + while (this.next()) { + // out += this.tok(); + this.tok(); + } + + return renderer; + } + + /** + * Next Token + */ + private boolean next() { + return ((this.token = this.tokens.pop()) != null); + } + + /** + * Parse Current Token + */ + private void tok() { + switch (this.token.type) { + case space: + break; + case hr: + this.renderer.hr(); + break; + case heading: + // this.renderer.heading(this.inline.output(this.token.text), + // this.token.depth, this.token.text); + this.renderer.heading(this.token.text, this.token.depth, this.token.text); + break; + case code: + this.renderer.code(this.token.text, this.token.lang, this.token.escaped); + break; + case paragraph: + this.renderer.startParagraph(); + this.inline.output(this.token.text); + this.renderer.endParagraph(); + break; + } + + } + +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java index ff0e17bf9..5b833e689 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java @@ -13,61 +13,61 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class RegExp { - - protected String source; - private Pattern pattern; - - public RegExp(String source) { - this.source = source; - } - - public Matcher exec(String s) { - if (source == null) { - return null; - } - if (pattern == null) { - pattern = Pattern.compile(source); - } - Matcher matcher = pattern.matcher(s); - if (matcher.find()) { - return matcher; - } - return null; - } - - public RegExp replace(String name, RegExp val) { - return replace(name, val.source); - } - - public RegExp replace(String name, String val) { - if (name == null) - return new RegExp(this.source); - val = val.replaceAll("(^|[^\\[])\\^", "$1"); - this.source = this.source.replaceFirst(name, Matcher.quoteReplacement(val)); - return this; - } - - public RegExp replaceAll(String name, RegExp val) { - return replaceAll(name, val.source); - } - - public RegExp replaceAll(String name, String val) { - if (name == null) - return new RegExp(this.source); - val = val.replaceAll("(^|[^\\[])\\^", "$1"); - this.source = this.source.replaceAll(name, Matcher.quoteReplacement(val)); - return this; - } - - public static final RegExp noop() { - return new RegExp(null); - } - -} + */ +package org.eclipse.tm4e.markdown.marked; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RegExp { + + protected String source; + private Pattern pattern; + + public RegExp(String source) { + this.source = source; + } + + public Matcher exec(String s) { + if (source == null) { + return null; + } + if (pattern == null) { + pattern = Pattern.compile(source); + } + Matcher matcher = pattern.matcher(s); + if (matcher.find()) { + return matcher; + } + return null; + } + + public RegExp replace(String name, RegExp val) { + return replace(name, val.source); + } + + public RegExp replace(String name, String val) { + if (name == null) + return new RegExp(this.source); + val = val.replaceAll("(^|[^\\[])\\^", "$1"); + this.source = this.source.replaceFirst(name, Matcher.quoteReplacement(val)); + return this; + } + + public RegExp replaceAll(String name, RegExp val) { + return replaceAll(name, val.source); + } + + public RegExp replaceAll(String name, String val) { + if (name == null) + return new RegExp(this.source); + val = val.replaceAll("(^|[^\\[])\\^", "$1"); + this.source = this.source.replaceAll(name, Matcher.quoteReplacement(val)); + return this; + } + + public static final RegExp noop() { + return new RegExp(null); + } + +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java index 143f0f07a..9fe204c8c 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java @@ -13,38 +13,38 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public class Token { - - public final TokenType type; - public final String text; - public final int depth; - public final String lang; - public final boolean escaped; - - public Token(TokenType type) { - this(type, null); - } - - public Token(TokenType type, String text) { - this(type, text, -1); - } - - public Token(TokenType type, String text, int depth) { - this(type, text, depth, null, false); - } - - public Token(TokenType type, String lang, String text) { - this(type, text, -1, lang, false); - } - - private Token(TokenType type, String text, int depth, String lang, boolean escaped) { - this.type = type; - this.text = text; - this.depth = depth; - this.lang = lang; - this.escaped = escaped; - } -} + */ +package org.eclipse.tm4e.markdown.marked; + +public class Token { + + public final TokenType type; + public final String text; + public final int depth; + public final String lang; + public final boolean escaped; + + public Token(TokenType type) { + this(type, null); + } + + public Token(TokenType type, String text) { + this(type, text, -1); + } + + public Token(TokenType type, String text, int depth) { + this(type, text, depth, null, false); + } + + public Token(TokenType type, String lang, String text) { + this(type, text, -1, lang, false); + } + + private Token(TokenType type, String text, int depth, String lang, boolean escaped) { + this.type = type; + this.text = text; + this.depth = depth; + this.lang = lang; + this.escaped = escaped; + } +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/TokenType.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/TokenType.java index d15dfd1e7..90b14e2a7 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/TokenType.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/TokenType.java @@ -13,10 +13,10 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -public enum TokenType { - - space, hr, heading, code, table, blockquote_start, blockquote_end, list_start, list_end, list_item_start, list_item_end, loose_item_start, html, paragraph, text; -} + */ +package org.eclipse.tm4e.markdown.marked; + +public enum TokenType { + + space, hr, heading, code, table, blockquote_start, blockquote_end, list_start, list_end, list_item_start, list_item_end, loose_item_start, html, paragraph, text; +} diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java index 597f0c3db..dff707ae3 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java @@ -13,26 +13,26 @@ * Contributors: * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.markdown.marked; - -import java.util.ArrayList; -import java.util.Collections; - -public class Tokens extends ArrayList { - - public Object links; - - public Tokens reverse() { - Collections.reverse(this); - return this; - } - - public Token pop() { - if (super.isEmpty()) { - return null; - } - return super.remove(super.size() - 1); - } - -} + */ +package org.eclipse.tm4e.markdown.marked; + +import java.util.ArrayList; +import java.util.Collections; + +public class Tokens extends ArrayList { + + public Object links; + + public Tokens reverse() { + Collections.reverse(this); + return this; + } + + public Token pop() { + if (super.isEmpty()) { + return null; + } + return super.remove(super.size() - 1); + } + +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java index a067c4dbe..b5d9e2a45 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java @@ -1,61 +1,61 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -import org.eclipse.core.runtime.IConfigurationElement; - -/** - * Grammar definition defined by the "org.eclipse.tm4e.registry.grammars" - * extension point. Here a sample to register TypeScript TextMate grammar. - * - *
- * 
-      
-      
-   
- * 
- * - */ -public class GrammarDefinition extends TMResource implements IGrammarDefinition { - - private String scopeName; - - /** - * Constructor for user preferences (loaded from Json with Gson). - */ - public GrammarDefinition() { - super(); - } - - /** - * Constructor for extension point. - * - * @param scopeName - */ - public GrammarDefinition(String scopeName, String path) { - super(path); - this.scopeName = scopeName; - } - - public GrammarDefinition(IConfigurationElement ce) { - super(ce); - this.scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); - } - - @Override - public String getScopeName() { - return scopeName; - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +import org.eclipse.core.runtime.IConfigurationElement; + +/** + * Grammar definition defined by the "org.eclipse.tm4e.registry.grammars" + * extension point. Here a sample to register TypeScript TextMate grammar. + * + *
+ * 
+      
+      
+   
+ * 
+ * + */ +public class GrammarDefinition extends TMResource implements IGrammarDefinition { + + private String scopeName; + + /** + * Constructor for user preferences (loaded from Json with Gson). + */ + public GrammarDefinition() { + super(); + } + + /** + * Constructor for extension point. + * + * @param scopeName + */ + public GrammarDefinition(String scopeName, String path) { + super(path); + this.scopeName = scopeName; + } + + public GrammarDefinition(IConfigurationElement ce) { + super(ce); + this.scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); + } + + @Override + public String getScopeName() { + return scopeName; + } +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarDefinition.java index d4cfc1470..b53be1a0b 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarDefinition.java @@ -1,26 +1,26 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -/** - * TextMate grammar definition API. - * - */ -public interface IGrammarDefinition extends ITMResource { - - /** - * Returns the scope name of the TextMate grammar. - * - * @return the scope name of the TextMate grammar. - */ - String getScopeName(); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +/** + * TextMate grammar definition API. + * + */ +public interface IGrammarDefinition extends ITMResource { + + /** + * Returns the scope name of the TextMate grammar. + * + * @return the scope name of the TextMate grammar. + */ + String getScopeName(); +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java index 79c8662f3..0ff301f53 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java @@ -1,100 +1,100 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.osgi.service.prefs.BackingStoreException; - -/** - * - * TextMate Grammar registry manager API. - * - */ -public interface IGrammarRegistryManager { - - // --------------- TextMate grammar definitions methods - - /** - * Returns the list of registered TextMate grammar definitions. - * - * @return the list of registered TextMate grammar definitions. - */ - IGrammarDefinition[] getDefinitions(); - - /** - * Add grammar definition to the registry. - * - * NOTE: you must call save() method if you wish to save in the preferences. - * - * @param definition - */ - void registerGrammarDefinition(IGrammarDefinition definition); - - /** - * Remove grammar definition from the registry. - * - * NOTE: you must call save() method if you wish to save in the preferences. - * - * @param definition - */ - void unregisterGrammarDefinition(IGrammarDefinition definition); - - /** - * Save the grammar definitions. - * @throws BackingStoreException - */ - void save() throws BackingStoreException; - - // --------------- TextMate grammar queries methods. - - /** - * @param contentTypes the content types to lookup for grammar association. - * @return the first {@link IGrammar} that applies to given content-types, or - * null if no content-type has a grammar associated. Grammars associated - * with parent content-types will be returned if applicable. - */ - IGrammar getGrammarFor(IContentType[] contentTypes); - - /** - * Returns the {@link IGrammar} for the given scope name and null otherwise. - * - * @param contentTypes - * the content type. - * @return the {@link IGrammar} for the given scope name and null otherwise. - */ - IGrammar getGrammarForScope(String scopeName); - - /** - * Returns the {@link IGrammar} for the given file type and null otherwise. - * - * @param contentTypes - * the content type. - * @return the {@link IGrammar} for the file type name and null otherwise. - */ - IGrammar getGrammarForFileType(String fileType); - - /** - * Returns the list of content types bound with the given scope name and - * null otherwise. - * - * @param scopeName - * @return the list of content types bound with the given scope name and - * null otherwise. - */ - List getContentTypesForScope(String scopeName); - - Collection getInjections(String scopeName); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.osgi.service.prefs.BackingStoreException; + +/** + * + * TextMate Grammar registry manager API. + * + */ +public interface IGrammarRegistryManager { + + // --------------- TextMate grammar definitions methods + + /** + * Returns the list of registered TextMate grammar definitions. + * + * @return the list of registered TextMate grammar definitions. + */ + IGrammarDefinition[] getDefinitions(); + + /** + * Add grammar definition to the registry. + * + * NOTE: you must call save() method if you wish to save in the preferences. + * + * @param definition + */ + void registerGrammarDefinition(IGrammarDefinition definition); + + /** + * Remove grammar definition from the registry. + * + * NOTE: you must call save() method if you wish to save in the preferences. + * + * @param definition + */ + void unregisterGrammarDefinition(IGrammarDefinition definition); + + /** + * Save the grammar definitions. + * @throws BackingStoreException + */ + void save() throws BackingStoreException; + + // --------------- TextMate grammar queries methods. + + /** + * @param contentTypes the content types to lookup for grammar association. + * @return the first {@link IGrammar} that applies to given content-types, or + * null if no content-type has a grammar associated. Grammars associated + * with parent content-types will be returned if applicable. + */ + IGrammar getGrammarFor(IContentType[] contentTypes); + + /** + * Returns the {@link IGrammar} for the given scope name and null otherwise. + * + * @param contentTypes + * the content type. + * @return the {@link IGrammar} for the given scope name and null otherwise. + */ + IGrammar getGrammarForScope(String scopeName); + + /** + * Returns the {@link IGrammar} for the given file type and null otherwise. + * + * @param contentTypes + * the content type. + * @return the {@link IGrammar} for the file type name and null otherwise. + */ + IGrammar getGrammarForFileType(String fileType); + + /** + * Returns the list of content types bound with the given scope name and + * null otherwise. + * + * @param scopeName + * @return the list of content types bound with the given scope name and + * null otherwise. + */ + List getContentTypesForScope(String scopeName); + + Collection getInjections(String scopeName); +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java index c9dda95b4..52bce04a1 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java @@ -1,27 +1,27 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -/** - * TextMate definition API. - * - */ -public interface ITMDefinition { - - /** - * Returns the plugin id which has registered the TextMate resource. - * - * @return the plugin id which has registered the TextMate resource. - */ - String getPluginId(); - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +/** + * TextMate definition API. + * + */ +public interface ITMDefinition { + + /** + * Returns the plugin id which has registered the TextMate resource. + * + * @return the plugin id which has registered the TextMate resource. + */ + String getPluginId(); + +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java index 7358d08b6..7c32e1f07 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java @@ -1,37 +1,37 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -import java.io.IOException; -import java.io.InputStream; - -/** - * TextMate resource definition API. - * - */ -public interface ITMResource extends ITMDefinition { - - /** - * Returns the TextMate resource path. - * - * @return the TextMate resource path. - */ - String getPath(); - - /** - * Returns the stream of the TextMate resource. - * - * @return the stream of the TextMate resource. - * @throws IOException - */ - InputStream getInputStream() throws IOException; -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +import java.io.IOException; +import java.io.InputStream; + +/** + * TextMate resource definition API. + * + */ +public interface ITMResource extends ITMDefinition { + + /** + * Returns the TextMate resource path. + * + * @return the TextMate resource path. + */ + String getPath(); + + /** + * Returns the stream of the TextMate resource. + * + * @return the stream of the TextMate resource. + * @throws IOException + */ + InputStream getInputStream() throws IOException; +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java index 1ebaa1b48..138f167b8 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java @@ -1,63 +1,63 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.tm4e.registry.internal.GrammarRegistryManager; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -/** - * OSGi Activator for TextMate Eclipse registry bundle. - * - */ -public class TMEclipseRegistryPlugin implements BundleActivator { - - public static final String PLUGIN_ID = "org.eclipse.tm4e.registry"; - - private static BundleContext context; - - static BundleContext getContext() { - return context; - } - - @Override - public void start(BundleContext bundleContext) throws Exception { - TMEclipseRegistryPlugin.context = bundleContext; - } - - @Override - public void stop(BundleContext bundleContext) throws Exception { - TMEclipseRegistryPlugin.context = null; - } - - /** - * Returns the TextMate grammar manager. - * - * @return the TextMate grammar manager. - */ - public static IGrammarRegistryManager getGrammarRegistryManager() { - return GrammarRegistryManager.getInstance(); - } - - /** - * Returns true if the debug option is enabled and false otherwise. - * - * @param option - * the option name - * @return true if the debug option is enabled and false otherwise. - */ - public static boolean isDebugOptionEnabled(String option) { - String enabled = Platform.getDebugOption(option); - return enabled != null && Boolean.parseBoolean(enabled); - } + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.tm4e.registry.internal.GrammarRegistryManager; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * OSGi Activator for TextMate Eclipse registry bundle. + * + */ +public class TMEclipseRegistryPlugin implements BundleActivator { + + public static final String PLUGIN_ID = "org.eclipse.tm4e.registry"; + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + @Override + public void start(BundleContext bundleContext) throws Exception { + TMEclipseRegistryPlugin.context = bundleContext; + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + TMEclipseRegistryPlugin.context = null; + } + + /** + * Returns the TextMate grammar manager. + * + * @return the TextMate grammar manager. + */ + public static IGrammarRegistryManager getGrammarRegistryManager() { + return GrammarRegistryManager.getInstance(); + } + + /** + * Returns true if the debug option is enabled and false otherwise. + * + * @param option + * the option name + * @return true if the debug option is enabled and false otherwise. + */ + public static boolean isDebugOptionEnabled(String option) { + String enabled = Platform.getDebugOption(option); + return enabled != null && Boolean.parseBoolean(enabled); + } } \ No newline at end of file diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index 3e5e4b055..8d4f21d52 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -1,100 +1,100 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Scanner; - -import org.eclipse.core.runtime.IConfigurationElement; - -/** - * TextMate Resource. - */ -public class TMResource implements ITMResource { - - private static final String PLATFORM_PLUGIN = "platform:/plugin/"; //$NON-NLS-1$ - - private String path; - private String pluginId; - - /** - * Constructor for user preferences (loaded from Json with Gson). - */ - public TMResource() { - - } - - /** - * Constructor for extension point. - * - * @param path - */ - public TMResource(String path) { - this.path = path; - } - - public TMResource(IConfigurationElement ce) { - this(ce.getAttribute(XMLConstants.PATH_ATTR)); - this.pluginId = ce.getNamespaceIdentifier(); - } - - public TMResource(String path, String pluginId) { - this.path = path; - this.pluginId = pluginId; - } - - @Override - public String getPath() { - return path; - } - - @Override - public String getPluginId() { - return pluginId; - } - - @Override - public InputStream getInputStream() throws IOException { - if (path == null || path.length() < 0) { - return null; - } - if (pluginId != null) { - URL url = new URL(new StringBuilder(PLATFORM_PLUGIN).append(pluginId).append("/").append(path).toString()); - return url.openStream(); - } - return new FileInputStream(new File(path)); - } - - protected String getResourceContent() { - try { - InputStream in = this.getInputStream(); - if (in == null) { - return null; - } - return convertStreamToString(in); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - private static String convertStreamToString(InputStream is) { - try (Scanner s = new Scanner(is)) { - s.useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; - } - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Scanner; + +import org.eclipse.core.runtime.IConfigurationElement; + +/** + * TextMate Resource. + */ +public class TMResource implements ITMResource { + + private static final String PLATFORM_PLUGIN = "platform:/plugin/"; //$NON-NLS-1$ + + private String path; + private String pluginId; + + /** + * Constructor for user preferences (loaded from Json with Gson). + */ + public TMResource() { + + } + + /** + * Constructor for extension point. + * + * @param path + */ + public TMResource(String path) { + this.path = path; + } + + public TMResource(IConfigurationElement ce) { + this(ce.getAttribute(XMLConstants.PATH_ATTR)); + this.pluginId = ce.getNamespaceIdentifier(); + } + + public TMResource(String path, String pluginId) { + this.path = path; + this.pluginId = pluginId; + } + + @Override + public String getPath() { + return path; + } + + @Override + public String getPluginId() { + return pluginId; + } + + @Override + public InputStream getInputStream() throws IOException { + if (path == null || path.length() < 0) { + return null; + } + if (pluginId != null) { + URL url = new URL(new StringBuilder(PLATFORM_PLUGIN).append(pluginId).append("/").append(path).toString()); + return url.openStream(); + } + return new FileInputStream(new File(path)); + } + + protected String getResourceContent() { + try { + InputStream in = this.getInputStream(); + if (in == null) { + return null; + } + return convertStreamToString(in); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static String convertStreamToString(InputStream is) { + try (Scanner s = new Scanner(is)) { + s.useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } + } +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java index 632e0f507..26ac52771 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java @@ -1,95 +1,95 @@ -/** - * Copyright (c) 2015, 2021 Angelo ZERR and others. +/** + * Copyright (c) 2015, 2021 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.tm4e.registry.internal.AbstractGrammarRegistryManager; -import org.osgi.service.prefs.BackingStoreException; - -/** - * Working copy of grammar registry manager. - * - */ -public class WorkingCopyGrammarRegistryManager extends AbstractGrammarRegistryManager { - - private final IGrammarRegistryManager manager; - - private List added; - - private List removed; - - public WorkingCopyGrammarRegistryManager(IGrammarRegistryManager manager) { - this.manager = manager; - load(); - } - - private void load() { - // Copy grammar definitions - IGrammarDefinition[] definitions = manager.getDefinitions(); - for (IGrammarDefinition definition : definitions) { - super.registerGrammarDefinition(definition); - // Copy binding scope/content types - String scopeName = definition.getScopeName(); - manager.getContentTypesForScope(scopeName).forEach(contentType -> super.registerContentTypeBinding(contentType, scopeName)); - // Copy injection - Collection injections = manager.getInjections(scopeName); - if (injections != null) { - for (String injectFrom : injections) { - super.registerInjection(injectFrom, scopeName); - } - } - } - } - - @Override - public void registerGrammarDefinition(IGrammarDefinition definition) { - super.registerGrammarDefinition(definition); - if (added == null) { - added = new ArrayList<>(); - } - added.add(definition); - } - - @Override - public void unregisterGrammarDefinition(IGrammarDefinition definition) { - super.unregisterGrammarDefinition(definition); - if (added != null && added.contains(definition)) { - added.remove(definition); - } else { - if (removed == null) { - removed = new ArrayList<>(); - } - removed.add(definition); - } - } - - @Override - public void save() throws BackingStoreException { - if (added != null) { - for (IGrammarDefinition definition : added) { - manager.registerGrammarDefinition(definition); - } - } - if (removed != null) { - for (IGrammarDefinition definition : removed) { - manager.unregisterGrammarDefinition(definition); - } - } - if (added != null || removed != null) { - manager.save(); - } - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.tm4e.registry.internal.AbstractGrammarRegistryManager; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Working copy of grammar registry manager. + * + */ +public class WorkingCopyGrammarRegistryManager extends AbstractGrammarRegistryManager { + + private final IGrammarRegistryManager manager; + + private List added; + + private List removed; + + public WorkingCopyGrammarRegistryManager(IGrammarRegistryManager manager) { + this.manager = manager; + load(); + } + + private void load() { + // Copy grammar definitions + IGrammarDefinition[] definitions = manager.getDefinitions(); + for (IGrammarDefinition definition : definitions) { + super.registerGrammarDefinition(definition); + // Copy binding scope/content types + String scopeName = definition.getScopeName(); + manager.getContentTypesForScope(scopeName).forEach(contentType -> super.registerContentTypeBinding(contentType, scopeName)); + // Copy injection + Collection injections = manager.getInjections(scopeName); + if (injections != null) { + for (String injectFrom : injections) { + super.registerInjection(injectFrom, scopeName); + } + } + } + } + + @Override + public void registerGrammarDefinition(IGrammarDefinition definition) { + super.registerGrammarDefinition(definition); + if (added == null) { + added = new ArrayList<>(); + } + added.add(definition); + } + + @Override + public void unregisterGrammarDefinition(IGrammarDefinition definition) { + super.unregisterGrammarDefinition(definition); + if (added != null && added.contains(definition)) { + added.remove(definition); + } else { + if (removed == null) { + removed = new ArrayList<>(); + } + removed.add(definition); + } + } + + @Override + public void save() throws BackingStoreException { + if (added != null) { + for (IGrammarDefinition definition : added) { + manager.registerGrammarDefinition(definition); + } + } + if (removed != null) { + for (IGrammarDefinition definition : removed) { + manager.unregisterGrammarDefinition(definition); + } + } + if (added != null || removed != null) { + manager.save(); + } + } + +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java index 50324c392..80f4482c7 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java @@ -1,37 +1,37 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry; - -/** - * XML constants used with the "org.eclipse.tm4e.registry.grammars" extension - * point. - * - */ -public class XMLConstants { - - // grammar definition - public static final String GRAMMAR_ELT = "grammar"; - public static final String NAME_ATTR = "name"; - public static final String SCOPE_NAME_ATTR = "scopeName"; - public static final String PATH_ATTR = "path"; - - // scopeNameContentTypeBinding definition - public static final String SCOPE_NAME_CONTENT_TYPE_BINDING_ELT = "scopeNameContentTypeBinding"; - public static final String CONTENT_TYPE_ID_ATTR = "contentTypeId"; - - // injection definition - public static final String INJECTION_ELT = "injection"; - public static final String INJECT_TO_ATTR = "injectTo"; - - public static final String ID_ATTR = "id"; - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry; + +/** + * XML constants used with the "org.eclipse.tm4e.registry.grammars" extension + * point. + * + */ +public class XMLConstants { + + // grammar definition + public static final String GRAMMAR_ELT = "grammar"; + public static final String NAME_ATTR = "name"; + public static final String SCOPE_NAME_ATTR = "scopeName"; + public static final String PATH_ATTR = "path"; + + // scopeNameContentTypeBinding definition + public static final String SCOPE_NAME_CONTENT_TYPE_BINDING_ELT = "scopeNameContentTypeBinding"; + public static final String CONTENT_TYPE_ID_ATTR = "contentTypeId"; + + // injection definition + public static final String INJECTION_ELT = "injection"; + public static final String INJECT_TO_ATTR = "injectTo"; + + public static final String ID_ATTR = "id"; + +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java index 3cc8e1ff5..2ba622f50 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java @@ -1,236 +1,236 @@ -/** - * Copyright (c) 2015-2019 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes - */ -package org.eclipse.tm4e.registry.internal; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.registry.IRegistryOptions; -import org.eclipse.tm4e.core.registry.Registry; -import org.eclipse.tm4e.registry.IGrammarDefinition; -import org.eclipse.tm4e.registry.IGrammarRegistryManager; - -/** - * Eclipse grammar registry. - * - */ -public abstract class AbstractGrammarRegistryManager extends Registry implements IGrammarRegistryManager { - - protected final GrammarCache pluginCache; - protected final GrammarCache userCache; - - private static class EclipseRegistryOptions implements IRegistryOptions { - - private AbstractGrammarRegistryManager registry; - - public void setRegistry(AbstractGrammarRegistryManager registry) { - this.registry = registry; - } - - @Override - public Collection getInjections(String scopeName) { - return registry.getInjections(scopeName); - } - - @Override - public String getFilePath(String scopeName) { - IGrammarDefinition info = registry.getDefinition(scopeName); - return info != null ? info.getPath() : null; - } - - @Override - public InputStream getInputStream(String scopeName) throws IOException { - IGrammarDefinition info = registry.getDefinition(scopeName); - return info != null ? info.getInputStream() : null; - } - } - - public AbstractGrammarRegistryManager() { - this(new EclipseRegistryOptions()); - ((EclipseRegistryOptions) getLocator()).setRegistry(this); - } - - public AbstractGrammarRegistryManager(IRegistryOptions locator) { - super(locator); - this.pluginCache = new GrammarCache(); - this.userCache = new GrammarCache(); - } - - @Override - public IGrammar getGrammarFor(IContentType[] contentTypes) { - if (contentTypes == null) { - return null; - } - // Find grammar by content type - for (IContentType contentType : contentTypes) { - String scopeName = getScopeNameForContentType(contentType); - if (scopeName != null) { - IGrammar grammar = getGrammarForScope(scopeName); - if (grammar != null) { - return grammar; - } - } - } - return null; - } - - @Override - public IGrammar getGrammarForScope(String scopeName) { - return getGrammar(scopeName); - } - - @Override - public IGrammar getGrammarForFileType(String fileType) { - // TODO: cache grammar by file types - IGrammarDefinition[] definitions = getDefinitions(); - // #202 - if(fileType.startsWith(".")) { - fileType=fileType.substring(1); - } - for (IGrammarDefinition definition : definitions) { - // Not very optimized because it forces the load of the whole - // grammar. - // Extension Point grammar should perhaps stores file type bindings - // like content type/scope binding? - IGrammar grammar = getGrammarForScope(definition.getScopeName()); - if (grammar != null) { - Collection fileTypes = grammar.getFileTypes(); - if (fileTypes.contains(fileType)) { - return grammar; - } - } - } - return null; - } - - /** - * Returns the whole registered grammar definition. - * - * @return - */ - @Override - public IGrammarDefinition[] getDefinitions() { - Collection pluginDefinitions = pluginCache.getDefinitions(); - Collection userDefinitions = userCache.getDefinitions(); - Collection definitions = new ArrayList<>(pluginDefinitions); - definitions.addAll(userDefinitions); - return definitions.toArray(new IGrammarDefinition[definitions.size()]); - } - - /** - * Returns the loaded grammar from the given scopeName and null - * otherwise. - * - * @param scopeName - * @return the loaded grammar from the given scopeName and null - * otherwise. - */ - public IGrammar getGrammar(String scopeName) { - if (scopeName == null) { - return null; - } - IGrammar grammar = super.grammarForScopeName(scopeName); - if (grammar != null) { - return grammar; - } - return super.loadGrammar(scopeName); - } - - /** - * Returns the grammar definition from the given scopeName and - * null otherwise. - * - * @param scopeName - * @return the grammar definition from the given scopeName and - * null otherwise. - */ - public IGrammarDefinition getDefinition(String scopeName) { - IGrammarDefinition definition = userCache.getDefinition(scopeName); - if (definition != null) { - return definition; - } - return pluginCache.getDefinition(scopeName); - } - - /** - * Returns list of scope names to inject for the given - * scopeName and null otheriwse. - * - * @param scopeName - * @return list of scope names to inject for the given - * scopeName and null otheriwse. - */ - @Override - public Collection getInjections(String scopeName) { - return pluginCache.getInjections(scopeName); - } - - /** - * Register the given scopeName to inject to the given scope - * name injectTo. - * - * @param scopeName - * @param injectTo - */ - public void registerInjection(String scopeName, String injectTo) { - pluginCache.registerInjection(scopeName, injectTo); - } - - /** - * @param contentType - * @return scope name bound with the given content type (or its base type) and - * null otherwise. - */ - public String getScopeNameForContentType(IContentType contentType) { - while (contentType != null) { - String scopeName = pluginCache.getScopeNameForContentType(contentType); - if (scopeName != null) { - return scopeName; - } - contentType = contentType.getBaseType(); - } - return null; - } - - @Override - public List getContentTypesForScope(String scopeName) { - return pluginCache.getContentTypesForScope(scopeName); - } - - public void registerContentTypeBinding(IContentType contentType, String scopeName) { - pluginCache.registerContentTypeBinding(contentType, scopeName); - } - - @Override - public void registerGrammarDefinition(IGrammarDefinition definition) { - if (definition.getPluginId() == null) { - userCache.registerGrammarDefinition(definition); - } else { - pluginCache.registerGrammarDefinition(definition); - } - } - - @Override - public void unregisterGrammarDefinition(IGrammarDefinition definition) { - if (definition.getPluginId() == null) { - userCache.unregisterGrammarDefinition(definition); - } else { - pluginCache.unregisterGrammarDefinition(definition); - } - } -} +/** + * Copyright (c) 2015-2019 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes + */ +package org.eclipse.tm4e.registry.internal; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.registry.IRegistryOptions; +import org.eclipse.tm4e.core.registry.Registry; +import org.eclipse.tm4e.registry.IGrammarDefinition; +import org.eclipse.tm4e.registry.IGrammarRegistryManager; + +/** + * Eclipse grammar registry. + * + */ +public abstract class AbstractGrammarRegistryManager extends Registry implements IGrammarRegistryManager { + + protected final GrammarCache pluginCache; + protected final GrammarCache userCache; + + private static class EclipseRegistryOptions implements IRegistryOptions { + + private AbstractGrammarRegistryManager registry; + + public void setRegistry(AbstractGrammarRegistryManager registry) { + this.registry = registry; + } + + @Override + public Collection getInjections(String scopeName) { + return registry.getInjections(scopeName); + } + + @Override + public String getFilePath(String scopeName) { + IGrammarDefinition info = registry.getDefinition(scopeName); + return info != null ? info.getPath() : null; + } + + @Override + public InputStream getInputStream(String scopeName) throws IOException { + IGrammarDefinition info = registry.getDefinition(scopeName); + return info != null ? info.getInputStream() : null; + } + } + + public AbstractGrammarRegistryManager() { + this(new EclipseRegistryOptions()); + ((EclipseRegistryOptions) getLocator()).setRegistry(this); + } + + public AbstractGrammarRegistryManager(IRegistryOptions locator) { + super(locator); + this.pluginCache = new GrammarCache(); + this.userCache = new GrammarCache(); + } + + @Override + public IGrammar getGrammarFor(IContentType[] contentTypes) { + if (contentTypes == null) { + return null; + } + // Find grammar by content type + for (IContentType contentType : contentTypes) { + String scopeName = getScopeNameForContentType(contentType); + if (scopeName != null) { + IGrammar grammar = getGrammarForScope(scopeName); + if (grammar != null) { + return grammar; + } + } + } + return null; + } + + @Override + public IGrammar getGrammarForScope(String scopeName) { + return getGrammar(scopeName); + } + + @Override + public IGrammar getGrammarForFileType(String fileType) { + // TODO: cache grammar by file types + IGrammarDefinition[] definitions = getDefinitions(); + // #202 + if(fileType.startsWith(".")) { + fileType=fileType.substring(1); + } + for (IGrammarDefinition definition : definitions) { + // Not very optimized because it forces the load of the whole + // grammar. + // Extension Point grammar should perhaps stores file type bindings + // like content type/scope binding? + IGrammar grammar = getGrammarForScope(definition.getScopeName()); + if (grammar != null) { + Collection fileTypes = grammar.getFileTypes(); + if (fileTypes.contains(fileType)) { + return grammar; + } + } + } + return null; + } + + /** + * Returns the whole registered grammar definition. + * + * @return + */ + @Override + public IGrammarDefinition[] getDefinitions() { + Collection pluginDefinitions = pluginCache.getDefinitions(); + Collection userDefinitions = userCache.getDefinitions(); + Collection definitions = new ArrayList<>(pluginDefinitions); + definitions.addAll(userDefinitions); + return definitions.toArray(new IGrammarDefinition[definitions.size()]); + } + + /** + * Returns the loaded grammar from the given scopeName and null + * otherwise. + * + * @param scopeName + * @return the loaded grammar from the given scopeName and null + * otherwise. + */ + public IGrammar getGrammar(String scopeName) { + if (scopeName == null) { + return null; + } + IGrammar grammar = super.grammarForScopeName(scopeName); + if (grammar != null) { + return grammar; + } + return super.loadGrammar(scopeName); + } + + /** + * Returns the grammar definition from the given scopeName and + * null otherwise. + * + * @param scopeName + * @return the grammar definition from the given scopeName and + * null otherwise. + */ + public IGrammarDefinition getDefinition(String scopeName) { + IGrammarDefinition definition = userCache.getDefinition(scopeName); + if (definition != null) { + return definition; + } + return pluginCache.getDefinition(scopeName); + } + + /** + * Returns list of scope names to inject for the given + * scopeName and null otheriwse. + * + * @param scopeName + * @return list of scope names to inject for the given + * scopeName and null otheriwse. + */ + @Override + public Collection getInjections(String scopeName) { + return pluginCache.getInjections(scopeName); + } + + /** + * Register the given scopeName to inject to the given scope + * name injectTo. + * + * @param scopeName + * @param injectTo + */ + public void registerInjection(String scopeName, String injectTo) { + pluginCache.registerInjection(scopeName, injectTo); + } + + /** + * @param contentType + * @return scope name bound with the given content type (or its base type) and + * null otherwise. + */ + public String getScopeNameForContentType(IContentType contentType) { + while (contentType != null) { + String scopeName = pluginCache.getScopeNameForContentType(contentType); + if (scopeName != null) { + return scopeName; + } + contentType = contentType.getBaseType(); + } + return null; + } + + @Override + public List getContentTypesForScope(String scopeName) { + return pluginCache.getContentTypesForScope(scopeName); + } + + public void registerContentTypeBinding(IContentType contentType, String scopeName) { + pluginCache.registerContentTypeBinding(contentType, scopeName); + } + + @Override + public void registerGrammarDefinition(IGrammarDefinition definition) { + if (definition.getPluginId() == null) { + userCache.registerGrammarDefinition(definition); + } else { + pluginCache.registerGrammarDefinition(definition); + } + } + + @Override + public void unregisterGrammarDefinition(IGrammarDefinition definition) { + if (definition.getPluginId() == null) { + userCache.unregisterGrammarDefinition(definition); + } else { + pluginCache.unregisterGrammarDefinition(definition); + } + } +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java index 51d8a7cc8..db4a17286 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java @@ -1,126 +1,126 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.tm4e.registry.IGrammarDefinition; - -/** - * Grammar cache. - * - */ -public class GrammarCache { - - private final Map definitions; - private final Map> injections; - private final Map scopeNameBindings; - - public GrammarCache() { - this.definitions = new HashMap<>(); - this.injections = new HashMap<>(); - this.scopeNameBindings = new HashMap<>(); - } - - /** - * Register a grammar definition. - * - * @param definition - * the grammar definition to register. - */ - public void registerGrammarDefinition(IGrammarDefinition definition) { - definitions.put(definition.getScopeName(), definition); - } - - public void unregisterGrammarDefinition(IGrammarDefinition definition) { - definitions.remove(definition.getScopeName()); - } - - /** - * Returns the whole registered grammar definition. - * - * @return - */ - public Collection getDefinitions() { - return this.definitions.values(); - } - - /** - * Returns the grammar definition from the given scopeName and - * null otherwise. - * - * @param scopeName - * @return the grammar definition from the given scopeName and - * null otherwise. - */ - public IGrammarDefinition getDefinition(String scopeName) { - return definitions.get(scopeName); - } - - /** - * Returns list of scope names to inject for the given - * scopeName and null otheriwse. - * - * @param scopeName - * @return list of scope names to inject for the given - * scopeName and null otheriwse. - */ - public Collection getInjections(String scopeName) { - return injections.get(scopeName); - } - - /** - * Register the given scopeName to inject to the given scope - * name injectTo. - * - * @param scopeName - * @param injectTo - */ - public void registerInjection(String scopeName, String injectTo) { - Collection injections = getInjections(injectTo); - if (injections == null) { - injections = new ArrayList<>(); - this.injections.put(injectTo, injections); - } - injections.add(scopeName); - } - - /** - * Returns scope name bound with the given content type and null otherwise. - * - * @param contentType - * @return scope name bound with the given content type and null otherwise. - */ - public String getScopeNameForContentType(IContentType contentType) { - return scopeNameBindings.get(contentType); - } - - public List getContentTypesForScope(String scopeName) { - if (scopeName == null) { - return List.of(); - } - return scopeNameBindings.entrySet().stream().filter(map -> scopeName.equals(map.getValue())) - .map(Entry::getKey).collect(Collectors.toList()); - } - - public void registerContentTypeBinding(IContentType contentType, String scopeName) { - scopeNameBindings.put(contentType, scopeName); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry.internal; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.tm4e.registry.IGrammarDefinition; + +/** + * Grammar cache. + * + */ +public class GrammarCache { + + private final Map definitions; + private final Map> injections; + private final Map scopeNameBindings; + + public GrammarCache() { + this.definitions = new HashMap<>(); + this.injections = new HashMap<>(); + this.scopeNameBindings = new HashMap<>(); + } + + /** + * Register a grammar definition. + * + * @param definition + * the grammar definition to register. + */ + public void registerGrammarDefinition(IGrammarDefinition definition) { + definitions.put(definition.getScopeName(), definition); + } + + public void unregisterGrammarDefinition(IGrammarDefinition definition) { + definitions.remove(definition.getScopeName()); + } + + /** + * Returns the whole registered grammar definition. + * + * @return + */ + public Collection getDefinitions() { + return this.definitions.values(); + } + + /** + * Returns the grammar definition from the given scopeName and + * null otherwise. + * + * @param scopeName + * @return the grammar definition from the given scopeName and + * null otherwise. + */ + public IGrammarDefinition getDefinition(String scopeName) { + return definitions.get(scopeName); + } + + /** + * Returns list of scope names to inject for the given + * scopeName and null otheriwse. + * + * @param scopeName + * @return list of scope names to inject for the given + * scopeName and null otheriwse. + */ + public Collection getInjections(String scopeName) { + return injections.get(scopeName); + } + + /** + * Register the given scopeName to inject to the given scope + * name injectTo. + * + * @param scopeName + * @param injectTo + */ + public void registerInjection(String scopeName, String injectTo) { + Collection injections = getInjections(injectTo); + if (injections == null) { + injections = new ArrayList<>(); + this.injections.put(injectTo, injections); + } + injections.add(scopeName); + } + + /** + * Returns scope name bound with the given content type and null otherwise. + * + * @param contentType + * @return scope name bound with the given content type and null otherwise. + */ + public String getScopeNameForContentType(IContentType contentType) { + return scopeNameBindings.get(contentType); + } + + public List getContentTypesForScope(String scopeName) { + if (scopeName == null) { + return List.of(); + } + return scopeNameBindings.entrySet().stream().filter(map -> scopeName.equals(map.getValue())) + .map(Entry::getKey).collect(Collectors.toList()); + } + + public void registerContentTypeBinding(IContentType contentType, String scopeName) { + scopeNameBindings.put(contentType, scopeName); + } + +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java index 9ba7d5429..358bb3039 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java @@ -1,114 +1,114 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry.internal; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.tm4e.registry.GrammarDefinition; -import org.eclipse.tm4e.registry.IGrammarDefinition; -import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; -import org.eclipse.tm4e.registry.XMLConstants; -import org.eclipse.tm4e.registry.internal.preferences.PreferenceConstants; -import org.eclipse.tm4e.registry.internal.preferences.PreferenceHelper; -import org.osgi.service.prefs.BackingStoreException; - -/** - * Grammar registry manager singleton. - */ -public class GrammarRegistryManager extends AbstractGrammarRegistryManager { - - private static final String EXTENSION_GRAMMARS = "grammars"; - - private static GrammarRegistryManager INSTANCE; - - public static GrammarRegistryManager getInstance() { - if (INSTANCE != null) { - return INSTANCE; - } - INSTANCE = createInstance(); - return INSTANCE; - } - - private static synchronized GrammarRegistryManager createInstance() { - if (INSTANCE != null) { - return INSTANCE; - } - GrammarRegistryManager manager = new GrammarRegistryManager(); - manager.load(); - return manager; - } - - private GrammarRegistryManager() { - } - - private void load() { - loadGrammarsFromExtensionPoints(); - loadGrammarsFromPreferences(); - } - - /** - * Load TextMate grammars from extension point. - */ - private void loadGrammarsFromExtensionPoints() { - IConfigurationElement[] cf = Platform.getExtensionRegistry() - .getConfigurationElementsFor(TMEclipseRegistryPlugin.PLUGIN_ID, EXTENSION_GRAMMARS); - for (IConfigurationElement ce : cf) { - String extensionName = ce.getName(); - if (XMLConstants.GRAMMAR_ELT.equals(extensionName)) { - super.registerGrammarDefinition(new GrammarDefinition(ce)); - } else if (XMLConstants.INJECTION_ELT.equals(extensionName)) { - String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); - String injectTo = ce.getAttribute(XMLConstants.INJECT_TO_ATTR); - super.registerInjection(scopeName, injectTo); - } else if (XMLConstants.SCOPE_NAME_CONTENT_TYPE_BINDING_ELT.equals(extensionName)) { - String contentTypeId = ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR); - IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId); - if (contentType == null) { - Platform.getLog(getClass()).warn("No content-type found with id='" + contentTypeId + "', ignoring TM4E association."); - } else { - String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); - super.registerContentTypeBinding(contentType, scopeName); - } - } - } - } - - /** - * Load TextMate grammars from preferences. - */ - private void loadGrammarsFromPreferences() { - // Load grammar definitions from the - // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); - String json = prefs.get(PreferenceConstants.GRAMMARS, null); - if (json != null) { - IGrammarDefinition[] definitions = PreferenceHelper.loadGrammars(json); - for (IGrammarDefinition definition : definitions) { - userCache.registerGrammarDefinition(definition); - } - } - } - - @Override - public void save() throws BackingStoreException { - // Save grammar definitions in the - // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" - String json = PreferenceHelper.toJson(userCache.getDefinitions()); - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); - prefs.put(PreferenceConstants.GRAMMARS, json); - prefs.flush(); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry.internal; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.tm4e.registry.GrammarDefinition; +import org.eclipse.tm4e.registry.IGrammarDefinition; +import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; +import org.eclipse.tm4e.registry.XMLConstants; +import org.eclipse.tm4e.registry.internal.preferences.PreferenceConstants; +import org.eclipse.tm4e.registry.internal.preferences.PreferenceHelper; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Grammar registry manager singleton. + */ +public class GrammarRegistryManager extends AbstractGrammarRegistryManager { + + private static final String EXTENSION_GRAMMARS = "grammars"; + + private static GrammarRegistryManager INSTANCE; + + public static GrammarRegistryManager getInstance() { + if (INSTANCE != null) { + return INSTANCE; + } + INSTANCE = createInstance(); + return INSTANCE; + } + + private static synchronized GrammarRegistryManager createInstance() { + if (INSTANCE != null) { + return INSTANCE; + } + GrammarRegistryManager manager = new GrammarRegistryManager(); + manager.load(); + return manager; + } + + private GrammarRegistryManager() { + } + + private void load() { + loadGrammarsFromExtensionPoints(); + loadGrammarsFromPreferences(); + } + + /** + * Load TextMate grammars from extension point. + */ + private void loadGrammarsFromExtensionPoints() { + IConfigurationElement[] cf = Platform.getExtensionRegistry() + .getConfigurationElementsFor(TMEclipseRegistryPlugin.PLUGIN_ID, EXTENSION_GRAMMARS); + for (IConfigurationElement ce : cf) { + String extensionName = ce.getName(); + if (XMLConstants.GRAMMAR_ELT.equals(extensionName)) { + super.registerGrammarDefinition(new GrammarDefinition(ce)); + } else if (XMLConstants.INJECTION_ELT.equals(extensionName)) { + String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); + String injectTo = ce.getAttribute(XMLConstants.INJECT_TO_ATTR); + super.registerInjection(scopeName, injectTo); + } else if (XMLConstants.SCOPE_NAME_CONTENT_TYPE_BINDING_ELT.equals(extensionName)) { + String contentTypeId = ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR); + IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId); + if (contentType == null) { + Platform.getLog(getClass()).warn("No content-type found with id='" + contentTypeId + "', ignoring TM4E association."); + } else { + String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); + super.registerContentTypeBinding(contentType, scopeName); + } + } + } + } + + /** + * Load TextMate grammars from preferences. + */ + private void loadGrammarsFromPreferences() { + // Load grammar definitions from the + // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); + String json = prefs.get(PreferenceConstants.GRAMMARS, null); + if (json != null) { + IGrammarDefinition[] definitions = PreferenceHelper.loadGrammars(json); + for (IGrammarDefinition definition : definitions) { + userCache.registerGrammarDefinition(definition); + } + } + } + + @Override + public void save() throws BackingStoreException { + // Save grammar definitions in the + // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" + String json = PreferenceHelper.toJson(userCache.getDefinitions()); + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); + prefs.put(PreferenceConstants.GRAMMARS, json); + prefs.flush(); + } + +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java index c00d93274..aa25832f8 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java @@ -1,26 +1,26 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry.internal.preferences; - -/** - * Preferences constants for grammar. - * - */ -public class PreferenceConstants { - - public static final String GRAMMARS = "org.eclipse.tm4e.registry.grammars"; - - public static final String SCOPE_NAME_CONTENTTYPE_BINDINGS = "org.eclipse.tm4e.registry.scopeNameContentTypeBindings"; - - public static final String INJECTIONS = "org.eclipse.tm4e.registry.injections"; - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry.internal.preferences; + +/** + * Preferences constants for grammar. + * + */ +public class PreferenceConstants { + + public static final String GRAMMARS = "org.eclipse.tm4e.registry.grammars"; + + public static final String SCOPE_NAME_CONTENTTYPE_BINDINGS = "org.eclipse.tm4e.registry.scopeNameContentTypeBindings"; + + public static final String INJECTIONS = "org.eclipse.tm4e.registry.injections"; + +} diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java index a3542b21f..9b4a92456 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java @@ -1,45 +1,45 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.registry.internal.preferences; - -import java.util.Collection; - -import org.eclipse.tm4e.registry.GrammarDefinition; -import org.eclipse.tm4e.registry.IGrammarDefinition; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.InstanceCreator; - -/** - * Helper class load, save grammar preferences with Json format. - * - */ -public class PreferenceHelper { - - private static final Gson DEFAULT_GSON; - - static { - DEFAULT_GSON = new GsonBuilder() - .registerTypeAdapter(IGrammarDefinition.class, (InstanceCreator) type -> new GrammarDefinition()) - .create(); - } - - public static IGrammarDefinition[] loadGrammars(String json) { - return DEFAULT_GSON.fromJson(json, GrammarDefinition[].class); - } - - public static String toJson(Collection definitions) { - return DEFAULT_GSON.toJson(definitions); - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.registry.internal.preferences; + +import java.util.Collection; + +import org.eclipse.tm4e.registry.GrammarDefinition; +import org.eclipse.tm4e.registry.IGrammarDefinition; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.InstanceCreator; + +/** + * Helper class load, save grammar preferences with Json format. + * + */ +public class PreferenceHelper { + + private static final Gson DEFAULT_GSON; + + static { + DEFAULT_GSON = new GsonBuilder() + .registerTypeAdapter(IGrammarDefinition.class, (InstanceCreator) type -> new GrammarDefinition()) + .create(); + } + + public static IGrammarDefinition[] loadGrammars(String json) { + return DEFAULT_GSON.fromJson(json, GrammarDefinition[].class); + } + + public static String toJson(Collection definitions) { + return DEFAULT_GSON.toJson(definitions); + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/TMSamplesPlugin.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/TMSamplesPlugin.java index 130c98ab8..0a0c3843b 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/TMSamplesPlugin.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/TMSamplesPlugin.java @@ -1,78 +1,78 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class TMSamplesPlugin extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.tm4e.samples"; //$NON-NLS-1$ - - // The shared instance - private static TMSamplesPlugin plugin; - - /** - * The constructor - */ - public TMSamplesPlugin() { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework. - * BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework. - * BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static TMSamplesPlugin getDefault() { - return plugin; - } - - /** - * Returns an image descriptor for the image file at the given plug-in - * relative path - * - * @param path - * the path - * @return the image descriptor - */ - public static ImageDescriptor getImageDescriptor(String path) { - return imageDescriptorFromPlugin(PLUGIN_ID, path); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class TMSamplesPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.tm4e.samples"; //$NON-NLS-1$ + + // The shared instance + private static TMSamplesPlugin plugin; + + /** + * The constructor + */ + public TMSamplesPlugin() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework. + * BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework. + * BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TMSamplesPlugin getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given plug-in + * relative path + * + * @param path + * the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2Editor.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2Editor.java index 2a824ff64..610a92fbe 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2Editor.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2Editor.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.angular2; - -import org.eclipse.ui.editors.text.TextEditor; - -public class Angular2Editor extends TextEditor { - - public Angular2Editor() { - setSourceViewerConfiguration(new Angular2ViewerConfiguration()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.angular2; + +import org.eclipse.ui.editors.text.TextEditor; + +public class Angular2Editor extends TextEditor { + + public Angular2Editor() { + setSourceViewerConfiguration(new Angular2ViewerConfiguration()); + } +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2ViewerConfiguration.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2ViewerConfiguration.java index 4b115d321..b8725b001 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2ViewerConfiguration.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/angular2/Angular2ViewerConfiguration.java @@ -1,68 +1,68 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.angular2; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.registry.IRegistryOptions; -import org.eclipse.tm4e.core.registry.Registry; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; - -public class Angular2ViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { - // Defines a TextMate Presentation reconcilier - TMPresentationReconciler reconciler = new TMPresentationReconciler(); - // Set the Angular2 grammar - reconciler.setGrammar(getGrammar()); - return reconciler; - } - - private IGrammar getGrammar() { - Registry registry = new Registry(new IRegistryOptions() { - - @Override - public InputStream getInputStream(String scopeName) throws IOException { - return Angular2ViewerConfiguration.class.getResourceAsStream(getFilePath(scopeName)); - } - - @Override - public Collection getInjections(String scopeName) { - return Arrays.asList("template.ng", "styles.ng", "source.ng.css"); - } - - @Override - public String getFilePath(String scopeName) { -// if ("source.ng.css".equals(scopeName)) { -// return "source.ng.css.json"; -// } else if ("source.ng.ts".equals(scopeName)) { -// return "source.ng.ts.json"; -// } else if ("template.ng".equals(scopeName)) { -// return "template.ng.json"; -// } else if ("styles.ng".equals(scopeName)) { -// return "styles.ng.json"; -// } - return scopeName + ".json"; - } - }); - return registry.loadGrammar("source.ng.ts"); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.angular2; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collection; + +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.registry.IRegistryOptions; +import org.eclipse.tm4e.core.registry.Registry; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; + +public class Angular2ViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { + // Defines a TextMate Presentation reconcilier + TMPresentationReconciler reconciler = new TMPresentationReconciler(); + // Set the Angular2 grammar + reconciler.setGrammar(getGrammar()); + return reconciler; + } + + private IGrammar getGrammar() { + Registry registry = new Registry(new IRegistryOptions() { + + @Override + public InputStream getInputStream(String scopeName) throws IOException { + return Angular2ViewerConfiguration.class.getResourceAsStream(getFilePath(scopeName)); + } + + @Override + public Collection getInjections(String scopeName) { + return Arrays.asList("template.ng", "styles.ng", "source.ng.css"); + } + + @Override + public String getFilePath(String scopeName) { +// if ("source.ng.css".equals(scopeName)) { +// return "source.ng.css.json"; +// } else if ("source.ng.ts".equals(scopeName)) { +// return "source.ng.ts.json"; +// } else if ("template.ng".equals(scopeName)) { +// return "template.ng.json"; +// } else if ("styles.ng".equals(scopeName)) { +// return "styles.ng.json"; +// } + return scopeName + ".json"; + } + }); + return registry.loadGrammar("source.ng.ts"); + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerEditor.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerEditor.java index f6a40edad..a83903b8d 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerEditor.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerEditor.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.freemarker; - -import org.eclipse.ui.editors.text.TextEditor; - -public class FreemarkerEditor extends TextEditor { - - public FreemarkerEditor() { - setSourceViewerConfiguration(new FreemarkerViewerConfiguration()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.freemarker; + +import org.eclipse.ui.editors.text.TextEditor; + +public class FreemarkerEditor extends TextEditor { + + public FreemarkerEditor() { + setSourceViewerConfiguration(new FreemarkerViewerConfiguration()); + } +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerViewerConfiguration.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerViewerConfiguration.java index cae4cf76b..efd0ccad2 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerViewerConfiguration.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/freemarker/FreemarkerViewerConfiguration.java @@ -1,27 +1,27 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.freemarker; - -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; - -public class FreemarkerViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { - // Defines a TextMate Presentation reconcilier - return new TMPresentationReconciler(); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.freemarker; + +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; + +public class FreemarkerViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { + // Defines a TextMate Presentation reconcilier + return new TMPresentationReconciler(); + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLEditor.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLEditor.java index 613e8a2f6..a116e5f08 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLEditor.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLEditor.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.html; - -import org.eclipse.ui.editors.text.TextEditor; - -public class HTMLEditor extends TextEditor { - - public HTMLEditor() { - setSourceViewerConfiguration(new HTMLViewerConfiguration()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.html; + +import org.eclipse.ui.editors.text.TextEditor; + +public class HTMLEditor extends TextEditor { + + public HTMLEditor() { + setSourceViewerConfiguration(new HTMLViewerConfiguration()); + } +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLViewerConfiguration.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLViewerConfiguration.java index 2f4b11b57..e5945d684 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLViewerConfiguration.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/html/HTMLViewerConfiguration.java @@ -1,27 +1,27 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.html; - -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; - -public class HTMLViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { - // Defines a TextMate Presentation reconcilier - return new TMPresentationReconciler(); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.html; + +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; + +public class HTMLViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { + // Defines a TextMate Presentation reconcilier + return new TMPresentationReconciler(); + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPEditor.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPEditor.java index f053200c0..d5c1ab426 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPEditor.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPEditor.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.php; - -import org.eclipse.ui.editors.text.TextEditor; - -public class PHPEditor extends TextEditor { - - public PHPEditor() { - setSourceViewerConfiguration(new PHPViewerConfiguration()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.php; + +import org.eclipse.ui.editors.text.TextEditor; + +public class PHPEditor extends TextEditor { + + public PHPEditor() { + setSourceViewerConfiguration(new PHPViewerConfiguration()); + } +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPViewerConfiguration.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPViewerConfiguration.java index 665e30531..5eb3ed598 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPViewerConfiguration.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/php/PHPViewerConfiguration.java @@ -1,27 +1,27 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.php; - -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; - -public class PHPViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { - // Defines a TextMate Presentation reconcilier - return new TMPresentationReconciler(); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.php; + +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; + +public class PHPViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { + // Defines a TextMate Presentation reconcilier + return new TMPresentationReconciler(); + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXEditor.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXEditor.java index 85fde4765..5288e1026 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXEditor.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXEditor.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.typescript; - -import org.eclipse.ui.editors.text.TextEditor; - -public class JSXEditor extends TextEditor { - - public JSXEditor() { - setSourceViewerConfiguration(new JSXViewerConfiguration()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.typescript; + +import org.eclipse.ui.editors.text.TextEditor; + +public class JSXEditor extends TextEditor { + + public JSXEditor() { + setSourceViewerConfiguration(new JSXViewerConfiguration()); + } +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXViewerConfiguration.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXViewerConfiguration.java index 346863028..0590f857a 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXViewerConfiguration.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/JSXViewerConfiguration.java @@ -1,44 +1,44 @@ -/** - * Copyright (c) 2015-2018 Angelo ZERR. +/** + * Copyright (c) 2015-2018 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.typescript; - -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.registry.Registry; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; - -public class JSXViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { - // Defines a TextMate Presentation reconcilier - TMPresentationReconciler reconciler = new TMPresentationReconciler(); - // Set the TypeScript grammar - reconciler.setGrammar(getGrammar()); - return reconciler; - } - - private IGrammar getGrammar() { - // TODO: cache the grammar - Registry registry = new Registry(); - try { - return registry.loadGrammarFromPathSync("TypeScriptReact.tmLanguage.json", - JSXViewerConfiguration.class.getResourceAsStream("TypeScriptReact.tmLanguage.json")); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.typescript; + +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.registry.Registry; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; + +public class JSXViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { + // Defines a TextMate Presentation reconcilier + TMPresentationReconciler reconciler = new TMPresentationReconciler(); + // Set the TypeScript grammar + reconciler.setGrammar(getGrammar()); + return reconciler; + } + + private IGrammar getGrammar() { + // TODO: cache the grammar + Registry registry = new Registry(); + try { + return registry.loadGrammarFromPathSync("TypeScriptReact.tmLanguage.json", + JSXViewerConfiguration.class.getResourceAsStream("TypeScriptReact.tmLanguage.json")); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptEditor.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptEditor.java index c95852dae..e18201811 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptEditor.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptEditor.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.typescript; - -import org.eclipse.ui.editors.text.TextEditor; - -public class TypeScriptEditor extends TextEditor { - - public TypeScriptEditor() { - setSourceViewerConfiguration(new TypeScriptViewerConfiguration()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.typescript; + +import org.eclipse.ui.editors.text.TextEditor; + +public class TypeScriptEditor extends TextEditor { + + public TypeScriptEditor() { + setSourceViewerConfiguration(new TypeScriptViewerConfiguration()); + } +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptViewerConfiguration.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptViewerConfiguration.java index d4617a846..2a6385a5d 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptViewerConfiguration.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/typescript/TypeScriptViewerConfiguration.java @@ -1,45 +1,45 @@ -/** - * Copyright (c) 2015-2018 Angelo ZERR. +/** + * Copyright (c) 2015-2018 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.typescript; - -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.registry.Registry; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; - -public class TypeScriptViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { - // Defines a TextMate Presentation reconcilier - TMPresentationReconciler reconciler = new TMPresentationReconciler(); - // Set the TypeScript grammar - reconciler.setGrammar(getGrammar()); - //reconciler.setThemeId(ThemeIdConstants.Monokai); - return reconciler; - } - - private IGrammar getGrammar() { - // TODO: cache the grammar - Registry registry = new Registry(); - try { - return registry.loadGrammarFromPathSync("TypeScript.tmLanguage.json", - TypeScriptViewerConfiguration.class.getResourceAsStream("TypeScript.tmLanguage.json")); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.typescript; + +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.registry.Registry; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; + +public class TypeScriptViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { + // Defines a TextMate Presentation reconcilier + TMPresentationReconciler reconciler = new TMPresentationReconciler(); + // Set the TypeScript grammar + reconciler.setGrammar(getGrammar()); + //reconciler.setThemeId(ThemeIdConstants.Monokai); + return reconciler; + } + + private IGrammar getGrammar() { + // TODO: cache the grammar + Registry registry = new Registry(); + try { + return registry.loadGrammarFromPathSync("TypeScript.tmLanguage.json", + TypeScriptViewerConfiguration.class.getResourceAsStream("TypeScript.tmLanguage.json")); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLEditor.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLEditor.java index 12011c34c..a2ae224df 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLEditor.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLEditor.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.yaml; - -import org.eclipse.ui.editors.text.TextEditor; - -public class YAMLEditor extends TextEditor { - - public YAMLEditor() { - setSourceViewerConfiguration(new YAMLViewerConfiguration()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.yaml; + +import org.eclipse.ui.editors.text.TextEditor; + +public class YAMLEditor extends TextEditor { + + public YAMLEditor() { + setSourceViewerConfiguration(new YAMLViewerConfiguration()); + } +} diff --git a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLViewerConfiguration.java b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLViewerConfiguration.java index adff61b92..907adaadb 100644 --- a/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLViewerConfiguration.java +++ b/org.eclipse.tm4e.samples/src/main/java/org/eclipse/tm4e/samples/yaml/YAMLViewerConfiguration.java @@ -1,27 +1,27 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.samples.yaml; - -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; - -public class YAMLViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { - // Defines a TextMate Presentation reconcilier - return new TMPresentationReconciler(); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.samples.yaml; + +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; + +public class YAMLViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) { + // Defines a TextMate Presentation reconcilier + return new TMPresentationReconciler(); + } + +} diff --git a/org.eclipse.tm4e.samples/syntaxes/YAML.tmLanguage b/org.eclipse.tm4e.samples/syntaxes/YAML.tmLanguage index 175f45d7b..63f85b8f9 100644 --- a/org.eclipse.tm4e.samples/syntaxes/YAML.tmLanguage +++ b/org.eclipse.tm4e.samples/syntaxes/YAML.tmLanguage @@ -1,1164 +1,1164 @@ - - - - - fileTypes - - yaml - yml - rviz - reek - clang-format - yaml-tmlanguage - syntax - sublime-syntax - - firstLineMatch - ^%YAML( ?1.\d+)? - keyEquivalent - ^~Y - name - YAML - patterns - - - include - #comment - - - include - #property - - - include - #directive - - - match - ^--- - name - entity.other.document.begin.yaml - - - match - ^\.{3} - name - entity.other.document.end.yaml - - - include - #node - - - repository - - block-collection - - patterns - - - include - #block-sequence - - - include - #block-mapping - - - - block-mapping - - patterns - - - include - #block-pair - - - - block-node - - patterns - - - include - #prototype - - - include - #block-scalar - - - include - #block-collection - - - include - #flow-scalar-plain-out - - - include - #flow-node - - - - block-pair - - patterns - - - begin - \? - beginCaptures - - 1 - - name - punctuation.definition.key-value.begin.yaml - - - end - (?=\?)|^ *(:)|(:) - endCaptures - - 1 - - name - punctuation.separator.key-value.mapping.yaml - - 2 - - name - invalid.illegal.expected-newline.yaml - - - name - meta.block-mapping.yaml - patterns - - - include - #block-node - - - - - begin - (?x) - (?= - (?x: - [^\s[-?:,\[\]{}#&*!|>'"%@`]] - | [?:-] \S - ) - ( - [^\s:] - | : \S - | \s+ (?![#\s]) - )* - \s* - : - (\s|$) - ) - - end - (?x) - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - ) - - patterns - - - include - #flow-scalar-plain-out-implicit-type - - - begin - (?x) - [^\s[-?:,\[\]{}#&*!|>'"%@`]] - | [?:-] \S - - beginCaptures - - 0 - - name - entity.name.tag.yaml - - - contentName - entity.name.tag.yaml - end - (?x) - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - ) - - name - string.unquoted.plain.out.yaml - - - - - match - :(?=\s|$) - name - punctuation.separator.key-value.mapping.yaml - - - - block-scalar - - begin - (?:(\|)|(>))([1-9])?([-+])?(.*\n?) - beginCaptures - - 1 - - name - punctuation.definition.block.scalar.literal.yaml - - 2 - - name - punctuation.definition.block.scalar.folded.yaml - - 3 - - name - constant.numeric.indentation-indicator.yaml - - 4 - - name - support.other.chomping-indicator.yaml - - 5 - - patterns - - - include - #comment - - - match - .+ - name - invalid.illegal.expected-comment-or-newline.yaml - - - - - end - ^(?=\S)|(?!\G) - patterns - - - begin - ^([ ]+)(?! ) - end - ^(?!\1|\s*$) - name - string.unquoted.block.yaml - - - - block-sequence - - match - (-)( |\t|$) - name - punctuation.definition.block.sequence.item.yaml - - comment - - begin - (?:(^[ \t]*)|[ \t]+)(?=#\p{Print}*$) - beginCaptures - - 1 - - name - punctuation.whitespace.comment.leading.yaml - - - end - (?!\G) - patterns - - - begin - # - beginCaptures - - 0 - - name - punctuation.definition.comment.yaml - - - end - \n - name - comment.line.number-sign.yaml - - - - directive - - begin - ^% - beginCaptures - - 0 - - name - punctuation.definition.directive.begin.yaml - - - end - (?=$|[ \t]+($|#)) - name - meta.directive.yaml - patterns - - - captures - - 1 - - name - keyword.other.directive.yaml.yaml - - 2 - - name - constant.numeric.yaml-version.yaml - - - match - \G(YAML)[ \t]+(\d+\.\d+) - - - captures - - 1 - - name - keyword.other.directive.tag.yaml - - 2 - - name - storage.type.tag-handle.yaml - - 3 - - name - support.type.tag-prefix.yaml - - - match - (?x) - \G - (TAG) - (?:[ \t]+ - ((?:!(?:[0-9A-Za-z\-]*!)?)) - (?:[ \t]+ ( - ! (?x: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )* - | (?![,!\[\]{}]) (?x: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )+ - ) - )? - )? - - - - captures - - 1 - - name - support.other.directive.reserved.yaml - - 2 - - name - string.unquoted.directive-name.yaml - - 3 - - name - string.unquoted.directive-parameter.yaml - - - match - (?x) \G (\w+) (?:[ \t]+ (\w+) (?:[ \t]+ (\w+))? )? - - - match - \S+ - name - invalid.illegal.unrecognized.yaml - - - - flow-alias - - captures - - 1 - - name - keyword.control.flow.alias.yaml - - 2 - - name - punctuation.definition.alias.yaml - - 3 - - name - variable.other.alias.yaml - - 4 - - name - invalid.illegal.character.anchor.yaml - - - match - ((\*))([^\s\[\]/{/},]+)([^\s\]},]\S*)? - - flow-collection - - patterns - - - include - #flow-sequence - - - include - #flow-mapping - - - - flow-mapping - - begin - \{ - beginCaptures - - 0 - - name - punctuation.definition.mapping.begin.yaml - - - end - \} - endCaptures - - 0 - - name - punctuation.definition.mapping.end.yaml - - - name - meta.flow-mapping.yaml - patterns - - - include - #prototype - - - match - , - name - punctuation.separator.mapping.yaml - - - include - #flow-pair - - - - flow-node - - patterns - - - include - #prototype - - - include - #flow-alias - - - include - #flow-collection - - - include - #flow-scalar - - - - flow-pair - - patterns - - - begin - \? - beginCaptures - - 0 - - name - punctuation.definition.key-value.begin.yaml - - - end - (?=[},\]]) - name - meta.flow-pair.explicit.yaml - patterns - - - include - #prototype - - - include - #flow-pair - - - include - #flow-node - - - begin - :(?=\s|$|[\[\]{},]) - beginCaptures - - 0 - - name - punctuation.separator.key-value.mapping.yaml - - - end - (?=[},\]]) - patterns - - - include - #flow-value - - - - - - - begin - (?x) - (?= - (?: - [^\s[-?:,\[\]{}#&*!|>'"%@`]] - | [?:-] [^\s[\[\]{},]] - ) - ( - [^\s:[\[\]{},]] - | : [^\s[\[\]{},]] - | \s+ (?![#\s]) - )* - \s* - : - (\s|$) - ) - - end - (?x) - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - | \s* : [\[\]{},] - | \s* [\[\]{},] - ) - - name - meta.flow-pair.key.yaml - patterns - - - include - #flow-scalar-plain-in-implicit-type - - - begin - (?x) - [^\s[-?:,\[\]{}#&*!|>'"%@`]] - | [?:-] [^\s[\[\]{},]] - - beginCaptures - - 0 - - name - entity.name.tag.yaml - - - contentName - entity.name.tag.yaml - end - (?x) - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - | \s* : [\[\]{},] - | \s* [\[\]{},] - ) - - name - string.unquoted.plain.in.yaml - - - - - include - #flow-node - - - begin - :(?=\s|$|[\[\]{},]) - captures - - 0 - - name - punctuation.separator.key-value.mapping.yaml - - - end - (?=[},\]]) - name - meta.flow-pair.yaml - patterns - - - include - #flow-value - - - - - - flow-scalar - - patterns - - - include - #flow-scalar-double-quoted - - - include - #flow-scalar-single-quoted - - - include - #flow-scalar-plain-in - - - - flow-scalar-double-quoted - - begin - " - beginCaptures - - 0 - - name - punctuation.definition.string.begin.yaml - - - end - " - endCaptures - - 0 - - name - punctuation.definition.string.end.yaml - - - name - string.quoted.double.yaml - patterns - - - match - \\([0abtnvfre "/\\N_Lp]|x\d\d|u\d{4}|U\d{8}) - name - constant.character.escape.yaml - - - match - \\\n - name - constant.character.escape.double-quoted.newline.yaml - - - - flow-scalar-plain-in - - patterns - - - include - #flow-scalar-plain-in-implicit-type - - - begin - (?x) - [^\s[-?:,\[\]{}#&*!|>'"%@`]] - | [?:-] [^\s[\[\]{},]] - - end - (?x) - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - | \s* : [\[\]{},] - | \s* [\[\]{},] - ) - - name - string.unquoted.plain.in.yaml - - - - flow-scalar-plain-in-implicit-type - - patterns - - - captures - - 1 - - name - constant.language.null.yaml - - 2 - - name - constant.language.boolean.yaml - - 3 - - name - constant.numeric.integer.yaml - - 4 - - name - constant.numeric.float.yaml - - 5 - - name - constant.other.timestamp.yaml - - 6 - - name - constant.language.value.yaml - - 7 - - name - constant.language.merge.yaml - - - match - (?x) - (?x: - (null|Null|NULL|~) - | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF) - | ( - (?: - [-+]? 0b [0-1_]+ # (base 2) - | [-+]? 0 [0-7_]+ # (base 8) - | [-+]? (?: 0|[1-9][0-9_]*) # (base 10) - | [-+]? 0x [0-9a-fA-F_]+ # (base 16) - | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60) - ) - ) - | ( - (?x: - [-+]? (?: [0-9] [0-9_]*)? \. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10) - | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \. [0-9_]* # (base 60) - | [-+]? \. (?: inf|Inf|INF) # (infinity) - | \. (?: nan|NaN|NAN) # (not a number) - ) - ) - | ( - (?x: - \d{4} - \d{2} - \d{2} # (y-m-d) - | \d{4} # (year) - - \d{1,2} # (month) - - \d{1,2} # (day) - (?: [Tt] | [ \t]+) \d{1,2} # (hour) - : \d{2} # (minute) - : \d{2} # (second) - (?: \.\d*)? # (fraction) - (?: - (?:[ \t]*) Z - | [-+] \d{1,2} (?: :\d{1,2})? - )? # (time zone) - ) - ) - | (=) - | (<<) - ) - (?: - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - | \s* : [\[\]{},] - | \s* [\[\]{},] - ) - ) - - - - - flow-scalar-plain-out - - patterns - - - include - #flow-scalar-plain-out-implicit-type - - - begin - (?x) - [^\s[-?:,\[\]{}#&*!|>'"%@`]] - | [?:-] \S - - end - (?x) - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - ) - - name - string.unquoted.plain.out.yaml - - - - flow-scalar-plain-out-implicit-type - - patterns - - - captures - - 1 - - name - constant.language.null.yaml - - 2 - - name - constant.language.boolean.yaml - - 3 - - name - constant.numeric.integer.yaml - - 4 - - name - constant.numeric.float.yaml - - 5 - - name - constant.other.timestamp.yaml - - 6 - - name - constant.language.value.yaml - - 7 - - name - constant.language.merge.yaml - - - match - (?x) - (?x: - (null|Null|NULL|~) - | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF) - | ( - (?: - [-+]? 0b [0-1_]+ # (base 2) - | [-+]? 0 [0-7_]+ # (base 8) - | [-+]? (?: 0|[1-9][0-9_]*) # (base 10) - | [-+]? 0x [0-9a-fA-F_]+ # (base 16) - | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60) - ) - ) - | ( - (?x: - [-+]? (?: [0-9] [0-9_]*)? \. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10) - | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \. [0-9_]* # (base 60) - | [-+]? \. (?: inf|Inf|INF) # (infinity) - | \. (?: nan|NaN|NAN) # (not a number) - ) - ) - | ( - (?x: - \d{4} - \d{2} - \d{2} # (y-m-d) - | \d{4} # (year) - - \d{1,2} # (month) - - \d{1,2} # (day) - (?: [Tt] | [ \t]+) \d{1,2} # (hour) - : \d{2} # (minute) - : \d{2} # (second) - (?: \.\d*)? # (fraction) - (?: - (?:[ \t]*) Z - | [-+] \d{1,2} (?: :\d{1,2})? - )? # (time zone) - ) - ) - | (=) - | (<<) - ) - (?x: - (?= - \s* $ - | \s+ \# - | \s* : (\s|$) - ) - ) - - - - - flow-scalar-single-quoted - - begin - ' - beginCaptures - - 0 - - name - punctuation.definition.string.begin.yaml - - - end - '(?!') - endCaptures - - 0 - - name - punctuation.definition.string.end.yaml - - - name - string.quoted.single.yaml - patterns - - - match - '' - name - constant.character.escape.single-quoted.yaml - - - - flow-sequence - - begin - \[ - beginCaptures - - 0 - - name - punctuation.definition.sequence.begin.yaml - - - end - \] - endCaptures - - 0 - - name - punctuation.definition.sequence.end.yaml - - - name - meta.flow-sequence.yaml - patterns - - - include - #prototype - - - match - , - name - punctuation.separator.sequence.yaml - - - include - #flow-pair - - - include - #flow-node - - - - flow-value - - patterns - - - begin - \G(?![},\]]) - end - (?=[},\]]) - name - meta.flow-pair.value.yaml - patterns - - - include - #flow-node - - - - - - node - - patterns - - - include - #block-node - - - - property - - begin - (?=!|&) - end - (?!\G) - name - meta.property.yaml - patterns - - - captures - - 1 - - name - keyword.control.property.anchor.yaml - - 2 - - name - punctuation.definition.anchor.yaml - - 3 - - name - entity.name.type.anchor.yaml - - 4 - - name - invalid.illegal.character.anchor.yaml - - - match - \G((&))([^\s\[\]/{/},]+)(\S+)? - - - match - (?x) - \G - (?: - ! < (?: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )+ > - | (?:!(?:[0-9A-Za-z\-]*!)?) (?: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$_.~*'()] )+ - | ! - ) - (?=\ |\t|$) - - name - storage.type.tag-handle.yaml - - - match - \S+ - name - invalid.illegal.tag-handle.yaml - - - - prototype - - patterns - - - include - #comment - - - include - #property - - - - - scopeName - source.yaml - uuid - 686AD6AE-33F3-4493-9512-9E9FC1D5417F - + + + + + fileTypes + + yaml + yml + rviz + reek + clang-format + yaml-tmlanguage + syntax + sublime-syntax + + firstLineMatch + ^%YAML( ?1.\d+)? + keyEquivalent + ^~Y + name + YAML + patterns + + + include + #comment + + + include + #property + + + include + #directive + + + match + ^--- + name + entity.other.document.begin.yaml + + + match + ^\.{3} + name + entity.other.document.end.yaml + + + include + #node + + + repository + + block-collection + + patterns + + + include + #block-sequence + + + include + #block-mapping + + + + block-mapping + + patterns + + + include + #block-pair + + + + block-node + + patterns + + + include + #prototype + + + include + #block-scalar + + + include + #block-collection + + + include + #flow-scalar-plain-out + + + include + #flow-node + + + + block-pair + + patterns + + + begin + \? + beginCaptures + + 1 + + name + punctuation.definition.key-value.begin.yaml + + + end + (?=\?)|^ *(:)|(:) + endCaptures + + 1 + + name + punctuation.separator.key-value.mapping.yaml + + 2 + + name + invalid.illegal.expected-newline.yaml + + + name + meta.block-mapping.yaml + patterns + + + include + #block-node + + + + + begin + (?x) + (?= + (?x: + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] \S + ) + ( + [^\s:] + | : \S + | \s+ (?![#\s]) + )* + \s* + : + (\s|$) + ) + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + + patterns + + + include + #flow-scalar-plain-out-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] \S + + beginCaptures + + 0 + + name + entity.name.tag.yaml + + + contentName + entity.name.tag.yaml + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + + name + string.unquoted.plain.out.yaml + + + + + match + :(?=\s|$) + name + punctuation.separator.key-value.mapping.yaml + + + + block-scalar + + begin + (?:(\|)|(>))([1-9])?([-+])?(.*\n?) + beginCaptures + + 1 + + name + punctuation.definition.block.scalar.literal.yaml + + 2 + + name + punctuation.definition.block.scalar.folded.yaml + + 3 + + name + constant.numeric.indentation-indicator.yaml + + 4 + + name + support.other.chomping-indicator.yaml + + 5 + + patterns + + + include + #comment + + + match + .+ + name + invalid.illegal.expected-comment-or-newline.yaml + + + + + end + ^(?=\S)|(?!\G) + patterns + + + begin + ^([ ]+)(?! ) + end + ^(?!\1|\s*$) + name + string.unquoted.block.yaml + + + + block-sequence + + match + (-)( |\t|$) + name + punctuation.definition.block.sequence.item.yaml + + comment + + begin + (?:(^[ \t]*)|[ \t]+)(?=#\p{Print}*$) + beginCaptures + + 1 + + name + punctuation.whitespace.comment.leading.yaml + + + end + (?!\G) + patterns + + + begin + # + beginCaptures + + 0 + + name + punctuation.definition.comment.yaml + + + end + \n + name + comment.line.number-sign.yaml + + + + directive + + begin + ^% + beginCaptures + + 0 + + name + punctuation.definition.directive.begin.yaml + + + end + (?=$|[ \t]+($|#)) + name + meta.directive.yaml + patterns + + + captures + + 1 + + name + keyword.other.directive.yaml.yaml + + 2 + + name + constant.numeric.yaml-version.yaml + + + match + \G(YAML)[ \t]+(\d+\.\d+) + + + captures + + 1 + + name + keyword.other.directive.tag.yaml + + 2 + + name + storage.type.tag-handle.yaml + + 3 + + name + support.type.tag-prefix.yaml + + + match + (?x) + \G + (TAG) + (?:[ \t]+ + ((?:!(?:[0-9A-Za-z\-]*!)?)) + (?:[ \t]+ ( + ! (?x: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )* + | (?![,!\[\]{}]) (?x: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )+ + ) + )? + )? + + + + captures + + 1 + + name + support.other.directive.reserved.yaml + + 2 + + name + string.unquoted.directive-name.yaml + + 3 + + name + string.unquoted.directive-parameter.yaml + + + match + (?x) \G (\w+) (?:[ \t]+ (\w+) (?:[ \t]+ (\w+))? )? + + + match + \S+ + name + invalid.illegal.unrecognized.yaml + + + + flow-alias + + captures + + 1 + + name + keyword.control.flow.alias.yaml + + 2 + + name + punctuation.definition.alias.yaml + + 3 + + name + variable.other.alias.yaml + + 4 + + name + invalid.illegal.character.anchor.yaml + + + match + ((\*))([^\s\[\]/{/},]+)([^\s\]},]\S*)? + + flow-collection + + patterns + + + include + #flow-sequence + + + include + #flow-mapping + + + + flow-mapping + + begin + \{ + beginCaptures + + 0 + + name + punctuation.definition.mapping.begin.yaml + + + end + \} + endCaptures + + 0 + + name + punctuation.definition.mapping.end.yaml + + + name + meta.flow-mapping.yaml + patterns + + + include + #prototype + + + match + , + name + punctuation.separator.mapping.yaml + + + include + #flow-pair + + + + flow-node + + patterns + + + include + #prototype + + + include + #flow-alias + + + include + #flow-collection + + + include + #flow-scalar + + + + flow-pair + + patterns + + + begin + \? + beginCaptures + + 0 + + name + punctuation.definition.key-value.begin.yaml + + + end + (?=[},\]]) + name + meta.flow-pair.explicit.yaml + patterns + + + include + #prototype + + + include + #flow-pair + + + include + #flow-node + + + begin + :(?=\s|$|[\[\]{},]) + beginCaptures + + 0 + + name + punctuation.separator.key-value.mapping.yaml + + + end + (?=[},\]]) + patterns + + + include + #flow-value + + + + + + + begin + (?x) + (?= + (?: + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] [^\s[\[\]{},]] + ) + ( + [^\s:[\[\]{},]] + | : [^\s[\[\]{},]] + | \s+ (?![#\s]) + )* + \s* + : + (\s|$) + ) + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + + name + meta.flow-pair.key.yaml + patterns + + + include + #flow-scalar-plain-in-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] [^\s[\[\]{},]] + + beginCaptures + + 0 + + name + entity.name.tag.yaml + + + contentName + entity.name.tag.yaml + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + + name + string.unquoted.plain.in.yaml + + + + + include + #flow-node + + + begin + :(?=\s|$|[\[\]{},]) + captures + + 0 + + name + punctuation.separator.key-value.mapping.yaml + + + end + (?=[},\]]) + name + meta.flow-pair.yaml + patterns + + + include + #flow-value + + + + + + flow-scalar + + patterns + + + include + #flow-scalar-double-quoted + + + include + #flow-scalar-single-quoted + + + include + #flow-scalar-plain-in + + + + flow-scalar-double-quoted + + begin + " + beginCaptures + + 0 + + name + punctuation.definition.string.begin.yaml + + + end + " + endCaptures + + 0 + + name + punctuation.definition.string.end.yaml + + + name + string.quoted.double.yaml + patterns + + + match + \\([0abtnvfre "/\\N_Lp]|x\d\d|u\d{4}|U\d{8}) + name + constant.character.escape.yaml + + + match + \\\n + name + constant.character.escape.double-quoted.newline.yaml + + + + flow-scalar-plain-in + + patterns + + + include + #flow-scalar-plain-in-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] [^\s[\[\]{},]] + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + + name + string.unquoted.plain.in.yaml + + + + flow-scalar-plain-in-implicit-type + + patterns + + + captures + + 1 + + name + constant.language.null.yaml + + 2 + + name + constant.language.boolean.yaml + + 3 + + name + constant.numeric.integer.yaml + + 4 + + name + constant.numeric.float.yaml + + 5 + + name + constant.other.timestamp.yaml + + 6 + + name + constant.language.value.yaml + + 7 + + name + constant.language.merge.yaml + + + match + (?x) + (?x: + (null|Null|NULL|~) + | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF) + | ( + (?: + [-+]? 0b [0-1_]+ # (base 2) + | [-+]? 0 [0-7_]+ # (base 8) + | [-+]? (?: 0|[1-9][0-9_]*) # (base 10) + | [-+]? 0x [0-9a-fA-F_]+ # (base 16) + | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60) + ) + ) + | ( + (?x: + [-+]? (?: [0-9] [0-9_]*)? \. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10) + | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \. [0-9_]* # (base 60) + | [-+]? \. (?: inf|Inf|INF) # (infinity) + | \. (?: nan|NaN|NAN) # (not a number) + ) + ) + | ( + (?x: + \d{4} - \d{2} - \d{2} # (y-m-d) + | \d{4} # (year) + - \d{1,2} # (month) + - \d{1,2} # (day) + (?: [Tt] | [ \t]+) \d{1,2} # (hour) + : \d{2} # (minute) + : \d{2} # (second) + (?: \.\d*)? # (fraction) + (?: + (?:[ \t]*) Z + | [-+] \d{1,2} (?: :\d{1,2})? + )? # (time zone) + ) + ) + | (=) + | (<<) + ) + (?: + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + ) + + + + + flow-scalar-plain-out + + patterns + + + include + #flow-scalar-plain-out-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] \S + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + + name + string.unquoted.plain.out.yaml + + + + flow-scalar-plain-out-implicit-type + + patterns + + + captures + + 1 + + name + constant.language.null.yaml + + 2 + + name + constant.language.boolean.yaml + + 3 + + name + constant.numeric.integer.yaml + + 4 + + name + constant.numeric.float.yaml + + 5 + + name + constant.other.timestamp.yaml + + 6 + + name + constant.language.value.yaml + + 7 + + name + constant.language.merge.yaml + + + match + (?x) + (?x: + (null|Null|NULL|~) + | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF) + | ( + (?: + [-+]? 0b [0-1_]+ # (base 2) + | [-+]? 0 [0-7_]+ # (base 8) + | [-+]? (?: 0|[1-9][0-9_]*) # (base 10) + | [-+]? 0x [0-9a-fA-F_]+ # (base 16) + | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60) + ) + ) + | ( + (?x: + [-+]? (?: [0-9] [0-9_]*)? \. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10) + | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \. [0-9_]* # (base 60) + | [-+]? \. (?: inf|Inf|INF) # (infinity) + | \. (?: nan|NaN|NAN) # (not a number) + ) + ) + | ( + (?x: + \d{4} - \d{2} - \d{2} # (y-m-d) + | \d{4} # (year) + - \d{1,2} # (month) + - \d{1,2} # (day) + (?: [Tt] | [ \t]+) \d{1,2} # (hour) + : \d{2} # (minute) + : \d{2} # (second) + (?: \.\d*)? # (fraction) + (?: + (?:[ \t]*) Z + | [-+] \d{1,2} (?: :\d{1,2})? + )? # (time zone) + ) + ) + | (=) + | (<<) + ) + (?x: + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + ) + + + + + flow-scalar-single-quoted + + begin + ' + beginCaptures + + 0 + + name + punctuation.definition.string.begin.yaml + + + end + '(?!') + endCaptures + + 0 + + name + punctuation.definition.string.end.yaml + + + name + string.quoted.single.yaml + patterns + + + match + '' + name + constant.character.escape.single-quoted.yaml + + + + flow-sequence + + begin + \[ + beginCaptures + + 0 + + name + punctuation.definition.sequence.begin.yaml + + + end + \] + endCaptures + + 0 + + name + punctuation.definition.sequence.end.yaml + + + name + meta.flow-sequence.yaml + patterns + + + include + #prototype + + + match + , + name + punctuation.separator.sequence.yaml + + + include + #flow-pair + + + include + #flow-node + + + + flow-value + + patterns + + + begin + \G(?![},\]]) + end + (?=[},\]]) + name + meta.flow-pair.value.yaml + patterns + + + include + #flow-node + + + + + + node + + patterns + + + include + #block-node + + + + property + + begin + (?=!|&) + end + (?!\G) + name + meta.property.yaml + patterns + + + captures + + 1 + + name + keyword.control.property.anchor.yaml + + 2 + + name + punctuation.definition.anchor.yaml + + 3 + + name + entity.name.type.anchor.yaml + + 4 + + name + invalid.illegal.character.anchor.yaml + + + match + \G((&))([^\s\[\]/{/},]+)(\S+)? + + + match + (?x) + \G + (?: + ! < (?: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )+ > + | (?:!(?:[0-9A-Za-z\-]*!)?) (?: %\p{XDigit}{2} | [0-9A-Za-z\-#;/?:@&=+$_.~*'()] )+ + | ! + ) + (?=\ |\t|$) + + name + storage.type.tag-handle.yaml + + + match + \S+ + name + invalid.illegal.tag-handle.yaml + + + + prototype + + patterns + + + include + #comment + + + include + #property + + + + + scopeName + source.yaml + uuid + 686AD6AE-33F3-4493-9512-9E9FC1D5417F + \ No newline at end of file diff --git a/org.eclipse.tm4e.samples/syntaxes/ftl.tmLanguage b/org.eclipse.tm4e.samples/syntaxes/ftl.tmLanguage index 735880650..9be988de3 100644 --- a/org.eclipse.tm4e.samples/syntaxes/ftl.tmLanguage +++ b/org.eclipse.tm4e.samples/syntaxes/ftl.tmLanguage @@ -1,147 +1,147 @@ - - - - - fileTypes - - ftl - - foldingStartMarker - (?x) - (<(?i:head|body|table|thead|tbody|tfoot|tr|div|nav|section|aside|header|select|fieldset|style|script|ul|ol|form|dl)\b.*?> - |<!--(?!.*-->) - |\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/))) - |(\[|<)(\#|@)\w+.*\(\]|>) - ) - foldingStopMarker - (?x) - (</(?i:head|body|table|thead|tbody|tfoot|tr|div|nav|section|aside|header|select|fieldset|style|script|ul|ol|form|dl)> - |^\s*--> - |(^|\s)\} - |(\[|<)/(\#|@)\w+.*(\]|>) - ) - keyEquivalent - ^~F - name - FreeMarker - patterns - - - begin - [<\[]#-- - captures - - 0 - - name - punctuation.definition.comment.ftl - - - end - --[>\]] - name - comment.block.ftl - - - captures - - 1 - - name - punctuation.definition.function.ftl - - 2 - - name - punctuation.definition.function.ftl - - 3 - - name - entity.name.function.ftl - - 5 - - name - variable.parameter.function.ftl - - 8 - - name - entity.name.function.ftl - - 9 - - name - punctuation.definition.function.ftl - - - match - ([<\[](#|@))(\w+(\.\w+)*)((\s+[^>\]]+)*?)\s*((\/)?([>\]])) - name - meta.function.ftl - - - captures - - 1 - - name - punctuation.definition.function.ftl - - 2 - - name - punctuation.definition.function.ftl - - 3 - - name - entity.name.function.ftl - - 5 - - name - punctuation.definition.function.ftl - - - match - ([<\[]\/(#|@))(\w+(\.\w+)*)\s*([>\]]) - name - meta.function.ftl - - - captures - - 1 - - name - punctuation.definition.variable.ftl - - 3 - - name - entity.name.function.ftl - - 4 - - name - punctuation.definition.variable.ftl - - - match - (\$\{)\.?[a-zA-Z_\(][\w\(\)+-\/\*]+(\.?[\w\(\)+-\/\*]+)*(.*?|\?\?|\!)?(\}) - name - variable.other.readwrite.local.ftl - - - include - text.html.basic - - - scopeName - text.html.ftl - uuid - C011BB07-875D-4DEB-9582-0E1FEC0D1E4E - + + + + + fileTypes + + ftl + + foldingStartMarker + (?x) + (<(?i:head|body|table|thead|tbody|tfoot|tr|div|nav|section|aside|header|select|fieldset|style|script|ul|ol|form|dl)\b.*?> + |<!--(?!.*-->) + |\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/))) + |(\[|<)(\#|@)\w+.*\(\]|>) + ) + foldingStopMarker + (?x) + (</(?i:head|body|table|thead|tbody|tfoot|tr|div|nav|section|aside|header|select|fieldset|style|script|ul|ol|form|dl)> + |^\s*--> + |(^|\s)\} + |(\[|<)/(\#|@)\w+.*(\]|>) + ) + keyEquivalent + ^~F + name + FreeMarker + patterns + + + begin + [<\[]#-- + captures + + 0 + + name + punctuation.definition.comment.ftl + + + end + --[>\]] + name + comment.block.ftl + + + captures + + 1 + + name + punctuation.definition.function.ftl + + 2 + + name + punctuation.definition.function.ftl + + 3 + + name + entity.name.function.ftl + + 5 + + name + variable.parameter.function.ftl + + 8 + + name + entity.name.function.ftl + + 9 + + name + punctuation.definition.function.ftl + + + match + ([<\[](#|@))(\w+(\.\w+)*)((\s+[^>\]]+)*?)\s*((\/)?([>\]])) + name + meta.function.ftl + + + captures + + 1 + + name + punctuation.definition.function.ftl + + 2 + + name + punctuation.definition.function.ftl + + 3 + + name + entity.name.function.ftl + + 5 + + name + punctuation.definition.function.ftl + + + match + ([<\[]\/(#|@))(\w+(\.\w+)*)\s*([>\]]) + name + meta.function.ftl + + + captures + + 1 + + name + punctuation.definition.variable.ftl + + 3 + + name + entity.name.function.ftl + + 4 + + name + punctuation.definition.variable.ftl + + + match + (\$\{)\.?[a-zA-Z_\(][\w\(\)+-\/\*]+(\.?[\w\(\)+-\/\*]+)*(.*?|\?\?|\!)?(\}) + name + variable.other.readwrite.local.ftl + + + include + text.html.basic + + + scopeName + text.html.ftl + uuid + C011BB07-875D-4DEB-9582-0E1FEC0D1E4E + \ No newline at end of file diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java index 0a76fae71..b60b9f800 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java @@ -9,16 +9,16 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.internal.model; - +package org.eclipse.tm4e.ui.internal.model; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import org.eclipse.jface.text.Document; import org.junit.jupiter.api.Test; - -public class DocumentLineListTest { - + +public class DocumentLineListTest { + @Test public void testMultiLineChange() { Document document = new Document(); @@ -31,5 +31,5 @@ public void testMultiLineChange() { document.set("a\nb"); assertEquals(2, lineList.getNumberOfLines()); } - -} + +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java index bd33112df..306193777 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java @@ -1,73 +1,73 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.text; - -import org.eclipse.tm4e.ui.text.ICommand; - -public abstract class Command implements ICommand { - - private final String name; - private String styleRanges; - private boolean done; - - public Command(String name) { - this.name = name; - this.done = false; - } - - @Override - public String getName() { - return name; - } - - public void setStyleRanges(String styleRanges) { - this.styleRanges = styleRanges; - } - - @Override - public String getStyleRanges() { - return styleRanges; - } - - public void execute() { - if (!done) { - doExecute(); - done = true; - } - } - - protected abstract void doExecute(); - - protected abstract Integer getLineTo(); - - public static String toText(String text) { - StringBuilder newText = new StringBuilder(); - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - switch (c) { - case '\n': - newText.append("\\n"); - break; - case '\r': - newText.append("\\r"); - break; - case '"': - newText.append("\\\""); - break; - default: - newText.append(c); - } - } - return newText.toString(); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.text; + +import org.eclipse.tm4e.ui.text.ICommand; + +public abstract class Command implements ICommand { + + private final String name; + private String styleRanges; + private boolean done; + + public Command(String name) { + this.name = name; + this.done = false; + } + + @Override + public String getName() { + return name; + } + + public void setStyleRanges(String styleRanges) { + this.styleRanges = styleRanges; + } + + @Override + public String getStyleRanges() { + return styleRanges; + } + + public void execute() { + if (!done) { + doExecute(); + done = true; + } + } + + protected abstract void doExecute(); + + protected abstract Integer getLineTo(); + + public static String toText(String text) { + StringBuilder newText = new StringBuilder(); + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + switch (c) { + case '\n': + newText.append("\\n"); + break; + case '\r': + newText.append("\\r"); + break; + case '"': + newText.append("\\\""); + break; + default: + newText.append(c); + } + } + return newText.toString(); + } + +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java index da9286d83..bcf7c610d 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java @@ -1,54 +1,54 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.text; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; - -public class DocumentReplaceCommand extends Command { - - private final int pos; - private final int length; - private final String text; - private final Document document; - - public DocumentReplaceCommand(int pos, int length, String text, Document document) { - super(getName(pos, length, text)); - this.pos = pos; - this.length = length; - this.text = text; - this.document = document; - } - - public static String getName(int pos, int length, String text) { - return "document.replace(" + pos + ", " + length + ", \"" + toText(text) + "\");"; - } - - @Override - protected void doExecute() { - try { - document.replace(pos, length, text); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - - @Override - protected Integer getLineTo() { - try { - return document.getLineOfOffset(pos + length); - } catch (BadLocationException e) { - return null; - } - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.text; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; + +public class DocumentReplaceCommand extends Command { + + private final int pos; + private final int length; + private final String text; + private final Document document; + + public DocumentReplaceCommand(int pos, int length, String text, Document document) { + super(getName(pos, length, text)); + this.pos = pos; + this.length = length; + this.text = text; + this.document = document; + } + + public static String getName(int pos, int length, String text) { + return "document.replace(" + pos + ", " + length + ", \"" + toText(text) + "\");"; + } + + @Override + protected void doExecute() { + try { + document.replace(pos, length, text); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + @Override + protected Integer getLineTo() { + try { + return document.getLineOfOffset(pos + length); + } catch (BadLocationException e) { + return null; + } + } + +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java index bd789b8d4..90f1c1413 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java @@ -1,41 +1,41 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.text; - -import org.eclipse.jface.text.Document; - -public class DocumentSetCommand extends Command { - - private final String text; - private final Document document; - - public DocumentSetCommand(String text, Document document) { - super(getName(text)); - this.text = text; - this.document = document; - } - - public static String getName(String text) { - return "document.set(\"" + toText(text) + "\");"; - } - - @Override - protected void doExecute() { - document.set(text); - } - - @Override - protected Integer getLineTo() { - int numberOfLines =document.getNumberOfLines(); - return numberOfLines > 0 ? numberOfLines - 1 : null; - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.text; + +import org.eclipse.jface.text.Document; + +public class DocumentSetCommand extends Command { + + private final String text; + private final Document document; + + public DocumentSetCommand(String text, Document document) { + super(getName(text)); + this.text = text; + this.document = document; + } + + public static String getName(String text) { + return "document.set(\"" + toText(text) + "\");"; + } + + @Override + protected void doExecute() { + document.set(text); + } + + @Override + protected Integer getLineTo() { + int numberOfLines =document.getNumberOfLines(); + return numberOfLines > 0 ? numberOfLines - 1 : null; + } +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java index 2f52559ca..536c556e5 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java @@ -1,116 +1,116 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.text; - -import java.util.Arrays; -import java.util.Iterator; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.tm4e.ui.text.ITMPresentationReconcilerListener; - -public class StyleRangesCollector implements ITMPresentationReconcilerListener { - - private IDocument document; - private Command command; - private Integer waitForToLineNumber; - private boolean isFinished; - - private StringBuilder currentRanges; - - private Object lock = new Object(); - - public StyleRangesCollector() { - - } - - @Override - public void install(ITextViewer viewer, IDocument document) { - this.document = document; - } - - @Override - public void uninstall() { - this.document = null; - } - - @Override - public void colorize(TextPresentation presentation, Throwable error) { - add(presentation); - if (waitForToLineNumber != null) { - int offset = presentation.getExtent().getOffset() + presentation.getExtent().getLength(); - try { - if (waitForToLineNumber != document.getLineOfOffset(offset)) { - return; - } else { - waitForToLineNumber = null; - } - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - command.setStyleRanges("[" + currentRanges.toString() + "]"); - synchronized (lock) { - lock.notifyAll(); - } - } - - private String add(TextPresentation presentation) { - Iterator ranges = presentation.getAllStyleRangeIterator(); - while(ranges.hasNext()) { - if (currentRanges.length() > 0) { - currentRanges.append(", "); - } - currentRanges.append(ranges.next()); - } - return null; - } - - public static String toString(StyleRange[] ranges) { - return Arrays.asList(ranges).toString(); - } - - public void executeCommand(Command command) { - setCommand(command); - if (command.getStyleRanges() == null) { - synchronized (lock) { - try { - wait(command); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - public void wait(Command command) throws InterruptedException { - lock.wait(); - if (command.getStyleRanges() == null) { - wait(command); - } - } - - public void setCommand(Command command) { - this.currentRanges = new StringBuilder(); - this.command = command; - this.waitForToLineNumber = command.getLineTo(); - command.execute(); - } - - public boolean isFinished() { - return isFinished; - } - +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.text; + +import java.util.Arrays; +import java.util.Iterator; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.tm4e.ui.text.ITMPresentationReconcilerListener; + +public class StyleRangesCollector implements ITMPresentationReconcilerListener { + + private IDocument document; + private Command command; + private Integer waitForToLineNumber; + private boolean isFinished; + + private StringBuilder currentRanges; + + private Object lock = new Object(); + + public StyleRangesCollector() { + + } + + @Override + public void install(ITextViewer viewer, IDocument document) { + this.document = document; + } + + @Override + public void uninstall() { + this.document = null; + } + + @Override + public void colorize(TextPresentation presentation, Throwable error) { + add(presentation); + if (waitForToLineNumber != null) { + int offset = presentation.getExtent().getOffset() + presentation.getExtent().getLength(); + try { + if (waitForToLineNumber != document.getLineOfOffset(offset)) { + return; + } else { + waitForToLineNumber = null; + } + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + command.setStyleRanges("[" + currentRanges.toString() + "]"); + synchronized (lock) { + lock.notifyAll(); + } + } + + private String add(TextPresentation presentation) { + Iterator ranges = presentation.getAllStyleRangeIterator(); + while(ranges.hasNext()) { + if (currentRanges.length() > 0) { + currentRanges.append(", "); + } + currentRanges.append(ranges.next()); + } + return null; + } + + public static String toString(StyleRange[] ranges) { + return Arrays.asList(ranges).toString(); + } + + public void executeCommand(Command command) { + setCommand(command); + if (command.getStyleRanges() == null) { + synchronized (lock) { + try { + wait(command); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + public void wait(Command command) throws InterruptedException { + lock.wait(); + if (command.getStyleRanges() == null) { + wait(command); + } + } + + public void setCommand(Command command) { + this.currentRanges = new StringBuilder(); + this.command = command; + this.waitForToLineNumber = command.getLineTo(); + command.execute(); + } + + public boolean isFinished() { + return isFinished; + } + } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java index a6b1ff3ae..de03fbccb 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java @@ -1,54 +1,54 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.text; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.TextViewer; - -public class TextViewerInvalidateTextPresentationCommand extends Command { - - private final int offset; - private final int length; - private final TextViewer viewer; - - public TextViewerInvalidateTextPresentationCommand(int offset, int length, TextViewer viewer) { - super(getName(offset, length)); - this.offset = offset; - this.length = length; - this.viewer = viewer; - } - - public static String getName(int offset, int length) { - return "viewer.invalidateTextPresentation(" + offset + ", " + length + ");"; - } - - @Override - protected void doExecute() { - viewer.getTextWidget().getDisplay().syncExec(new Runnable() { - - @Override - public void run() { - viewer.invalidateTextPresentation(offset, length); - } - }); - } - - @Override - protected Integer getLineTo() { - try { - return viewer.getDocument().getLineOfOffset(offset + length); - } catch (BadLocationException e) { - return null; - } - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.text; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.TextViewer; + +public class TextViewerInvalidateTextPresentationCommand extends Command { + + private final int offset; + private final int length; + private final TextViewer viewer; + + public TextViewerInvalidateTextPresentationCommand(int offset, int length, TextViewer viewer) { + super(getName(offset, length)); + this.offset = offset; + this.length = length; + this.viewer = viewer; + } + + public static String getName(int offset, int length) { + return "viewer.invalidateTextPresentation(" + offset + ", " + length + ");"; + } + + @Override + protected void doExecute() { + viewer.getTextWidget().getDisplay().syncExec(new Runnable() { + + @Override + public void run() { + viewer.invalidateTextPresentation(offset, length); + } + }); + } + + @Override + protected Integer getLineTo() { + try { + return viewer.getDocument().getLineOfOffset(offset + length); + } catch (BadLocationException e) { + return null; + } + } + +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/ICommand.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/ICommand.java index 38e617e91..6da479436 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/ICommand.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/ICommand.java @@ -9,12 +9,12 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.text; - -public interface ICommand { - - String getName(); - - String getStyleRanges(); - -} +package org.eclipse.tm4e.ui.text; + +public interface ICommand { + + String getName(); + + String getStyleRanges(); + +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java index 07efeecf8..9e0e37c8a 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java @@ -9,8 +9,8 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.text; - +package org.eclipse.tm4e.ui.text; + import java.util.ArrayList; import java.util.List; @@ -26,79 +26,79 @@ import org.eclipse.tm4e.ui.internal.text.DocumentSetCommand; import org.eclipse.tm4e.ui.internal.text.StyleRangesCollector; import org.eclipse.tm4e.ui.internal.text.TextViewerInvalidateTextPresentationCommand; -import org.eclipse.tm4e.ui.themes.ITokenProvider; - -public class TMEditor { - - private final TextViewer viewer; - private final Document document; - private final Shell shell; - private StyleRangesCollector collector; - - private final List commands; - private TMPresentationReconciler reconciler; - - public TMEditor(IGrammar grammar, ITokenProvider tokenProvider, String text) { - shell = new Shell(); - viewer = new TextViewer(shell, SWT.NONE); - document = new Document(); - viewer.setDocument(document); - commands = new ArrayList<>(); - collector = new StyleRangesCollector(); - - setAndExecute(text); - - reconciler = new TMPresentationReconciler(); - reconciler.addTMPresentationReconcilerListener(collector); - reconciler.setGrammar(grammar); - reconciler.setTheme(tokenProvider); - reconciler.install(viewer); - - } - - public void set(String text) { - commands.add(new DocumentSetCommand(text, document)); - } - - private void setAndExecute(String text) { - Command command = new DocumentSetCommand(text, document); - commands.add(command); - collector.setCommand(command); - } - - public void replace(int pos, int length, String text) throws BadLocationException { - commands.add(new DocumentReplaceCommand(pos, length, text, document)); - } - - /** - * Invalidates the given range of the text presentation. - * - * @param offset - * the offset of the range to be invalidated - * @param length - * the length of the range to be invalidated - * - */ - public void invalidateTextPresentation(int offset, int length) { - commands.add(new TextViewerInvalidateTextPresentationCommand(offset, length, viewer)); - } - - public List execute() { - new Thread(() -> { - for (ICommand command : commands) { - collector.executeCommand((Command) command); - } - shell.getDisplay().syncExec(() -> shell.dispose()); - }).start(); - - Display display = shell.getDisplay(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - reconciler.uninstall(); - return commands; - } - -} +import org.eclipse.tm4e.ui.themes.ITokenProvider; + +public class TMEditor { + + private final TextViewer viewer; + private final Document document; + private final Shell shell; + private StyleRangesCollector collector; + + private final List commands; + private TMPresentationReconciler reconciler; + + public TMEditor(IGrammar grammar, ITokenProvider tokenProvider, String text) { + shell = new Shell(); + viewer = new TextViewer(shell, SWT.NONE); + document = new Document(); + viewer.setDocument(document); + commands = new ArrayList<>(); + collector = new StyleRangesCollector(); + + setAndExecute(text); + + reconciler = new TMPresentationReconciler(); + reconciler.addTMPresentationReconcilerListener(collector); + reconciler.setGrammar(grammar); + reconciler.setTheme(tokenProvider); + reconciler.install(viewer); + + } + + public void set(String text) { + commands.add(new DocumentSetCommand(text, document)); + } + + private void setAndExecute(String text) { + Command command = new DocumentSetCommand(text, document); + commands.add(command); + collector.setCommand(command); + } + + public void replace(int pos, int length, String text) throws BadLocationException { + commands.add(new DocumentReplaceCommand(pos, length, text, document)); + } + + /** + * Invalidates the given range of the text presentation. + * + * @param offset + * the offset of the range to be invalidated + * @param length + * the length of the range to be invalidated + * + */ + public void invalidateTextPresentation(int offset, int length) { + commands.add(new TextViewerInvalidateTextPresentationCommand(offset, length, viewer)); + } + + public List execute() { + new Thread(() -> { + for (ICommand command : commands) { + collector.executeCommand((Command) command); + } + shell.getDisplay().syncExec(() -> shell.dispose()); + }).start(); + + Display display = shell.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + reconciler.uninstall(); + return commands; + } + +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java index a2ed1c7db..342f6e89d 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java @@ -9,8 +9,8 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.text.typescript; - +package org.eclipse.tm4e.ui.text.typescript; + import static org.junit.jupiter.api.Assertions.*; import java.util.List; @@ -23,328 +23,328 @@ import org.eclipse.tm4e.ui.themes.css.CSSTokenProvider; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; - -public class TMPresentationReconcilerTypeScriptTest { - - @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") - @Test - public void colorizeTypescript() throws Exception { - - TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); - List commands = editor.execute(); - - assertEquals(1, commands.size()); - ICommand command = commands.get(0); - - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {3, 1, fontStyle=normal}, " - + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {5, 1, fontStyle=normal}, " - + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {7, 1, fontStyle=normal}, " - + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " - + "StyleRange {10, 2, fontStyle=normal}, " - + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {15, 1, fontStyle=normal}, " - + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {17, 1, fontStyle=normal}, " - + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {19, 1, fontStyle=normal}, " - + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " - + "StyleRange {22, 2, fontStyle=normal}, " - + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {27, 1, fontStyle=normal}, " - + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {29, 1, fontStyle=normal}, " - + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {31, 1, fontStyle=normal}, " - + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " - + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command.getStyleRanges()); - } - - @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") - @Test - public void colorizeTypescriptWithInvalidate1() throws Exception { - - TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); - editor.invalidateTextPresentation(0, 3); - List commands = editor.execute(); - - // document.set("let a = '';\nlet b = 10;\nlet c = true;"); - ICommand command0 = commands.get(0); - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {3, 1, fontStyle=normal}, " - + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {5, 1, fontStyle=normal}, " - + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {7, 1, fontStyle=normal}, " - + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " - + "StyleRange {10, 2, fontStyle=normal}, " - + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {15, 1, fontStyle=normal}, " - + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {17, 1, fontStyle=normal}, " - + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {19, 1, fontStyle=normal}, " - + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " - + "StyleRange {22, 2, fontStyle=normal}, " - + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {27, 1, fontStyle=normal}, " - + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {29, 1, fontStyle=normal}, " - + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {31, 1, fontStyle=normal}, " - + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " - + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); - - // viewer.invalidateTextPresentation(0, 3); - ICommand command1 = commands.get(1); - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); - - } - - @Disabled - @Test - public void colorizeTypescriptWithInvalidate2() throws Exception { - - TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); - editor.invalidateTextPresentation(0, 2); - List commands = editor.execute(); - - // document.set("let a = '';\nlet b = 10;\nlet c = true;"); - ICommand command0 = commands.get(0); - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {3, 1, fontStyle=normal}, " - + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {5, 1, fontStyle=normal}, " - + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {7, 1, fontStyle=normal}, " - + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " - + "StyleRange {10, 2, fontStyle=normal}, " - + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {15, 1, fontStyle=normal}, " - + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {17, 1, fontStyle=normal}, " - + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {19, 1, fontStyle=normal}, " - + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " - + "StyleRange {22, 2, fontStyle=normal}, " - + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {27, 1, fontStyle=normal}, " - + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {29, 1, fontStyle=normal}, " - + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {31, 1, fontStyle=normal}, " - + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " - + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); - - // viewer.invalidateTextPresentation(0, 2); - ICommand command1 = commands.get(1); - assertEquals( - "[" - + "StyleRange {0, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); - - } - - @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") - @Test - public void colorizeTypescriptWithInvalidate3() throws Exception { - - TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); - editor.invalidateTextPresentation(1, 2); - List commands = editor.execute(); - - // document.set("let a = '';\nlet b = 10;\nlet c = true;"); - ICommand command0 = commands.get(0); - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {3, 1, fontStyle=normal}, " - + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {5, 1, fontStyle=normal}, " - + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {7, 1, fontStyle=normal}, " - + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " - + "StyleRange {10, 2, fontStyle=normal}, " - + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {15, 1, fontStyle=normal}, " - + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {17, 1, fontStyle=normal}, " - + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {19, 1, fontStyle=normal}, " - + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " - + "StyleRange {22, 2, fontStyle=normal}, " - + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {27, 1, fontStyle=normal}, " - + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {29, 1, fontStyle=normal}, " - + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {31, 1, fontStyle=normal}, " - + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " - + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); - - // viewer.invalidateTextPresentation(1, 2); - ICommand command1 = commands.get(1); - assertEquals( - "[" - + "StyleRange {1, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); - - } - - @Disabled - @Test - public void colorizeTypescriptWithInvalidate4() throws Exception { - - TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); - editor.invalidateTextPresentation(1, 1); - List commands = editor.execute(); - - // document.set("let a = '';\nlet b = 10;\nlet c = true;"); - ICommand command0 = commands.get(0); - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {3, 1, fontStyle=normal}, " - + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {5, 1, fontStyle=normal}, " - + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {7, 1, fontStyle=normal}, " - + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " - + "StyleRange {10, 2, fontStyle=normal}, " - + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {15, 1, fontStyle=normal}, " - + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {17, 1, fontStyle=normal}, " - + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {19, 1, fontStyle=normal}, " - + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " - + "StyleRange {22, 2, fontStyle=normal}, " - + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {27, 1, fontStyle=normal}, " - + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {29, 1, fontStyle=normal}, " - + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {31, 1, fontStyle=normal}, " - + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " - + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); - - // viewer.invalidateTextPresentation(1, 1); - ICommand command1 = commands.get(1); - assertEquals( - "[" - + "StyleRange {1, 1, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); - - } - - @Disabled - @Test - public void colorizeTypescriptWithInvalidate8() throws Exception { - - TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); - editor.invalidateTextPresentation(1, 8); - List commands = editor.execute(); - - // document.set("let a = '';\nlet b = 10;\nlet c = true;"); - ICommand command0 = commands.get(0); - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {3, 1, fontStyle=normal}, " - + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {5, 1, fontStyle=normal}, " - + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {7, 1, fontStyle=normal}, " - + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " - + "StyleRange {10, 2, fontStyle=normal}, " - + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {15, 1, fontStyle=normal}, " - + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {17, 1, fontStyle=normal}, " - + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {19, 1, fontStyle=normal}, " - + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " - + "StyleRange {22, 2, fontStyle=normal}, " - + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " - + "StyleRange {27, 1, fontStyle=normal}, " - + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {29, 1, fontStyle=normal}, " - + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " - + "StyleRange {31, 1, fontStyle=normal}, " - + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " - + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); - - // viewer.invalidateTextPresentation(1, 8); - ICommand command1 = commands.get(1); - assertEquals( - "[" - + "StyleRange {1, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); - - } - - @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") - @Test - public void colorizeTypescriptWithInvalidateAndSeveralLines() throws Exception { - - TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "a\r\n\r\nb"); - editor.invalidateTextPresentation(0, 6); - - List commands = editor.execute(); - - assertEquals(2, commands.size()); - - for (ICommand command : commands) { - assertEquals( - "[" - + "StyleRange {0, 3, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " - + "StyleRange {3, 2, fontStyle=normal}, " - + "StyleRange {5, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}" - + "]", - command.getStyleRanges()); - } - } - - private static ITokenProvider getTokenProvider() { - return new CSSTokenProvider(TMEditor.class.getResourceAsStream("Solarized-light.css")); - } - - public static IGrammar getGrammar() { - Registry registry = new Registry(); - try { - return registry.loadGrammarFromPathSync("TypeScript.tmLanguage.json", - TMPresentationReconcilerTypeScriptTest.class.getClassLoader().getResourceAsStream("/grammars/TypeScript.tmLanguage.json")); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } + +public class TMPresentationReconcilerTypeScriptTest { + + @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") + @Test + public void colorizeTypescript() throws Exception { + + TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); + List commands = editor.execute(); + + assertEquals(1, commands.size()); + ICommand command = commands.get(0); + + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {3, 1, fontStyle=normal}, " + + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {5, 1, fontStyle=normal}, " + + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {7, 1, fontStyle=normal}, " + + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " + + "StyleRange {10, 2, fontStyle=normal}, " + + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {15, 1, fontStyle=normal}, " + + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {17, 1, fontStyle=normal}, " + + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {19, 1, fontStyle=normal}, " + + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " + + "StyleRange {22, 2, fontStyle=normal}, " + + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {27, 1, fontStyle=normal}, " + + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {29, 1, fontStyle=normal}, " + + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {31, 1, fontStyle=normal}, " + + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + + "StyleRange {36, 1, fontStyle=normal}" + + "]", + command.getStyleRanges()); + } + + @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") + @Test + public void colorizeTypescriptWithInvalidate1() throws Exception { + + TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); + editor.invalidateTextPresentation(0, 3); + List commands = editor.execute(); + + // document.set("let a = '';\nlet b = 10;\nlet c = true;"); + ICommand command0 = commands.get(0); + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {3, 1, fontStyle=normal}, " + + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {5, 1, fontStyle=normal}, " + + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {7, 1, fontStyle=normal}, " + + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " + + "StyleRange {10, 2, fontStyle=normal}, " + + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {15, 1, fontStyle=normal}, " + + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {17, 1, fontStyle=normal}, " + + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {19, 1, fontStyle=normal}, " + + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " + + "StyleRange {22, 2, fontStyle=normal}, " + + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {27, 1, fontStyle=normal}, " + + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {29, 1, fontStyle=normal}, " + + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {31, 1, fontStyle=normal}, " + + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + + "StyleRange {36, 1, fontStyle=normal}" + + "]", + command0.getStyleRanges()); + + // viewer.invalidateTextPresentation(0, 3); + ICommand command1 = commands.get(1); + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" + + "]", + command1.getStyleRanges()); + + } + + @Disabled + @Test + public void colorizeTypescriptWithInvalidate2() throws Exception { + + TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); + editor.invalidateTextPresentation(0, 2); + List commands = editor.execute(); + + // document.set("let a = '';\nlet b = 10;\nlet c = true;"); + ICommand command0 = commands.get(0); + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {3, 1, fontStyle=normal}, " + + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {5, 1, fontStyle=normal}, " + + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {7, 1, fontStyle=normal}, " + + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " + + "StyleRange {10, 2, fontStyle=normal}, " + + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {15, 1, fontStyle=normal}, " + + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {17, 1, fontStyle=normal}, " + + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {19, 1, fontStyle=normal}, " + + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " + + "StyleRange {22, 2, fontStyle=normal}, " + + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {27, 1, fontStyle=normal}, " + + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {29, 1, fontStyle=normal}, " + + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {31, 1, fontStyle=normal}, " + + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + + "StyleRange {36, 1, fontStyle=normal}" + + "]", + command0.getStyleRanges()); + + // viewer.invalidateTextPresentation(0, 2); + ICommand command1 = commands.get(1); + assertEquals( + "[" + + "StyleRange {0, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" + + "]", + command1.getStyleRanges()); + + } + + @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") + @Test + public void colorizeTypescriptWithInvalidate3() throws Exception { + + TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); + editor.invalidateTextPresentation(1, 2); + List commands = editor.execute(); + + // document.set("let a = '';\nlet b = 10;\nlet c = true;"); + ICommand command0 = commands.get(0); + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {3, 1, fontStyle=normal}, " + + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {5, 1, fontStyle=normal}, " + + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {7, 1, fontStyle=normal}, " + + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " + + "StyleRange {10, 2, fontStyle=normal}, " + + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {15, 1, fontStyle=normal}, " + + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {17, 1, fontStyle=normal}, " + + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {19, 1, fontStyle=normal}, " + + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " + + "StyleRange {22, 2, fontStyle=normal}, " + + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {27, 1, fontStyle=normal}, " + + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {29, 1, fontStyle=normal}, " + + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {31, 1, fontStyle=normal}, " + + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + + "StyleRange {36, 1, fontStyle=normal}" + + "]", + command0.getStyleRanges()); + + // viewer.invalidateTextPresentation(1, 2); + ICommand command1 = commands.get(1); + assertEquals( + "[" + + "StyleRange {1, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" + + "]", + command1.getStyleRanges()); + + } + + @Disabled + @Test + public void colorizeTypescriptWithInvalidate4() throws Exception { + + TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); + editor.invalidateTextPresentation(1, 1); + List commands = editor.execute(); + + // document.set("let a = '';\nlet b = 10;\nlet c = true;"); + ICommand command0 = commands.get(0); + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {3, 1, fontStyle=normal}, " + + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {5, 1, fontStyle=normal}, " + + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {7, 1, fontStyle=normal}, " + + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " + + "StyleRange {10, 2, fontStyle=normal}, " + + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {15, 1, fontStyle=normal}, " + + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {17, 1, fontStyle=normal}, " + + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {19, 1, fontStyle=normal}, " + + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " + + "StyleRange {22, 2, fontStyle=normal}, " + + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {27, 1, fontStyle=normal}, " + + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {29, 1, fontStyle=normal}, " + + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {31, 1, fontStyle=normal}, " + + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + + "StyleRange {36, 1, fontStyle=normal}" + + "]", + command0.getStyleRanges()); + + // viewer.invalidateTextPresentation(1, 1); + ICommand command1 = commands.get(1); + assertEquals( + "[" + + "StyleRange {1, 1, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" + + "]", + command1.getStyleRanges()); + + } + + @Disabled + @Test + public void colorizeTypescriptWithInvalidate8() throws Exception { + + TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); + editor.invalidateTextPresentation(1, 8); + List commands = editor.execute(); + + // document.set("let a = '';\nlet b = 10;\nlet c = true;"); + ICommand command0 = commands.get(0); + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {3, 1, fontStyle=normal}, " + + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {5, 1, fontStyle=normal}, " + + "StyleRange {6, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {7, 1, fontStyle=normal}, " + + "StyleRange {8, 2, fontStyle=normal, foreground=Color {42, 161, 152, 255}}, " + + "StyleRange {10, 2, fontStyle=normal}, " + + "StyleRange {12, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {15, 1, fontStyle=normal}, " + + "StyleRange {16, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {17, 1, fontStyle=normal}, " + + "StyleRange {18, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {19, 1, fontStyle=normal}, " + + "StyleRange {20, 2, fontStyle=normal, foreground=Color {211, 54, 130, 255}}, " + + "StyleRange {22, 2, fontStyle=normal}, " + + "StyleRange {24, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + + "StyleRange {27, 1, fontStyle=normal}, " + + "StyleRange {28, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {29, 1, fontStyle=normal}, " + + "StyleRange {30, 1, fontStyle=normal, foreground=Color {133, 153, 0, 255}}, " + + "StyleRange {31, 1, fontStyle=normal}, " + + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + + "StyleRange {36, 1, fontStyle=normal}" + + "]", + command0.getStyleRanges()); + + // viewer.invalidateTextPresentation(1, 8); + ICommand command1 = commands.get(1); + assertEquals( + "[" + + "StyleRange {1, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" + + "]", + command1.getStyleRanges()); + + } + + @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") + @Test + public void colorizeTypescriptWithInvalidateAndSeveralLines() throws Exception { + + TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "a\r\n\r\nb"); + editor.invalidateTextPresentation(0, 6); + + List commands = editor.execute(); + + assertEquals(2, commands.size()); + + for (ICommand command : commands) { + assertEquals( + "[" + + "StyleRange {0, 3, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + + "StyleRange {3, 2, fontStyle=normal}, " + + "StyleRange {5, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}" + + "]", + command.getStyleRanges()); + } + } + + private static ITokenProvider getTokenProvider() { + return new CSSTokenProvider(TMEditor.class.getResourceAsStream("Solarized-light.css")); + } + + public static IGrammar getGrammar() { + Registry registry = new Registry(); + try { + return registry.loadGrammarFromPathSync("TypeScript.tmLanguage.json", + TMPresentationReconcilerTypeScriptTest.class.getClassLoader().getResourceAsStream("/grammars/TypeScript.tmLanguage.json")); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java index 796737abb..d0e356a66 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java @@ -9,16 +9,16 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.themes; - -import org.eclipse.tm4e.ui.internal.themes.AbstractThemeManager; -import org.osgi.service.prefs.BackingStoreException; - -public class MockThemeManager extends AbstractThemeManager { - - @Override - public void save() throws BackingStoreException { - - } - -} +package org.eclipse.tm4e.ui.themes; + +import org.eclipse.tm4e.ui.internal.themes.AbstractThemeManager; +import org.osgi.service.prefs.BackingStoreException; + +public class MockThemeManager extends AbstractThemeManager { + + @Override + public void save() throws BackingStoreException { + + } + +} diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java index 02abdfa07..7b41dd3de 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java @@ -1,71 +1,71 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Test for theme manager. - * - */ -public class ThemeManagerTest implements ThemeIdConstants { - - private IThemeManager manager; - - @BeforeEach - public void init() { - manager = new MockThemeManager(); - - // Register theme - manager.registerTheme(new Theme(SolarizedLight, "./themes/SolarizedLight.css", "SolarizedLight", false, true)); - manager.registerTheme(new Theme(Light, "./themes/Light.css", "Light", false, false)); - manager.registerTheme(new Theme(Dark, "./themes/Dark.css", "Dark", true, true)); - manager.registerTheme(new Theme(Monokai, "./themes/Monokai.css", "Monokai", true, false)); - } - - - @Test - public void themes() { - // All themes - ITheme[] themes = manager.getThemes(); - assertNotNull(themes); - assertEquals(4, themes.length); - } - - @Test - public void defaultThemeAssociation() { - // Default theme - ITheme theme = manager.getDefaultTheme(); - assertNotNull(theme); - assertEquals(SolarizedLight, theme.getId()); - } - - @Test - public void darkThemes() { - // All themes for Dark E4 CSS Theme - ITheme[] darkThemes = manager.getThemes(true); - assertNotNull(darkThemes); - assertEquals(2, darkThemes.length); - assertEquals(Dark, darkThemes[0].getId()); - assertEquals(Monokai, darkThemes[1].getId()); - - // All themes for Other E4 CSS Theme - ITheme[] otherThemes = manager.getThemes(false); - assertNotNull(otherThemes); - assertEquals(2, otherThemes.length); - assertEquals(SolarizedLight, otherThemes[0].getId()); - assertEquals(Light, otherThemes[1].getId()); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Test for theme manager. + * + */ +public class ThemeManagerTest implements ThemeIdConstants { + + private IThemeManager manager; + + @BeforeEach + public void init() { + manager = new MockThemeManager(); + + // Register theme + manager.registerTheme(new Theme(SolarizedLight, "./themes/SolarizedLight.css", "SolarizedLight", false, true)); + manager.registerTheme(new Theme(Light, "./themes/Light.css", "Light", false, false)); + manager.registerTheme(new Theme(Dark, "./themes/Dark.css", "Dark", true, true)); + manager.registerTheme(new Theme(Monokai, "./themes/Monokai.css", "Monokai", true, false)); + } + + + @Test + public void themes() { + // All themes + ITheme[] themes = manager.getThemes(); + assertNotNull(themes); + assertEquals(4, themes.length); + } + + @Test + public void defaultThemeAssociation() { + // Default theme + ITheme theme = manager.getDefaultTheme(); + assertNotNull(theme); + assertEquals(SolarizedLight, theme.getId()); + } + + @Test + public void darkThemes() { + // All themes for Dark E4 CSS Theme + ITheme[] darkThemes = manager.getThemes(true); + assertNotNull(darkThemes); + assertEquals(2, darkThemes.length); + assertEquals(Dark, darkThemes[0].getId()); + assertEquals(Monokai, darkThemes[1].getId()); + + // All themes for Other E4 CSS Theme + ITheme[] otherThemes = manager.getThemes(false); + assertNotNull(otherThemes); + assertEquals(2, otherThemes.length); + assertEquals(SolarizedLight, otherThemes[0].getId()); + assertEquals(Light, otherThemes[1].getId()); + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java index 8f7c14597..23bd0f0e1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java @@ -1,138 +1,138 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui; - -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.tm4e.ui.internal.model.TMModelManager; -import org.eclipse.tm4e.ui.internal.snippets.SnippetManager; -import org.eclipse.tm4e.ui.internal.themes.ThemeManager; -import org.eclipse.tm4e.ui.model.ITMModelManager; -import org.eclipse.tm4e.ui.snippets.ISnippetManager; -import org.eclipse.tm4e.ui.themes.ColorManager; -import org.eclipse.tm4e.ui.themes.IThemeManager; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class TMUIPlugin extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.tm4e.ui"; //$NON-NLS-1$ - private static final String TRACE_ID = PLUGIN_ID + "/trace"; //$NON-NLS-1$ - - // The shared instance - private static TMUIPlugin plugin; - - /** - * The constructor - */ - public TMUIPlugin() { - } - - public void trace(String message) { - if (Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID))) { - getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); - } - } - - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - boolean isDebugOn = Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID)); - if (isDebugOn) { - Logger tm4eCoreLogger = Logger.getLogger("org.eclipse.tm4e"); - tm4eCoreLogger.setLevel(Level.FINEST); - tm4eCoreLogger.addHandler(new Handler() { - - @Override public void publish(LogRecord record) { - TMUIPlugin.getDefault().getLog().log(new Status( - toSeverity(record.getLevel()), - "org.eclipse.tm4e.core", - record.getMessage() - )); - } - - private int toSeverity(Level level) { - if (level.intValue() >= Level.SEVERE.intValue()) { - return IStatus.ERROR; - } - if (level.intValue() >= Level.WARNING.intValue()) { - return IStatus.WARNING; - } - return IStatus.INFO; - } - - @Override public void flush() { - // nothing to do - } - - @Override public void close() throws SecurityException { - // nothing to do - } - }); - } - } - - @Override - public void stop(BundleContext context) throws Exception { - ColorManager.getInstance().dispose(); - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static TMUIPlugin getDefault() { - return plugin; - } - - /** - * Returns the TextMate model manager. - * - * @return the TextMate model manager. - */ - public static ITMModelManager getTMModelManager() { - return TMModelManager.getInstance(); - } - - /** - * Returns the TextMate themes manager. - * - * @return the TextMate themes manager. - */ - public static IThemeManager getThemeManager() { - return ThemeManager.getInstance(); - } - - /** - * Returns the Snippet manager. - * - * @return the Snippet manager. - */ - public static ISnippetManager getSnippetManager() { - return SnippetManager.getInstance(); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui; + +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.tm4e.ui.internal.model.TMModelManager; +import org.eclipse.tm4e.ui.internal.snippets.SnippetManager; +import org.eclipse.tm4e.ui.internal.themes.ThemeManager; +import org.eclipse.tm4e.ui.model.ITMModelManager; +import org.eclipse.tm4e.ui.snippets.ISnippetManager; +import org.eclipse.tm4e.ui.themes.ColorManager; +import org.eclipse.tm4e.ui.themes.IThemeManager; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class TMUIPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.tm4e.ui"; //$NON-NLS-1$ + private static final String TRACE_ID = PLUGIN_ID + "/trace"; //$NON-NLS-1$ + + // The shared instance + private static TMUIPlugin plugin; + + /** + * The constructor + */ + public TMUIPlugin() { + } + + public void trace(String message) { + if (Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID))) { + getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); + } + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + boolean isDebugOn = Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID)); + if (isDebugOn) { + Logger tm4eCoreLogger = Logger.getLogger("org.eclipse.tm4e"); + tm4eCoreLogger.setLevel(Level.FINEST); + tm4eCoreLogger.addHandler(new Handler() { + + @Override public void publish(LogRecord record) { + TMUIPlugin.getDefault().getLog().log(new Status( + toSeverity(record.getLevel()), + "org.eclipse.tm4e.core", + record.getMessage() + )); + } + + private int toSeverity(Level level) { + if (level.intValue() >= Level.SEVERE.intValue()) { + return IStatus.ERROR; + } + if (level.intValue() >= Level.WARNING.intValue()) { + return IStatus.WARNING; + } + return IStatus.INFO; + } + + @Override public void flush() { + // nothing to do + } + + @Override public void close() throws SecurityException { + // nothing to do + } + }); + } + } + + @Override + public void stop(BundleContext context) throws Exception { + ColorManager.getInstance().dispose(); + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TMUIPlugin getDefault() { + return plugin; + } + + /** + * Returns the TextMate model manager. + * + * @return the TextMate model manager. + */ + public static ITMModelManager getTMModelManager() { + return TMModelManager.getInstance(); + } + + /** + * Returns the TextMate themes manager. + * + * @return the TextMate themes manager. + */ + public static IThemeManager getThemeManager() { + return ThemeManager.getInstance(); + } + + /** + * Returns the Snippet manager. + * + * @return the Snippet manager. + */ + public static ISnippetManager getSnippetManager() { + return SnippetManager.getInstance(); + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java index a90881834..c0df882a7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java @@ -1,39 +1,39 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal; - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; -import org.eclipse.ui.IEditorPart; - -/** - * An Eclipse property tester to check if a given editor part is linked to the - * {@link TMPresentationReconciler}. - * - */ -public class TMPropertyTester extends PropertyTester { - - private static final String CAN_SUPPORT_TEXT_MATE = "canSupportTextMate"; - - @Override - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (CAN_SUPPORT_TEXT_MATE.equals(property)) { - if (receiver instanceof IEditorPart) { - IEditorPart editorPart = (IEditorPart) receiver; - TMPresentationReconciler reconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); - return reconciler != null && reconciler.isEnabled(); - } - } - return false; - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; +import org.eclipse.ui.IEditorPart; + +/** + * An Eclipse property tester to check if a given editor part is linked to the + * {@link TMPresentationReconciler}. + * + */ +public class TMPropertyTester extends PropertyTester { + + private static final String CAN_SUPPORT_TEXT_MATE = "canSupportTextMate"; + + @Override + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + if (CAN_SUPPORT_TEXT_MATE.equals(property)) { + if (receiver instanceof IEditorPart) { + IEditorPart editorPart = (IEditorPart) receiver; + TMPresentationReconciler reconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); + return reconciler != null && reconciler.isEnabled(); + } + } + return false; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java index ae490de7b..2f1ec1fe7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java @@ -1,93 +1,93 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal; - -import org.eclipse.osgi.util.NLS; - -/** - * Helper class to get NLSed messages. - * - */ -public class TMUIMessages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.tm4e.ui.internal.TMUIMessages"; //$NON-NLS-1$ - - // Buttons - public static String Button_new; - public static String Button_edit; - public static String Button_remove; - public static String Button_browse_FileSystem; - public static String Button_browse_Workspace; - - // TextMate preferences page - public static String TextMatePreferencePage_GrammarRelatedLink; - public static String TextMatePreferencePage_LanguageConfigurationRelatedLink; - public static String TextMatePreferencePage_ThemeRelatedLink; - - // Grammar preferences page - public static String GrammarPreferencePage_title; - public static String GrammarPreferencePage_description; - public static String GrammarPreferencePage_column_scopeName; - public static String GrammarPreferencePage_column_path; - public static String GrammarPreferencePage_column_pluginId; - public static String GrammarPreferencePage_tab_general_text; - public static String GrammarInfoWidget_name_text; - public static String GrammarInfoWidget_scopeName_text; - public static String GrammarInfoWidget_fileTypes_text; - public static String GrammarPreferencePage_tab_contentType_text; - public static String GrammarPreferencePage_tab_theme_text; - public static String GrammarPreferencePage_tab_injection_text; - public static String GrammarPreferencePage_preview; - - // Theme preferences page - public static String ThemePreferencePage_title; - public static String ThemePreferencePage_description; - public static String ThemePreferencePage_column_name; - public static String ThemePreferencePage_column_path; - public static String ThemePreferencePage_column_pluginId; - public static String ThemePreferencePage_darkThemeButton_label; - public static String ThemePreferencePage_defaultThemeButton_label; - public static String ThemePreferencePage_preview; - - // Widgets - public static String ContentTypesBindingWidget_description; - public static String ThemeAssociationsWidget_description; - public static String ThemeAssociationsWidget_remove_dialog_title; - public static String ThemeAssociationsWidget_remove_dialog_message; - public static String ThemeAssociationLabelProvider_light; - public static String ThemeAssociationLabelProvider_dark; - - // Wizards - public static String SelectGrammarWizardPage_title; - public static String SelectGrammarWizardPage_description; - public static String SelectGrammarWizardPage_file_label; - public static String SelectGrammarWizardPage_file_error_required; - public static String SelectGrammarWizardPage_file_error_load; - public static String SelectGrammarWizardPage_file_error_invalid; - - public static String CreateThemeAssociationWizardPage_title; - public static String CreateThemeAssociationWizardPage_description; - public static String CreateThemeAssociationWizardPage_theme_text; - public static String CreateThemeAssociationWizardPage_grammar_text; - public static String CreateThemeAssociationWizardPage_theme_error_required; - public static String CreateThemeAssociationWizardPage_grammar_error_required; - public static String CreateThemeAssociationWizardPage_whenDark_text; - - // TMPresentationReconciler register dialog confirmation - public static String TMPresentationReconciler_register_dialog_title; - public static String TMPresentationReconciler_register_dialog_message; - - static { - NLS.initializeMessages(BUNDLE_NAME, TMUIMessages.class); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal; + +import org.eclipse.osgi.util.NLS; + +/** + * Helper class to get NLSed messages. + * + */ +public class TMUIMessages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.tm4e.ui.internal.TMUIMessages"; //$NON-NLS-1$ + + // Buttons + public static String Button_new; + public static String Button_edit; + public static String Button_remove; + public static String Button_browse_FileSystem; + public static String Button_browse_Workspace; + + // TextMate preferences page + public static String TextMatePreferencePage_GrammarRelatedLink; + public static String TextMatePreferencePage_LanguageConfigurationRelatedLink; + public static String TextMatePreferencePage_ThemeRelatedLink; + + // Grammar preferences page + public static String GrammarPreferencePage_title; + public static String GrammarPreferencePage_description; + public static String GrammarPreferencePage_column_scopeName; + public static String GrammarPreferencePage_column_path; + public static String GrammarPreferencePage_column_pluginId; + public static String GrammarPreferencePage_tab_general_text; + public static String GrammarInfoWidget_name_text; + public static String GrammarInfoWidget_scopeName_text; + public static String GrammarInfoWidget_fileTypes_text; + public static String GrammarPreferencePage_tab_contentType_text; + public static String GrammarPreferencePage_tab_theme_text; + public static String GrammarPreferencePage_tab_injection_text; + public static String GrammarPreferencePage_preview; + + // Theme preferences page + public static String ThemePreferencePage_title; + public static String ThemePreferencePage_description; + public static String ThemePreferencePage_column_name; + public static String ThemePreferencePage_column_path; + public static String ThemePreferencePage_column_pluginId; + public static String ThemePreferencePage_darkThemeButton_label; + public static String ThemePreferencePage_defaultThemeButton_label; + public static String ThemePreferencePage_preview; + + // Widgets + public static String ContentTypesBindingWidget_description; + public static String ThemeAssociationsWidget_description; + public static String ThemeAssociationsWidget_remove_dialog_title; + public static String ThemeAssociationsWidget_remove_dialog_message; + public static String ThemeAssociationLabelProvider_light; + public static String ThemeAssociationLabelProvider_dark; + + // Wizards + public static String SelectGrammarWizardPage_title; + public static String SelectGrammarWizardPage_description; + public static String SelectGrammarWizardPage_file_label; + public static String SelectGrammarWizardPage_file_error_required; + public static String SelectGrammarWizardPage_file_error_load; + public static String SelectGrammarWizardPage_file_error_invalid; + + public static String CreateThemeAssociationWizardPage_title; + public static String CreateThemeAssociationWizardPage_description; + public static String CreateThemeAssociationWizardPage_theme_text; + public static String CreateThemeAssociationWizardPage_grammar_text; + public static String CreateThemeAssociationWizardPage_theme_error_required; + public static String CreateThemeAssociationWizardPage_grammar_error_required; + public static String CreateThemeAssociationWizardPage_whenDark_text; + + // TMPresentationReconciler register dialog confirmation + public static String TMPresentationReconciler_register_dialog_title; + public static String TMPresentationReconciler_register_dialog_message; + + static { + NLS.initializeMessages(BUNDLE_NAME, TMUIMessages.class); + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java index fb549daae..85b5ab8d1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java @@ -1,104 +1,104 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.menus; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.expressions.IEvaluationContext; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; -import org.eclipse.tm4e.ui.themes.ITheme; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.IThemeManager; -import org.eclipse.tm4e.ui.themes.ThemeAssociation; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.ISources; -import org.eclipse.ui.actions.CompoundContributionItem; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.menus.IWorkbenchContribution; -import org.eclipse.ui.services.IServiceLocator; -import org.osgi.service.prefs.BackingStoreException; - -/** - * Contribute "Switch to theme" menu item with list of available themes. - * - */ -public class ThemeContribution extends CompoundContributionItem implements IWorkbenchContribution { - - private IHandlerService handlerService; - - @Override - public void initialize(IServiceLocator serviceLocator) { - handlerService = serviceLocator.getService(IHandlerService.class); - } - - @Override - protected IContributionItem[] getContributionItems() { - List items = new ArrayList<>(); - if (handlerService != null) { - IEditorPart editorPart = getActivePart(handlerService.getCurrentState()); - if (editorPart != null) { - IThemeManager manager = TMUIPlugin.getThemeManager(); - boolean dark = manager.isDarkEclipseTheme(); - ITheme[] themes = manager.getThemes(); - TMPresentationReconciler presentationReconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); - if (themes != null && presentationReconciler != null) { - String scopeName = presentationReconciler.getGrammar().getScopeName(); - ITheme selectedTheme = manager.getThemeForScope(scopeName, dark); - for (ITheme theme : themes) { - IAction action = createAction(scopeName, theme, dark); - if (theme.equals(selectedTheme)) { - action.setChecked(true); - } - IContributionItem item = new ActionContributionItem(action); - items.add(item); - } - } - - } - } - return items.toArray(new IContributionItem[items.size()]); - } - - private Action createAction(final String scopeName, final ITheme theme, boolean whenDark) { - return new Action(theme.getName()) { - @Override - public void run() { - IThemeManager manager = TMUIPlugin.getThemeManager(); - IThemeAssociation association = new ThemeAssociation(theme.getId(), scopeName, whenDark); - manager.registerThemeAssociation(association); - try { - manager.save(); - } catch (BackingStoreException e) { - e.printStackTrace(); - } - } - }; - } - - private static IEditorPart getActivePart(IEvaluationContext context) { - if (context == null) - return null; - - Object activePart = context.getVariable(ISources.ACTIVE_PART_NAME); - if ((activePart instanceof IEditorPart)) - return (IEditorPart) activePart; - - return null; - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.menus; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; +import org.eclipse.tm4e.ui.themes.ITheme; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.IThemeManager; +import org.eclipse.tm4e.ui.themes.ThemeAssociation; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.ISources; +import org.eclipse.ui.actions.CompoundContributionItem; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.menus.IWorkbenchContribution; +import org.eclipse.ui.services.IServiceLocator; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Contribute "Switch to theme" menu item with list of available themes. + * + */ +public class ThemeContribution extends CompoundContributionItem implements IWorkbenchContribution { + + private IHandlerService handlerService; + + @Override + public void initialize(IServiceLocator serviceLocator) { + handlerService = serviceLocator.getService(IHandlerService.class); + } + + @Override + protected IContributionItem[] getContributionItems() { + List items = new ArrayList<>(); + if (handlerService != null) { + IEditorPart editorPart = getActivePart(handlerService.getCurrentState()); + if (editorPart != null) { + IThemeManager manager = TMUIPlugin.getThemeManager(); + boolean dark = manager.isDarkEclipseTheme(); + ITheme[] themes = manager.getThemes(); + TMPresentationReconciler presentationReconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); + if (themes != null && presentationReconciler != null) { + String scopeName = presentationReconciler.getGrammar().getScopeName(); + ITheme selectedTheme = manager.getThemeForScope(scopeName, dark); + for (ITheme theme : themes) { + IAction action = createAction(scopeName, theme, dark); + if (theme.equals(selectedTheme)) { + action.setChecked(true); + } + IContributionItem item = new ActionContributionItem(action); + items.add(item); + } + } + + } + } + return items.toArray(new IContributionItem[items.size()]); + } + + private Action createAction(final String scopeName, final ITheme theme, boolean whenDark) { + return new Action(theme.getName()) { + @Override + public void run() { + IThemeManager manager = TMUIPlugin.getThemeManager(); + IThemeAssociation association = new ThemeAssociation(theme.getId(), scopeName, whenDark); + manager.registerThemeAssociation(association); + try { + manager.save(); + } catch (BackingStoreException e) { + e.printStackTrace(); + } + } + }; + } + + private static IEditorPart getActivePart(IEvaluationContext context) { + if (context == null) + return null; + + Object activePart = context.getVariable(ISources.ACTIVE_PART_NAME); + if ((activePart instanceof IEditorPart)) + return (IEditorPart) activePart; + + return null; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java index b6eddca6c..769b794fb 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java @@ -1,59 +1,59 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.model; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; - -/** - * Utilities class for {@link IDocument}. - * - */ -public class DocumentHelper { - - public static int getStartLine(DocumentEvent event) throws BadLocationException { - return event.getDocument().getLineOfOffset(event.getOffset()); - } - - public static int getEndLine(DocumentEvent event, boolean documentAboutToBeChanged) throws BadLocationException { - int length = documentAboutToBeChanged ? event.getLength() : event.getText().length(); - return event.getDocument().getLineOfOffset(event.getOffset() + length); - } - - public static boolean isRemove(DocumentEvent event) { - return event.getText() == null || event.getText().length() == 0; - } - - public static boolean isInsert(DocumentEvent event) { - return event.getLength() == 0 && event.getText() != null; - } - - public static String getLineText(IDocument document, int line, boolean withLineDelimiter) - throws BadLocationException { - int lo = document.getLineOffset(line); - int ll = document.getLineLength(line); - if (!withLineDelimiter) { - String delim = document.getLineDelimiter(line); - ll = ll - (delim != null ? delim.length() : 0); - } - return document.get(lo, ll); - } - - public static IRegion getRegion(IDocument document, int fromLine, int toLine) throws BadLocationException { - int startOffset = document.getLineOffset(fromLine); - int endOffset = document.getLineOffset(toLine) + document.getLineLength(toLine); - return new Region(startOffset, endOffset - startOffset); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.model; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; + +/** + * Utilities class for {@link IDocument}. + * + */ +public class DocumentHelper { + + public static int getStartLine(DocumentEvent event) throws BadLocationException { + return event.getDocument().getLineOfOffset(event.getOffset()); + } + + public static int getEndLine(DocumentEvent event, boolean documentAboutToBeChanged) throws BadLocationException { + int length = documentAboutToBeChanged ? event.getLength() : event.getText().length(); + return event.getDocument().getLineOfOffset(event.getOffset() + length); + } + + public static boolean isRemove(DocumentEvent event) { + return event.getText() == null || event.getText().length() == 0; + } + + public static boolean isInsert(DocumentEvent event) { + return event.getLength() == 0 && event.getText() != null; + } + + public static String getLineText(IDocument document, int line, boolean withLineDelimiter) + throws BadLocationException { + int lo = document.getLineOffset(line); + int ll = document.getLineLength(line); + if (!withLineDelimiter) { + String delim = document.getLineDelimiter(line); + ll = ll - (delim != null ? delim.length() : 0); + } + return document.get(lo, ll); + } + + public static IRegion getRegion(IDocument document, int fromLine, int toLine) throws BadLocationException { + int startOffset = document.getLineOffset(fromLine); + int endOffset = document.getLineOffset(toLine) + document.getLineLength(toLine); + return new Region(startOffset, endOffset - startOffset); + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java index 1b5ff2dc8..917650471 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java @@ -1,50 +1,50 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation 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: - * IBM Corporation - initial API and implementation - * QNX Software System - *******************************************************************************/ -package org.eclipse.tm4e.ui.internal.model; - -import java.io.IOException; -import java.io.InputStream; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -/** - * Input stream which reads from a document - */ -public class DocumentInputStream extends InputStream { - - private final IDocument fDocument; - private int fCurrPos; - - public DocumentInputStream(IDocument document) { - fDocument= document; - fCurrPos= 0; - } - - public IDocument getDocument() { - return fDocument; - } - - /** - * {@inheritDoc} - */ - @Override - public int read() throws IOException { - try { - if (fCurrPos < fDocument.getLength()) { - return fDocument.getChar(fCurrPos++); - } - } catch (BadLocationException e) { - } - return -1; - } - +/******************************************************************************* + * Copyright (c) 2005, 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * QNX Software System + *******************************************************************************/ +package org.eclipse.tm4e.ui.internal.model; + +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +/** + * Input stream which reads from a document + */ +public class DocumentInputStream extends InputStream { + + private final IDocument fDocument; + private int fCurrPos; + + public DocumentInputStream(IDocument document) { + fDocument= document; + fCurrPos= 0; + } + + public IDocument getDocument() { + return fDocument; + } + + /** + * {@inheritDoc} + */ + @Override + public int read() throws IOException { + try { + if (fCurrPos < fDocument.getLength()) { + return fDocument.getChar(fCurrPos++); + } + } catch (BadLocationException e) { + } + return -1; + } + } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java index e4fd88b6d..6fac24261 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java @@ -1,110 +1,110 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.model; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.tm4e.core.model.AbstractLineList; -import org.eclipse.tm4e.ui.TMUIPlugin; - -/** - * TextMate {@link AbstractLineList} implementation with Eclipse - * {@link IDocument}. - * - * Goal of this class is to synchronize Eclipse {@link DocumentEvent} with - * TextMate model lines. - * - */ -public class DocumentLineList extends AbstractLineList { - - private final IDocument document; - private final InternalListener listener; - - public DocumentLineList(IDocument document) { - this.document = document; - this.listener = new InternalListener(); - document.addDocumentListener(listener); - for (int i = 0; i < document.getNumberOfLines(); i++) { - addLine(i); - } - } - - private class InternalListener implements IDocumentListener { - - @Override - public void documentAboutToBeChanged(DocumentEvent event) { - try { - if (!DocumentHelper.isInsert(event)) { - // Remove or Replace (Remove + Insert) - removeLine(event); - } - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - - private void removeLine(DocumentEvent event) throws BadLocationException { - int startLine = DocumentHelper.getStartLine(event); - int endLine = DocumentHelper.getEndLine(event, true); - for (int i = endLine; i > startLine; i--) { - DocumentLineList.this.removeLine(i); - } - } - - @Override - public void documentChanged(DocumentEvent event) { - try { - int startLine = DocumentHelper.getStartLine(event); - if (!DocumentHelper.isRemove(event)) { - int endLine = DocumentHelper.getEndLine(event, false); - // Insert new lines - for (int i = startLine; i < endLine; i++) { - DocumentLineList.this.addLine(i + 1); - } - if (startLine == endLine) { - DocumentLineList.this.updateLine(startLine); - } - } else { - // Update line - DocumentLineList.this.updateLine(startLine); - } - invalidateLine(startLine); - } catch (BadLocationException e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); - } - } - } - - @Override - public int getNumberOfLines() { - return document.getNumberOfLines(); - } - - @Override - public String getLineText(int line) throws Exception { - return DocumentHelper.getLineText(document, line, false); - } - - @Override - public int getLineLength(int line) throws Exception { - return document.getLineLength(line); - } - - @Override - public void dispose() { - document.removeDocumentListener(listener); - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.model; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.tm4e.core.model.AbstractLineList; +import org.eclipse.tm4e.ui.TMUIPlugin; + +/** + * TextMate {@link AbstractLineList} implementation with Eclipse + * {@link IDocument}. + * + * Goal of this class is to synchronize Eclipse {@link DocumentEvent} with + * TextMate model lines. + * + */ +public class DocumentLineList extends AbstractLineList { + + private final IDocument document; + private final InternalListener listener; + + public DocumentLineList(IDocument document) { + this.document = document; + this.listener = new InternalListener(); + document.addDocumentListener(listener); + for (int i = 0; i < document.getNumberOfLines(); i++) { + addLine(i); + } + } + + private class InternalListener implements IDocumentListener { + + @Override + public void documentAboutToBeChanged(DocumentEvent event) { + try { + if (!DocumentHelper.isInsert(event)) { + // Remove or Replace (Remove + Insert) + removeLine(event); + } + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + private void removeLine(DocumentEvent event) throws BadLocationException { + int startLine = DocumentHelper.getStartLine(event); + int endLine = DocumentHelper.getEndLine(event, true); + for (int i = endLine; i > startLine; i--) { + DocumentLineList.this.removeLine(i); + } + } + + @Override + public void documentChanged(DocumentEvent event) { + try { + int startLine = DocumentHelper.getStartLine(event); + if (!DocumentHelper.isRemove(event)) { + int endLine = DocumentHelper.getEndLine(event, false); + // Insert new lines + for (int i = startLine; i < endLine; i++) { + DocumentLineList.this.addLine(i + 1); + } + if (startLine == endLine) { + DocumentLineList.this.updateLine(startLine); + } + } else { + // Update line + DocumentLineList.this.updateLine(startLine); + } + invalidateLine(startLine); + } catch (BadLocationException e) { + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } + } + } + + @Override + public int getNumberOfLines() { + return document.getNumberOfLines(); + } + + @Override + public String getLineText(int line) throws Exception { + return DocumentHelper.getLineText(document, line, false); + } + + @Override + public int getLineLength(int line) throws Exception { + return document.getLineLength(line); + } + + @Override + public void dispose() { + document.removeDocumentListener(listener); + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java index 31dae8949..7bcda2b1e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java @@ -1,30 +1,30 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.model; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.tm4e.core.model.TMModel; - -public class TMDocumentModel extends TMModel { - - private final IDocument document; - - public TMDocumentModel(IDocument document) { - super(new DocumentLineList(document)); - this.document = document; - } - - public IDocument getDocument() { - return document; - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.model; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.tm4e.core.model.TMModel; + +public class TMDocumentModel extends TMModel { + + private final IDocument document; + + public TMDocumentModel(IDocument document) { + super(new DocumentLineList(document)); + this.document = document; + } + + public IDocument getDocument() { + return document; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java index f04e11af2..72e895eab 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java @@ -1,57 +1,57 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.model; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.tm4e.core.model.ITMModel; -import org.eclipse.tm4e.ui.model.ITMModelManager; - -/** - * TextMate model manager which connect/disconnect a TextModel model - * {@link ITMModel} with an Eclipse {@link IDocument}. - */ -public class TMModelManager implements ITMModelManager { - - private static final ITMModelManager INSTANCE = new TMModelManager(); - - public static ITMModelManager getInstance() { - return INSTANCE; - } - - private final Map models; - - private TMModelManager() { - models = new HashMap<>(); - } - - @Override - public ITMModel connect(IDocument document) { - ITMModel model = models.get(document); - if (model != null) { - return model; - } - model = new TMDocumentModel(document); - models.put(document, model); - return model; - } - - @Override - public void disconnect(IDocument document) { - ITMModel model = models.remove(document); - if (model != null) { - model.dispose(); - } - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.model; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.tm4e.core.model.ITMModel; +import org.eclipse.tm4e.ui.model.ITMModelManager; + +/** + * TextMate model manager which connect/disconnect a TextModel model + * {@link ITMModel} with an Eclipse {@link IDocument}. + */ +public class TMModelManager implements ITMModelManager { + + private static final ITMModelManager INSTANCE = new TMModelManager(); + + public static ITMModelManager getInstance() { + return INSTANCE; + } + + private final Map models; + + private TMModelManager() { + models = new HashMap<>(); + } + + @Override + public ITMModel connect(IDocument document) { + ITMModel model = models.get(document); + if (model != null) { + return model; + } + model = new TMDocumentModel(document); + models.put(document, model); + return model; + } + + @Override + public void disconnect(IDocument document) { + ITMModel model = models.remove(document); + if (model != null) { + model.dispose(); + } + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java index 4afb63789..1a3a282cd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java @@ -1,28 +1,28 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.preferences; - -/** - * Preferences constants for theme. - * - */ -public class PreferenceConstants { - - public static final String THEMES = "org.eclipse.tm4e.ui.themes"; - - public static final String THEME_ASSOCIATIONS = "org.eclipse.tm4e.ui.themeAssociations"; - - public static final String E4_THEME_ID = "themeid"; //$NON-NLS-1$ - - public static final String EDITOR_CURRENTLINE_HIGHLIGHT = "currentLineColor"; //$NON-NLS-1$ - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.preferences; + +/** + * Preferences constants for theme. + * + */ +public class PreferenceConstants { + + public static final String THEMES = "org.eclipse.tm4e.ui.themes"; + + public static final String THEME_ASSOCIATIONS = "org.eclipse.tm4e.ui.themeAssociations"; + + public static final String E4_THEME_ID = "themeid"; //$NON-NLS-1$ + + public static final String EDITOR_CURRENTLINE_HIGHLIGHT = "currentLineColor"; //$NON-NLS-1$ + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java index 2114f5ecd..769363846 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java @@ -1,42 +1,42 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.preferences; - -import java.util.Collection; - -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.ThemeAssociation; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.InstanceCreator; - -/** - * Helper class load, save theme preferences with Json format. - * - */ -public class PreferenceHelper { - - private static final Gson DEFAULT_GSON; - - static { - DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(IThemeAssociation.class, (InstanceCreator) type -> new ThemeAssociation()).create(); - } - - public static IThemeAssociation[] loadThemeAssociations(String json) { - return DEFAULT_GSON.fromJson(json, ThemeAssociation[].class); - } - - public static String toJsonThemeAssociations(Collection themeAssociations) { - return DEFAULT_GSON.toJson(themeAssociations); - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.preferences; + +import java.util.Collection; + +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.ThemeAssociation; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.InstanceCreator; + +/** + * Helper class load, save theme preferences with Json format. + * + */ +public class PreferenceHelper { + + private static final Gson DEFAULT_GSON; + + static { + DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(IThemeAssociation.class, (InstanceCreator) type -> new ThemeAssociation()).create(); + } + + public static IThemeAssociation[] loadThemeAssociations(String json) { + return DEFAULT_GSON.fromJson(json, ThemeAssociation[].class); + } + + public static String toJsonThemeAssociations(Collection themeAssociations) { + return DEFAULT_GSON.toJson(themeAssociations); + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java index 0c9ae773c..125694382 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java @@ -1,62 +1,62 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.snippets; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.tm4e.registry.TMResource; -import org.eclipse.tm4e.registry.XMLConstants; -import org.eclipse.tm4e.ui.snippets.ISnippet; - -public class Snippet extends TMResource implements ISnippet { - - private String scopeName; - private String name; - - /** - * Constructor for user preferences (loaded from Json with Gson). - */ - public Snippet() { - super(); - } - - /** - * Constructor for extension point. - * - * @param scopeName - */ - public Snippet(String scopeName, String path, String name) { - super(path); - this.scopeName = scopeName; - this.name = name; - } - - public Snippet(IConfigurationElement ce) { - super(ce); - this.scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); - this.name = ce.getAttribute(XMLConstants.NAME_ATTR); - } - - @Override - public String getName() { - return name; - } - - @Override - public String getContent() { - return getResourceContent(); - } - - @Override - public String getScopeName() { - return scopeName; - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.snippets; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.tm4e.registry.TMResource; +import org.eclipse.tm4e.registry.XMLConstants; +import org.eclipse.tm4e.ui.snippets.ISnippet; + +public class Snippet extends TMResource implements ISnippet { + + private String scopeName; + private String name; + + /** + * Constructor for user preferences (loaded from Json with Gson). + */ + public Snippet() { + super(); + } + + /** + * Constructor for extension point. + * + * @param scopeName + */ + public Snippet(String scopeName, String path, String name) { + super(path); + this.scopeName = scopeName; + this.name = name; + } + + public Snippet(IConfigurationElement ce) { + super(ce); + this.scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); + this.name = ce.getAttribute(XMLConstants.NAME_ATTR); + } + + @Override + public String getName() { + return name; + } + + @Override + public String getContent() { + return getResourceContent(); + } + + @Override + public String getScopeName() { + return scopeName; + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java index 8e8ba08bc..7877b3b41 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java @@ -1,92 +1,92 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.snippets; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.snippets.ISnippet; -import org.eclipse.tm4e.ui.snippets.ISnippetManager; - -public class SnippetManager implements ISnippetManager { - - private static final ISnippet[] EMPTY_SNIPPETS = {}; - - private static final String SNIPPET_ELT = "snippet"; - - // "snippets" extension point - private static final String EXTENSION_SNIPPETS = "snippets"; //$NON-NLS-1$ - - private static ISnippetManager INSTANCE; - - public static ISnippetManager getInstance() { - if (INSTANCE != null) { - return INSTANCE; - } - INSTANCE = createInstance(); - return INSTANCE; - } - - private static synchronized ISnippetManager createInstance() { - if (INSTANCE != null) { - return INSTANCE; - } - SnippetManager manager = new SnippetManager(); - manager.load(); - return manager; - } - - private final Map> snippets; - - public SnippetManager() { - this.snippets = new HashMap<>(); - } - - private void load() { - loadGrammarsFromExtensionPoints(); - } - - /** - * Load snippets from extension point. - */ - private void loadGrammarsFromExtensionPoints() { - IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, - EXTENSION_SNIPPETS); - for (IConfigurationElement ce : cf) { - String extensionName = ce.getName(); - if (SNIPPET_ELT.equals(extensionName)) { - this.registerSnippet(new Snippet(ce)); - } - } - } - - private void registerSnippet(Snippet snippet) { - String scopeName = snippet.getScopeName(); - Collection snippets = this.snippets.get(scopeName); - if (snippets == null) { - snippets = new ArrayList<>(); - this.snippets.put(scopeName, snippets); - } - snippets.add(snippet); - } - - @Override - public ISnippet[] getSnippets(String scopeName) { - Collection snippets = this.snippets.get(scopeName); - return snippets != null ? snippets.toArray(new ISnippet[snippets.size()]) : EMPTY_SNIPPETS; - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.snippets; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.snippets.ISnippet; +import org.eclipse.tm4e.ui.snippets.ISnippetManager; + +public class SnippetManager implements ISnippetManager { + + private static final ISnippet[] EMPTY_SNIPPETS = {}; + + private static final String SNIPPET_ELT = "snippet"; + + // "snippets" extension point + private static final String EXTENSION_SNIPPETS = "snippets"; //$NON-NLS-1$ + + private static ISnippetManager INSTANCE; + + public static ISnippetManager getInstance() { + if (INSTANCE != null) { + return INSTANCE; + } + INSTANCE = createInstance(); + return INSTANCE; + } + + private static synchronized ISnippetManager createInstance() { + if (INSTANCE != null) { + return INSTANCE; + } + SnippetManager manager = new SnippetManager(); + manager.load(); + return manager; + } + + private final Map> snippets; + + public SnippetManager() { + this.snippets = new HashMap<>(); + } + + private void load() { + loadGrammarsFromExtensionPoints(); + } + + /** + * Load snippets from extension point. + */ + private void loadGrammarsFromExtensionPoints() { + IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, + EXTENSION_SNIPPETS); + for (IConfigurationElement ce : cf) { + String extensionName = ce.getName(); + if (SNIPPET_ELT.equals(extensionName)) { + this.registerSnippet(new Snippet(ce)); + } + } + } + + private void registerSnippet(Snippet snippet) { + String scopeName = snippet.getScopeName(); + Collection snippets = this.snippets.get(scopeName); + if (snippets == null) { + snippets = new ArrayList<>(); + this.snippets.put(scopeName, snippets); + } + snippets.add(snippet); + } + + @Override + public ISnippet[] getSnippets(String scopeName) { + Collection snippets = this.snippets.get(scopeName); + return snippets != null ? snippets.toArray(new ISnippet[snippets.size()]) : EMPTY_SNIPPETS; + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java index a5227d354..ad44fdb38 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java @@ -1,205 +1,205 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.text; - -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.tm4e.ui.text.ITMPresentationReconcilerListener; - -public class TMPresentationReconcilerTestGenerator - implements ITMPresentationReconcilerListener, IDocumentListener, ITextListener { - - private ITextViewer viewer; - private IDocument document; - - private final StringBuilder code = new StringBuilder(); - - /*private List commands; - - private class Command { - final String command; - StyleRange[] ranges; - Throwable error; - - public Command(String command) { - this.command = command; - } - }*/ - - public TMPresentationReconcilerTestGenerator() { - //this.commands = new ArrayList<>(); - } - - @Override - public void install(ITextViewer viewer, IDocument document) { - this.viewer = viewer; - this.document = document; - document.addDocumentListener(this); - viewer.addTextListener(this); - - write("package org.eclipse.tm4e.ui.text;", true); - write("", true); - - write("import org.eclipse.jface.text.Document;", true); - write("import org.eclipse.jface.text.IDocument;", true); - write("import org.eclipse.jface.text.TextViewer;", true); - write("import org.eclipse.swt.SWT;", true); - write("import org.eclipse.swt.widgets.Display;", true); - write("import org.eclipse.swt.widgets.Shell;", true); - write("import org.eclipse.tm4e.core.grammar.IGrammar;", true); - write("import org.eclipse.tm4e.core.registry.Registry;", true); - write("import org.eclipse.tm4e.ui.text.TMPresentationReconciler;", true); - write("import org.eclipse.tm4e.ui.themes.ITokenProvider;", true); - write("import org.eclipse.tm4e.ui.themes.css.CSSTokenProvider;", true); - write("import org.junit.Test;", true); - write("", true); - - write("public class TMPresentationReconcilerTest {", true); - write("", true); - - write("\t@Test", true); - write("\tpublic void colorize() throws Exception {", true); - write("", true); - write("\t\tDisplay display = new Display();", true); - write("\t\tShell shell = new Shell(display);", true); - write("\t\tTextViewer viewer = new TextViewer(shell, SWT.NONE);", true); - write("\t\tIDocument document = new Document();", true); - write("\t\tviewer.setDocument(document);", true); - write("\t\tdocument.set(\""); - write(toText(document.get())); - write("\");", true); - - // commands.add(new Command("document.set(...)")); - write("", true); - write("\t\tTMPresentationReconciler reconciler = new TMPresentationReconciler();", true); - write("\t\treconciler.setTokenProvider(getTokenProvider());", true); - write("\t\treconciler.setGrammar(getGrammar());", true); - write("\t\treconciler.install(viewer);", true); - write("", true); - - } - - public String toText(String text) { - StringBuilder newText = new StringBuilder(); - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - switch (c) { - case '\n': - newText.append("\\n"); - break; - case '\r': - newText.append("\\r"); - break; - case '"': - newText.append("\\\""); - break; - default: - newText.append(c); - } - } - return newText.toString(); - } - - @Override - public void uninstall() { - -// for (Command command : commands) { -// write(toString(command.ranges)); -// } -// - write("", true); - write("\t\twhile (!shell.isDisposed()) {", true); - write("\t\t}", true); - - write("\t}", true); - - write("\tprivate static ITokenProvider getTokenProvider() {", true); - write("\t\treturn new CSSTokenProvider(TMPresentationReconcilerTest.class.getResourceAsStream(\"Solarized-light.css\"));", - true); - write("\t}", true); - write("", true); - - write("\tprivate static IGrammar getGrammar() {", true); - write("\t\tRegistry registry = new Registry();", true); - write("\t\ttry {", true); - write("\t\tString grammar=\"YouGrammar.tmLanguage\";", true); - write("\t\t\treturn registry.loadGrammarFromPathSync(grammar,TMPresentationReconcilerTest.class.getResourceAsStream(grammar));", - true); - write("\t\t} catch (Exception e) {", true); - write("\t\t\te.printStackTrace();", true); - write("\t\treturn null;", true); - write("\t\t}", true); - write("\t}", true); - - write("}"); - - System.err.println(code.toString()); - document.removeDocumentListener(this); - viewer.removeTextListener(this); - //commands.clear(); - - } - - @Override - public void colorize(TextPresentation presentation, Throwable e) { -// Command command = commands.get(commands.size() - 1); -// if (e != null) { -// command.error = e; -// } else { -// command.ranges = viewer.getTextWidget().getStyleRanges(); -// } - } - - private void write(String s, boolean newLine) { - code.append(s); - if (newLine) { - code.append("\n"); - } - } - - private void write(String s) { - write(s, false); - } - - @Override - public void documentAboutToBeChanged(DocumentEvent event) { - - } - - @Override - public void documentChanged(DocumentEvent event) { - - String command = "document.replace(" + event.getOffset() + ", " + event.getLength() + ", \"" - + toText(event.getText()) + "\");"; - write("\t\t" + command, true); - - //commands.add(new Command(command)); - } - - @Override - public void textChanged(TextEvent event) { - if (event.getDocumentEvent() != null) { - return; - } - - String command = "viewer.invalidateTextPresentation(" + event.getOffset() + ", " + event.getLength() + ");"; - write("\t\t" + command, true); - - //commands.add(new Command(command)); - - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.text; + +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.jface.text.ITextListener; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.TextEvent; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.tm4e.ui.text.ITMPresentationReconcilerListener; + +public class TMPresentationReconcilerTestGenerator + implements ITMPresentationReconcilerListener, IDocumentListener, ITextListener { + + private ITextViewer viewer; + private IDocument document; + + private final StringBuilder code = new StringBuilder(); + + /*private List commands; + + private class Command { + final String command; + StyleRange[] ranges; + Throwable error; + + public Command(String command) { + this.command = command; + } + }*/ + + public TMPresentationReconcilerTestGenerator() { + //this.commands = new ArrayList<>(); + } + + @Override + public void install(ITextViewer viewer, IDocument document) { + this.viewer = viewer; + this.document = document; + document.addDocumentListener(this); + viewer.addTextListener(this); + + write("package org.eclipse.tm4e.ui.text;", true); + write("", true); + + write("import org.eclipse.jface.text.Document;", true); + write("import org.eclipse.jface.text.IDocument;", true); + write("import org.eclipse.jface.text.TextViewer;", true); + write("import org.eclipse.swt.SWT;", true); + write("import org.eclipse.swt.widgets.Display;", true); + write("import org.eclipse.swt.widgets.Shell;", true); + write("import org.eclipse.tm4e.core.grammar.IGrammar;", true); + write("import org.eclipse.tm4e.core.registry.Registry;", true); + write("import org.eclipse.tm4e.ui.text.TMPresentationReconciler;", true); + write("import org.eclipse.tm4e.ui.themes.ITokenProvider;", true); + write("import org.eclipse.tm4e.ui.themes.css.CSSTokenProvider;", true); + write("import org.junit.Test;", true); + write("", true); + + write("public class TMPresentationReconcilerTest {", true); + write("", true); + + write("\t@Test", true); + write("\tpublic void colorize() throws Exception {", true); + write("", true); + write("\t\tDisplay display = new Display();", true); + write("\t\tShell shell = new Shell(display);", true); + write("\t\tTextViewer viewer = new TextViewer(shell, SWT.NONE);", true); + write("\t\tIDocument document = new Document();", true); + write("\t\tviewer.setDocument(document);", true); + write("\t\tdocument.set(\""); + write(toText(document.get())); + write("\");", true); + + // commands.add(new Command("document.set(...)")); + write("", true); + write("\t\tTMPresentationReconciler reconciler = new TMPresentationReconciler();", true); + write("\t\treconciler.setTokenProvider(getTokenProvider());", true); + write("\t\treconciler.setGrammar(getGrammar());", true); + write("\t\treconciler.install(viewer);", true); + write("", true); + + } + + public String toText(String text) { + StringBuilder newText = new StringBuilder(); + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + switch (c) { + case '\n': + newText.append("\\n"); + break; + case '\r': + newText.append("\\r"); + break; + case '"': + newText.append("\\\""); + break; + default: + newText.append(c); + } + } + return newText.toString(); + } + + @Override + public void uninstall() { + +// for (Command command : commands) { +// write(toString(command.ranges)); +// } +// + write("", true); + write("\t\twhile (!shell.isDisposed()) {", true); + write("\t\t}", true); + + write("\t}", true); + + write("\tprivate static ITokenProvider getTokenProvider() {", true); + write("\t\treturn new CSSTokenProvider(TMPresentationReconcilerTest.class.getResourceAsStream(\"Solarized-light.css\"));", + true); + write("\t}", true); + write("", true); + + write("\tprivate static IGrammar getGrammar() {", true); + write("\t\tRegistry registry = new Registry();", true); + write("\t\ttry {", true); + write("\t\tString grammar=\"YouGrammar.tmLanguage\";", true); + write("\t\t\treturn registry.loadGrammarFromPathSync(grammar,TMPresentationReconcilerTest.class.getResourceAsStream(grammar));", + true); + write("\t\t} catch (Exception e) {", true); + write("\t\t\te.printStackTrace();", true); + write("\t\treturn null;", true); + write("\t\t}", true); + write("\t}", true); + + write("}"); + + System.err.println(code.toString()); + document.removeDocumentListener(this); + viewer.removeTextListener(this); + //commands.clear(); + + } + + @Override + public void colorize(TextPresentation presentation, Throwable e) { +// Command command = commands.get(commands.size() - 1); +// if (e != null) { +// command.error = e; +// } else { +// command.ranges = viewer.getTextWidget().getStyleRanges(); +// } + } + + private void write(String s, boolean newLine) { + code.append(s); + if (newLine) { + code.append("\n"); + } + } + + private void write(String s) { + write(s, false); + } + + @Override + public void documentAboutToBeChanged(DocumentEvent event) { + + } + + @Override + public void documentChanged(DocumentEvent event) { + + String command = "document.replace(" + event.getOffset() + ", " + event.getLength() + ", \"" + + toText(event.getText()) + "\");"; + write("\t\t" + command, true); + + //commands.add(new Command(command)); + } + + @Override + public void textChanged(TextEvent event) { + if (event.getDocumentEvent() != null) { + return; + } + + String command = "viewer.invalidateTextPresentation(" + event.getOffset() + ", " + event.getLength() + ");"; + write("\t\t" + command, true); + + //commands.add(new Command(command)); + + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index f1b2b4e4d..60ac2e1bb 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -1,148 +1,148 @@ -/** - * Copyright (c) 2015, 2021 Angelo ZERR and others. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.themes; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.eclipse.swt.graphics.RGB; -import org.eclipse.tm4e.ui.themes.ITheme; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.IThemeManager; -import org.eclipse.tm4e.ui.themes.ITokenProvider; -import org.eclipse.tm4e.ui.themes.ThemeAssociation; -import org.eclipse.tm4e.ui.utils.PreferenceUtils; - -/** - * TextMate theme manager implementation. - * - */ -public abstract class AbstractThemeManager implements IThemeManager { - - private final Map themes; - private final ThemeAssociationRegistry themeAssociationRegistry; - - public AbstractThemeManager() { - this.themes = new LinkedHashMap<>(); - this.themeAssociationRegistry = new ThemeAssociationRegistry(); - } - - @Override - public void registerTheme(ITheme theme) { - themes.put(theme.getId(), theme); - } - - @Override - public void unregisterTheme(ITheme theme) { - themes.remove(theme.getId()); - } - - @Override - public ITheme getThemeById(String themeId) { - return themes.get(themeId); - } - - @Override - public ITheme[] getThemes() { - Collection themes = this.themes.values(); - return themes.toArray(new ITheme[themes.size()]); - } - - @Override - public ITheme getDefaultTheme() { - boolean dark = isDarkEclipseTheme(); - return getDefaultTheme(dark); - } - - public ITheme getDefaultTheme(boolean dark) { - for (ITheme theme : this.themes.values()) { - if (theme.isDark() == dark && theme.isDefault()) { - return theme; - } - } - return null; - } - - @Override - public ITheme[] getThemes(boolean dark) { - Collection themes = this.themes.values(); - return themes.stream().filter(theme -> (theme.isDark() == dark)) - .collect(Collectors.toList()).toArray(new ITheme[0]); - } - - @Override - public boolean isDarkEclipseTheme() { - return isDarkEclipseTheme(PreferenceUtils.getE4PreferenceCSSThemeId()); - } - - @Override - public boolean isDarkEclipseTheme(String eclipseThemeId) { - return eclipseThemeId != null && eclipseThemeId.toLowerCase().contains("dark"); - } - - @Override - public ITheme getThemeForScope(String scopeName, boolean dark) { - IThemeAssociation association = themeAssociationRegistry.getThemeAssociationFor(scopeName, dark); - if (association != null) { - String themeId = association.getThemeId(); - return getThemeById(themeId); - } - return getDefaultTheme(dark); - } - - @Override - public ITheme getThemeForScope(String scopeName) { - return getThemeForScope(scopeName, isDarkEclipseTheme()); - } - - @Override - public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { - List associations = new ArrayList<>(); - IThemeAssociation light = themeAssociationRegistry.getThemeAssociationFor(scopeName, false); - if (light == null) { - light = new ThemeAssociation(getDefaultTheme(false).getId(), scopeName, false); - } - associations.add(light); - IThemeAssociation dark = themeAssociationRegistry.getThemeAssociationFor(scopeName, true); - if (dark == null) { - dark = new ThemeAssociation(getDefaultTheme(true).getId(), scopeName, true); - } - associations.add(dark); - return associations.toArray(new IThemeAssociation[associations.size()]); - } - - @Override - public void registerThemeAssociation(IThemeAssociation association) { - themeAssociationRegistry.register(association); - } - - @Override - public void unregisterThemeAssociation(IThemeAssociation association) { - themeAssociationRegistry.unregister(association); - } - - @Override - public IThemeAssociation[] getAllThemeAssociations() { - List associations = themeAssociationRegistry.getThemeAssociations(); - return associations.toArray(new IThemeAssociation[associations.size()]); - } - - @Override - public ITokenProvider getThemeForScope(String scopeName, RGB background) { - return getThemeForScope(scopeName, 0.299 * background.red + 0.587 * background.green + 0.114 * background.blue < 128); - } - -} +/** + * Copyright (c) 2015, 2021 Angelo ZERR and others. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.themes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.eclipse.swt.graphics.RGB; +import org.eclipse.tm4e.ui.themes.ITheme; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.IThemeManager; +import org.eclipse.tm4e.ui.themes.ITokenProvider; +import org.eclipse.tm4e.ui.themes.ThemeAssociation; +import org.eclipse.tm4e.ui.utils.PreferenceUtils; + +/** + * TextMate theme manager implementation. + * + */ +public abstract class AbstractThemeManager implements IThemeManager { + + private final Map themes; + private final ThemeAssociationRegistry themeAssociationRegistry; + + public AbstractThemeManager() { + this.themes = new LinkedHashMap<>(); + this.themeAssociationRegistry = new ThemeAssociationRegistry(); + } + + @Override + public void registerTheme(ITheme theme) { + themes.put(theme.getId(), theme); + } + + @Override + public void unregisterTheme(ITheme theme) { + themes.remove(theme.getId()); + } + + @Override + public ITheme getThemeById(String themeId) { + return themes.get(themeId); + } + + @Override + public ITheme[] getThemes() { + Collection themes = this.themes.values(); + return themes.toArray(new ITheme[themes.size()]); + } + + @Override + public ITheme getDefaultTheme() { + boolean dark = isDarkEclipseTheme(); + return getDefaultTheme(dark); + } + + public ITheme getDefaultTheme(boolean dark) { + for (ITheme theme : this.themes.values()) { + if (theme.isDark() == dark && theme.isDefault()) { + return theme; + } + } + return null; + } + + @Override + public ITheme[] getThemes(boolean dark) { + Collection themes = this.themes.values(); + return themes.stream().filter(theme -> (theme.isDark() == dark)) + .collect(Collectors.toList()).toArray(new ITheme[0]); + } + + @Override + public boolean isDarkEclipseTheme() { + return isDarkEclipseTheme(PreferenceUtils.getE4PreferenceCSSThemeId()); + } + + @Override + public boolean isDarkEclipseTheme(String eclipseThemeId) { + return eclipseThemeId != null && eclipseThemeId.toLowerCase().contains("dark"); + } + + @Override + public ITheme getThemeForScope(String scopeName, boolean dark) { + IThemeAssociation association = themeAssociationRegistry.getThemeAssociationFor(scopeName, dark); + if (association != null) { + String themeId = association.getThemeId(); + return getThemeById(themeId); + } + return getDefaultTheme(dark); + } + + @Override + public ITheme getThemeForScope(String scopeName) { + return getThemeForScope(scopeName, isDarkEclipseTheme()); + } + + @Override + public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { + List associations = new ArrayList<>(); + IThemeAssociation light = themeAssociationRegistry.getThemeAssociationFor(scopeName, false); + if (light == null) { + light = new ThemeAssociation(getDefaultTheme(false).getId(), scopeName, false); + } + associations.add(light); + IThemeAssociation dark = themeAssociationRegistry.getThemeAssociationFor(scopeName, true); + if (dark == null) { + dark = new ThemeAssociation(getDefaultTheme(true).getId(), scopeName, true); + } + associations.add(dark); + return associations.toArray(new IThemeAssociation[associations.size()]); + } + + @Override + public void registerThemeAssociation(IThemeAssociation association) { + themeAssociationRegistry.register(association); + } + + @Override + public void unregisterThemeAssociation(IThemeAssociation association) { + themeAssociationRegistry.unregister(association); + } + + @Override + public IThemeAssociation[] getAllThemeAssociations() { + List associations = themeAssociationRegistry.getThemeAssociations(); + return associations.toArray(new IThemeAssociation[associations.size()]); + } + + @Override + public ITokenProvider getThemeForScope(String scopeName, RGB background) { + return getThemeForScope(scopeName, 0.299 * background.red + 0.587 * background.green + 0.114 * background.blue < 128); + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java index ff6efec12..bd985bd88 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java @@ -1,139 +1,139 @@ -/** - * Copyright (c) 2015-2018 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.themes; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.eclipse.tm4e.ui.themes.IThemeAssociation; - -/** - * Base Theme association registry. - * - */ -public class BaseThemeAssociationRegistry { - - private IThemeAssociation defaultAssociation; - private final Map> eclipseThemeIds; - private final List allAssociations; - - public BaseThemeAssociationRegistry() { - eclipseThemeIds = new HashMap<>(); - this.allAssociations = new ArrayList<>(); - } - - public void register(IThemeAssociation association) { - //String eclipseThemeId = association.getEclipseThemeId(); - // when association is marked as default or scope name is defined, - // update the default association or association for a given E4 Theme. - /*if (association.isDefault()) { - if (eclipseThemeId == null) { - defaultAssociation = association; - } else { - register(association, eclipseThemeId); - } - } else if (eclipseThemeId != null) { - register(association, eclipseThemeId); - }*/ - allAssociations.clear(); - } - - public void unregister(IThemeAssociation association) { - //String eclipseThemeId = association.getEclipseThemeId(); - /*if (association.isDefault()) { - if (eclipseThemeId == null) { - defaultAssociation = null; - } - }*/ -// Collection associations = eclipseThemeIds.get(eclipseThemeId); -// if (associations != null) { -// for (IThemeAssociation a : associations) { -// if (a.equals(association)) { -// associations.remove(a); -// break; -// } -// } -// } - allAssociations.clear(); - } - - public IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { - List associations = eclipseThemeIds.get(eclipseThemeId); - if (associations != null) { - if (associations.size() == 1) { - return associations.get(0); - } - /*for (IThemeAssociation association : associations) { - if (association.isDefault()) { - return association; - } - }*/ - } - return null; - } - - public IThemeAssociation[] getThemeAssociations(boolean isDefault) { - /*if (isDefault) { - return getThemeAssociations().stream().filter(theme -> theme.isDefault()).collect(Collectors.toList()) - .toArray(new IThemeAssociation[0]); - }*/ - return getThemeAssociations().toArray(new IThemeAssociation[allAssociations.size()]); - } - - public IThemeAssociation getDefaultAssociation() { - return defaultAssociation; - } - - public IThemeAssociation[] getThemeAssociationsForTheme(String themeId) { - return getThemeAssociations().stream().filter(themeAssociation -> themeId.equals(themeAssociation.getThemeId())) - .collect(Collectors.toList()).toArray(new IThemeAssociation[0]); - } - - public boolean hasThemeAssociationsForTheme(String themeId, String eclipseThemeId) { -// Collection associations = eclipseThemeIds.get(eclipseThemeId); -// if (associations != null) { -// for (IThemeAssociation themeAssociation : associations) { -// if (themeId.equals(themeAssociation.getThemeId())) { -// return eclipseThemeId.equals(themeAssociation.getEclipseThemeId()); -// } -// } -// return false; -// } else { -// Set>> s = eclipseThemeIds.entrySet(); -// for (Entry> entry : s) { -// for (IThemeAssociation themeAssociation : entry.getValue()) { -// if (themeId.equals(themeAssociation.getThemeId())) { -// return eclipseThemeId.equals(themeAssociation.getEclipseThemeId()); -// } -// } -// } -// } - return true; - } - - public List getThemeAssociations() { - if (allAssociations.isEmpty()) { - if (defaultAssociation != null) { - allAssociations.add(defaultAssociation); - } - Collection> associations = eclipseThemeIds.values(); - for (Collection collection : associations) { - allAssociations.addAll(collection); - } - } - return allAssociations; - } -} +/** + * Copyright (c) 2015-2018 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.themes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.eclipse.tm4e.ui.themes.IThemeAssociation; + +/** + * Base Theme association registry. + * + */ +public class BaseThemeAssociationRegistry { + + private IThemeAssociation defaultAssociation; + private final Map> eclipseThemeIds; + private final List allAssociations; + + public BaseThemeAssociationRegistry() { + eclipseThemeIds = new HashMap<>(); + this.allAssociations = new ArrayList<>(); + } + + public void register(IThemeAssociation association) { + //String eclipseThemeId = association.getEclipseThemeId(); + // when association is marked as default or scope name is defined, + // update the default association or association for a given E4 Theme. + /*if (association.isDefault()) { + if (eclipseThemeId == null) { + defaultAssociation = association; + } else { + register(association, eclipseThemeId); + } + } else if (eclipseThemeId != null) { + register(association, eclipseThemeId); + }*/ + allAssociations.clear(); + } + + public void unregister(IThemeAssociation association) { + //String eclipseThemeId = association.getEclipseThemeId(); + /*if (association.isDefault()) { + if (eclipseThemeId == null) { + defaultAssociation = null; + } + }*/ +// Collection associations = eclipseThemeIds.get(eclipseThemeId); +// if (associations != null) { +// for (IThemeAssociation a : associations) { +// if (a.equals(association)) { +// associations.remove(a); +// break; +// } +// } +// } + allAssociations.clear(); + } + + public IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { + List associations = eclipseThemeIds.get(eclipseThemeId); + if (associations != null) { + if (associations.size() == 1) { + return associations.get(0); + } + /*for (IThemeAssociation association : associations) { + if (association.isDefault()) { + return association; + } + }*/ + } + return null; + } + + public IThemeAssociation[] getThemeAssociations(boolean isDefault) { + /*if (isDefault) { + return getThemeAssociations().stream().filter(theme -> theme.isDefault()).collect(Collectors.toList()) + .toArray(new IThemeAssociation[0]); + }*/ + return getThemeAssociations().toArray(new IThemeAssociation[allAssociations.size()]); + } + + public IThemeAssociation getDefaultAssociation() { + return defaultAssociation; + } + + public IThemeAssociation[] getThemeAssociationsForTheme(String themeId) { + return getThemeAssociations().stream().filter(themeAssociation -> themeId.equals(themeAssociation.getThemeId())) + .collect(Collectors.toList()).toArray(new IThemeAssociation[0]); + } + + public boolean hasThemeAssociationsForTheme(String themeId, String eclipseThemeId) { +// Collection associations = eclipseThemeIds.get(eclipseThemeId); +// if (associations != null) { +// for (IThemeAssociation themeAssociation : associations) { +// if (themeId.equals(themeAssociation.getThemeId())) { +// return eclipseThemeId.equals(themeAssociation.getEclipseThemeId()); +// } +// } +// return false; +// } else { +// Set>> s = eclipseThemeIds.entrySet(); +// for (Entry> entry : s) { +// for (IThemeAssociation themeAssociation : entry.getValue()) { +// if (themeId.equals(themeAssociation.getThemeId())) { +// return eclipseThemeId.equals(themeAssociation.getEclipseThemeId()); +// } +// } +// } +// } + return true; + } + + public List getThemeAssociations() { + if (allAssociations.isEmpty()) { + if (defaultAssociation != null) { + allAssociations.add(defaultAssociation); + } + Collection> associations = eclipseThemeIds.values(); + for (Collection collection : associations) { + allAssociations.addAll(collection); + } + } + return allAssociations; + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java index 2f06f5ce6..98171eb37 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java @@ -1,167 +1,167 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.themes; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.tm4e.ui.themes.IThemeAssociation; - -/** - * Theme association registry. - * - */ -public class ThemeAssociationRegistry { - - private final Map scopes; - - private static class EclipseThemeAssociation { - - private IThemeAssociation light; - private IThemeAssociation dark; - - public IThemeAssociation getLight() { - return light; - } - - public void setLight(IThemeAssociation light) { - this.light = light; - } - - public IThemeAssociation getDark() { - return dark; - } - - public void setDark(IThemeAssociation dark) { - this.dark = dark; - } - - } - - public ThemeAssociationRegistry() { - scopes = new HashMap<>(); - } - - public IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) { - // From theme assiocations - IThemeAssociation userAssociation = null; - EclipseThemeAssociation registry = scopes.get(scopeName); - if (registry != null) { - userAssociation = dark ? registry.getDark() : registry.getLight(); - } - if (userAssociation != null) { - return userAssociation; - } - return null; - } - - public void register(IThemeAssociation association) { - String scopeName = association.getScopeName(); - EclipseThemeAssociation registry = scopes.get(scopeName); - if (registry == null) { - registry = new EclipseThemeAssociation(); - scopes.put(scopeName, registry); - } - boolean dark = association.isWhenDark(); - if (dark) { - registry.setDark(association); - } else { - registry.setLight(association); - } - } - - public void unregister(IThemeAssociation association) { - String scopeName = association.getScopeName(); - EclipseThemeAssociation registry = scopes.get(scopeName); - if (registry != null) { - boolean dark = association.isWhenDark(); - if (dark) { - registry.setDark(null); - } else { - registry.setLight(null); - } - } - } - - // public IThemeAssociation getThemeAssociationFor(String scopeName, String - // eclipseThemeId) { - // IThemeAssociation association = null; - // BaseThemeAssociationRegistry registry = scopes.get(scopeName); - // if (registry != null) { - // association = registry.getThemeAssociationFor(eclipseThemeId); - // if (association == null) { - // association = registry.getDefaultAssociation(); - // } - // } - // if (association == null) { - // association = super.getThemeAssociationFor(eclipseThemeId); - // } - // return association != null ? association : getDefaultAssociation(); - // } - - // public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { - // BaseThemeAssociationRegistry registry = scopes.get(scopeName); - // if (registry != null) { - // // Get the user associations (from preferences) - // List userAssociations = registry.getThemeAssociations(); - // // Get the default associations (from plugin) - // /*List defaultAssociations = - // getThemeAssociations().stream() - // .filter().collect(Collectors.toList()); - // // Add default association if user associations doesn't define it. - // for (IThemeAssociation defaultAssociation : defaultAssociations) { - // if (!(contains(userAssociations, defaultAssociation))) { - // userAssociations.add(defaultAssociation); - // } - // }*/ - // return userAssociations.toArray(new IThemeAssociation[0]); - // } - // return getThemeAssociations(true); - // } - // - // private boolean contains(List userAssociations, - // IThemeAssociation defaultAssociation) { - //// for (IThemeAssociation userAssociation : userAssociations) { - //// if (defaultAssociation.getEclipseThemeId() == null) { - //// if (userAssociation.getEclipseThemeId() == null) { - //// return true; - //// } - //// } else { - //// if - // (defaultAssociation.getEclipseThemeId().equals(userAssociation.getEclipseThemeId())) - // { - //// return true; - //// } - //// } - //// } - // return false; - // } - // - // @Override - public List getThemeAssociations() { - List associations = new ArrayList<>(); - Collection eclipseAssociations = scopes.values(); - for (EclipseThemeAssociation eclipseAssociation : eclipseAssociations) { - if (eclipseAssociation.getLight() != null) { - associations.add(eclipseAssociation.getLight()); - } - if (eclipseAssociation.getDark() != null) { - associations.add(eclipseAssociation.getDark()); - } - } - return associations; - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.themes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.tm4e.ui.themes.IThemeAssociation; + +/** + * Theme association registry. + * + */ +public class ThemeAssociationRegistry { + + private final Map scopes; + + private static class EclipseThemeAssociation { + + private IThemeAssociation light; + private IThemeAssociation dark; + + public IThemeAssociation getLight() { + return light; + } + + public void setLight(IThemeAssociation light) { + this.light = light; + } + + public IThemeAssociation getDark() { + return dark; + } + + public void setDark(IThemeAssociation dark) { + this.dark = dark; + } + + } + + public ThemeAssociationRegistry() { + scopes = new HashMap<>(); + } + + public IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) { + // From theme assiocations + IThemeAssociation userAssociation = null; + EclipseThemeAssociation registry = scopes.get(scopeName); + if (registry != null) { + userAssociation = dark ? registry.getDark() : registry.getLight(); + } + if (userAssociation != null) { + return userAssociation; + } + return null; + } + + public void register(IThemeAssociation association) { + String scopeName = association.getScopeName(); + EclipseThemeAssociation registry = scopes.get(scopeName); + if (registry == null) { + registry = new EclipseThemeAssociation(); + scopes.put(scopeName, registry); + } + boolean dark = association.isWhenDark(); + if (dark) { + registry.setDark(association); + } else { + registry.setLight(association); + } + } + + public void unregister(IThemeAssociation association) { + String scopeName = association.getScopeName(); + EclipseThemeAssociation registry = scopes.get(scopeName); + if (registry != null) { + boolean dark = association.isWhenDark(); + if (dark) { + registry.setDark(null); + } else { + registry.setLight(null); + } + } + } + + // public IThemeAssociation getThemeAssociationFor(String scopeName, String + // eclipseThemeId) { + // IThemeAssociation association = null; + // BaseThemeAssociationRegistry registry = scopes.get(scopeName); + // if (registry != null) { + // association = registry.getThemeAssociationFor(eclipseThemeId); + // if (association == null) { + // association = registry.getDefaultAssociation(); + // } + // } + // if (association == null) { + // association = super.getThemeAssociationFor(eclipseThemeId); + // } + // return association != null ? association : getDefaultAssociation(); + // } + + // public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { + // BaseThemeAssociationRegistry registry = scopes.get(scopeName); + // if (registry != null) { + // // Get the user associations (from preferences) + // List userAssociations = registry.getThemeAssociations(); + // // Get the default associations (from plugin) + // /*List defaultAssociations = + // getThemeAssociations().stream() + // .filter().collect(Collectors.toList()); + // // Add default association if user associations doesn't define it. + // for (IThemeAssociation defaultAssociation : defaultAssociations) { + // if (!(contains(userAssociations, defaultAssociation))) { + // userAssociations.add(defaultAssociation); + // } + // }*/ + // return userAssociations.toArray(new IThemeAssociation[0]); + // } + // return getThemeAssociations(true); + // } + // + // private boolean contains(List userAssociations, + // IThemeAssociation defaultAssociation) { + //// for (IThemeAssociation userAssociation : userAssociations) { + //// if (defaultAssociation.getEclipseThemeId() == null) { + //// if (userAssociation.getEclipseThemeId() == null) { + //// return true; + //// } + //// } else { + //// if + // (defaultAssociation.getEclipseThemeId().equals(userAssociation.getEclipseThemeId())) + // { + //// return true; + //// } + //// } + //// } + // return false; + // } + // + // @Override + public List getThemeAssociations() { + List associations = new ArrayList<>(); + Collection eclipseAssociations = scopes.values(); + for (EclipseThemeAssociation eclipseAssociation : eclipseAssociations) { + if (eclipseAssociation.getLight() != null) { + associations.add(eclipseAssociation.getLight()); + } + if (eclipseAssociation.getDark() != null) { + associations.add(eclipseAssociation.getDark()); + } + } + return associations; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java index e2e78db22..4a20edd8e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java @@ -1,181 +1,181 @@ -/** - * Copyright (c) 2015, 2021 Angelo ZERR and others. +/** + * Copyright (c) 2015, 2021 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.themes; - - -import java.util.Arrays; -import java.util.stream.Collectors; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; -import org.eclipse.tm4e.ui.internal.preferences.PreferenceHelper; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.Theme; -import org.eclipse.tm4e.ui.themes.ThemeAssociation; -import org.eclipse.tm4e.ui.utils.PreferenceUtils; -import org.osgi.service.prefs.BackingStoreException; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * Theme manager singleton. - */ -public class ThemeManager extends AbstractThemeManager { - - // "themes" extension point - private static final String EXTENSION_THEMES = "themes"; //$NON-NLS-1$ - - // "theme" declaration - private static final String THEME_ELT = "theme"; //$NON-NLS-1$ - - // "themeAssociation" declaration - private static final String THEME_ASSOCIATION_ELT = "themeAssociation"; //$NON-NLS-1$ - - private static ThemeManager INSTANCE; - - public static ThemeManager getInstance() { - if (INSTANCE != null) { - return INSTANCE; - } - INSTANCE = createInstance(); - return INSTANCE; - } - - private static synchronized ThemeManager createInstance() { - if (INSTANCE != null) { - return INSTANCE; - } - ThemeManager manager = new ThemeManager(); - manager.load(); - return manager; - } - - private ThemeManager() { - } - - private void load() { - loadThemesFromExtensionPoints(); - loadThemesFromPreferences(); - } - - /** - * Load TextMate Themes from extension point. - */ - private void loadThemesFromExtensionPoints() { - IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, - EXTENSION_THEMES); - for (IConfigurationElement ce : cf) { - String name = ce.getName(); - if (THEME_ELT.equals(name)) { - super.registerTheme(new Theme(ce)); - } else if (THEME_ASSOCIATION_ELT.equals(name)) { - super.registerThemeAssociation(new ThemeAssociation(ce)); - } - } - } - - /** - * Load TextMate Themes from preferences. - */ - private void loadThemesFromPreferences() { - // Load Theme definitions from the - // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); - String json = prefs.get(PreferenceConstants.THEMES, null); - if (json != null) { - for (JsonObject element : new Gson().fromJson(json, JsonObject[].class)) { - String name = element.get("id").getAsString(); - super.registerTheme(new Theme(name, element.get("path").getAsString(), name, element.get("dark").getAsBoolean(), false)); - } - } - - json = prefs.get(PreferenceConstants.THEME_ASSOCIATIONS, null); - if (json != null) { - IThemeAssociation[] themeAssociations = PreferenceHelper.loadThemeAssociations(json); - for (IThemeAssociation association : themeAssociations) { - super.registerThemeAssociation(association); - } - } - } - - @Override - public void save() throws BackingStoreException { - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); - // Save Themes in the - // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" - prefs.put(PreferenceConstants.THEMES, Arrays.stream(getThemes()) // - .filter(t -> t.getPluginId() == null) // - .map(theme -> { - JsonObject json = new JsonObject(); - json.addProperty("id", theme.getId()); - json.addProperty("path", theme.getPath()); - json.addProperty("dark", theme.isDark()); - return json; - }).collect(JsonArray::new, (JsonArray array, JsonObject object) -> array.add(object), (r,r1) -> {}) - .toString()); - - // Save Theme associations in the - // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" - String json = PreferenceHelper.toJsonThemeAssociations(Arrays.stream(getAllThemeAssociations()) - .filter(t -> t.getPluginId() == null).collect(Collectors.toList())); - prefs.put(PreferenceConstants.THEME_ASSOCIATIONS, json); - - // Save preferences - prefs.flush(); - } - - /** - * Add preference change listener to observe changed of Eclipse E4 Theme and - * TextMate theme association with grammar. - * - * @param themeChangeListener - */ - public void addPreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { - // Observe change of Eclipse E4 Theme - IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); - if (preferences != null) { - preferences.addPreferenceChangeListener(themeChangeListener); - } - // Observe change of TextMate Theme association - preferences = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); - if (preferences != null) { - preferences.addPreferenceChangeListener(themeChangeListener); - } - } - - /** - * Remove preference change listener to observe changed of Eclipse E4 Theme and - * TextMate theme association with grammar. - * - * @param themeChangeListener - */ - public void removePreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { - // Observe change of Eclipse E4 Theme - IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); - if (preferences != null) { - preferences.removePreferenceChangeListener(themeChangeListener); - } - // Observe change of TextMate Theme association - preferences = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); - if (preferences != null) { - preferences.removePreferenceChangeListener(themeChangeListener); - } - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.themes; + + +import java.util.Arrays; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; +import org.eclipse.tm4e.ui.internal.preferences.PreferenceHelper; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.Theme; +import org.eclipse.tm4e.ui.themes.ThemeAssociation; +import org.eclipse.tm4e.ui.utils.PreferenceUtils; +import org.osgi.service.prefs.BackingStoreException; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +/** + * Theme manager singleton. + */ +public class ThemeManager extends AbstractThemeManager { + + // "themes" extension point + private static final String EXTENSION_THEMES = "themes"; //$NON-NLS-1$ + + // "theme" declaration + private static final String THEME_ELT = "theme"; //$NON-NLS-1$ + + // "themeAssociation" declaration + private static final String THEME_ASSOCIATION_ELT = "themeAssociation"; //$NON-NLS-1$ + + private static ThemeManager INSTANCE; + + public static ThemeManager getInstance() { + if (INSTANCE != null) { + return INSTANCE; + } + INSTANCE = createInstance(); + return INSTANCE; + } + + private static synchronized ThemeManager createInstance() { + if (INSTANCE != null) { + return INSTANCE; + } + ThemeManager manager = new ThemeManager(); + manager.load(); + return manager; + } + + private ThemeManager() { + } + + private void load() { + loadThemesFromExtensionPoints(); + loadThemesFromPreferences(); + } + + /** + * Load TextMate Themes from extension point. + */ + private void loadThemesFromExtensionPoints() { + IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, + EXTENSION_THEMES); + for (IConfigurationElement ce : cf) { + String name = ce.getName(); + if (THEME_ELT.equals(name)) { + super.registerTheme(new Theme(ce)); + } else if (THEME_ASSOCIATION_ELT.equals(name)) { + super.registerThemeAssociation(new ThemeAssociation(ce)); + } + } + } + + /** + * Load TextMate Themes from preferences. + */ + private void loadThemesFromPreferences() { + // Load Theme definitions from the + // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + String json = prefs.get(PreferenceConstants.THEMES, null); + if (json != null) { + for (JsonObject element : new Gson().fromJson(json, JsonObject[].class)) { + String name = element.get("id").getAsString(); + super.registerTheme(new Theme(name, element.get("path").getAsString(), name, element.get("dark").getAsBoolean(), false)); + } + } + + json = prefs.get(PreferenceConstants.THEME_ASSOCIATIONS, null); + if (json != null) { + IThemeAssociation[] themeAssociations = PreferenceHelper.loadThemeAssociations(json); + for (IThemeAssociation association : themeAssociations) { + super.registerThemeAssociation(association); + } + } + } + + @Override + public void save() throws BackingStoreException { + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + // Save Themes in the + // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" + prefs.put(PreferenceConstants.THEMES, Arrays.stream(getThemes()) // + .filter(t -> t.getPluginId() == null) // + .map(theme -> { + JsonObject json = new JsonObject(); + json.addProperty("id", theme.getId()); + json.addProperty("path", theme.getPath()); + json.addProperty("dark", theme.isDark()); + return json; + }).collect(JsonArray::new, (JsonArray array, JsonObject object) -> array.add(object), (r,r1) -> {}) + .toString()); + + // Save Theme associations in the + // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" + String json = PreferenceHelper.toJsonThemeAssociations(Arrays.stream(getAllThemeAssociations()) + .filter(t -> t.getPluginId() == null).collect(Collectors.toList())); + prefs.put(PreferenceConstants.THEME_ASSOCIATIONS, json); + + // Save preferences + prefs.flush(); + } + + /** + * Add preference change listener to observe changed of Eclipse E4 Theme and + * TextMate theme association with grammar. + * + * @param themeChangeListener + */ + public void addPreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { + // Observe change of Eclipse E4 Theme + IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); + if (preferences != null) { + preferences.addPreferenceChangeListener(themeChangeListener); + } + // Observe change of TextMate Theme association + preferences = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + if (preferences != null) { + preferences.addPreferenceChangeListener(themeChangeListener); + } + } + + /** + * Remove preference change listener to observe changed of Eclipse E4 Theme and + * TextMate theme association with grammar. + * + * @param themeChangeListener + */ + public void removePreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { + // Observe change of Eclipse E4 Theme + IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); + if (preferences != null) { + preferences.removePreferenceChangeListener(themeChangeListener); + } + // Observe change of TextMate Theme association + preferences = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + if (preferences != null) { + preferences.removePreferenceChangeListener(themeChangeListener); + } + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java index 289fe92eb..cb1561705 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java @@ -1,125 +1,125 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.themes; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.tm4e.ui.themes.ITheme; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.IThemeManager; -import org.osgi.service.prefs.BackingStoreException; - -/** - * Working copy of theme manager. - * - */ -public class WorkingCopyThemeManager extends AbstractThemeManager { - - private final IThemeManager manager; - - private List themeAdded; - private List themeRemoved; - - private List associationAdded; - private List associationRemoved; - - public WorkingCopyThemeManager(IThemeManager manager) { - this.manager = manager; - load(); - } - - private void load() { - // Copy themes - ITheme[] themes = manager.getThemes(); - for (ITheme theme : themes) { - super.registerTheme(theme); - } - // Copy theme associations - IThemeAssociation[] associations = manager.getAllThemeAssociations(); - for (IThemeAssociation association : associations) { - super.registerThemeAssociation(association); - } - } - - @Override - public void registerTheme(ITheme theme) { - super.registerTheme(theme); - if (themeAdded == null) { - themeAdded = new ArrayList<>(); - } - themeAdded.add(theme); - } - - @Override - public void unregisterTheme(ITheme theme) { - super.unregisterTheme(theme); - if (themeAdded != null && themeAdded.contains(theme)) { - themeAdded.remove(theme); - } else { - if (themeRemoved == null) { - themeRemoved = new ArrayList<>(); - } - themeRemoved.add(theme); - } - } - - @Override - public void registerThemeAssociation(IThemeAssociation association) { - super.registerThemeAssociation(association); - if (associationAdded == null) { - associationAdded = new ArrayList<>(); - } - associationAdded.add(association); - } - - @Override - public void unregisterThemeAssociation(IThemeAssociation association) { - super.unregisterThemeAssociation(association); - if (associationAdded != null && associationAdded.contains(association)) { - associationAdded.remove(association); - } else { - if (associationRemoved == null) { - associationRemoved = new ArrayList<>(); - } - associationRemoved.add(association); - } - } - - @Override - public void save() throws BackingStoreException { - if (themeAdded != null) { - for (ITheme theme : themeAdded) { - manager.registerTheme(theme); - } - } - if (themeRemoved != null) { - for (ITheme theme : themeRemoved) { - manager.unregisterTheme(theme); - } - } - if (associationAdded != null) { - for (IThemeAssociation association : associationAdded) { - manager.registerThemeAssociation(association); - } - } - if (associationRemoved != null) { - for (IThemeAssociation association : associationRemoved) { - manager.unregisterThemeAssociation(association); - } - } - if (themeAdded != null || themeRemoved != null || associationAdded != null || associationRemoved != null) { - manager.save(); - } - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.themes; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.tm4e.ui.themes.ITheme; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.IThemeManager; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Working copy of theme manager. + * + */ +public class WorkingCopyThemeManager extends AbstractThemeManager { + + private final IThemeManager manager; + + private List themeAdded; + private List themeRemoved; + + private List associationAdded; + private List associationRemoved; + + public WorkingCopyThemeManager(IThemeManager manager) { + this.manager = manager; + load(); + } + + private void load() { + // Copy themes + ITheme[] themes = manager.getThemes(); + for (ITheme theme : themes) { + super.registerTheme(theme); + } + // Copy theme associations + IThemeAssociation[] associations = manager.getAllThemeAssociations(); + for (IThemeAssociation association : associations) { + super.registerThemeAssociation(association); + } + } + + @Override + public void registerTheme(ITheme theme) { + super.registerTheme(theme); + if (themeAdded == null) { + themeAdded = new ArrayList<>(); + } + themeAdded.add(theme); + } + + @Override + public void unregisterTheme(ITheme theme) { + super.unregisterTheme(theme); + if (themeAdded != null && themeAdded.contains(theme)) { + themeAdded.remove(theme); + } else { + if (themeRemoved == null) { + themeRemoved = new ArrayList<>(); + } + themeRemoved.add(theme); + } + } + + @Override + public void registerThemeAssociation(IThemeAssociation association) { + super.registerThemeAssociation(association); + if (associationAdded == null) { + associationAdded = new ArrayList<>(); + } + associationAdded.add(association); + } + + @Override + public void unregisterThemeAssociation(IThemeAssociation association) { + super.unregisterThemeAssociation(association); + if (associationAdded != null && associationAdded.contains(association)) { + associationAdded.remove(association); + } else { + if (associationRemoved == null) { + associationRemoved = new ArrayList<>(); + } + associationRemoved.add(association); + } + } + + @Override + public void save() throws BackingStoreException { + if (themeAdded != null) { + for (ITheme theme : themeAdded) { + manager.registerTheme(theme); + } + } + if (themeRemoved != null) { + for (ITheme theme : themeRemoved) { + manager.unregisterTheme(theme); + } + } + if (associationAdded != null) { + for (IThemeAssociation association : associationAdded) { + manager.registerThemeAssociation(association); + } + } + if (associationRemoved != null) { + for (IThemeAssociation association : associationRemoved) { + manager.unregisterThemeAssociation(association); + } + } + if (themeAdded != null || themeRemoved != null || associationAdded != null || associationRemoved != null) { + manager.save(); + } + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java index 2cef14c01..2bd8ccd90 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java @@ -1,47 +1,47 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; - -/** - * Sort the selected column and refresh the viewer. - * - */ -public class ColumnSelectionAdapter extends SelectionAdapter { - - private final TableColumn fTableColumn; - private final TableViewer tableViewer; - private final int fColumnIndex; - private final ColumnViewerComparator viewerComparator; - - public ColumnSelectionAdapter(TableColumn column, TableViewer tableViewer, int index, ColumnViewerComparator vc) { - fTableColumn = column; - this.tableViewer = tableViewer; - fColumnIndex = index; - viewerComparator = vc; - } - - @Override - public void widgetSelected(SelectionEvent e) { - viewerComparator.setColumn(fColumnIndex); - int dir = viewerComparator.getDirection(); - Table table = tableViewer.getTable(); - table.setSortDirection(dir); - table.setSortColumn(fTableColumn); - tableViewer.refresh(); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + +/** + * Sort the selected column and refresh the viewer. + * + */ +public class ColumnSelectionAdapter extends SelectionAdapter { + + private final TableColumn fTableColumn; + private final TableViewer tableViewer; + private final int fColumnIndex; + private final ColumnViewerComparator viewerComparator; + + public ColumnSelectionAdapter(TableColumn column, TableViewer tableViewer, int index, ColumnViewerComparator vc) { + fTableColumn = column; + this.tableViewer = tableViewer; + fColumnIndex = index; + viewerComparator = vc; + } + + @Override + public void widgetSelected(SelectionEvent e) { + viewerComparator.setColumn(fColumnIndex); + int dir = viewerComparator.getDirection(); + Table table = tableViewer.getTable(); + table.setSortDirection(dir); + table.setSortColumn(fTableColumn); + tableViewer.refresh(); + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java index d292b4268..496b5858b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java @@ -1,76 +1,76 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; - -/** - * Viewer compoarator which sort a given column. - * - */ -public class ColumnViewerComparator extends ViewerComparator { - - private int fSortColumn; - - private int fSortOrder; // 1 = asc, -1 = desc - - public ColumnViewerComparator() { - fSortColumn = 0; - fSortOrder = 1; - } - - /** - * Returns the {@linkplain SWT} style constant for the sort direction. - * - * @return {@link SWT#DOWN} for asc sorting, {@link SWT#UP} otherwise - */ - public int getDirection() { - return fSortOrder == 1 ? SWT.DOWN : SWT.UP; - } - - /** - * Sets the sort column. If the newly set sort column equals the previous - * set sort column, the sort direction changes. - * - * @param column - * New sort column - */ - public void setColumn(int column) { - if (column == fSortColumn) { - fSortOrder *= -1; - } else { - fSortColumn = column; - fSortOrder = 1; - } - } - - @Override - public int compare(Viewer viewer, Object e1, Object e2) { - - if (viewer instanceof TableViewer) { - IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider(); - - String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); - String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); - int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : ""); - return sortResult * fSortOrder; - } - - return super.compare(viewer, e1, e2); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; + +/** + * Viewer compoarator which sort a given column. + * + */ +public class ColumnViewerComparator extends ViewerComparator { + + private int fSortColumn; + + private int fSortOrder; // 1 = asc, -1 = desc + + public ColumnViewerComparator() { + fSortColumn = 0; + fSortOrder = 1; + } + + /** + * Returns the {@linkplain SWT} style constant for the sort direction. + * + * @return {@link SWT#DOWN} for asc sorting, {@link SWT#UP} otherwise + */ + public int getDirection() { + return fSortOrder == 1 ? SWT.DOWN : SWT.UP; + } + + /** + * Sets the sort column. If the newly set sort column equals the previous + * set sort column, the sort direction changes. + * + * @param column + * New sort column + */ + public void setColumn(int column) { + if (column == fSortColumn) { + fSortOrder *= -1; + } else { + fSortColumn = column; + fSortOrder = 1; + } + } + + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + + if (viewer instanceof TableViewer) { + IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider(); + + String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); + String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); + int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : ""); + return sortResult * fSortOrder; + } + + return super.compare(viewer, e1, e2); + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java index 7be1ba9c2..2192a04e7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java @@ -1,56 +1,56 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; - -/** - * Label provider for {@link IContentType}. - */ -public class ContentTypeLabelProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getText(Object element) { - return getColumnText(element, 0); - } - - @Override - public String getColumnText(Object element, int columnIndex) { - switch (columnIndex) { - case 0: - IContentType contentType = null; - if(element instanceof IContentType) { - contentType = (IContentType) element; - } else if(element instanceof String) { - String contentTypeId = (String) element; - contentType = Platform.getContentTypeManager().getContentType(contentTypeId); - if (contentType == null) { - return contentTypeId; - } - } else { - return ""; //$NON-NLS-1$ - } - return contentType.getName() + " (" + contentType.getId() + ")"; - default: - return ""; //$NON-NLS-1$ - } - } +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +/** + * Label provider for {@link IContentType}. + */ +public class ContentTypeLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getText(Object element) { + return getColumnText(element, 0); + } + + @Override + public String getColumnText(Object element, int columnIndex) { + switch (columnIndex) { + case 0: + IContentType contentType = null; + if(element instanceof IContentType) { + contentType = (IContentType) element; + } else if(element instanceof String) { + String contentTypeId = (String) element; + contentType = Platform.getContentTypeManager().getContentType(contentTypeId); + if (contentType == null) { + return contentTypeId; + } + } else { + return ""; //$NON-NLS-1$ + } + return contentType.getName() + " (" + contentType.getId() + ")"; + default: + return ""; //$NON-NLS-1$ + } + } } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java index 93df342d9..98ffbc9a9 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java @@ -1,34 +1,34 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.tm4e.ui.internal.TMUIMessages; - -/** - * Widget which displays content type list on the ledt and "New", "Remove" - * buttons on the right. - * - */ -public class ContentTypesBindingWidget extends TableAndButtonsWidget { - - public ContentTypesBindingWidget(Composite parent, int style) { - super(parent, style, TMUIMessages.ContentTypesBindingWidget_description); - super.setContentProvider(ArrayContentProvider.getInstance()); - super.setLabelProvider(new ContentTypeLabelProvider()); - } - - @Override - protected void createButtons(Composite parent) { - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tm4e.ui.internal.TMUIMessages; + +/** + * Widget which displays content type list on the ledt and "New", "Remove" + * buttons on the right. + * + */ +public class ContentTypesBindingWidget extends TableAndButtonsWidget { + + public ContentTypesBindingWidget(Composite parent, int style) { + super(parent, style, TMUIMessages.ContentTypesBindingWidget_description); + super.setContentProvider(ArrayContentProvider.getInstance()); + super.setLabelProvider(new ContentTypeLabelProvider()); + } + + @Override + protected void createButtons(Composite parent) { + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java index c9163f515..0580b891b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java @@ -1,41 +1,41 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.tm4e.registry.IGrammarRegistryManager; - -/** - * A content provider for the template grammar page's table viewer. - * - */ -public class GrammarDefinitionContentProvider implements IStructuredContentProvider { - - private IGrammarRegistryManager registry; - - @Override - public Object[] getElements(Object input) { - return registry.getDefinitions(); - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - registry = (IGrammarRegistryManager) newInput; - } - - @Override - public void dispose() { - registry = null; - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.tm4e.registry.IGrammarRegistryManager; + +/** + * A content provider for the template grammar page's table viewer. + * + */ +public class GrammarDefinitionContentProvider implements IStructuredContentProvider { + + private IGrammarRegistryManager registry; + + @Override + public Object[] getElements(Object input) { + return registry.getDefinitions(); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + registry = (IGrammarRegistryManager) newInput; + } + + @Override + public void dispose() { + registry = null; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java index 3d99b94b1..1df3925b5 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java @@ -1,49 +1,49 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.tm4e.registry.IGrammarDefinition; - -/** - * Label provider for grammar definition. - */ -public class GrammarDefinitionLabelProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getText(Object element) { - return getColumnText(element, 0); - } - - @Override - public String getColumnText(Object element, int columnIndex) { - IGrammarDefinition definition = (IGrammarDefinition) element; - - switch (columnIndex) { - case 0: - return definition.getScopeName(); - case 1: - return definition.getPath(); - case 2: - return definition.getPluginId(); - default: - return ""; //$NON-NLS-1$ - } - } + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.tm4e.registry.IGrammarDefinition; + +/** + * Label provider for grammar definition. + */ +public class GrammarDefinitionLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getText(Object element) { + return getColumnText(element, 0); + } + + @Override + public String getColumnText(Object element, int columnIndex) { + IGrammarDefinition definition = (IGrammarDefinition) element; + + switch (columnIndex) { + case 0: + return definition.getScopeName(); + case 1: + return definition.getPath(); + case 2: + return definition.getPluginId(); + default: + return ""; //$NON-NLS-1$ + } + } } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java index 8dee3b007..1e8df69db 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java @@ -1,102 +1,102 @@ -/** - * Copyright (c) 2015-2019 Angelo ZERR. +/** + * Copyright (c) 2015-2019 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import java.util.Collection; -import java.util.stream.Collectors; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.ui.internal.TMUIMessages; - -/** - * - * Widget which display grammar information like name, scope, and file types. - */ -public class GrammarInfoWidget extends Composite { - - private Text nameText; - private Text scopeNameText; - private Text fileTypesText; - - public GrammarInfoWidget(Composite parent, int style) { - super(parent, style); - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginLeft = 0; - layout.marginRight = 0; - super.setLayout(layout); - super.setLayoutData(new GridData(GridData.FILL_BOTH)); - createUI(this); - } - - private void createUI(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginLeft = 0; - layout.marginRight = 0; - parent.setLayout(layout); - parent.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label grammarNameLabel = new Label(parent, SWT.NONE); - grammarNameLabel.setText(TMUIMessages.GrammarInfoWidget_name_text); - nameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); - nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label grammarScopeNameLabel = new Label(parent, SWT.NONE); - grammarScopeNameLabel.setText(TMUIMessages.GrammarInfoWidget_scopeName_text); - scopeNameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); - scopeNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label grammarFileTypesLabel = new Label(parent, SWT.NONE); - grammarFileTypesLabel.setText(TMUIMessages.GrammarInfoWidget_fileTypes_text); - fileTypesText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); - fileTypesText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - } - - public void refresh(IGrammar grammar) { - if (grammar == null) { - nameText.setText(""); - scopeNameText.setText(""); - fileTypesText.setText(""); - } else { - String name = grammar.getName(); - nameText.setText(name != null ? name : ""); - String scope = grammar.getScopeName(); - scopeNameText.setText(scope != null ? scope : ""); - Collection fileTypes = grammar.getFileTypes(); - String types = fileTypes.stream().map(Object::toString).collect(Collectors.joining(",")); - fileTypesText.setText(types); - } - } - - public Text getGrammarNameText() { - return nameText; - } - - public Text getScopeNameText() { - return scopeNameText; - } - - public Text getFileTypesText() { - return fileTypesText; - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import java.util.Collection; +import java.util.stream.Collectors; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.ui.internal.TMUIMessages; + +/** + * + * Widget which display grammar information like name, scope, and file types. + */ +public class GrammarInfoWidget extends Composite { + + private Text nameText; + private Text scopeNameText; + private Text fileTypesText; + + public GrammarInfoWidget(Composite parent, int style) { + super(parent, style); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginLeft = 0; + layout.marginRight = 0; + super.setLayout(layout); + super.setLayoutData(new GridData(GridData.FILL_BOTH)); + createUI(this); + } + + private void createUI(Composite ancestor) { + Composite parent = new Composite(ancestor, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginLeft = 0; + layout.marginRight = 0; + parent.setLayout(layout); + parent.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label grammarNameLabel = new Label(parent, SWT.NONE); + grammarNameLabel.setText(TMUIMessages.GrammarInfoWidget_name_text); + nameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); + nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label grammarScopeNameLabel = new Label(parent, SWT.NONE); + grammarScopeNameLabel.setText(TMUIMessages.GrammarInfoWidget_scopeName_text); + scopeNameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); + scopeNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label grammarFileTypesLabel = new Label(parent, SWT.NONE); + grammarFileTypesLabel.setText(TMUIMessages.GrammarInfoWidget_fileTypes_text); + fileTypesText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); + fileTypesText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + } + + public void refresh(IGrammar grammar) { + if (grammar == null) { + nameText.setText(""); + scopeNameText.setText(""); + fileTypesText.setText(""); + } else { + String name = grammar.getName(); + nameText.setText(name != null ? name : ""); + String scope = grammar.getScopeName(); + scopeNameText.setText(scope != null ? scope : ""); + Collection fileTypes = grammar.getFileTypes(); + String types = fileTypes.stream().map(Object::toString).collect(Collectors.joining(",")); + fileTypesText.setText(types); + } + } + + public Text getGrammarNameText() { + return nameText; + } + + public Text getScopeNameText() { + return scopeNameText; + } + + public Text getFileTypesText() { + return fileTypesText; + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java index 1dbd8cc4a..3df567c47 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java @@ -1,84 +1,84 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.source.IOverviewRuler; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.IVerticalRuler; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.ui.text.TMPresentationReconciler; -import org.eclipse.tm4e.ui.themes.ITheme; - -/** - * Simple TextMate Viewer. - * - */ -public class TMViewer extends SourceViewer { - - private TMPresentationReconciler reconciler; - - public TMViewer(Composite parent, IVerticalRuler ruler, int styles) { - super(parent, ruler, styles); - init(); - } - - public TMViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, - boolean showAnnotationsOverview, int styles) { - super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); - init(); - } - - private void init() { - this.reconciler = new TMPresentationReconciler(); - SourceViewerConfiguration configuration = new TMSourceViewerConfiguration(); - this.configure(configuration); - } - - private class TMSourceViewerConfiguration extends SourceViewerConfiguration { - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - return reconciler; - } - - } - - public void setGrammar(IGrammar grammar) { - reconciler.setGrammar(grammar); - if (getDocument() == null) { - super.setDocument(new Document()); - } - } - - public void setTheme(ITheme theme) { - reconciler.setTheme(theme); - StyledText styledText = getTextWidget(); - styledText.setForeground(null); - styledText.setBackground(null); - theme.initializeViewerColors(styledText); - getTextWidget().setFont(JFaceResources.getTextFont()); - } - - public void setText(String text) { - if (getDocument() == null) { - super.setDocument(new Document()); - } - getDocument().set(text); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.source.IOverviewRuler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.IVerticalRuler; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.ui.text.TMPresentationReconciler; +import org.eclipse.tm4e.ui.themes.ITheme; + +/** + * Simple TextMate Viewer. + * + */ +public class TMViewer extends SourceViewer { + + private TMPresentationReconciler reconciler; + + public TMViewer(Composite parent, IVerticalRuler ruler, int styles) { + super(parent, ruler, styles); + init(); + } + + public TMViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, + boolean showAnnotationsOverview, int styles) { + super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); + init(); + } + + private void init() { + this.reconciler = new TMPresentationReconciler(); + SourceViewerConfiguration configuration = new TMSourceViewerConfiguration(); + this.configure(configuration); + } + + private class TMSourceViewerConfiguration extends SourceViewerConfiguration { + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + return reconciler; + } + + } + + public void setGrammar(IGrammar grammar) { + reconciler.setGrammar(grammar); + if (getDocument() == null) { + super.setDocument(new Document()); + } + } + + public void setTheme(ITheme theme) { + reconciler.setTheme(theme); + StyledText styledText = getTextWidget(); + styledText.setForeground(null); + styledText.setBackground(null); + theme.initializeViewerColors(styledText); + getTextWidget().setFont(JFaceResources.getTextFont()); + } + + public void setText(String text) { + if (getDocument() == null) { + super.setDocument(new Document()); + } + getDocument().set(text); + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java index 975ae0cfc..83883d6d7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java @@ -1,123 +1,123 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Table; - -/** - * Widget which display a table on the left and buttons on the right. - * - */ -public abstract class TableAndButtonsWidget extends Composite { - - private TableViewer viewer; - - public TableAndButtonsWidget(Composite parent, int style, String title) { - super(parent, style); - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginLeft = 0; - layout.marginRight = 0; - super.setLayout(layout); - createUI(title, this); - } - - private void createUI(String title, Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginLeft = 0; - layout.marginRight = 0; - parent.setLayout(layout); - parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // Title - createTitle(title, parent); - - // Table - createTable(parent); - - // Buttons - Composite buttonsComposite = new Composite(parent, SWT.NONE); - layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginLeft = 0; - layout.marginRight = 0; - buttonsComposite.setLayout(layout); - buttonsComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_VERTICAL)); - createButtons(buttonsComposite); - } - - protected abstract void createButtons(Composite parent); - - private void createTitle(String title, Composite ancestor) { - if (title == null) { - return; - } - Label label = new Label(ancestor, SWT.NONE); - label.setText(title); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - label.setLayoutData(data); - } - - private void createTable(Composite parent) { - Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); - table.setHeaderVisible(false); - table.setLinesVisible(false); - - viewer = new TableViewer(table); - table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - } - - public void setInput(Object input) { - viewer.setInput(input); - } - - public TableViewer getViewer() { - return viewer; - } - - public void setLabelProvider(IBaseLabelProvider labelProvider) { - viewer.setLabelProvider(labelProvider); - } - - public void setContentProvider(IContentProvider provider) { - viewer.setContentProvider(provider); - } - - public void addSelectionChangedListener(ISelectionChangedListener listener) { - viewer.addSelectionChangedListener(listener); - } - - public void setSelection(IStructuredSelection selection) { - viewer.setSelection(selection); - } - - public IStructuredSelection getSelection() { - return viewer.getStructuredSelection(); - } -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; + +/** + * Widget which display a table on the left and buttons on the right. + * + */ +public abstract class TableAndButtonsWidget extends Composite { + + private TableViewer viewer; + + public TableAndButtonsWidget(Composite parent, int style, String title) { + super(parent, style); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginLeft = 0; + layout.marginRight = 0; + super.setLayout(layout); + createUI(title, this); + } + + private void createUI(String title, Composite ancestor) { + Composite parent = new Composite(ancestor, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginLeft = 0; + layout.marginRight = 0; + parent.setLayout(layout); + parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // Title + createTitle(title, parent); + + // Table + createTable(parent); + + // Buttons + Composite buttonsComposite = new Composite(parent, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginLeft = 0; + layout.marginRight = 0; + buttonsComposite.setLayout(layout); + buttonsComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_VERTICAL)); + createButtons(buttonsComposite); + } + + protected abstract void createButtons(Composite parent); + + private void createTitle(String title, Composite ancestor) { + if (title == null) { + return; + } + Label label = new Label(ancestor, SWT.NONE); + label.setText(title); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + label.setLayoutData(data); + } + + private void createTable(Composite parent) { + Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); + table.setHeaderVisible(false); + table.setLinesVisible(false); + + viewer = new TableViewer(table); + table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + } + + public void setInput(Object input) { + viewer.setInput(input); + } + + public TableViewer getViewer() { + return viewer; + } + + public void setLabelProvider(IBaseLabelProvider labelProvider) { + viewer.setLabelProvider(labelProvider); + } + + public void setContentProvider(IContentProvider provider) { + viewer.setContentProvider(provider); + } + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + viewer.addSelectionChangedListener(listener); + } + + public void setSelection(IStructuredSelection selection) { + viewer.setSelection(selection); + } + + public IStructuredSelection getSelection() { + return viewer.getStructuredSelection(); + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java index c31673bf4..83a0a92d6 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java @@ -1,61 +1,61 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.internal.TMUIMessages; -import org.eclipse.tm4e.ui.themes.ITheme; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.IThemeManager; - -/** - * Label provider for TextMate theme association. - */ -public class ThemeAssociationLabelProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getText(Object element) { - return getColumnText(element, 0); - } - - @Override - public String getColumnText(Object element, int columnIndex) { - IThemeAssociation association = (IThemeAssociation) element; - switch (columnIndex) { - case 0: - ITheme theme = getTheme(association); - String themeName = theme != null ? theme.getName() : association.getThemeId(); - if (association.isWhenDark()) { - return NLS.bind(TMUIMessages.ThemeAssociationLabelProvider_dark, themeName); - } - return NLS.bind(TMUIMessages.ThemeAssociationLabelProvider_light, themeName); - default: - return ""; //$NON-NLS-1$ - } - } - - private ITheme getTheme(IThemeAssociation association) { - String themeId = association.getThemeId(); - IThemeManager themeManager = TMUIPlugin.getThemeManager(); - return themeManager.getThemeById(themeId); - } - + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.graphics.Image; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.internal.TMUIMessages; +import org.eclipse.tm4e.ui.themes.ITheme; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.IThemeManager; + +/** + * Label provider for TextMate theme association. + */ +public class ThemeAssociationLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getText(Object element) { + return getColumnText(element, 0); + } + + @Override + public String getColumnText(Object element, int columnIndex) { + IThemeAssociation association = (IThemeAssociation) element; + switch (columnIndex) { + case 0: + ITheme theme = getTheme(association); + String themeName = theme != null ? theme.getName() : association.getThemeId(); + if (association.isWhenDark()) { + return NLS.bind(TMUIMessages.ThemeAssociationLabelProvider_dark, themeName); + } + return NLS.bind(TMUIMessages.ThemeAssociationLabelProvider_light, themeName); + default: + return ""; //$NON-NLS-1$ + } + } + + private ITheme getTheme(IThemeAssociation association) { + String themeId = association.getThemeId(); + IThemeManager themeManager = TMUIPlugin.getThemeManager(); + return themeManager.getThemeById(themeId); + } + } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java index fd400ee31..17456a469 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java @@ -1,120 +1,120 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import java.util.Iterator; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.tm4e.registry.IGrammarDefinition; -import org.eclipse.tm4e.ui.internal.TMUIMessages; -import org.eclipse.tm4e.ui.internal.wizards.CreateThemeAssociationWizard; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.IThemeManager; - -/** - * Widget which displays theme associations list on the left and "New", "Remove" - * buttons on the right. - * - */ -public class ThemeAssociationsWidget extends TableAndButtonsWidget { - - private final IThemeManager themeManager; - - private Button editButton; - private Button removeButton; - - private IGrammarDefinition definition; - - public ThemeAssociationsWidget(IThemeManager themeManager, Composite parent, int style) { - super(parent, style, TMUIMessages.ThemeAssociationsWidget_description); - this.themeManager = themeManager; - super.setContentProvider(ArrayContentProvider.getInstance()); - super.setLabelProvider(new ThemeAssociationLabelProvider()); - } - - @Override - protected void createButtons(Composite parent) { - editButton = new Button(parent, SWT.PUSH); - editButton.setText(TMUIMessages.Button_edit); - editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - editButton.addListener(SWT.Selection, e -> { - // Open the wizard to create association between theme and grammar. - CreateThemeAssociationWizard wizard = new CreateThemeAssociationWizard(false); - wizard.setInitialDefinition(definition); - IStructuredSelection selection = super.getSelection(); - wizard.setInitialAssociation(selection.isEmpty() ? null : (IThemeAssociation) selection.getFirstElement()); - wizard.setThemeManager(themeManager); - WizardDialog dialog = new WizardDialog(getShell(), wizard); - if (dialog.open() == Window.OK) { - IThemeAssociation association = wizard.getCreatedThemeAssociation(); - refresh(association); - } - }); - editButton.setEnabled(false); - - removeButton = new Button(parent, SWT.PUSH); - removeButton.setText(TMUIMessages.Button_remove); - removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - removeButton.addListener(SWT.Selection, e -> { - - if (MessageDialog.openConfirm(getShell(), TMUIMessages.ThemeAssociationsWidget_remove_dialog_title, - TMUIMessages.ThemeAssociationsWidget_remove_dialog_message)) { - IStructuredSelection selection = super.getSelection(); - Iterator it = selection.iterator(); - while (it.hasNext()) { - IThemeAssociation association = it.next(); - themeManager.unregisterThemeAssociation(association); - } - refresh(null); - } - - }); - removeButton.setEnabled(false); - } - - public Button getNewButton() { - return editButton; - } - - public Button getRemoveButton() { - return removeButton; - } - - public IThemeAssociation[] setGrammarDefinition(IGrammarDefinition definition) { - this.definition = definition; - return refresh(null); - } - - private IThemeAssociation[] refresh(IThemeAssociation association) { - IThemeAssociation[] themeAssociations = themeManager.getThemeAssociationsForScope(definition.getScopeName()); - // Refresh the list of associations - super.setInput(themeAssociations); - // Select the first of given association - if (association == null && themeAssociations != null && themeAssociations.length > 0) { - association = themeAssociations[0]; - } - if (association != null) { - super.setSelection(new StructuredSelection(association)); - } - return themeAssociations; - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import java.util.Iterator; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tm4e.registry.IGrammarDefinition; +import org.eclipse.tm4e.ui.internal.TMUIMessages; +import org.eclipse.tm4e.ui.internal.wizards.CreateThemeAssociationWizard; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.IThemeManager; + +/** + * Widget which displays theme associations list on the left and "New", "Remove" + * buttons on the right. + * + */ +public class ThemeAssociationsWidget extends TableAndButtonsWidget { + + private final IThemeManager themeManager; + + private Button editButton; + private Button removeButton; + + private IGrammarDefinition definition; + + public ThemeAssociationsWidget(IThemeManager themeManager, Composite parent, int style) { + super(parent, style, TMUIMessages.ThemeAssociationsWidget_description); + this.themeManager = themeManager; + super.setContentProvider(ArrayContentProvider.getInstance()); + super.setLabelProvider(new ThemeAssociationLabelProvider()); + } + + @Override + protected void createButtons(Composite parent) { + editButton = new Button(parent, SWT.PUSH); + editButton.setText(TMUIMessages.Button_edit); + editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + editButton.addListener(SWT.Selection, e -> { + // Open the wizard to create association between theme and grammar. + CreateThemeAssociationWizard wizard = new CreateThemeAssociationWizard(false); + wizard.setInitialDefinition(definition); + IStructuredSelection selection = super.getSelection(); + wizard.setInitialAssociation(selection.isEmpty() ? null : (IThemeAssociation) selection.getFirstElement()); + wizard.setThemeManager(themeManager); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + if (dialog.open() == Window.OK) { + IThemeAssociation association = wizard.getCreatedThemeAssociation(); + refresh(association); + } + }); + editButton.setEnabled(false); + + removeButton = new Button(parent, SWT.PUSH); + removeButton.setText(TMUIMessages.Button_remove); + removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + removeButton.addListener(SWT.Selection, e -> { + + if (MessageDialog.openConfirm(getShell(), TMUIMessages.ThemeAssociationsWidget_remove_dialog_title, + TMUIMessages.ThemeAssociationsWidget_remove_dialog_message)) { + IStructuredSelection selection = super.getSelection(); + Iterator it = selection.iterator(); + while (it.hasNext()) { + IThemeAssociation association = it.next(); + themeManager.unregisterThemeAssociation(association); + } + refresh(null); + } + + }); + removeButton.setEnabled(false); + } + + public Button getNewButton() { + return editButton; + } + + public Button getRemoveButton() { + return removeButton; + } + + public IThemeAssociation[] setGrammarDefinition(IGrammarDefinition definition) { + this.definition = definition; + return refresh(null); + } + + private IThemeAssociation[] refresh(IThemeAssociation association) { + IThemeAssociation[] themeAssociations = themeManager.getThemeAssociationsForScope(definition.getScopeName()); + // Refresh the list of associations + super.setInput(themeAssociations); + // Select the first of given association + if (association == null && themeAssociations != null && themeAssociations.length > 0) { + association = themeAssociations[0]; + } + if (association != null) { + super.setSelection(new StructuredSelection(association)); + } + return themeAssociations; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java index 88929902a..b58f9074f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java @@ -1,41 +1,41 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.tm4e.ui.themes.IThemeManager; - -/** - * A content provider for the template theme page's table viewer. - * - */ -public class ThemeContentProvider implements IStructuredContentProvider { - - private IThemeManager registry; - - @Override - public Object[] getElements(Object input) { - return registry.getThemes(); - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - registry = (IThemeManager) newInput; - } - - @Override - public void dispose() { - registry = null; - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.tm4e.ui.themes.IThemeManager; + +/** + * A content provider for the template theme page's table viewer. + * + */ +public class ThemeContentProvider implements IStructuredContentProvider { + + private IThemeManager registry; + + @Override + public Object[] getElements(Object input) { + return registry.getThemes(); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + registry = (IThemeManager) newInput; + } + + @Override + public void dispose() { + registry = null; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java index b46d57b8a..01dec2bc8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java @@ -1,49 +1,49 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.widgets; - -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.tm4e.ui.themes.ITheme; - -/** - * Label provider for TextMate theme. - */ -public class ThemeLabelProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getText(Object element) { - ITheme theme = (ITheme) element; - return theme.getName(); - } - - @Override - public String getColumnText(Object element, int columnIndex) { - ITheme theme = (ITheme) element; - switch (columnIndex) { - case 0: - return theme.getName(); - case 1: - return theme.getPath(); - case 2: - return theme.getPluginId(); - default: - return ""; //$NON-NLS-1$ - } - } + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.tm4e.ui.themes.ITheme; + +/** + * Label provider for TextMate theme. + */ +public class ThemeLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getText(Object element) { + ITheme theme = (ITheme) element; + return theme.getName(); + } + + @Override + public String getColumnText(Object element, int columnIndex) { + ITheme theme = (ITheme) element; + switch (columnIndex) { + case 0: + return theme.getName(); + case 1: + return theme.getPath(); + case 2: + return theme.getPluginId(); + default: + return ""; //$NON-NLS-1$ + } + } } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java index a355fedb2..14aaa1181 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java @@ -1,109 +1,109 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * - */ -package org.eclipse.tm4e.ui.internal.wizards; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.DialogPage; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; - -/** - * Abstract class for wizard page. - * - */ -public abstract class AbstractWizardPage extends WizardPage implements Listener { - - protected AbstractWizardPage(String pageName) { - super(pageName); - } - - protected AbstractWizardPage(String pageName, String title, ImageDescriptor titleImage) { - super(pageName, title, titleImage); - } - - @Override - public final void createControl(Composite parent) { - initializeDialogUnits(parent); - // top level group - Composite topLevel = new Composite(parent, SWT.NONE); - topLevel.setLayout(new GridLayout()); - topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); - topLevel.setFont(parent.getFont()); - - // Create Body UI - createBody(topLevel); - // initialize page with default values - initializeDefaultValues(); - // Validate page fields. -// validateAndUpdateStatus(null); - setControl(topLevel); - } - - @Override - public void handleEvent(Event event) { - validateAndUpdateStatus(event); - } - - private void validateAndUpdateStatus(Event event) { - IStatus status = validatePage(event); - statusChanged(status == null ? Status.OK_STATUS : status); - } - - public void statusChanged(IStatus status) { - setPageComplete(!status.matches(IStatus.ERROR)); - applyToStatusLine(this, status); - } - - /** - * Applies the status to the status line of a dialog page. - */ - private static void applyToStatusLine(DialogPage page, IStatus status) { - String message = Status.OK_STATUS.equals(status) ? null : status.getMessage(); - switch (status.getSeverity()) { - case IStatus.OK: - page.setMessage(message, IMessageProvider.NONE); - page.setErrorMessage(null); - break; - case IStatus.WARNING: - page.setMessage(message, IMessageProvider.WARNING); - page.setErrorMessage(null); - break; - case IStatus.INFO: - page.setMessage(message, IMessageProvider.INFORMATION); - page.setErrorMessage(null); - break; - default: - if (message != null && message.length() == 0) { - message = null; - } - page.setMessage(null); - page.setErrorMessage(message); - break; - } - } - - protected abstract void createBody(Composite parent); - - protected abstract void initializeDefaultValues(); - - protected abstract IStatus validatePage(Event event); - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + * + */ +package org.eclipse.tm4e.ui.internal.wizards; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.DialogPage; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; + +/** + * Abstract class for wizard page. + * + */ +public abstract class AbstractWizardPage extends WizardPage implements Listener { + + protected AbstractWizardPage(String pageName) { + super(pageName); + } + + protected AbstractWizardPage(String pageName, String title, ImageDescriptor titleImage) { + super(pageName, title, titleImage); + } + + @Override + public final void createControl(Composite parent) { + initializeDialogUnits(parent); + // top level group + Composite topLevel = new Composite(parent, SWT.NONE); + topLevel.setLayout(new GridLayout()); + topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); + topLevel.setFont(parent.getFont()); + + // Create Body UI + createBody(topLevel); + // initialize page with default values + initializeDefaultValues(); + // Validate page fields. +// validateAndUpdateStatus(null); + setControl(topLevel); + } + + @Override + public void handleEvent(Event event) { + validateAndUpdateStatus(event); + } + + private void validateAndUpdateStatus(Event event) { + IStatus status = validatePage(event); + statusChanged(status == null ? Status.OK_STATUS : status); + } + + public void statusChanged(IStatus status) { + setPageComplete(!status.matches(IStatus.ERROR)); + applyToStatusLine(this, status); + } + + /** + * Applies the status to the status line of a dialog page. + */ + private static void applyToStatusLine(DialogPage page, IStatus status) { + String message = Status.OK_STATUS.equals(status) ? null : status.getMessage(); + switch (status.getSeverity()) { + case IStatus.OK: + page.setMessage(message, IMessageProvider.NONE); + page.setErrorMessage(null); + break; + case IStatus.WARNING: + page.setMessage(message, IMessageProvider.WARNING); + page.setErrorMessage(null); + break; + case IStatus.INFO: + page.setMessage(message, IMessageProvider.INFORMATION); + page.setErrorMessage(null); + break; + default: + if (message != null && message.length() == 0) { + message = null; + } + page.setMessage(null); + page.setErrorMessage(message); + break; + } + } + + protected abstract void createBody(Composite parent); + + protected abstract void initializeDefaultValues(); + + protected abstract IStatus validatePage(Event event); + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java index d5580e88f..f5aaa9379 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java @@ -1,92 +1,92 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.wizards; - -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.tm4e.registry.IGrammarDefinition; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.IThemeManager; -import org.osgi.service.prefs.BackingStoreException; - -/** - * Wizard to create association between grammar and theme. - * - */ -public class CreateThemeAssociationWizard extends Wizard { - - private CreateThemeAssociationWizardPage mainPage; - - private IThemeAssociation createdThemeAssociation; - - private IThemeManager themeManager; - - private final boolean save; - - private IGrammarDefinition initialDefinition; - - private IThemeAssociation initialAssociation; - - public CreateThemeAssociationWizard() { - this(true); - } - - public CreateThemeAssociationWizard(boolean save) { - this.save = save; - setThemeManager(TMUIPlugin.getThemeManager()); - } - - /** - * Set theme managerto use to add the created theme associations. - * - * @param themeManager - */ - public void setThemeManager(IThemeManager themeManager) { - this.themeManager = themeManager; - } - - @Override - public void addPages() { - mainPage = new CreateThemeAssociationWizardPage(initialDefinition, initialAssociation); - addPage(mainPage); - } - - @Override - public boolean performFinish() { - IThemeAssociation association = mainPage.getThemeAssociation(); - themeManager.registerThemeAssociation(association); - if (save) { - try { - themeManager.save(); - } catch (BackingStoreException e) { - e.printStackTrace(); - return false; - } - } - createdThemeAssociation = association; - return true; - } - - public IThemeAssociation getCreatedThemeAssociation() { - return createdThemeAssociation; - } - - public void setInitialDefinition(IGrammarDefinition definition) { - this.initialDefinition = definition; - } - - public void setInitialAssociation(IThemeAssociation association) { - this.initialAssociation = association; - - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.wizards; + +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.tm4e.registry.IGrammarDefinition; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.IThemeManager; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Wizard to create association between grammar and theme. + * + */ +public class CreateThemeAssociationWizard extends Wizard { + + private CreateThemeAssociationWizardPage mainPage; + + private IThemeAssociation createdThemeAssociation; + + private IThemeManager themeManager; + + private final boolean save; + + private IGrammarDefinition initialDefinition; + + private IThemeAssociation initialAssociation; + + public CreateThemeAssociationWizard() { + this(true); + } + + public CreateThemeAssociationWizard(boolean save) { + this.save = save; + setThemeManager(TMUIPlugin.getThemeManager()); + } + + /** + * Set theme managerto use to add the created theme associations. + * + * @param themeManager + */ + public void setThemeManager(IThemeManager themeManager) { + this.themeManager = themeManager; + } + + @Override + public void addPages() { + mainPage = new CreateThemeAssociationWizardPage(initialDefinition, initialAssociation); + addPage(mainPage); + } + + @Override + public boolean performFinish() { + IThemeAssociation association = mainPage.getThemeAssociation(); + themeManager.registerThemeAssociation(association); + if (save) { + try { + themeManager.save(); + } catch (BackingStoreException e) { + e.printStackTrace(); + return false; + } + } + createdThemeAssociation = association; + return true; + } + + public IThemeAssociation getCreatedThemeAssociation() { + return createdThemeAssociation; + } + + public void setInitialDefinition(IGrammarDefinition definition) { + this.initialDefinition = definition; + } + + public void setInitialAssociation(IThemeAssociation association) { + this.initialAssociation = association; + + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java index 14bb1b168..8bcd80fba 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java @@ -1,131 +1,131 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.wizards; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.tm4e.registry.IGrammarDefinition; -import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.internal.TMUIMessages; -import org.eclipse.tm4e.ui.internal.widgets.GrammarDefinitionContentProvider; -import org.eclipse.tm4e.ui.internal.widgets.GrammarDefinitionLabelProvider; -import org.eclipse.tm4e.ui.internal.widgets.ThemeContentProvider; -import org.eclipse.tm4e.ui.internal.widgets.ThemeLabelProvider; -import org.eclipse.tm4e.ui.themes.ITheme; -import org.eclipse.tm4e.ui.themes.IThemeAssociation; -import org.eclipse.tm4e.ui.themes.ThemeAssociation; - -/** - * Wizard page to create association between grammar and theme. - * - */ -public class CreateThemeAssociationWizardPage extends AbstractWizardPage { - - private static final String PAGE_NAME = CreateThemeAssociationWizardPage.class.getName(); - - private ComboViewer themeViewer; - private ComboViewer grammarViewer; - private final IGrammarDefinition initialDefinition; - private final IThemeAssociation initialAssociation; - - private Button whenDarkButton; - - protected CreateThemeAssociationWizardPage(IGrammarDefinition initialDefinition, - IThemeAssociation initialAssociation) { - super(PAGE_NAME); - super.setTitle(TMUIMessages.CreateThemeAssociationWizardPage_title); - super.setDescription(TMUIMessages.CreateThemeAssociationWizardPage_description); - this.initialDefinition = initialDefinition; - this.initialAssociation = initialAssociation; - } - - @Override - protected void createBody(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - parent.setFont(parent.getFont()); - parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - parent.setLayout(new GridLayout(4, false)); - - // TextMate theme - Label label = new Label(parent, SWT.NONE); - label.setText(TMUIMessages.CreateThemeAssociationWizardPage_theme_text); - themeViewer = new ComboViewer(parent); - themeViewer.setLabelProvider(new ThemeLabelProvider()); - themeViewer.setContentProvider(new ThemeContentProvider()); - themeViewer.setInput(TMUIPlugin.getThemeManager()); - themeViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - themeViewer.getControl().addListener(SWT.Selection, this); - - label = new Label(parent, SWT.NONE); - label.setText(TMUIMessages.CreateThemeAssociationWizardPage_grammar_text); - grammarViewer = new ComboViewer(parent); - grammarViewer.setLabelProvider(new GrammarDefinitionLabelProvider()); - grammarViewer.setContentProvider(new GrammarDefinitionContentProvider()); - grammarViewer.setInput(TMEclipseRegistryPlugin.getGrammarRegistryManager()); - grammarViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - grammarViewer.getControl().addListener(SWT.Selection, this); - - if (initialDefinition != null) { - grammarViewer.setSelection(new StructuredSelection(initialDefinition)); - } - - whenDarkButton = new Button(parent, SWT.CHECK); - whenDarkButton.setText(TMUIMessages.CreateThemeAssociationWizardPage_whenDark_text); - GridData data = new GridData(); - data.horizontalSpan = 4; - whenDarkButton.setLayoutData(data); - if (initialAssociation != null) { - ITheme selectedTheme = TMUIPlugin.getThemeManager().getThemeById(initialAssociation.getThemeId()); - if (selectedTheme != null) { - themeViewer.setSelection(new StructuredSelection(selectedTheme)); - } - whenDarkButton.setSelection(initialAssociation.isWhenDark()); - } - } - - @Override - protected void initializeDefaultValues() { - setPageComplete(false); - } - - @Override - protected IStatus validatePage(Event event) { - if (themeViewer.getSelection().isEmpty()) { - return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, - TMUIMessages.CreateThemeAssociationWizardPage_theme_error_required); - } - if (grammarViewer.getSelection().isEmpty()) { - return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, - TMUIMessages.CreateThemeAssociationWizardPage_grammar_error_required); - } - return null; - } - - public IThemeAssociation getThemeAssociation() { - String themeId = ((ITheme) themeViewer.getStructuredSelection().getFirstElement()).getId(); - String scopeName = ((IGrammarDefinition) grammarViewer.getStructuredSelection().getFirstElement()) - .getScopeName(); - boolean whenDark = whenDarkButton.getSelection(); - return new ThemeAssociation(themeId, scopeName, whenDark); - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.wizards; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.tm4e.registry.IGrammarDefinition; +import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.internal.TMUIMessages; +import org.eclipse.tm4e.ui.internal.widgets.GrammarDefinitionContentProvider; +import org.eclipse.tm4e.ui.internal.widgets.GrammarDefinitionLabelProvider; +import org.eclipse.tm4e.ui.internal.widgets.ThemeContentProvider; +import org.eclipse.tm4e.ui.internal.widgets.ThemeLabelProvider; +import org.eclipse.tm4e.ui.themes.ITheme; +import org.eclipse.tm4e.ui.themes.IThemeAssociation; +import org.eclipse.tm4e.ui.themes.ThemeAssociation; + +/** + * Wizard page to create association between grammar and theme. + * + */ +public class CreateThemeAssociationWizardPage extends AbstractWizardPage { + + private static final String PAGE_NAME = CreateThemeAssociationWizardPage.class.getName(); + + private ComboViewer themeViewer; + private ComboViewer grammarViewer; + private final IGrammarDefinition initialDefinition; + private final IThemeAssociation initialAssociation; + + private Button whenDarkButton; + + protected CreateThemeAssociationWizardPage(IGrammarDefinition initialDefinition, + IThemeAssociation initialAssociation) { + super(PAGE_NAME); + super.setTitle(TMUIMessages.CreateThemeAssociationWizardPage_title); + super.setDescription(TMUIMessages.CreateThemeAssociationWizardPage_description); + this.initialDefinition = initialDefinition; + this.initialAssociation = initialAssociation; + } + + @Override + protected void createBody(Composite ancestor) { + Composite parent = new Composite(ancestor, SWT.NONE); + parent.setFont(parent.getFont()); + parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + parent.setLayout(new GridLayout(4, false)); + + // TextMate theme + Label label = new Label(parent, SWT.NONE); + label.setText(TMUIMessages.CreateThemeAssociationWizardPage_theme_text); + themeViewer = new ComboViewer(parent); + themeViewer.setLabelProvider(new ThemeLabelProvider()); + themeViewer.setContentProvider(new ThemeContentProvider()); + themeViewer.setInput(TMUIPlugin.getThemeManager()); + themeViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + themeViewer.getControl().addListener(SWT.Selection, this); + + label = new Label(parent, SWT.NONE); + label.setText(TMUIMessages.CreateThemeAssociationWizardPage_grammar_text); + grammarViewer = new ComboViewer(parent); + grammarViewer.setLabelProvider(new GrammarDefinitionLabelProvider()); + grammarViewer.setContentProvider(new GrammarDefinitionContentProvider()); + grammarViewer.setInput(TMEclipseRegistryPlugin.getGrammarRegistryManager()); + grammarViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + grammarViewer.getControl().addListener(SWT.Selection, this); + + if (initialDefinition != null) { + grammarViewer.setSelection(new StructuredSelection(initialDefinition)); + } + + whenDarkButton = new Button(parent, SWT.CHECK); + whenDarkButton.setText(TMUIMessages.CreateThemeAssociationWizardPage_whenDark_text); + GridData data = new GridData(); + data.horizontalSpan = 4; + whenDarkButton.setLayoutData(data); + if (initialAssociation != null) { + ITheme selectedTheme = TMUIPlugin.getThemeManager().getThemeById(initialAssociation.getThemeId()); + if (selectedTheme != null) { + themeViewer.setSelection(new StructuredSelection(selectedTheme)); + } + whenDarkButton.setSelection(initialAssociation.isWhenDark()); + } + } + + @Override + protected void initializeDefaultValues() { + setPageComplete(false); + } + + @Override + protected IStatus validatePage(Event event) { + if (themeViewer.getSelection().isEmpty()) { + return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, + TMUIMessages.CreateThemeAssociationWizardPage_theme_error_required); + } + if (grammarViewer.getSelection().isEmpty()) { + return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, + TMUIMessages.CreateThemeAssociationWizardPage_grammar_error_required); + } + return null; + } + + public IThemeAssociation getThemeAssociation() { + String themeId = ((ITheme) themeViewer.getStructuredSelection().getFirstElement()).getId(); + String scopeName = ((IGrammarDefinition) grammarViewer.getStructuredSelection().getFirstElement()) + .getScopeName(); + boolean whenDark = whenDarkButton.getSelection(); + return new ThemeAssociation(themeId, scopeName, whenDark); + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java index 015e85d93..b7566ae81 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java @@ -1,156 +1,156 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.wizards; - -import java.io.File; -import java.io.FileInputStream; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.registry.Registry; -import org.eclipse.tm4e.registry.GrammarDefinition; -import org.eclipse.tm4e.registry.IGrammarDefinition; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.internal.TMUIMessages; -import org.eclipse.tm4e.ui.internal.widgets.GrammarInfoWidget; - -/** - * Wizard page to select a textMate grammar file and register it in the grammar - * registry. - * - */ -public class SelectGrammarWizardPage extends AbstractWizardPage { - - private static final String PAGE_NAME = SelectGrammarWizardPage.class.getName(); - - protected static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json"}; - - private Button browseFileSystemButton; - private Button browseWorkspaceButton; - - private Text grammarFileText; - - private GrammarInfoWidget grammarInfoWidget; - - // private ContentTypesBindingWidget contentTypesWidget; - - protected SelectGrammarWizardPage() { - super(PAGE_NAME); - super.setTitle(TMUIMessages.SelectGrammarWizardPage_title); - super.setDescription(TMUIMessages.SelectGrammarWizardPage_description); - } - - @Override - protected void createBody(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - parent.setFont(parent.getFont()); - parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - parent.setLayout(new GridLayout(2, false)); - - // Text Field - grammarFileText = createText(parent, TMUIMessages.SelectGrammarWizardPage_file_label); - grammarFileText.addListener(SWT.Modify, this); - - // Buttons - Composite buttons = new Composite(parent, SWT.NONE); - buttons.setLayout(new GridLayout(2, false)); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 2; - gd.horizontalAlignment = SWT.RIGHT; - buttons.setLayoutData(gd); - - browseFileSystemButton = new Button(buttons, SWT.NONE); - browseFileSystemButton.setText(TMUIMessages.Button_browse_FileSystem); - browseFileSystemButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(parent.getShell()); - dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); - dialog.setFilterPath(grammarFileText.getText()); - String result = dialog.open(); - if (result != null && result.length() > 0) { - grammarFileText.setText(result); - } - } - }); - - browseWorkspaceButton = new Button(buttons, SWT.NONE); - browseWorkspaceButton.setText(TMUIMessages.Button_browse_Workspace); - browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - // TODO - } - }); - - grammarInfoWidget = new GrammarInfoWidget(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - grammarInfoWidget.setLayoutData(data); - } - - private Text createText(Composite parent, String s) { - Label label = new Label(parent, SWT.NONE); - label.setText(s); - - Text text = new Text(parent, SWT.BORDER); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return text; - } - - @Override - protected void initializeDefaultValues() { - setPageComplete(false); - } - - @Override - protected IStatus validatePage(Event event) { - grammarInfoWidget.refresh(null); - String path = grammarFileText.getText(); - if (path.length() == 0) { - return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, - TMUIMessages.SelectGrammarWizardPage_file_error_required); - } - File f = new File(path); - Registry registry = new Registry(); - try { - IGrammar grammar = registry.loadGrammarFromPathSync(f.getName(), new FileInputStream(f)); - if (grammar == null || grammar.getScopeName() == null) { - return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, - TMUIMessages.SelectGrammarWizardPage_file_error_invalid); - } - grammarInfoWidget.refresh(grammar); - } catch (Exception e) { - return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, - NLS.bind(TMUIMessages.SelectGrammarWizardPage_file_error_load, e.getMessage()), e); - } - return null; - } - - public IGrammarDefinition getGrammarDefinition() { - return new GrammarDefinition(grammarInfoWidget.getScopeNameText().getText(), grammarFileText.getText()); - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.wizards; + +import java.io.File; +import java.io.FileInputStream; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.registry.Registry; +import org.eclipse.tm4e.registry.GrammarDefinition; +import org.eclipse.tm4e.registry.IGrammarDefinition; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.internal.TMUIMessages; +import org.eclipse.tm4e.ui.internal.widgets.GrammarInfoWidget; + +/** + * Wizard page to select a textMate grammar file and register it in the grammar + * registry. + * + */ +public class SelectGrammarWizardPage extends AbstractWizardPage { + + private static final String PAGE_NAME = SelectGrammarWizardPage.class.getName(); + + protected static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json"}; + + private Button browseFileSystemButton; + private Button browseWorkspaceButton; + + private Text grammarFileText; + + private GrammarInfoWidget grammarInfoWidget; + + // private ContentTypesBindingWidget contentTypesWidget; + + protected SelectGrammarWizardPage() { + super(PAGE_NAME); + super.setTitle(TMUIMessages.SelectGrammarWizardPage_title); + super.setDescription(TMUIMessages.SelectGrammarWizardPage_description); + } + + @Override + protected void createBody(Composite ancestor) { + Composite parent = new Composite(ancestor, SWT.NONE); + parent.setFont(parent.getFont()); + parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + parent.setLayout(new GridLayout(2, false)); + + // Text Field + grammarFileText = createText(parent, TMUIMessages.SelectGrammarWizardPage_file_label); + grammarFileText.addListener(SWT.Modify, this); + + // Buttons + Composite buttons = new Composite(parent, SWT.NONE); + buttons.setLayout(new GridLayout(2, false)); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + gd.horizontalAlignment = SWT.RIGHT; + buttons.setLayoutData(gd); + + browseFileSystemButton = new Button(buttons, SWT.NONE); + browseFileSystemButton.setText(TMUIMessages.Button_browse_FileSystem); + browseFileSystemButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(parent.getShell()); + dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); + dialog.setFilterPath(grammarFileText.getText()); + String result = dialog.open(); + if (result != null && result.length() > 0) { + grammarFileText.setText(result); + } + } + }); + + browseWorkspaceButton = new Button(buttons, SWT.NONE); + browseWorkspaceButton.setText(TMUIMessages.Button_browse_Workspace); + browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // TODO + } + }); + + grammarInfoWidget = new GrammarInfoWidget(parent, SWT.NONE); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + grammarInfoWidget.setLayoutData(data); + } + + private Text createText(Composite parent, String s) { + Label label = new Label(parent, SWT.NONE); + label.setText(s); + + Text text = new Text(parent, SWT.BORDER); + text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + return text; + } + + @Override + protected void initializeDefaultValues() { + setPageComplete(false); + } + + @Override + protected IStatus validatePage(Event event) { + grammarInfoWidget.refresh(null); + String path = grammarFileText.getText(); + if (path.length() == 0) { + return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, + TMUIMessages.SelectGrammarWizardPage_file_error_required); + } + File f = new File(path); + Registry registry = new Registry(); + try { + IGrammar grammar = registry.loadGrammarFromPathSync(f.getName(), new FileInputStream(f)); + if (grammar == null || grammar.getScopeName() == null) { + return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, + TMUIMessages.SelectGrammarWizardPage_file_error_invalid); + } + grammarInfoWidget.refresh(grammar); + } catch (Exception e) { + return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, + NLS.bind(TMUIMessages.SelectGrammarWizardPage_file_error_load, e.getMessage()), e); + } + return null; + } + + public IGrammarDefinition getGrammarDefinition() { + return new GrammarDefinition(grammarInfoWidget.getScopeNameText().getText(), grammarFileText.getText()); + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java index 77e20de04..379c47282 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java @@ -1,86 +1,86 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.internal.wizards; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.tm4e.registry.IGrammarDefinition; -import org.eclipse.tm4e.registry.IGrammarRegistryManager; -import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.IWorkbench; -import org.osgi.service.prefs.BackingStoreException; - -/** - * Wizard to import TextMate grammar. - * - */ -public class TextMateGrammarImportWizard extends Wizard implements IImportWizard { - - private SelectGrammarWizardPage mainPage; - - private IGrammarDefinition createdDefinition; - - private IGrammarRegistryManager grammarRegistryManager; - - private final boolean save; - - public TextMateGrammarImportWizard() { - this(true); - } - - public TextMateGrammarImportWizard(boolean save) { - this.save = save; - setGrammarRegistryManager(TMEclipseRegistryPlugin.getGrammarRegistryManager()); - } - - /** - * Set grammar registry to use to add the created grammar definitions. - * - * @param grammarRegistryManager - */ - public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { - this.grammarRegistryManager = grammarRegistryManager; - } - - @Override - public void addPages() { - mainPage = new SelectGrammarWizardPage(); - addPage(mainPage); - } - - @Override - public boolean performFinish() { - IGrammarDefinition definition = mainPage.getGrammarDefinition(); - grammarRegistryManager.registerGrammarDefinition(definition); - if (save) { - try { - grammarRegistryManager.save(); - } catch (BackingStoreException e) { - e.printStackTrace(); - return false; - } - } - createdDefinition = definition; - return true; - } - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - - } - - public IGrammarDefinition getCreatedDefinition() { - return createdDefinition; - } - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.internal.wizards; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.tm4e.registry.IGrammarDefinition; +import org.eclipse.tm4e.registry.IGrammarRegistryManager; +import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Wizard to import TextMate grammar. + * + */ +public class TextMateGrammarImportWizard extends Wizard implements IImportWizard { + + private SelectGrammarWizardPage mainPage; + + private IGrammarDefinition createdDefinition; + + private IGrammarRegistryManager grammarRegistryManager; + + private final boolean save; + + public TextMateGrammarImportWizard() { + this(true); + } + + public TextMateGrammarImportWizard(boolean save) { + this.save = save; + setGrammarRegistryManager(TMEclipseRegistryPlugin.getGrammarRegistryManager()); + } + + /** + * Set grammar registry to use to add the created grammar definitions. + * + * @param grammarRegistryManager + */ + public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { + this.grammarRegistryManager = grammarRegistryManager; + } + + @Override + public void addPages() { + mainPage = new SelectGrammarWizardPage(); + addPage(mainPage); + } + + @Override + public boolean performFinish() { + IGrammarDefinition definition = mainPage.getGrammarDefinition(); + grammarRegistryManager.registerGrammarDefinition(definition); + if (save) { + try { + grammarRegistryManager.save(); + } catch (BackingStoreException e) { + e.printStackTrace(); + return false; + } + } + createdDefinition = definition; + return true; + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + + } + + public IGrammarDefinition getCreatedDefinition() { + return createdDefinition; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMModelManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMModelManager.java index e6d8cf304..7cd48fd86 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMModelManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMModelManager.java @@ -1,37 +1,37 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.model; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.tm4e.core.model.ITMModel; - -/** - * TextMate model manager API. - * - */ -public interface ITMModelManager { - - /** - * Connect the given document to a TextMate model. - * - * @param document - * @return the TextMate model connected to the document. - */ - ITMModel connect(IDocument document); - - /** - * Disconnect the TextMate model of the given document. - * - * @param document - */ - void disconnect(IDocument document); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.model; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.tm4e.core.model.ITMModel; + +/** + * TextMate model manager API. + * + */ +public interface ITMModelManager { + + /** + * Connect the given document to a TextMate model. + * + * @param document + * @return the TextMate model connected to the document. + */ + ITMModel connect(IDocument document); + + /** + * Disconnect the TextMate model of the given document. + * + * @param document + */ + void disconnect(IDocument document); +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippet.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippet.java index ff3d82467..74f7fcba7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippet.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippet.java @@ -1,43 +1,43 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.snippets; - -import org.eclipse.tm4e.registry.ITMResource; - -/** - * - * Snippet API. - * - */ -public interface ISnippet extends ITMResource { - - /** - * Returns the name of the snippet. - * - * @return the name of the snippet. - */ - String getName(); - - /** - * Returns the scope name of the snippet. - * - * @return the scope name of the snippet. - */ - String getScopeName(); - - /** - * Returns the content of the snippet. - * - * @return the content of the snippet. - */ - String getContent(); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.snippets; + +import org.eclipse.tm4e.registry.ITMResource; + +/** + * + * Snippet API. + * + */ +public interface ISnippet extends ITMResource { + + /** + * Returns the name of the snippet. + * + * @return the name of the snippet. + */ + String getName(); + + /** + * Returns the scope name of the snippet. + * + * @return the scope name of the snippet. + */ + String getScopeName(); + + /** + * Returns the content of the snippet. + * + * @return the content of the snippet. + */ + String getContent(); +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippetManager.java index 8c0712bb9..00b331e22 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippetManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/ISnippetManager.java @@ -1,27 +1,27 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.snippets; - -/** - * Snippet manager API. - * - */ -public interface ISnippetManager { - - /** - * Returns list of snippet for a given scope name and empty otherwise. - * - * @param scopeName - * @return list of snippet for a given scope name and empty otherwise. - */ - ISnippet[] getSnippets(String scopeName); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.snippets; + +/** + * Snippet manager API. + * + */ +public interface ISnippetManager { + + /** + * Returns list of snippet for a given scope name and empty otherwise. + * + * @param scopeName + * @return list of snippet for a given scope name and empty otherwise. + */ + ISnippet[] getSnippets(String scopeName); +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java index 29b976c8c..9e41d55f3 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java @@ -1,46 +1,46 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.text; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextPresentation; - -/** - * TextMate presentation reconciler listener. - * - */ -public interface ITMPresentationReconcilerListener { - - /** - * Install the given viewer and document. - * - * @param viewer - * @param document - */ - void install(ITextViewer viewer, IDocument document); - - /** - * Uninstall. - */ - void uninstall(); - - /** - * Colorize the StyledText with the given text presentation. - * - * @param presentation - * the text presentation. - * @param error - * when there are error. - */ - void colorize(TextPresentation presentation, Throwable error); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.text; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.TextPresentation; + +/** + * TextMate presentation reconciler listener. + * + */ +public interface ITMPresentationReconcilerListener { + + /** + * Install the given viewer and document. + * + * @param viewer + * @param document + */ + void install(ITextViewer viewer, IDocument document); + + /** + * Uninstall. + */ + void uninstall(); + + /** + * Colorize the StyledText with the given text presentation. + * + * @param presentation + * the text presentation. + * @param error + * when there are error. + */ + void colorize(TextPresentation presentation, Throwable error); +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index 93248095f..acb1e378a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -1,856 +1,856 @@ -/** - * Copyright (c) 2015-2019 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #220 Switch to theme only works once for open editor - * IBM Corporation Gerald Mitchell - bug fix - */ -package org.eclipse.tm4e.ui.text; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; -import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.CursorLinePainter; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IPainter; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITextViewerExtension5; -import org.eclipse.jface.text.PaintManager; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.TextViewer; -import org.eclipse.jface.text.presentation.IPresentationDamager; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.IPresentationRepairer; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Control; -import org.eclipse.tm4e.core.TMException; -import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.model.IModelTokensChangedListener; -import org.eclipse.tm4e.core.model.ITMModel; -import org.eclipse.tm4e.core.model.ModelTokensChangedEvent; -import org.eclipse.tm4e.core.model.Range; -import org.eclipse.tm4e.core.model.TMToken; -import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.internal.model.TMDocumentModel; -import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; -import org.eclipse.tm4e.ui.internal.text.TMPresentationReconcilerTestGenerator; -import org.eclipse.tm4e.ui.internal.themes.ThemeManager; -import org.eclipse.tm4e.ui.model.ITMModelManager; -import org.eclipse.tm4e.ui.themes.ITheme; -import org.eclipse.tm4e.ui.themes.IThemeManager; -import org.eclipse.tm4e.ui.themes.ITokenProvider; -import org.eclipse.tm4e.ui.utils.ClassHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeInfo; -import org.eclipse.tm4e.ui.utils.PreferenceUtils; -import org.eclipse.ui.IEditorPart; - -/** - * TextMate presentation reconciler which must be initialized with: - * - *
    - *
  • a TextMate grammar {@link IGrammar} used to initialize the TextMate model - * {@link TMDocumentModel}.
  • - *
  • a token provider {@link ITokenProvider} to retrieve the {@link IToken} - * from a TextMate token type .
  • - *
- * - */ -public class TMPresentationReconciler implements IPresentationReconciler { - - /** - * The default text attribute if non is returned as data by the current token - */ - private final Token defaultToken; - - /** The target viewer. */ - private ITextViewer viewer; - /** The internal listener. */ - private final InternalListener internalListener; - - private IGrammar grammar; - private boolean forcedGrammar; - - private ITokenProvider tokenProvider; - - private final TextAttribute fDefaultTextAttribute; - - private IPreferenceChangeListener themeChangeListener; - - private List listeners; - - private boolean initializeViewerColors; - - private boolean updateTextDecorations; - - /** - * true if the presentation reconciler is enabled (grammar and theme are - * available) and false otherwise. - */ - private boolean enabled; - - /** - * true if a {@link TMException} should be thrown if grammar or theme cannot be - * found and false otherwise. - */ - private boolean throwError; - - public TMPresentationReconciler() { - this.defaultToken = new Token(null); - this.internalListener = new InternalListener(); - this.fDefaultTextAttribute = new TextAttribute(null); - listeners = null; - if (TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/GenerateTest")) { - addTMPresentationReconcilerListener(new TMPresentationReconcilerTestGenerator()); - } - setThrowError(TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/ThrowError")); - } - - /** - * Listener to recolorize editors when E4 Theme from General / Appearance - * preferences changed or TextMate theme changed.. - * - */ - private class ThemeChangeListener implements IPreferenceChangeListener { - - @Override - public void preferenceChange(PreferenceChangeEvent event) { - IThemeManager themeManager = TMUIPlugin.getThemeManager(); - if (PreferenceConstants.E4_THEME_ID.equals(event.getKey())) { - preferenceThemeChange((String) event.getNewValue(), themeManager); - } else if (PreferenceConstants.THEME_ASSOCIATIONS.equals(event.getKey())) { - preferenceThemeChange(PreferenceUtils.getE4PreferenceCSSThemeId(), themeManager); - } - } - - private void preferenceThemeChange(String eclipseThemeId, IThemeManager themeManager) { - IDocument document = viewer.getDocument(); - if (document == null) { - return; - } - if (grammar == null) { - return; - } - // Select the well TextMate theme from the given E4 theme id. - boolean dark = themeManager.isDarkEclipseTheme(eclipseThemeId); - ITokenProvider newTheme = themeManager.getThemeForScope(grammar.getScopeName(), dark); - setTheme(newTheme); - } - } - - /** - * Internal listener class. - */ - class InternalListener implements ITextInputListener, IModelTokensChangedListener, ITextListener { - - private void fireInstall(ITextViewer viewer, IDocument document) { - if (listeners == null) { - return; - } - synchronized (listeners) { - for (ITMPresentationReconcilerListener listener : listeners) { - listener.install(viewer, document); - } - } - } - - private void fireUninstall() { - if (listeners == null) { - return; - } - synchronized (listeners) { - for (ITMPresentationReconcilerListener listener : listeners) { - listener.uninstall(); - } - } - } - - @Override - public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDocument) { - if (oldDocument != null) { - viewer.removeTextListener(this); - getTMModelManager().disconnect(oldDocument); - fireUninstall(); - } - } - - @Override - public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { - if (newDocument == null) { - return; - } - fireInstall(viewer, newDocument); - try { - viewer.addTextListener(this); - // Update the grammar - IGrammar localGrammar = findGrammar(newDocument); - - if (localGrammar != null) { - TMPresentationReconciler.this.grammar = localGrammar; - } else if (isThrowError()) { - throw new TMException("Cannot find TextMate grammar for the given document"); - } - - // Update the theme - if (localGrammar != null) { - String scopeName = localGrammar.getScopeName(); - if (tokenProvider == null) { - tokenProvider = TMUIPlugin.getThemeManager().getThemeForScope(scopeName, viewer.getTextWidget().getBackground().getRGB()); - } - if (tokenProvider != null) { - applyThemeEditor(); - } else if (isThrowError()) { - throw new TMException("Cannot find Theme for the given grammar '" + scopeName + "'"); - } - } - - boolean enable = TMPresentationReconciler.this.enabled = localGrammar != null && tokenProvider != null; - if (enable) { - // Connect a TextModel to the new document. - ITMModel model = getTMModelManager().connect(newDocument); - model.setGrammar(localGrammar); - - // Add model listener - model.addModelTokensChangedListener(this); - } - } catch (CoreException e) { - Platform.getLog(Platform.getBundle(TMEclipseRegistryPlugin.PLUGIN_ID)).log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, "Error while initializing TextMate model.", e)); - } - } - - /** - * Finds a grammar for the given document. - * @param newDocument - * @return - * @throws CoreException - */ - protected IGrammar findGrammar(@NonNull IDocument newDocument) throws CoreException { - IGrammar localGrammar = forcedGrammar ? TMPresentationReconciler.this.grammar : null; - if (localGrammar != null) { - return localGrammar; - } - ContentTypeInfo info = ContentTypeHelper.findContentTypes(newDocument); - if (info == null) { - return null; - } - return findGrammar(info); - } - - @Override - public void textChanged(TextEvent e) { - if (!e.getViewerRedrawState()) { - return; - } - // changed text: propagate previous style, which will be overridden - // later asynchronously by TM - if (e.getDocumentEvent() != null) { - int diff = e.getText().length() - e.getLength(); - if (diff == 0 || e.getOffset() <= 0) { - return; - } - StyleRange range = viewer.getTextWidget().getStyleRangeAtOffset(e.getOffset() - 1); - if (range == null) { - return; - } - range.length = Math.max(0, range.length + diff); - viewer.getTextWidget().setStyleRange(range); - return; - } - - // TextViewer#invalidateTextPresentation is called (because - // of validation, folding, etc) - // case 2), do the colorization. - IDocument document = viewer.getDocument(); - if (document == null) { - return; - } - IRegion region = computeRegionToRedraw(e, document); - if (enabled) { - // case where there is grammar & theme -> update text presentation with the - // grammar tokens - ITMModel model = getTMModelManager().connect(document); - if (model == null) { - return; - } - try { - TMPresentationReconciler.this.colorize(region, (TMDocumentModel) model); - } catch (BadLocationException e1) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e1.getMessage(), e1)); - } - } else { - // case where there is no grammar & theme -> update text presentation with the - // default styles (ex: to support highlighting with GenericEditor) - TextPresentation presentation = new TextPresentation(region, 100); - presentation.setDefaultStyleRange( - new StyleRange(region.getOffset(), region.getLength(), null, null)); - applyTextRegionCollection(presentation); - } - } - - protected @NonNull IRegion computeRegionToRedraw(@NonNull TextEvent e, @NonNull IDocument document) { - IRegion region = null; - if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) { - // redraw state change, damage the whole document - region = new Region(0, document.getLength()); - } else { - region = widgetRegion2ModelRegion(e); - } - if (region == null || region.getLength() == 0) { - return new Region(0, 0); - } - return region; - } - - /** - * Translates the given text event into the corresponding range of the viewer's - * document. - * - * @param e - * the text event - * @return the widget region corresponding the region of the given event or - * null if none - * @since 2.1 - */ - private IRegion widgetRegion2ModelRegion(TextEvent e) { - String text = e.getText(); - int length = text == null ? 0 : text.length(); - if (viewer instanceof ITextViewerExtension5) { - ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; - return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); - } - IRegion visible = viewer.getVisibleRegion(); - return new Region(e.getOffset() + visible.getOffset(), length); - } - - @Override - public void modelTokensChanged(ModelTokensChangedEvent event) { - Control control = viewer.getTextWidget(); - if (control != null) { - control.getDisplay().asyncExec(() -> { - if (viewer != null) { - colorize(event); - } - }); - } - } - - private void colorize(ModelTokensChangedEvent event) { - IDocument document = viewer.getDocument(); - if (document == null) { - return; - } - ITMModel model = event.model; - if (! (model instanceof TMDocumentModel)) { - return; - } - TMDocumentModel docModel = (TMDocumentModel) model; - for (Range range : event.ranges) { - try { - int length = document.getLineOffset(range.toLineNumber - 1) + document.getLineLength(range.toLineNumber - 1) - document.getLineOffset(range.fromLineNumber - 1); - IRegion region = new Region(document.getLineOffset(range.fromLineNumber -1), length); - TMPresentationReconciler.this.colorize(region, docModel); - } catch (BadLocationException ex) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); - } - } - } - - private IGrammar findGrammar(ContentTypeInfo info) { - if (info == null) { - return null; - } - IContentType[] contentTypes = info.getContentTypes(); - // Discover the well grammar from the contentTypes - IGrammar res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); - if (res == null) { - // Discover the well grammar from the filetype - String fileName = info.getFileName(); - if (fileName != null) { - String fileType = new Path(fileName).getFileExtension(); - res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarForFileType(fileType); - } - } - return res; - } - } - - public void setGrammar(IGrammar grammar) { - boolean changed = (viewer != null && ((this.grammar == null) || !this.grammar.equals(grammar))); - this.grammar = grammar; - this.forcedGrammar = true; - if (changed) { - // Grammar has changed, recreate the TextMate model - IDocument document = viewer.getDocument(); - if (document == null) { - return; - } - internalListener.inputDocumentAboutToBeChanged(viewer.getDocument(), null); - internalListener.inputDocumentChanged(null, document); - } - } - - public IGrammar getGrammar() { - return grammar; - } - - public ITokenProvider getTokenProvider() { - return tokenProvider; - } - - public void setTheme(final ITokenProvider newTheme) { - final ITokenProvider oldTheme = this.tokenProvider; - if (!Objects.equals(oldTheme, newTheme) && grammar != null) { - this.tokenProvider = newTheme; - applyThemeEditor(); - IDocument document = viewer.getDocument(); - ITMModel model = getTMModelManager().connect(document); - if (! (model instanceof TMDocumentModel)) { - return; - } - TMDocumentModel docModel = (TMDocumentModel) model; - try { - colorize(new Region(0, document.getLength()), docModel); - } catch (BadLocationException e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); - } - } - } - - @Override - public void install(ITextViewer viewer) { - Assert.isNotNull(viewer); - - this.viewer = viewer; - viewer.addTextInputListener(internalListener); - - IDocument document = viewer.getDocument(); - if (document != null) { - internalListener.inputDocumentChanged(null, document); - } - themeChangeListener = new ThemeChangeListener(); - ThemeManager.getInstance().addPreferenceChangeListener(themeChangeListener); - } - - @Override - public void uninstall() { - viewer.removeTextInputListener(internalListener); - // Ensure we uninstall all listeners - internalListener.inputDocumentAboutToBeChanged(viewer.getDocument(), null); - if (themeChangeListener != null) { - ThemeManager.getInstance().removePreferenceChangeListener(themeChangeListener); - } - themeChangeListener = null; - } - - @Override - public IPresentationDamager getDamager(String contentType) { - return null; - } - - @Override - public IPresentationRepairer getRepairer(String contentType) { - return null; - } - - private ITMModelManager getTMModelManager() { - return TMUIPlugin.getTMModelManager(); - } - - void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws BadLocationException{ - IDocument document = model.getDocument(); - final int fromLineNumber = document.getLineOfOffset(damage.getOffset()); - final int toLineNumber = document.getLineOfOffset(damage.getOffset() + damage.getLength()); - applyThemeEditorIfNeeded(); - // Refresh the UI Presentation - TMUIPlugin.getDefault().trace("Render from: " + fromLineNumber + " to: " + toLineNumber); - TextPresentation presentation = null; - Throwable error = null; - try { - presentation = new TextPresentation(damage, 1000); - - int lastStart = presentation.getExtent().getOffset(); - int length = 0; - boolean firstToken = true; - IToken lastToken = Token.UNDEFINED; - TextAttribute lastAttribute = getTokenTextAttribute(lastToken); - - List tokens = null; - for (int line = fromLineNumber; line <= toLineNumber; line++) { - tokens = model.getLineTokens(line); - if (tokens == null) { - // TextMate tokens was not computed for this line. - // This case comes from when the viewer is invalidated (by - // validation for instance) and textChanged is called. - // see https://github.com/eclipse/tm4e/issues/78 - TMUIPlugin.getDefault().trace("TextMate tokens not available for line " + line); - break; - } - int startLineOffset = document.getLineOffset(line); - for (int i = 0; i < tokens.size(); i++) { - TMToken currentToken = tokens.get(i); - TMToken nextToken = (i + 1 < tokens.size()) ? tokens.get(i + 1) : null; - int tokenStartIndex = currentToken.startIndex; - - if (isBeforeRegion(currentToken, startLineOffset, damage)) { - // The token is before the damage region - if (nextToken != null) { - if (isBeforeRegion(nextToken, startLineOffset, damage)) { - // ignore it - continue; - } else { - tokenStartIndex = damage.getOffset() - startLineOffset; - } - } else { - tokenStartIndex = damage.getOffset() - startLineOffset; - IToken token = toToken(currentToken); - lastAttribute = getTokenTextAttribute(token); - length += getTokenLengh(tokenStartIndex, nextToken, line, document); - firstToken = false; - // ignore it - continue; - } - } else if (isAfterRegion(currentToken, startLineOffset, damage)) { - // The token is after the damage region, stop the - // colorization process - break; - } - - IToken token = toToken(currentToken); - TextAttribute attribute = getTokenTextAttribute(token); - if (lastAttribute != null && lastAttribute.equals(attribute)) { - length += getTokenLengh(tokenStartIndex, nextToken, line, document); - firstToken = false; - } else { - if (!firstToken) { - addRange(presentation, lastStart, length, lastAttribute); - } - firstToken = false; - lastToken = token; - lastAttribute = attribute; - lastStart = tokenStartIndex + startLineOffset; - length = getTokenLengh(tokenStartIndex, nextToken, line, document); - } - } - } - // adjust the length - length = Math.min(length, damage.getOffset() + damage.getLength() - lastStart); - addRange(presentation, lastStart, length, lastAttribute); - applyTextRegionCollection(presentation); - } catch (Exception e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); - } finally { - fireColorize(presentation, error); - } - } - - /** - * Return true if the given token is before the given region and false - * otherwise. - * - * @param token - * @param startLineOffset - * @param damage - * @return - */ - private boolean isBeforeRegion(TMToken token, int startLineOffset, IRegion damage) { - return token.startIndex + startLineOffset < damage.getOffset(); - } - - /** - * Return true if the given token is after the given region and false otherwise. - * - * @param t - * @param startLineOffset - * @param damage - * @return - */ - private boolean isAfterRegion(TMToken t, int startLineOffset, IRegion damage) { - return t.startIndex + startLineOffset >= damage.getOffset() + damage.getLength(); - } - - private IToken toToken(TMToken t) { - IToken token = getTokenProvider().getToken(t.type); - if (token != null) { - return token; - } - return defaultToken; - } - - private int getTokenLengh(int tokenStartIndex, TMToken nextToken, int line, IDocument document) - throws BadLocationException { - if (nextToken != null) { - return nextToken.startIndex - tokenStartIndex; - } - return document.getLineLength(line) - tokenStartIndex; - } - - /** - * Returns a text attribute encoded in the given token. If the token's data is - * not null and a text attribute it is assumed that it is the - * encoded text attribute. It returns the default text attribute if there is no - * encoded text attribute found. - * - * @param token - * the token whose text attribute is to be determined - * @return the token's text attribute - */ - protected TextAttribute getTokenTextAttribute(IToken token) { - Object data = token.getData(); - if (data instanceof TextAttribute) { - return (TextAttribute) data; - } - return fDefaultTextAttribute; - } - - /** - * Adds style information to the given text presentation. - * - * @param presentation - * the text presentation to be extended - * @param offset - * the offset of the range to be styled - * @param length - * the length of the range to be styled - * @param attr - * the attribute describing the style of the range to be styled - * @param lastLineStyleRanges - */ - protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { - if (attr != null) { - int style = attr.getStyle(); - int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); - StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), - fontStyle); - styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0; - styleRange.underline = (style & TextAttribute.UNDERLINE) != 0; - styleRange.font = attr.getFont(); - presentation.addStyleRange(styleRange); - } - } - - /** - * Applies the given text presentation to the text viewer the presentation - * reconciler is installed on. - * - * @param presentation - * the text presentation to be applied to the text viewer - */ - private void applyTextRegionCollection(TextPresentation presentation) { - viewer.changeTextPresentation(presentation, false); - } - - /** - * Add a TextMate presentation reconciler listener. - * - * @param listener - * the TextMate presentation reconciler listener to add. - */ - public void addTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { - if (listeners == null) { - listeners = new ArrayList<>(); - } - synchronized (listeners) { - if (!listeners.contains(listener)) { - listeners.add(listener); - } - } - } - - /** - * Remove a TextMate presentation reconciler listener. - * - * @param listener - * the TextMate presentation reconciler listener to remove. - */ - public void removeTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { - if (listeners == null) { - return; - } - synchronized (listeners) { - listeners.remove(listener); - } - } - - /** - * Fire colorize. - * - * @param presentation - * @param error - */ - private void fireColorize(TextPresentation presentation, Throwable error) { - if (listeners == null) { - return; - } - synchronized (listeners) { - for (ITMPresentationReconcilerListener listener : listeners) { - listener.colorize(presentation, error); - } - } - } - - public static TMPresentationReconciler getTMPresentationReconciler(IEditorPart editorPart) { - if (editorPart == null) { - return null; - } - @Nullable ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); - if (target instanceof ITextViewer) { - ITextViewer textViewer = ((ITextViewer) target); - return TMPresentationReconciler.getTMPresentationReconciler(textViewer); - } - return null; - } - - /** - * Returns the {@link TMPresentationReconciler} of the given text viewer and - * null otherwise. - * - * @param textViewer - * @return the {@link TMPresentationReconciler} of the given text viewer and - * null otherwise. - */ - public static TMPresentationReconciler getTMPresentationReconciler(ITextViewer textViewer) { - try { - Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); - if (field != null) { - field.setAccessible(true); - Object presentationReconciler = field.get(textViewer); - //field is IPresentationRecounciler, looking for TMPresentationReconciler implementation - return presentationReconciler instanceof TMPresentationReconciler - ? (TMPresentationReconciler) presentationReconciler - : null; - } - } catch (SecurityException | NoSuchFieldException e) { - // if SourceViewer class no longer has fPresentationReconciler or changes access level - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); - } catch (IllegalArgumentException | IllegalAccessException | NullPointerException | ExceptionInInitializerError iae) { - //This should not be logged as an error. This is an expected possible outcome of field.get(textViewer). - //The method assumes ITextViewer is actually ISourceViewer, and specifically the SourceViewer implementation - // that was available at the current build. This code also works with any implementation that follows the - // internal structure if also an ITextViewer. - //If these assumptions are false, the method should return null. Logging causes repeat noise. - } - return null; - } - - /** - * Initialize foreground, background color, current line highlight from the - * current theme. - * - */ - private void applyThemeEditor() { - this.initializeViewerColors = false; - this.updateTextDecorations = false; - applyThemeEditorIfNeeded(); - } - - /** - * Initialize foreground, background color, current line highlight from the - * current theme if needed. - * - */ - private void applyThemeEditorIfNeeded() { - if (!initializeViewerColors) { - StyledText styledText = viewer.getTextWidget(); - ((ITheme) tokenProvider).initializeViewerColors(styledText); - initializeViewerColors = true; - } - if (updateTextDecorations) { - return; - } - try { - // Ugly code to update "current line highlight" : - // - get the PaintManager from the ITextViewer with reflection. - // - get the list of IPainter of PaintManager with reflection - // - loop for IPainter to retrieve CursorLinePainter which manages "current line - // highlight". - PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class); - if (paintManager == null) { - return; - } - List painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class); - if (painters == null) { - return; - } - for (IPainter painter : painters) { - if (painter instanceof CursorLinePainter) { - // Update current line highlight - Color background = tokenProvider.getEditorCurrentLineHighlight(); - if (background != null) { - ((CursorLinePainter) painter).setHighlightColor(background); - } - updateTextDecorations = true; - } - } - } catch (Exception e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); - } - } - - /** - * Set true if a {@link TMException} should be thrown if grammar or theme cannot - * be found and false otherwise. - * - * @param throwError - */ - public void setThrowError(boolean throwError) { - this.throwError = throwError; - } - - /** - * Return true if a {@link TMException} should be thrown if grammar or theme - * cannot be found and false otherwise. - * - * @return true if a {@link TMException} should be thrown if grammar or theme - * cannot be found and false otherwise. - */ - public boolean isThrowError() { - return throwError; - } - - /** - * Returns true if the presentation reconciler is enabled (grammar and theme are - * available) and false otherwise. - * - * @return true if the presentation reconciler is enabled (grammar and theme are - * available) and false otherwise. - */ - - public boolean isEnabled() { - return enabled; - } - -} +/** + * Copyright (c) 2015-2019 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #220 Switch to theme only works once for open editor + * IBM Corporation Gerald Mitchell - bug fix + */ +package org.eclipse.tm4e.ui.text; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.CursorLinePainter; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IPainter; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextInputListener; +import org.eclipse.jface.text.ITextListener; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.ITextViewerExtension5; +import org.eclipse.jface.text.PaintManager; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.TextEvent; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.jface.text.presentation.IPresentationDamager; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.IPresentationRepairer; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Control; +import org.eclipse.tm4e.core.TMException; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.model.IModelTokensChangedListener; +import org.eclipse.tm4e.core.model.ITMModel; +import org.eclipse.tm4e.core.model.ModelTokensChangedEvent; +import org.eclipse.tm4e.core.model.Range; +import org.eclipse.tm4e.core.model.TMToken; +import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.internal.model.TMDocumentModel; +import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; +import org.eclipse.tm4e.ui.internal.text.TMPresentationReconcilerTestGenerator; +import org.eclipse.tm4e.ui.internal.themes.ThemeManager; +import org.eclipse.tm4e.ui.model.ITMModelManager; +import org.eclipse.tm4e.ui.themes.ITheme; +import org.eclipse.tm4e.ui.themes.IThemeManager; +import org.eclipse.tm4e.ui.themes.ITokenProvider; +import org.eclipse.tm4e.ui.utils.ClassHelper; +import org.eclipse.tm4e.ui.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.utils.ContentTypeInfo; +import org.eclipse.tm4e.ui.utils.PreferenceUtils; +import org.eclipse.ui.IEditorPart; + +/** + * TextMate presentation reconciler which must be initialized with: + * + *
    + *
  • a TextMate grammar {@link IGrammar} used to initialize the TextMate model + * {@link TMDocumentModel}.
  • + *
  • a token provider {@link ITokenProvider} to retrieve the {@link IToken} + * from a TextMate token type .
  • + *
+ * + */ +public class TMPresentationReconciler implements IPresentationReconciler { + + /** + * The default text attribute if non is returned as data by the current token + */ + private final Token defaultToken; + + /** The target viewer. */ + private ITextViewer viewer; + /** The internal listener. */ + private final InternalListener internalListener; + + private IGrammar grammar; + private boolean forcedGrammar; + + private ITokenProvider tokenProvider; + + private final TextAttribute fDefaultTextAttribute; + + private IPreferenceChangeListener themeChangeListener; + + private List listeners; + + private boolean initializeViewerColors; + + private boolean updateTextDecorations; + + /** + * true if the presentation reconciler is enabled (grammar and theme are + * available) and false otherwise. + */ + private boolean enabled; + + /** + * true if a {@link TMException} should be thrown if grammar or theme cannot be + * found and false otherwise. + */ + private boolean throwError; + + public TMPresentationReconciler() { + this.defaultToken = new Token(null); + this.internalListener = new InternalListener(); + this.fDefaultTextAttribute = new TextAttribute(null); + listeners = null; + if (TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/GenerateTest")) { + addTMPresentationReconcilerListener(new TMPresentationReconcilerTestGenerator()); + } + setThrowError(TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/ThrowError")); + } + + /** + * Listener to recolorize editors when E4 Theme from General / Appearance + * preferences changed or TextMate theme changed.. + * + */ + private class ThemeChangeListener implements IPreferenceChangeListener { + + @Override + public void preferenceChange(PreferenceChangeEvent event) { + IThemeManager themeManager = TMUIPlugin.getThemeManager(); + if (PreferenceConstants.E4_THEME_ID.equals(event.getKey())) { + preferenceThemeChange((String) event.getNewValue(), themeManager); + } else if (PreferenceConstants.THEME_ASSOCIATIONS.equals(event.getKey())) { + preferenceThemeChange(PreferenceUtils.getE4PreferenceCSSThemeId(), themeManager); + } + } + + private void preferenceThemeChange(String eclipseThemeId, IThemeManager themeManager) { + IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + if (grammar == null) { + return; + } + // Select the well TextMate theme from the given E4 theme id. + boolean dark = themeManager.isDarkEclipseTheme(eclipseThemeId); + ITokenProvider newTheme = themeManager.getThemeForScope(grammar.getScopeName(), dark); + setTheme(newTheme); + } + } + + /** + * Internal listener class. + */ + class InternalListener implements ITextInputListener, IModelTokensChangedListener, ITextListener { + + private void fireInstall(ITextViewer viewer, IDocument document) { + if (listeners == null) { + return; + } + synchronized (listeners) { + for (ITMPresentationReconcilerListener listener : listeners) { + listener.install(viewer, document); + } + } + } + + private void fireUninstall() { + if (listeners == null) { + return; + } + synchronized (listeners) { + for (ITMPresentationReconcilerListener listener : listeners) { + listener.uninstall(); + } + } + } + + @Override + public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDocument) { + if (oldDocument != null) { + viewer.removeTextListener(this); + getTMModelManager().disconnect(oldDocument); + fireUninstall(); + } + } + + @Override + public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { + if (newDocument == null) { + return; + } + fireInstall(viewer, newDocument); + try { + viewer.addTextListener(this); + // Update the grammar + IGrammar localGrammar = findGrammar(newDocument); + + if (localGrammar != null) { + TMPresentationReconciler.this.grammar = localGrammar; + } else if (isThrowError()) { + throw new TMException("Cannot find TextMate grammar for the given document"); + } + + // Update the theme + if (localGrammar != null) { + String scopeName = localGrammar.getScopeName(); + if (tokenProvider == null) { + tokenProvider = TMUIPlugin.getThemeManager().getThemeForScope(scopeName, viewer.getTextWidget().getBackground().getRGB()); + } + if (tokenProvider != null) { + applyThemeEditor(); + } else if (isThrowError()) { + throw new TMException("Cannot find Theme for the given grammar '" + scopeName + "'"); + } + } + + boolean enable = TMPresentationReconciler.this.enabled = localGrammar != null && tokenProvider != null; + if (enable) { + // Connect a TextModel to the new document. + ITMModel model = getTMModelManager().connect(newDocument); + model.setGrammar(localGrammar); + + // Add model listener + model.addModelTokensChangedListener(this); + } + } catch (CoreException e) { + Platform.getLog(Platform.getBundle(TMEclipseRegistryPlugin.PLUGIN_ID)).log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, "Error while initializing TextMate model.", e)); + } + } + + /** + * Finds a grammar for the given document. + * @param newDocument + * @return + * @throws CoreException + */ + protected IGrammar findGrammar(@NonNull IDocument newDocument) throws CoreException { + IGrammar localGrammar = forcedGrammar ? TMPresentationReconciler.this.grammar : null; + if (localGrammar != null) { + return localGrammar; + } + ContentTypeInfo info = ContentTypeHelper.findContentTypes(newDocument); + if (info == null) { + return null; + } + return findGrammar(info); + } + + @Override + public void textChanged(TextEvent e) { + if (!e.getViewerRedrawState()) { + return; + } + // changed text: propagate previous style, which will be overridden + // later asynchronously by TM + if (e.getDocumentEvent() != null) { + int diff = e.getText().length() - e.getLength(); + if (diff == 0 || e.getOffset() <= 0) { + return; + } + StyleRange range = viewer.getTextWidget().getStyleRangeAtOffset(e.getOffset() - 1); + if (range == null) { + return; + } + range.length = Math.max(0, range.length + diff); + viewer.getTextWidget().setStyleRange(range); + return; + } + + // TextViewer#invalidateTextPresentation is called (because + // of validation, folding, etc) + // case 2), do the colorization. + IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + IRegion region = computeRegionToRedraw(e, document); + if (enabled) { + // case where there is grammar & theme -> update text presentation with the + // grammar tokens + ITMModel model = getTMModelManager().connect(document); + if (model == null) { + return; + } + try { + TMPresentationReconciler.this.colorize(region, (TMDocumentModel) model); + } catch (BadLocationException e1) { + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e1.getMessage(), e1)); + } + } else { + // case where there is no grammar & theme -> update text presentation with the + // default styles (ex: to support highlighting with GenericEditor) + TextPresentation presentation = new TextPresentation(region, 100); + presentation.setDefaultStyleRange( + new StyleRange(region.getOffset(), region.getLength(), null, null)); + applyTextRegionCollection(presentation); + } + } + + protected @NonNull IRegion computeRegionToRedraw(@NonNull TextEvent e, @NonNull IDocument document) { + IRegion region = null; + if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) { + // redraw state change, damage the whole document + region = new Region(0, document.getLength()); + } else { + region = widgetRegion2ModelRegion(e); + } + if (region == null || region.getLength() == 0) { + return new Region(0, 0); + } + return region; + } + + /** + * Translates the given text event into the corresponding range of the viewer's + * document. + * + * @param e + * the text event + * @return the widget region corresponding the region of the given event or + * null if none + * @since 2.1 + */ + private IRegion widgetRegion2ModelRegion(TextEvent e) { + String text = e.getText(); + int length = text == null ? 0 : text.length(); + if (viewer instanceof ITextViewerExtension5) { + ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; + return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); + } + IRegion visible = viewer.getVisibleRegion(); + return new Region(e.getOffset() + visible.getOffset(), length); + } + + @Override + public void modelTokensChanged(ModelTokensChangedEvent event) { + Control control = viewer.getTextWidget(); + if (control != null) { + control.getDisplay().asyncExec(() -> { + if (viewer != null) { + colorize(event); + } + }); + } + } + + private void colorize(ModelTokensChangedEvent event) { + IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + ITMModel model = event.model; + if (! (model instanceof TMDocumentModel)) { + return; + } + TMDocumentModel docModel = (TMDocumentModel) model; + for (Range range : event.ranges) { + try { + int length = document.getLineOffset(range.toLineNumber - 1) + document.getLineLength(range.toLineNumber - 1) - document.getLineOffset(range.fromLineNumber - 1); + IRegion region = new Region(document.getLineOffset(range.fromLineNumber -1), length); + TMPresentationReconciler.this.colorize(region, docModel); + } catch (BadLocationException ex) { + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + } + } + } + + private IGrammar findGrammar(ContentTypeInfo info) { + if (info == null) { + return null; + } + IContentType[] contentTypes = info.getContentTypes(); + // Discover the well grammar from the contentTypes + IGrammar res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); + if (res == null) { + // Discover the well grammar from the filetype + String fileName = info.getFileName(); + if (fileName != null) { + String fileType = new Path(fileName).getFileExtension(); + res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarForFileType(fileType); + } + } + return res; + } + } + + public void setGrammar(IGrammar grammar) { + boolean changed = (viewer != null && ((this.grammar == null) || !this.grammar.equals(grammar))); + this.grammar = grammar; + this.forcedGrammar = true; + if (changed) { + // Grammar has changed, recreate the TextMate model + IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + internalListener.inputDocumentAboutToBeChanged(viewer.getDocument(), null); + internalListener.inputDocumentChanged(null, document); + } + } + + public IGrammar getGrammar() { + return grammar; + } + + public ITokenProvider getTokenProvider() { + return tokenProvider; + } + + public void setTheme(final ITokenProvider newTheme) { + final ITokenProvider oldTheme = this.tokenProvider; + if (!Objects.equals(oldTheme, newTheme) && grammar != null) { + this.tokenProvider = newTheme; + applyThemeEditor(); + IDocument document = viewer.getDocument(); + ITMModel model = getTMModelManager().connect(document); + if (! (model instanceof TMDocumentModel)) { + return; + } + TMDocumentModel docModel = (TMDocumentModel) model; + try { + colorize(new Region(0, document.getLength()), docModel); + } catch (BadLocationException e) { + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } + } + } + + @Override + public void install(ITextViewer viewer) { + Assert.isNotNull(viewer); + + this.viewer = viewer; + viewer.addTextInputListener(internalListener); + + IDocument document = viewer.getDocument(); + if (document != null) { + internalListener.inputDocumentChanged(null, document); + } + themeChangeListener = new ThemeChangeListener(); + ThemeManager.getInstance().addPreferenceChangeListener(themeChangeListener); + } + + @Override + public void uninstall() { + viewer.removeTextInputListener(internalListener); + // Ensure we uninstall all listeners + internalListener.inputDocumentAboutToBeChanged(viewer.getDocument(), null); + if (themeChangeListener != null) { + ThemeManager.getInstance().removePreferenceChangeListener(themeChangeListener); + } + themeChangeListener = null; + } + + @Override + public IPresentationDamager getDamager(String contentType) { + return null; + } + + @Override + public IPresentationRepairer getRepairer(String contentType) { + return null; + } + + private ITMModelManager getTMModelManager() { + return TMUIPlugin.getTMModelManager(); + } + + void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws BadLocationException{ + IDocument document = model.getDocument(); + final int fromLineNumber = document.getLineOfOffset(damage.getOffset()); + final int toLineNumber = document.getLineOfOffset(damage.getOffset() + damage.getLength()); + applyThemeEditorIfNeeded(); + // Refresh the UI Presentation + TMUIPlugin.getDefault().trace("Render from: " + fromLineNumber + " to: " + toLineNumber); + TextPresentation presentation = null; + Throwable error = null; + try { + presentation = new TextPresentation(damage, 1000); + + int lastStart = presentation.getExtent().getOffset(); + int length = 0; + boolean firstToken = true; + IToken lastToken = Token.UNDEFINED; + TextAttribute lastAttribute = getTokenTextAttribute(lastToken); + + List tokens = null; + for (int line = fromLineNumber; line <= toLineNumber; line++) { + tokens = model.getLineTokens(line); + if (tokens == null) { + // TextMate tokens was not computed for this line. + // This case comes from when the viewer is invalidated (by + // validation for instance) and textChanged is called. + // see https://github.com/eclipse/tm4e/issues/78 + TMUIPlugin.getDefault().trace("TextMate tokens not available for line " + line); + break; + } + int startLineOffset = document.getLineOffset(line); + for (int i = 0; i < tokens.size(); i++) { + TMToken currentToken = tokens.get(i); + TMToken nextToken = (i + 1 < tokens.size()) ? tokens.get(i + 1) : null; + int tokenStartIndex = currentToken.startIndex; + + if (isBeforeRegion(currentToken, startLineOffset, damage)) { + // The token is before the damage region + if (nextToken != null) { + if (isBeforeRegion(nextToken, startLineOffset, damage)) { + // ignore it + continue; + } else { + tokenStartIndex = damage.getOffset() - startLineOffset; + } + } else { + tokenStartIndex = damage.getOffset() - startLineOffset; + IToken token = toToken(currentToken); + lastAttribute = getTokenTextAttribute(token); + length += getTokenLengh(tokenStartIndex, nextToken, line, document); + firstToken = false; + // ignore it + continue; + } + } else if (isAfterRegion(currentToken, startLineOffset, damage)) { + // The token is after the damage region, stop the + // colorization process + break; + } + + IToken token = toToken(currentToken); + TextAttribute attribute = getTokenTextAttribute(token); + if (lastAttribute != null && lastAttribute.equals(attribute)) { + length += getTokenLengh(tokenStartIndex, nextToken, line, document); + firstToken = false; + } else { + if (!firstToken) { + addRange(presentation, lastStart, length, lastAttribute); + } + firstToken = false; + lastToken = token; + lastAttribute = attribute; + lastStart = tokenStartIndex + startLineOffset; + length = getTokenLengh(tokenStartIndex, nextToken, line, document); + } + } + } + // adjust the length + length = Math.min(length, damage.getOffset() + damage.getLength() - lastStart); + addRange(presentation, lastStart, length, lastAttribute); + applyTextRegionCollection(presentation); + } catch (Exception e) { + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } finally { + fireColorize(presentation, error); + } + } + + /** + * Return true if the given token is before the given region and false + * otherwise. + * + * @param token + * @param startLineOffset + * @param damage + * @return + */ + private boolean isBeforeRegion(TMToken token, int startLineOffset, IRegion damage) { + return token.startIndex + startLineOffset < damage.getOffset(); + } + + /** + * Return true if the given token is after the given region and false otherwise. + * + * @param t + * @param startLineOffset + * @param damage + * @return + */ + private boolean isAfterRegion(TMToken t, int startLineOffset, IRegion damage) { + return t.startIndex + startLineOffset >= damage.getOffset() + damage.getLength(); + } + + private IToken toToken(TMToken t) { + IToken token = getTokenProvider().getToken(t.type); + if (token != null) { + return token; + } + return defaultToken; + } + + private int getTokenLengh(int tokenStartIndex, TMToken nextToken, int line, IDocument document) + throws BadLocationException { + if (nextToken != null) { + return nextToken.startIndex - tokenStartIndex; + } + return document.getLineLength(line) - tokenStartIndex; + } + + /** + * Returns a text attribute encoded in the given token. If the token's data is + * not null and a text attribute it is assumed that it is the + * encoded text attribute. It returns the default text attribute if there is no + * encoded text attribute found. + * + * @param token + * the token whose text attribute is to be determined + * @return the token's text attribute + */ + protected TextAttribute getTokenTextAttribute(IToken token) { + Object data = token.getData(); + if (data instanceof TextAttribute) { + return (TextAttribute) data; + } + return fDefaultTextAttribute; + } + + /** + * Adds style information to the given text presentation. + * + * @param presentation + * the text presentation to be extended + * @param offset + * the offset of the range to be styled + * @param length + * the length of the range to be styled + * @param attr + * the attribute describing the style of the range to be styled + * @param lastLineStyleRanges + */ + protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { + if (attr != null) { + int style = attr.getStyle(); + int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); + StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), + fontStyle); + styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0; + styleRange.underline = (style & TextAttribute.UNDERLINE) != 0; + styleRange.font = attr.getFont(); + presentation.addStyleRange(styleRange); + } + } + + /** + * Applies the given text presentation to the text viewer the presentation + * reconciler is installed on. + * + * @param presentation + * the text presentation to be applied to the text viewer + */ + private void applyTextRegionCollection(TextPresentation presentation) { + viewer.changeTextPresentation(presentation, false); + } + + /** + * Add a TextMate presentation reconciler listener. + * + * @param listener + * the TextMate presentation reconciler listener to add. + */ + public void addTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { + if (listeners == null) { + listeners = new ArrayList<>(); + } + synchronized (listeners) { + if (!listeners.contains(listener)) { + listeners.add(listener); + } + } + } + + /** + * Remove a TextMate presentation reconciler listener. + * + * @param listener + * the TextMate presentation reconciler listener to remove. + */ + public void removeTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { + if (listeners == null) { + return; + } + synchronized (listeners) { + listeners.remove(listener); + } + } + + /** + * Fire colorize. + * + * @param presentation + * @param error + */ + private void fireColorize(TextPresentation presentation, Throwable error) { + if (listeners == null) { + return; + } + synchronized (listeners) { + for (ITMPresentationReconcilerListener listener : listeners) { + listener.colorize(presentation, error); + } + } + } + + public static TMPresentationReconciler getTMPresentationReconciler(IEditorPart editorPart) { + if (editorPart == null) { + return null; + } + @Nullable ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); + if (target instanceof ITextViewer) { + ITextViewer textViewer = ((ITextViewer) target); + return TMPresentationReconciler.getTMPresentationReconciler(textViewer); + } + return null; + } + + /** + * Returns the {@link TMPresentationReconciler} of the given text viewer and + * null otherwise. + * + * @param textViewer + * @return the {@link TMPresentationReconciler} of the given text viewer and + * null otherwise. + */ + public static TMPresentationReconciler getTMPresentationReconciler(ITextViewer textViewer) { + try { + Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); + if (field != null) { + field.setAccessible(true); + Object presentationReconciler = field.get(textViewer); + //field is IPresentationRecounciler, looking for TMPresentationReconciler implementation + return presentationReconciler instanceof TMPresentationReconciler + ? (TMPresentationReconciler) presentationReconciler + : null; + } + } catch (SecurityException | NoSuchFieldException e) { + // if SourceViewer class no longer has fPresentationReconciler or changes access level + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } catch (IllegalArgumentException | IllegalAccessException | NullPointerException | ExceptionInInitializerError iae) { + //This should not be logged as an error. This is an expected possible outcome of field.get(textViewer). + //The method assumes ITextViewer is actually ISourceViewer, and specifically the SourceViewer implementation + // that was available at the current build. This code also works with any implementation that follows the + // internal structure if also an ITextViewer. + //If these assumptions are false, the method should return null. Logging causes repeat noise. + } + return null; + } + + /** + * Initialize foreground, background color, current line highlight from the + * current theme. + * + */ + private void applyThemeEditor() { + this.initializeViewerColors = false; + this.updateTextDecorations = false; + applyThemeEditorIfNeeded(); + } + + /** + * Initialize foreground, background color, current line highlight from the + * current theme if needed. + * + */ + private void applyThemeEditorIfNeeded() { + if (!initializeViewerColors) { + StyledText styledText = viewer.getTextWidget(); + ((ITheme) tokenProvider).initializeViewerColors(styledText); + initializeViewerColors = true; + } + if (updateTextDecorations) { + return; + } + try { + // Ugly code to update "current line highlight" : + // - get the PaintManager from the ITextViewer with reflection. + // - get the list of IPainter of PaintManager with reflection + // - loop for IPainter to retrieve CursorLinePainter which manages "current line + // highlight". + PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class); + if (paintManager == null) { + return; + } + List painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class); + if (painters == null) { + return; + } + for (IPainter painter : painters) { + if (painter instanceof CursorLinePainter) { + // Update current line highlight + Color background = tokenProvider.getEditorCurrentLineHighlight(); + if (background != null) { + ((CursorLinePainter) painter).setHighlightColor(background); + } + updateTextDecorations = true; + } + } + } catch (Exception e) { + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } + } + + /** + * Set true if a {@link TMException} should be thrown if grammar or theme cannot + * be found and false otherwise. + * + * @param throwError + */ + public void setThrowError(boolean throwError) { + this.throwError = throwError; + } + + /** + * Return true if a {@link TMException} should be thrown if grammar or theme + * cannot be found and false otherwise. + * + * @return true if a {@link TMException} should be thrown if grammar or theme + * cannot be found and false otherwise. + */ + public boolean isThrowError() { + return throwError; + } + + /** + * Returns true if the presentation reconciler is enabled (grammar and theme are + * available) and false otherwise. + * + * @return true if the presentation reconciler is enabled (grammar and theme are + * available) and false otherwise. + */ + + public boolean isEnabled() { + return enabled; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java index 4949e0754..4352a9e41 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java @@ -1,20 +1,20 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -/** - * Abstract class for {@link ITokenProvider}. - * - */ -public abstract class AbstractTokenProvider implements ITokenProvider { - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +/** + * Abstract class for {@link ITokenProvider}. + * + */ +public abstract class AbstractTokenProvider implements ITokenProvider { + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java index 3d3b25dd1..2ae20ba5c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java @@ -1,69 +1,69 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -import org.eclipse.swt.custom.StyledText; - -/** - * TextMate theme. - * - */ -public interface ITheme extends ITokenProvider { - - /** - * Returns the id of the theme. - * - * @return the id of the theme. - */ - String getId(); - - /** - * Returns the name of the theme. - * - * @return the name of the theme. - */ - String getName(); - - /** - * Returns the path of the theme. - * - * @return the path of the theme. - */ - String getPath(); - - /** - * Returns the plugin id. - * - * @return the plugin id - */ - String getPluginId(); - - /** - * Returns the theme content as CSS style sheet. - * - * @return the theme content as CSS style sheet. - */ - String toCSSStyleSheet(); - - boolean isDark(); - - boolean isDefault(); - - /** - * Initialize foreground, background color of the given {@link StyledText} with - * theme. - * - * @param textWidget - */ - void initializeViewerColors(StyledText styledText); - -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +import org.eclipse.swt.custom.StyledText; + +/** + * TextMate theme. + * + */ +public interface ITheme extends ITokenProvider { + + /** + * Returns the id of the theme. + * + * @return the id of the theme. + */ + String getId(); + + /** + * Returns the name of the theme. + * + * @return the name of the theme. + */ + String getName(); + + /** + * Returns the path of the theme. + * + * @return the path of the theme. + */ + String getPath(); + + /** + * Returns the plugin id. + * + * @return the plugin id + */ + String getPluginId(); + + /** + * Returns the theme content as CSS style sheet. + * + * @return the theme content as CSS style sheet. + */ + String toCSSStyleSheet(); + + boolean isDark(); + + boolean isDefault(); + + /** + * Initialize foreground, background color of the given {@link StyledText} with + * theme. + * + * @param textWidget + */ + void initializeViewerColors(StyledText styledText); + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java index 95148a237..253a798c3 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java @@ -1,37 +1,37 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -import org.eclipse.tm4e.registry.ITMDefinition; - -/** - * Theme association API. - * - */ -public interface IThemeAssociation extends ITMDefinition { - - /** - * Returns the TextMate theme id. - * - * @return the TextMate theme id. - */ - String getThemeId(); - - /** - * Returns the TextMate grammar scope linked to the theme id and null otherwise. - * - * @return the TextMate grammar scope to the theme id and null otherwise. - */ - String getScopeName(); - - boolean isWhenDark(); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +import org.eclipse.tm4e.registry.ITMDefinition; + +/** + * Theme association API. + * + */ +public interface IThemeAssociation extends ITMDefinition { + + /** + * Returns the TextMate theme id. + * + * @return the TextMate theme id. + */ + String getThemeId(); + + /** + * Returns the TextMate grammar scope linked to the theme id and null otherwise. + * + * @return the TextMate grammar scope to the theme id and null otherwise. + */ + String getScopeName(); + + boolean isWhenDark(); +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java index 20e09c006..6d14d5b1d 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java @@ -1,143 +1,143 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -import org.eclipse.swt.graphics.RGB; -import org.osgi.service.prefs.BackingStoreException; - -/** - * TextMate theme manager API. - * - */ -public interface IThemeManager { - - /** - * Register the given theme. - * - * @param theme - * to unregister. - */ - void registerTheme(ITheme theme); - - /** - * Unregister the given theme. - * - * @param theme - * to unregister. - */ - void unregisterTheme(ITheme theme); - - /** - * Returns the {@link ITheme} by the theme id. - * - * @param themeId - * the theme id. - * @return the {@link ITheme} by the theme id. - */ - ITheme getThemeById(String themeId); - - /** - * Returns the list of TextMate themes. - * - * @return the list of TextMate themes. - */ - ITheme[] getThemes(); - - /** - * Returns the default theme. - * - * @return the default theme. - */ - ITheme getDefaultTheme(); - - /** - * Returns the list of TextMate themes for the given eclipse theme id. - * - * @return the list of TextMate themes for the given eclipse theme id. - */ - ITheme[] getThemes(boolean dark); - - /** - * Returns the TextMate theme {@link ITheme} for the given TextMate grammar - * scopeName and E4 Theme eclipseThemeId. - * - * @param scopeName - * the TextMate grammar - * @param eclipseThemeId - * the E4 Theme. - * @return the TextMate theme {@link ITheme} for the given TextMate grammar - * scopeName and E4 Theme eclipseThemeId. - */ - ITheme getThemeForScope(String scopeName, boolean dark); - - /** - * Returns the TextMate theme {@link ITheme} for the given TextMate grammar - * scopeName and default E4 Theme. - * - * @param scopeName - * @return the TextMate theme {@link ITheme} for the given TextMate grammar - * scopeName and default E4 Theme. - */ - ITheme getThemeForScope(String scopeName); - - /** - * Register the given theme association. - * - * @param association - * to register. - */ - void registerThemeAssociation(IThemeAssociation association); - - /** - * Unregister the given theme association. - * - * @param association - * to unregister. - */ - void unregisterThemeAssociation(IThemeAssociation association); - - /** - * Returns list of all theme associations. - * - * @return list of all theme associations. - */ - IThemeAssociation[] getAllThemeAssociations(); - - /** - * Returns the theme associations for the given TextMate grammar - * scopeName. - * - * @param scopeName - * @return the theme associations for the given TextMate grammar - * scopeName. - */ - IThemeAssociation[] getThemeAssociationsForScope(String scopeName); - - /** - * Save the themes definitions. - * - * @throws BackingStoreException - */ - void save() throws BackingStoreException; - - boolean isDarkEclipseTheme(); - - boolean isDarkEclipseTheme(String eclipseThemeId); - - /** - * - * @param scopeName - * @param background - * @return the theme that will fit best for the defined background color - */ - ITokenProvider getThemeForScope(String scopeName, RGB background); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +import org.eclipse.swt.graphics.RGB; +import org.osgi.service.prefs.BackingStoreException; + +/** + * TextMate theme manager API. + * + */ +public interface IThemeManager { + + /** + * Register the given theme. + * + * @param theme + * to unregister. + */ + void registerTheme(ITheme theme); + + /** + * Unregister the given theme. + * + * @param theme + * to unregister. + */ + void unregisterTheme(ITheme theme); + + /** + * Returns the {@link ITheme} by the theme id. + * + * @param themeId + * the theme id. + * @return the {@link ITheme} by the theme id. + */ + ITheme getThemeById(String themeId); + + /** + * Returns the list of TextMate themes. + * + * @return the list of TextMate themes. + */ + ITheme[] getThemes(); + + /** + * Returns the default theme. + * + * @return the default theme. + */ + ITheme getDefaultTheme(); + + /** + * Returns the list of TextMate themes for the given eclipse theme id. + * + * @return the list of TextMate themes for the given eclipse theme id. + */ + ITheme[] getThemes(boolean dark); + + /** + * Returns the TextMate theme {@link ITheme} for the given TextMate grammar + * scopeName and E4 Theme eclipseThemeId. + * + * @param scopeName + * the TextMate grammar + * @param eclipseThemeId + * the E4 Theme. + * @return the TextMate theme {@link ITheme} for the given TextMate grammar + * scopeName and E4 Theme eclipseThemeId. + */ + ITheme getThemeForScope(String scopeName, boolean dark); + + /** + * Returns the TextMate theme {@link ITheme} for the given TextMate grammar + * scopeName and default E4 Theme. + * + * @param scopeName + * @return the TextMate theme {@link ITheme} for the given TextMate grammar + * scopeName and default E4 Theme. + */ + ITheme getThemeForScope(String scopeName); + + /** + * Register the given theme association. + * + * @param association + * to register. + */ + void registerThemeAssociation(IThemeAssociation association); + + /** + * Unregister the given theme association. + * + * @param association + * to unregister. + */ + void unregisterThemeAssociation(IThemeAssociation association); + + /** + * Returns list of all theme associations. + * + * @return list of all theme associations. + */ + IThemeAssociation[] getAllThemeAssociations(); + + /** + * Returns the theme associations for the given TextMate grammar + * scopeName. + * + * @param scopeName + * @return the theme associations for the given TextMate grammar + * scopeName. + */ + IThemeAssociation[] getThemeAssociationsForScope(String scopeName); + + /** + * Save the themes definitions. + * + * @throws BackingStoreException + */ + void save() throws BackingStoreException; + + boolean isDarkEclipseTheme(); + + boolean isDarkEclipseTheme(String eclipseThemeId); + + /** + * + * @param scopeName + * @param background + * @return the theme that will fit best for the defined background color + */ + ITokenProvider getThemeForScope(String scopeName, RGB background); +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java index c3e5e54e7..1353c36fa 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java @@ -1,40 +1,40 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. +/** + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.swt.graphics.Color; - -/** - * Provider to retrieve Eclipse {@link IToken} from the TextMate token type. - * - */ -public interface ITokenProvider { - - /** - * Returns the Eclipse {@link IToken} from the given type and null otherwise. - * - * @param type - * @return the Eclipse {@link IToken} from the given type and null otherwise. - */ - IToken getToken(String type); - - Color getEditorBackground(); - - Color getEditorForeground(); - - Color getEditorSelectionBackground(); - - Color getEditorSelectionForeground(); - - Color getEditorCurrentLineHighlight(); -} + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.swt.graphics.Color; + +/** + * Provider to retrieve Eclipse {@link IToken} from the TextMate token type. + * + */ +public interface ITokenProvider { + + /** + * Returns the Eclipse {@link IToken} from the given type and null otherwise. + * + * @param type + * @return the Eclipse {@link IToken} from the given type and null otherwise. + */ + IToken getToken(String type); + + Color getEditorBackground(); + + Color getEditorForeground(); + + Color getEditorSelectionBackground(); + + Color getEditorSelectionForeground(); + + Color getEditorCurrentLineHighlight(); +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java index df11feea7..0d3b175a6 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java @@ -1,180 +1,180 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -import java.io.InputStream; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.tm4e.registry.TMResource; -import org.eclipse.tm4e.registry.XMLConstants; -import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; -import org.eclipse.tm4e.ui.themes.css.CSSTokenProvider; -import org.eclipse.ui.texteditor.AbstractTextEditor; - -/** - * {@link ITheme} implementation. - * - */ -public class Theme extends TMResource implements ITheme { - - private static final String DARK_ATTR = "dark"; - private static final String DEFAULT_ATTR = "default"; - - private ITokenProvider tokenProvider; - - private String id; - private String name; - private boolean dark; - private boolean isDefault; - - /** - * Constructor for user preferences (loaded from Json with Gson). - */ - public Theme() { - super(); - } - - /** - * Constructor for extension point. - * - * @param id - */ - public Theme(String id, String path, String name, boolean dark, boolean isDefault) { - super(path); - this.id = id; - this.name = name; - this.dark = dark; - this.isDefault = isDefault; - } - - public Theme(IConfigurationElement ce) { - super(ce); - id = ce.getAttribute(XMLConstants.ID_ATTR); - name = ce.getAttribute(XMLConstants.NAME_ATTR); - dark = Boolean.parseBoolean(ce.getAttribute(DARK_ATTR)); - isDefault = Boolean.parseBoolean(ce.getAttribute(DEFAULT_ATTR)); - } - - @Override - public String getId() { - return id; - } - - @Override - public String getName() { - return name; - } - - @Override - public IToken getToken(String type) { - ITokenProvider provider = getTokenProvider(); - return provider != null ? provider.getToken(type) : null; - } - - @Override - public Color getEditorForeground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorForeground() : null; - return ColorManager.getInstance() - .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND); - } - - @Override - public Color getEditorBackground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorBackground() : null; - return ColorManager.getInstance() - .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); - } - - @Override - public Color getEditorSelectionForeground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorSelectionForeground() : null; - return ColorManager.getInstance() - .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND); - } - - @Override - public Color getEditorSelectionBackground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorSelectionBackground() : null; - return ColorManager.getInstance() - .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND); - } - - @Override - public Color getEditorCurrentLineHighlight() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorCurrentLineHighlight() : null; - ColorManager manager = ColorManager.getInstance(); - return manager.isColorUserDefined(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND) - ? manager.getPreferenceEditorColor(PreferenceConstants.EDITOR_CURRENTLINE_HIGHLIGHT) - : themeColor; - } - - private ITokenProvider getTokenProvider() { - if (tokenProvider == null) { - try { - InputStream in = super.getInputStream(); - if (in == null) { - return null; - } - tokenProvider = new CSSTokenProvider(in); - } catch (Exception e) { - e.printStackTrace(); - } - } - return tokenProvider; - } - - @Override - public String toCSSStyleSheet() { - return super.getResourceContent(); - } - - @Override - public boolean isDark() { - return dark; - } - - @Override - public boolean isDefault() { - return isDefault; - } - - @Override - public void initializeViewerColors(StyledText styledText) { - Color color = getEditorBackground(); - if (color != null) { - styledText.setBackground(color); - } - - color = getEditorForeground(); - if (color != null) { - styledText.setForeground(color); - } - - color = getEditorSelectionBackground(); - if (color != null) { - styledText.setSelectionBackground(color); - } - - color = getEditorSelectionForeground(); - if (color != null) { - styledText.setSelectionForeground(color); - } - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +import java.io.InputStream; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.tm4e.registry.TMResource; +import org.eclipse.tm4e.registry.XMLConstants; +import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; +import org.eclipse.tm4e.ui.themes.css.CSSTokenProvider; +import org.eclipse.ui.texteditor.AbstractTextEditor; + +/** + * {@link ITheme} implementation. + * + */ +public class Theme extends TMResource implements ITheme { + + private static final String DARK_ATTR = "dark"; + private static final String DEFAULT_ATTR = "default"; + + private ITokenProvider tokenProvider; + + private String id; + private String name; + private boolean dark; + private boolean isDefault; + + /** + * Constructor for user preferences (loaded from Json with Gson). + */ + public Theme() { + super(); + } + + /** + * Constructor for extension point. + * + * @param id + */ + public Theme(String id, String path, String name, boolean dark, boolean isDefault) { + super(path); + this.id = id; + this.name = name; + this.dark = dark; + this.isDefault = isDefault; + } + + public Theme(IConfigurationElement ce) { + super(ce); + id = ce.getAttribute(XMLConstants.ID_ATTR); + name = ce.getAttribute(XMLConstants.NAME_ATTR); + dark = Boolean.parseBoolean(ce.getAttribute(DARK_ATTR)); + isDefault = Boolean.parseBoolean(ce.getAttribute(DEFAULT_ATTR)); + } + + @Override + public String getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public IToken getToken(String type) { + ITokenProvider provider = getTokenProvider(); + return provider != null ? provider.getToken(type) : null; + } + + @Override + public Color getEditorForeground() { + ITokenProvider provider = getTokenProvider(); + Color themeColor = provider != null ? provider.getEditorForeground() : null; + return ColorManager.getInstance() + .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND); + } + + @Override + public Color getEditorBackground() { + ITokenProvider provider = getTokenProvider(); + Color themeColor = provider != null ? provider.getEditorBackground() : null; + return ColorManager.getInstance() + .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); + } + + @Override + public Color getEditorSelectionForeground() { + ITokenProvider provider = getTokenProvider(); + Color themeColor = provider != null ? provider.getEditorSelectionForeground() : null; + return ColorManager.getInstance() + .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND); + } + + @Override + public Color getEditorSelectionBackground() { + ITokenProvider provider = getTokenProvider(); + Color themeColor = provider != null ? provider.getEditorSelectionBackground() : null; + return ColorManager.getInstance() + .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND); + } + + @Override + public Color getEditorCurrentLineHighlight() { + ITokenProvider provider = getTokenProvider(); + Color themeColor = provider != null ? provider.getEditorCurrentLineHighlight() : null; + ColorManager manager = ColorManager.getInstance(); + return manager.isColorUserDefined(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND) + ? manager.getPreferenceEditorColor(PreferenceConstants.EDITOR_CURRENTLINE_HIGHLIGHT) + : themeColor; + } + + private ITokenProvider getTokenProvider() { + if (tokenProvider == null) { + try { + InputStream in = super.getInputStream(); + if (in == null) { + return null; + } + tokenProvider = new CSSTokenProvider(in); + } catch (Exception e) { + e.printStackTrace(); + } + } + return tokenProvider; + } + + @Override + public String toCSSStyleSheet() { + return super.getResourceContent(); + } + + @Override + public boolean isDark() { + return dark; + } + + @Override + public boolean isDefault() { + return isDefault; + } + + @Override + public void initializeViewerColors(StyledText styledText) { + Color color = getEditorBackground(); + if (color != null) { + styledText.setBackground(color); + } + + color = getEditorForeground(); + if (color != null) { + styledText.setForeground(color); + } + + color = getEditorSelectionBackground(); + if (color != null) { + styledText.setSelectionBackground(color); + } + + color = getEditorSelectionForeground(); + if (color != null) { + styledText.setSelectionForeground(color); + } + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java index 14c165bbd..d0ad5d810 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java @@ -1,139 +1,139 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -import org.eclipse.core.runtime.IConfigurationElement; - -/** - * Theme association implementation. - * - */ -public class ThemeAssociation implements IThemeAssociation { - - private static final String THEME_ID_ATTR = "themeId"; //$NON-NLS-1$ - private static final String SCOPE_NAME_ATTR = "scopeName"; //$NON-NLS-1$ - private static final String WHEN_DARK_ATTR = "whenDark"; //$NON-NLS-1$ - - private String themeId; - private String scopeName; - private boolean whenDark; - private String pluginId; - - /** - * Constructor for user preferences (loaded from Json with Gson). - */ - public ThemeAssociation() { - super(); - } - - /** - * Constructor to register theme associations for a given scope name. - * - * @param themeId - * @param scopeName - * @param whenDark - */ - public ThemeAssociation(String themeId, String scopeName, boolean whenDark) { - this.themeId = themeId; - this.scopeName = scopeName; - this.whenDark = whenDark; - } - - public ThemeAssociation(IConfigurationElement ce) { - this(ce.getAttribute(THEME_ID_ATTR), ce.getAttribute(SCOPE_NAME_ATTR), - "true".equals(ce.getAttribute(WHEN_DARK_ATTR))); - this.pluginId = ce.getNamespaceIdentifier(); - } - - @Override - public String getPluginId() { - return pluginId; - } - - @Override - public String getThemeId() { - return themeId; - } - - @Override - public String getScopeName() { - return scopeName; - } - - @Override - public boolean isWhenDark() { - return whenDark; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((pluginId == null) ? 0 : pluginId.hashCode()); - result = prime * result + ((scopeName == null) ? 0 : scopeName.hashCode()); - result = prime * result + ((themeId == null) ? 0 : themeId.hashCode()); - result = prime * result + (whenDark ? 1231 : 1237); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ThemeAssociation other = (ThemeAssociation) obj; - if (pluginId == null) { - if (other.pluginId != null) - return false; - } else if (!pluginId.equals(other.pluginId)) - return false; - if (scopeName == null) { - if (other.scopeName != null) - return false; - } else if (!scopeName.equals(other.scopeName)) - return false; - if (themeId == null) { - if (other.themeId != null) - return false; - } else if (!themeId.equals(other.themeId)) - return false; - if (whenDark != other.whenDark) - return false; - return true; - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +import org.eclipse.core.runtime.IConfigurationElement; + +/** + * Theme association implementation. + * + */ +public class ThemeAssociation implements IThemeAssociation { + + private static final String THEME_ID_ATTR = "themeId"; //$NON-NLS-1$ + private static final String SCOPE_NAME_ATTR = "scopeName"; //$NON-NLS-1$ + private static final String WHEN_DARK_ATTR = "whenDark"; //$NON-NLS-1$ + + private String themeId; + private String scopeName; + private boolean whenDark; + private String pluginId; + + /** + * Constructor for user preferences (loaded from Json with Gson). + */ + public ThemeAssociation() { + super(); + } + + /** + * Constructor to register theme associations for a given scope name. + * + * @param themeId + * @param scopeName + * @param whenDark + */ + public ThemeAssociation(String themeId, String scopeName, boolean whenDark) { + this.themeId = themeId; + this.scopeName = scopeName; + this.whenDark = whenDark; + } + + public ThemeAssociation(IConfigurationElement ce) { + this(ce.getAttribute(THEME_ID_ATTR), ce.getAttribute(SCOPE_NAME_ATTR), + "true".equals(ce.getAttribute(WHEN_DARK_ATTR))); + this.pluginId = ce.getNamespaceIdentifier(); + } + + @Override + public String getPluginId() { + return pluginId; + } + + @Override + public String getThemeId() { + return themeId; + } + + @Override + public String getScopeName() { + return scopeName; + } + + @Override + public boolean isWhenDark() { + return whenDark; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((pluginId == null) ? 0 : pluginId.hashCode()); + result = prime * result + ((scopeName == null) ? 0 : scopeName.hashCode()); + result = prime * result + ((themeId == null) ? 0 : themeId.hashCode()); + result = prime * result + (whenDark ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ThemeAssociation other = (ThemeAssociation) obj; + if (pluginId == null) { + if (other.pluginId != null) + return false; + } else if (!pluginId.equals(other.pluginId)) + return false; + if (scopeName == null) { + if (other.scopeName != null) + return false; + } else if (!scopeName.equals(other.scopeName)) + return false; + if (themeId == null) { + if (other.themeId != null) + return false; + } else if (!themeId.equals(other.themeId)) + return false; + if (whenDark != other.whenDark) + return false; + return true; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java index aa57143ce..8703f5b0a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeIdConstants.java @@ -1,25 +1,25 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes; - -/** - * Default TextMate theme ID constants. - * - */ -public interface ThemeIdConstants { - - String Light = "org.eclipse.tm4e.ui.themes.Light"; - String Monokai = "org.eclipse.tm4e.ui.themes.Monokai"; - String SolarizedLight = "org.eclipse.tm4e.ui.themes.SolarizedLight"; - String Dark = "org.eclipse.tm4e.ui.themes.Dark"; - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes; + +/** + * Default TextMate theme ID constants. + * + */ +public interface ThemeIdConstants { + + String Light = "org.eclipse.tm4e.ui.themes.Light"; + String Monokai = "org.eclipse.tm4e.ui.themes.Monokai"; + String SolarizedLight = "org.eclipse.tm4e.ui.themes.SolarizedLight"; + String Dark = "org.eclipse.tm4e.ui.themes.Dark"; + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java index 349bb38ca..7d9eebf26 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java @@ -1,126 +1,126 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.themes.css; - -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.tm4e.core.theme.IStyle; -import org.eclipse.tm4e.core.theme.RGB; -import org.eclipse.tm4e.core.theme.css.CSSParser; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.themes.AbstractTokenProvider; -import org.eclipse.tm4e.ui.themes.ColorManager; - -public class CSSTokenProvider extends AbstractTokenProvider { - - private final Map tokenMaps; - private CSSParser parser; - - public CSSTokenProvider(InputStream in) { - tokenMaps = new HashMap<>(); - try { - parser = new CSSParser(in); - for (IStyle style : parser.getStyles()) { - RGB color = style.getColor(); - if (color != null) { - int s = SWT.NORMAL; - if (style.isBold()) { - s = s | SWT.BOLD; - } - if (style.isItalic()) { - s = s | SWT.ITALIC; - } - if (style.isUnderline()) { - s = s | TextAttribute.UNDERLINE; - } - if (style.isStrikeThrough()) { - s = s | TextAttribute.STRIKETHROUGH; - } - tokenMaps.put(style, - new Token(new TextAttribute(ColorManager.getInstance().getColor(color), null, s))); - } - } - } catch (Exception e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); - } - } - - @Override - public IToken getToken(String type) { - if (type == null) { - return null; - } - IStyle style = parser.getBestStyle(type.split("[.]")); - if (style != null) { - IToken t = tokenMaps.get(style); - if (t != null) { - return t; - } - } - return null; - } - - @Override - public Color getEditorForeground() { - IStyle style = parser.getBestStyle("editor"); - if (style != null && style.getColor() != null) { - return ColorManager.getInstance().getColor(style.getColor()); - } - return null; - } - - @Override - public Color getEditorBackground() { - IStyle style = parser.getBestStyle("editor"); - if (style != null && style.getBackgroundColor() != null) { - return ColorManager.getInstance().getColor(style.getBackgroundColor()); - } - return null; - } - - @Override - public Color getEditorSelectionForeground() { - IStyle style = parser.getBestStyle("editor", "selection"); - if (style != null && style.getColor() != null) { - return ColorManager.getInstance().getColor(style.getColor()); - } - return null; - } - - @Override - public Color getEditorSelectionBackground() { - IStyle style = parser.getBestStyle("editor", "selection"); - if (style != null && style.getBackgroundColor() != null) { - return ColorManager.getInstance().getColor(style.getBackgroundColor()); - } - return null; - } - - @Override - public Color getEditorCurrentLineHighlight() { - IStyle style = parser.getBestStyle("editor", "lineHighlight"); - if (style != null && style.getBackgroundColor() != null) { - return ColorManager.getInstance().getColor(style.getBackgroundColor()); - } - return null; - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.themes.css; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.tm4e.core.theme.IStyle; +import org.eclipse.tm4e.core.theme.RGB; +import org.eclipse.tm4e.core.theme.css.CSSParser; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.themes.AbstractTokenProvider; +import org.eclipse.tm4e.ui.themes.ColorManager; + +public class CSSTokenProvider extends AbstractTokenProvider { + + private final Map tokenMaps; + private CSSParser parser; + + public CSSTokenProvider(InputStream in) { + tokenMaps = new HashMap<>(); + try { + parser = new CSSParser(in); + for (IStyle style : parser.getStyles()) { + RGB color = style.getColor(); + if (color != null) { + int s = SWT.NORMAL; + if (style.isBold()) { + s = s | SWT.BOLD; + } + if (style.isItalic()) { + s = s | SWT.ITALIC; + } + if (style.isUnderline()) { + s = s | TextAttribute.UNDERLINE; + } + if (style.isStrikeThrough()) { + s = s | TextAttribute.STRIKETHROUGH; + } + tokenMaps.put(style, + new Token(new TextAttribute(ColorManager.getInstance().getColor(color), null, s))); + } + } + } catch (Exception e) { + TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } + } + + @Override + public IToken getToken(String type) { + if (type == null) { + return null; + } + IStyle style = parser.getBestStyle(type.split("[.]")); + if (style != null) { + IToken t = tokenMaps.get(style); + if (t != null) { + return t; + } + } + return null; + } + + @Override + public Color getEditorForeground() { + IStyle style = parser.getBestStyle("editor"); + if (style != null && style.getColor() != null) { + return ColorManager.getInstance().getColor(style.getColor()); + } + return null; + } + + @Override + public Color getEditorBackground() { + IStyle style = parser.getBestStyle("editor"); + if (style != null && style.getBackgroundColor() != null) { + return ColorManager.getInstance().getColor(style.getBackgroundColor()); + } + return null; + } + + @Override + public Color getEditorSelectionForeground() { + IStyle style = parser.getBestStyle("editor", "selection"); + if (style != null && style.getColor() != null) { + return ColorManager.getInstance().getColor(style.getColor()); + } + return null; + } + + @Override + public Color getEditorSelectionBackground() { + IStyle style = parser.getBestStyle("editor", "selection"); + if (style != null && style.getBackgroundColor() != null) { + return ColorManager.getInstance().getColor(style.getBackgroundColor()); + } + return null; + } + + @Override + public Color getEditorCurrentLineHighlight() { + IStyle style = parser.getBestStyle("editor", "lineHighlight"); + if (style != null && style.getBackgroundColor() != null) { + return ColorManager.getInstance().getColor(style.getBackgroundColor()); + } + return null; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java index dc7496a25..ccfce1ed5 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java @@ -1,53 +1,53 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.utils; - -import java.lang.reflect.Field; - -/** - * Class Reflection utilities. - * - */ -public class ClassHelper { - - @SuppressWarnings("unchecked") - public static T getFieldValue(Object object, String name, Class clazz) { - Field f = getDeclaredField(clazz, name); - if (f != null) { - try { - return (T) f.get(object); - } catch (Exception e) { - return null; - } - } - return null; - } - - public static T getFieldValue(Object object, String name) { - return getFieldValue(object, name, object.getClass()); - } - - public static Field getDeclaredField(Class clazz, String name) { - if (clazz == null) { - return null; - } - try { - Field f = clazz.getDeclaredField(name); - f.setAccessible(true); - return f; - } catch (NoSuchFieldException e) { - return getDeclaredField(clazz.getSuperclass(), name); - } catch (SecurityException e) { - return null; - } - } -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.utils; + +import java.lang.reflect.Field; + +/** + * Class Reflection utilities. + * + */ +public class ClassHelper { + + @SuppressWarnings("unchecked") + public static T getFieldValue(Object object, String name, Class clazz) { + Field f = getDeclaredField(clazz, name); + if (f != null) { + try { + return (T) f.get(object); + } catch (Exception e) { + return null; + } + } + return null; + } + + public static T getFieldValue(Object object, String name) { + return getFieldValue(object, name, object.getClass()); + } + + public static Field getDeclaredField(Class clazz, String name) { + if (clazz == null) { + return null; + } + try { + Field f = clazz.getDeclaredField(name); + f.setAccessible(true); + return f; + } catch (NoSuchFieldException e) { + return getDeclaredField(clazz.getSuperclass(), name); + } catch (SecurityException e) { + return null; + } + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java index e2d41511b..b8fee9325 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java @@ -1,231 +1,231 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.ui.utils; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; - -import org.eclipse.core.filebuffers.FileBuffers; -import org.eclipse.core.filebuffers.ITextFileBuffer; -import org.eclipse.core.filebuffers.ITextFileBufferManager; -import org.eclipse.core.filesystem.EFS; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.jface.text.IDocument; -import org.eclipse.tm4e.ui.internal.model.DocumentInputStream; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IStorageEditorInput; - -/** - * {@link IContentType} utilities. - * - */ -public class ContentTypeHelper { - - /** - * Find the content types from the given {@link IDocument} and null otherwise. - * - * @param document - * @return the content types from the given {@link IDocument} and null - * otherwise. - * @throws CoreException - */ - public static ContentTypeInfo findContentTypes(IDocument document) throws CoreException { - // Find content types from FileBuffers - ContentTypeInfo contentTypes = findContentTypesFromFileBuffers(document); - if (contentTypes != null) { - return contentTypes; - } - // Find content types from the IEditorInput - return findContentTypesFromEditorInput(document); - } - - /** - * Find the content type with the given contentTypeId - * - * @param contentTypeId - * @return matching content type or null - */ - public static IContentType getContentTypeById(String contentTypeId) { - IContentTypeManager manager = Platform.getContentTypeManager(); - return manager.getContentType(contentTypeId); - } - - // ------------------------- Find content types from FileBuffers - - /** - * Find the content types from the given {@link IDocument} by using - * {@link ITextFileBufferManager} and null otherwise. - * - * @param document - * @return the content types from the given {@link IDocument} by using - * {@link ITextFileBufferManager} and null otherwise. - * @throws CoreException - */ - private static ContentTypeInfo findContentTypesFromFileBuffers(IDocument document) throws CoreException { - ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); - ITextFileBuffer buffer = bufferManager.getTextFileBuffer(document); - if (buffer != null) { - return getContentTypes(buffer); - } - return null; - } - - /** - * Returns the content types from the given {@link ITextFileBuffer}. - * - * @param buffer - * @return the content types from the given {@link ITextFileBuffer}. - * @throws CoreException - */ - private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws CoreException { - try { - String fileName = buffer.getFileStore().getName(); - Collection contentTypes = new LinkedHashSet<>(); - IContentType bufferContentType = buffer.getContentType(); - if (bufferContentType != null) { - contentTypes.add(bufferContentType); - } - if (buffer.isDirty()) { - // Buffer is dirty (content of the filesystem is not synch with - // the editor content), use IDocument content. - try (InputStream input = new DocumentInputStream(buffer.getDocument())){ - IContentType[] contentTypesForInput = Platform.getContentTypeManager().findContentTypesFor(input, fileName); - if (contentTypesForInput != null) { - contentTypes.addAll(Arrays.asList(contentTypesForInput)); - return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new)); - } - } - } - - // Buffer is synchronized with filesystem content - try (InputStream contents = getContents(buffer)){ - contentTypes.addAll(Arrays.asList(Platform.getContentTypeManager().findContentTypesFor(contents, fileName))); - return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new)); - } catch (Throwable e) { - return null; - } - } catch (IOException x) { - x.printStackTrace(); - return null; - } - } - - /** - * Returns the content of the given buffer. - * - * @param buffer - * @return the content of the given buffer. - * @throws CoreException - */ - private static InputStream getContents(ITextFileBuffer buffer) throws CoreException { - IPath path = buffer.getLocation(); - if (path != null) { - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IFile file = workspaceRoot.getFile(path); - if (file.exists() && buffer.isSynchronized()) { - return file.getContents(); - } - } - return buffer.getFileStore().openInputStream(EFS.NONE, null); - } - - // ------------------------- Find content types from FileBuffers - - /** - * Find the content types from the given {@link IDocument} by using - * {@link IEditorInput} and null otherwise. - * - * @param document - * @return the content types from the given {@link IDocument} by using - * {@link IEditorInput} and null otherwise. - */ - private static ContentTypeInfo findContentTypesFromEditorInput(IDocument document) { - IEditorInput editorInput = getEditorInput(document); - if (editorInput != null) { - if (editorInput instanceof IStorageEditorInput) { - InputStream input = null; - try { - IStorage storage = ((IStorageEditorInput) editorInput).getStorage(); - String fileName = storage.getName(); - input = storage.getContents(); - return new ContentTypeInfo(fileName, - Platform.getContentTypeManager().findContentTypesFor(input, fileName)); - } catch (Exception e) { - return null; - } finally { - try { - if (input != null) - input.close(); - } catch (IOException x) { - } - } - } else { - // TODO: manage other type of IEditorInput - } - } - return null; - } - - /** - * Returns the {@link IEditorInput} from the given document and null otherwise. - * - * @param document - * @return the {@link IEditorInput} from the given document and null otherwise. - */ - private static IEditorInput getEditorInput(IDocument document) { - try { - // This utilities class is very ugly, I have not found a clean mean - // to retrieve the IEditorInput linked to a document. - // Here the strategy to retrieve the IEditorInput: - - // AbstractDocumentProvider#ElementInfo add a IDocumentListener to - // the document. - // ElementInfo contains a fElement which is the IEditorInput (like - // ISorageEditorInput, see StorageDocumentProvider) - - // get list of IDocumentListener - ListenerList listeners = ClassHelper.getFieldValue(document, "fDocumentListeners"); - if (listeners != null) { - // Get AbstractDocumentProvider#ElementInfo - Object[] l = listeners.getListeners(); - for (int i = 0; i < l.length; i++) { - Object /* AbstractDocumentProvider#ElementInfo */ info = l[i]; - try { - /* The element for which the info is stored */ - Object input = ClassHelper.getFieldValue(info, "fElement"); - if (input instanceof IEditorInput) { - return (IEditorInput) input; - } - } catch (Exception e) { - - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - -} +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.ui.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; + +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.filebuffers.ITextFileBuffer; +import org.eclipse.core.filebuffers.ITextFileBufferManager; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.jface.text.IDocument; +import org.eclipse.tm4e.ui.internal.model.DocumentInputStream; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IStorageEditorInput; + +/** + * {@link IContentType} utilities. + * + */ +public class ContentTypeHelper { + + /** + * Find the content types from the given {@link IDocument} and null otherwise. + * + * @param document + * @return the content types from the given {@link IDocument} and null + * otherwise. + * @throws CoreException + */ + public static ContentTypeInfo findContentTypes(IDocument document) throws CoreException { + // Find content types from FileBuffers + ContentTypeInfo contentTypes = findContentTypesFromFileBuffers(document); + if (contentTypes != null) { + return contentTypes; + } + // Find content types from the IEditorInput + return findContentTypesFromEditorInput(document); + } + + /** + * Find the content type with the given contentTypeId + * + * @param contentTypeId + * @return matching content type or null + */ + public static IContentType getContentTypeById(String contentTypeId) { + IContentTypeManager manager = Platform.getContentTypeManager(); + return manager.getContentType(contentTypeId); + } + + // ------------------------- Find content types from FileBuffers + + /** + * Find the content types from the given {@link IDocument} by using + * {@link ITextFileBufferManager} and null otherwise. + * + * @param document + * @return the content types from the given {@link IDocument} by using + * {@link ITextFileBufferManager} and null otherwise. + * @throws CoreException + */ + private static ContentTypeInfo findContentTypesFromFileBuffers(IDocument document) throws CoreException { + ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); + ITextFileBuffer buffer = bufferManager.getTextFileBuffer(document); + if (buffer != null) { + return getContentTypes(buffer); + } + return null; + } + + /** + * Returns the content types from the given {@link ITextFileBuffer}. + * + * @param buffer + * @return the content types from the given {@link ITextFileBuffer}. + * @throws CoreException + */ + private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws CoreException { + try { + String fileName = buffer.getFileStore().getName(); + Collection contentTypes = new LinkedHashSet<>(); + IContentType bufferContentType = buffer.getContentType(); + if (bufferContentType != null) { + contentTypes.add(bufferContentType); + } + if (buffer.isDirty()) { + // Buffer is dirty (content of the filesystem is not synch with + // the editor content), use IDocument content. + try (InputStream input = new DocumentInputStream(buffer.getDocument())){ + IContentType[] contentTypesForInput = Platform.getContentTypeManager().findContentTypesFor(input, fileName); + if (contentTypesForInput != null) { + contentTypes.addAll(Arrays.asList(contentTypesForInput)); + return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new)); + } + } + } + + // Buffer is synchronized with filesystem content + try (InputStream contents = getContents(buffer)){ + contentTypes.addAll(Arrays.asList(Platform.getContentTypeManager().findContentTypesFor(contents, fileName))); + return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new)); + } catch (Throwable e) { + return null; + } + } catch (IOException x) { + x.printStackTrace(); + return null; + } + } + + /** + * Returns the content of the given buffer. + * + * @param buffer + * @return the content of the given buffer. + * @throws CoreException + */ + private static InputStream getContents(ITextFileBuffer buffer) throws CoreException { + IPath path = buffer.getLocation(); + if (path != null) { + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IFile file = workspaceRoot.getFile(path); + if (file.exists() && buffer.isSynchronized()) { + return file.getContents(); + } + } + return buffer.getFileStore().openInputStream(EFS.NONE, null); + } + + // ------------------------- Find content types from FileBuffers + + /** + * Find the content types from the given {@link IDocument} by using + * {@link IEditorInput} and null otherwise. + * + * @param document + * @return the content types from the given {@link IDocument} by using + * {@link IEditorInput} and null otherwise. + */ + private static ContentTypeInfo findContentTypesFromEditorInput(IDocument document) { + IEditorInput editorInput = getEditorInput(document); + if (editorInput != null) { + if (editorInput instanceof IStorageEditorInput) { + InputStream input = null; + try { + IStorage storage = ((IStorageEditorInput) editorInput).getStorage(); + String fileName = storage.getName(); + input = storage.getContents(); + return new ContentTypeInfo(fileName, + Platform.getContentTypeManager().findContentTypesFor(input, fileName)); + } catch (Exception e) { + return null; + } finally { + try { + if (input != null) + input.close(); + } catch (IOException x) { + } + } + } else { + // TODO: manage other type of IEditorInput + } + } + return null; + } + + /** + * Returns the {@link IEditorInput} from the given document and null otherwise. + * + * @param document + * @return the {@link IEditorInput} from the given document and null otherwise. + */ + private static IEditorInput getEditorInput(IDocument document) { + try { + // This utilities class is very ugly, I have not found a clean mean + // to retrieve the IEditorInput linked to a document. + // Here the strategy to retrieve the IEditorInput: + + // AbstractDocumentProvider#ElementInfo add a IDocumentListener to + // the document. + // ElementInfo contains a fElement which is the IEditorInput (like + // ISorageEditorInput, see StorageDocumentProvider) + + // get list of IDocumentListener + ListenerList listeners = ClassHelper.getFieldValue(document, "fDocumentListeners"); + if (listeners != null) { + // Get AbstractDocumentProvider#ElementInfo + Object[] l = listeners.getListeners(); + for (int i = 0; i < l.length; i++) { + Object /* AbstractDocumentProvider#ElementInfo */ info = l[i]; + try { + /* The element for which the info is stored */ + Object input = ClassHelper.getFieldValue(info, "fElement"); + if (input instanceof IEditorInput) { + return (IEditorInput) input; + } + } catch (Exception e) { + + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeInfo.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeInfo.java index 0923bccad..d3cdcbd63 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeInfo.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeInfo.java @@ -9,30 +9,30 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.utils; - -import org.eclipse.core.runtime.content.IContentType; - -/** - * - * @author azerr - * - */ -public class ContentTypeInfo { - - private final String fileName; - private final IContentType[] contentTypes; - - public ContentTypeInfo(String fileName, IContentType[] contentTypes) { - this.fileName = fileName; - this.contentTypes = contentTypes; - } - - public String getFileName() { - return fileName; - } - - public IContentType[] getContentTypes() { - return contentTypes; - } -} +package org.eclipse.tm4e.ui.utils; + +import org.eclipse.core.runtime.content.IContentType; + +/** + * + * @author azerr + * + */ +public class ContentTypeInfo { + + private final String fileName; + private final IContentType[] contentTypes; + + public ContentTypeInfo(String fileName, IContentType[] contentTypes) { + this.fileName = fileName; + this.contentTypes = contentTypes; + } + + public String getFileName() { + return fileName; + } + + public IContentType[] getContentTypes() { + return contentTypes; + } +} diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/PreferenceUtils.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/PreferenceUtils.java index 072449a77..925f1f0bb 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/PreferenceUtils.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/PreferenceUtils.java @@ -9,57 +9,57 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.utils; - -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.tm4e.ui.TMUIPlugin; -import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; - -public class PreferenceUtils { - - private static final String E4_CSS_PREFERENCE_NAME = "org.eclipse.e4.ui.css.swt.theme"; //$NON-NLS-1$ - private static final String EDITORS_PREFERENCE_NAME = "org.eclipse.ui.editors"; //$NON-NLS-1$ - - private PreferenceUtils() { - } - - /** - * Get e4 preferences store - * - * @return preferences store - */ - public static IEclipsePreferences getE4PreferenceStore() { - return InstanceScope.INSTANCE.getNode(E4_CSS_PREFERENCE_NAME); - } - - /** - * Get Id of the current eclipse theme - * - * @return themeIf of the current eclipse theme - */ - public static String getE4PreferenceCSSThemeId() { - IEclipsePreferences preferences = getE4PreferenceStore(); - return preferences != null ? preferences.get(PreferenceConstants.E4_THEME_ID, null) : null; - } - - /** - * Get editors preferences store - * - * @return preferences store - */ - public static IEclipsePreferences getEditorsPreferenceStore() { - return InstanceScope.INSTANCE.getNode(EDITORS_PREFERENCE_NAME); - } - - /** - * Get TM4E preferences store - * - * @return preferences store - */ - public static IPreferenceStore getTM4EPreferencesStore() { - return TMUIPlugin.getDefault().getPreferenceStore(); - - } -} +package org.eclipse.tm4e.ui.utils; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; + +public class PreferenceUtils { + + private static final String E4_CSS_PREFERENCE_NAME = "org.eclipse.e4.ui.css.swt.theme"; //$NON-NLS-1$ + private static final String EDITORS_PREFERENCE_NAME = "org.eclipse.ui.editors"; //$NON-NLS-1$ + + private PreferenceUtils() { + } + + /** + * Get e4 preferences store + * + * @return preferences store + */ + public static IEclipsePreferences getE4PreferenceStore() { + return InstanceScope.INSTANCE.getNode(E4_CSS_PREFERENCE_NAME); + } + + /** + * Get Id of the current eclipse theme + * + * @return themeIf of the current eclipse theme + */ + public static String getE4PreferenceCSSThemeId() { + IEclipsePreferences preferences = getE4PreferenceStore(); + return preferences != null ? preferences.get(PreferenceConstants.E4_THEME_ID, null) : null; + } + + /** + * Get editors preferences store + * + * @return preferences store + */ + public static IEclipsePreferences getEditorsPreferenceStore() { + return InstanceScope.INSTANCE.getNode(EDITORS_PREFERENCE_NAME); + } + + /** + * Get TM4E preferences store + * + * @return preferences store + */ + public static IPreferenceStore getTM4EPreferencesStore() { + return TMUIPlugin.getDefault().getPreferenceStore(); + + } +} From 1ee8f06318cfed42c73fd4c2d21907acc1fee575 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 5 Dec 2021 21:20:58 +0100 Subject: [PATCH 017/202] add .gitattributes --- .gitattributes | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..6bb66b660 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,45 @@ +# based on https://github.com/alexkaratarakis/gitattributes/ + +# Handle line endings automatically for files detected as text +# and leave all files detected as binary untouched. +* text=auto + +# +# The above will handle all files NOT found below +# +# These files are text and should be normalized (Convert crlf => lf) +*.gitattributes text +.gitignore text +*.bash text eol=lf +*.bat text eol=crlf +*.cmd text eol=crlf +*.css text diff=css +*.exsd text +*.htm text diff=html +*.html text diff=html +*.ini text +*.md text diff=markdown +*.java text diff=java +*.js text +*.json text +*.properties text +*.sh text +*.tmLanguage text +*.ts text +*.txt text +*.xsd text +*.xml text +*.yaml text +*.yml text +MANIFEST.MF text +Dockerfile text eol=lf +Jenkinsfile text +LICENSE text + +# These files are binary and should be left untouched +# (binary is a macro for -text -diff) +*.gif binary +*.ico binary +*.jpeg binary +*.jpg binary +*.png binary From d8e2c87d6684a3b20ec2dac54cf28f0189cf906d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Dec 2021 11:24:16 +0000 Subject: [PATCH 018/202] Bump wagon-ftp from 3.4.3 to 3.5.1 Bumps wagon-ftp from 3.4.3 to 3.5.1. --- updated-dependencies: - dependency-name: org.apache.maven.wagon:wagon-ftp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- org.eclipse.tm4e.repository/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.repository/pom.xml b/org.eclipse.tm4e.repository/pom.xml index d903e9b9c..a47d1ff4a 100644 --- a/org.eclipse.tm4e.repository/pom.xml +++ b/org.eclipse.tm4e.repository/pom.xml @@ -13,7 +13,7 @@ org.apache.maven.wagon wagon-ftp - 3.4.3 + 3.5.1 From 5605045ebf2784777c04b3aa47ea693f453a781e Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Thu, 6 Jan 2022 23:23:03 +0100 Subject: [PATCH 019/202] Fix comment actions * Fix condition in plugin.xml and handler to allow working with multipage editors * Failback to multiple line blocks comment for line comments when only block comments are available. This makes comment working for m2e pom.xml editor --- .../META-INF/MANIFEST.MF | 2 +- ...language-configuration-no-linecomment.json | 5 ++ .../plugin.xml | 11 ++++ .../tests/TestComment.java | 51 +++++++++++++++ ...asLanguageConfigurationPropertyTester.java | 5 +- .../ToggleLineCommentHandler.java | 65 +++++++++++++++---- target-platform/tm4e-target.target | 2 +- 7 files changed, 123 insertions(+), 18 deletions(-) create mode 100644 org.eclipse.tm4e.languageconfiguration.tests/language-configurations/language-configuration-no-linecomment.json create mode 100644 org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java diff --git a/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF b/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF index 91da0b012..494383737 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Require-Bundle: org.junit;bundle-version="4.12.0", org.eclipse.ui.workbench, org.eclipse.ui.editors, org.eclipse.ui.workbench.texteditor, - org.eclipse.jface.text, + org.eclipse.jface.text;bundle-version="3.19", org.eclipse.ui Bundle-ActivationPolicy: lazy Import-Package: org.junit.jupiter.api diff --git a/org.eclipse.tm4e.languageconfiguration.tests/language-configurations/language-configuration-no-linecomment.json b/org.eclipse.tm4e.languageconfiguration.tests/language-configurations/language-configuration-no-linecomment.json new file mode 100644 index 000000000..efcf41973 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration.tests/language-configurations/language-configuration-no-linecomment.json @@ -0,0 +1,5 @@ +{ + "comments": { + "blockComment": [ "/*", "*/" ] + } +} diff --git a/org.eclipse.tm4e.languageconfiguration.tests/plugin.xml b/org.eclipse.tm4e.languageconfiguration.tests/plugin.xml index 177332244..f1356e3d2 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/plugin.xml +++ b/org.eclipse.tm4e.languageconfiguration.tests/plugin.xml @@ -10,6 +10,13 @@ name="Test Language Configuration content-type" priority="normal"> + + @@ -17,6 +24,10 @@ contentTypeId="org.eclipse.tm4e.languageconfiguration.tests.content-type1" path="language-configurations/language-configuration.json"> + + diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java b/org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java new file mode 100644 index 000000000..b441dea08 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2021 Red Hat Inc. and others. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.tm4e.languageconfiguration.tests; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.texteditor.ITextEditor; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +public class TestComment { + + @AfterEach + public void tearDown() throws Exception { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false); + for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + p.delete(true, null); + } + } + + @Test + public void testIndentOnNewLine() throws Exception { + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis()); + p.create(null); + p.open(null); + IFile file = p.getFile("whatever.noLineComment"); + file.create(new ByteArrayInputStream("a\nb\nc".getBytes()), true, null); + ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, "org.eclipse.ui.genericeditor.GenericEditor"); + IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); + IHandlerService service = PlatformUI.getWorkbench().getService(IHandlerService.class); + editor.getSelectionProvider().setSelection(new TextSelection(0, 5)); + service.executeCommand("org.eclipse.tm4e.languageconfiguration.togglelinecommentcommand", null); + assertEquals("/*a*/\n/*b*/\n/*c*/", doc.get()); + } +} diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java index dd68234f8..5acb00080 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java @@ -12,6 +12,7 @@ package org.eclipse.tm4e.languageconfiguration; import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.text.IDocument; @@ -26,10 +27,10 @@ public class HasLanguageConfigurationPropertyTester extends PropertyTester { @Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (!(receiver instanceof ITextEditor)) { + ITextEditor editor = Adapters.adapt(receiver, ITextEditor.class); + if (editor == null) { return false; } - ITextEditor editor = (ITextEditor) receiver; IEditorInput input = editor.getEditorInput(); IDocumentProvider docProvider = editor.getDocumentProvider(); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java index 5d1a91110..823c4c20a 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java @@ -11,14 +11,19 @@ */ package org.eclipse.tm4e.languageconfiguration; +import java.util.HashSet; +import java.util.Set; + import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IMultiTextSelection; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRewriteTarget; import org.eclipse.jface.text.ITextSelection; @@ -45,10 +50,10 @@ public class ToggleLineCommentHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart part = HandlerUtil.getActiveEditor(event); - if (!(part instanceof ITextEditor)) { + ITextEditor editor = Adapters.adapt(part, ITextEditor.class); + if (editor == null) { return null; } - ITextEditor editor = (ITextEditor) part; ISelection selection = editor.getSelectionProvider().getSelection(); if (!(selection instanceof ITextSelection)) { return null; @@ -87,8 +92,18 @@ public Object execute(ExecutionEvent event) throws ExecutionException { target.beginCompoundChange(); } try { - if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && commentSupport.getLineComment() != null) { - updateLineComment(document, textSelection, commentSupport.getLineComment(), editor); + if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId())) { + if (commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty()) { + updateLineComment(document, textSelection, commentSupport.getLineComment(), editor); + } else if (commentSupport.getBlockComment() != null) { + Set lines = computeLines(textSelection, document); + for (int line : lines) { + int lineOffset = document.getLineOffset(line); + int lineLength = document.getLineLength(line); + ITextSelection range = new TextSelection(lineOffset, line == document.getNumberOfLines() - 1 ? lineLength : lineLength - 1); + toggleBlockComment(document, range, commentSupport, editor); + } + } } else { IRegion existingBlock = getBlockComment(document, textSelection, commentSupport); if (ADD_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock == null) { @@ -108,6 +123,34 @@ public Object execute(ExecutionEvent event) throws ExecutionException { return null; } + private Set computeLines(ITextSelection textSelection, IDocument document) throws BadLocationException { + IRegion[] regions = textSelection instanceof IMultiTextSelection ? + ((IMultiTextSelection)textSelection).getRegions() : + new IRegion[] { new Region(textSelection.getOffset(), textSelection.getLength()) }; + Set lines = new HashSet<>(); + for (IRegion region : regions) { + int lineFrom = document.getLineOfOffset(region.getOffset()); + int lineTo = document.getLineOfOffset(region.getOffset() + region.getLength()); + for (int line = lineFrom; line <= lineTo; line++) { + lines.add(line); + } + } + return lines; + } + + private void toggleBlockComment(IDocument document, ITextSelection textSelection, CommentSupport commentSupport, ITextEditor editor) throws BadLocationException { + IRegion existingBlock = getBlockComment(document, textSelection, commentSupport); + CharacterPair blockComment = commentSupport.getBlockComment(); + if (blockComment == null) { + return; + } + if (existingBlock == null) { + addBlockComment(document, textSelection, blockComment, editor); + } else { + removeBlockComment(document, textSelection, existingBlock, blockComment, editor); + } + } + /** * Returns true if comment support is valid according the command to do and * false otherwise. @@ -118,9 +161,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException { * false otherwise. */ private boolean isValid(CommentSupport commentSupport, Command command) { - if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId())) { - // check if line comment is valid. - return commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty(); + if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty()) { + return true; } // check if block comment is valid CharacterPair characterPair = commentSupport.getBlockComment(); @@ -240,16 +282,11 @@ private void removeLineComments(IDocument document, ITextSelection selection, St private void addLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor) throws BadLocationException { - int lineNumber = selection.getStartLine(); - int endLineNumber = selection.getEndLine(); int insertedChars = 0; - while (lineNumber <= endLineNumber) { + for (int lineNumber : computeLines(selection, document)) { document.replace(document.getLineOffset(lineNumber), 0, comment); - if (lineNumber != endLineNumber) { - insertedChars += comment.length(); - } - lineNumber++; + insertedChars += comment.length(); } ITextSelection newSelection = new TextSelection(selection.getOffset() + comment.length(), selection.getLength() + insertedChars); diff --git a/target-platform/tm4e-target.target b/target-platform/tm4e-target.target index 6b50e5689..7f5441bb8 100644 --- a/target-platform/tm4e-target.target +++ b/target-platform/tm4e-target.target @@ -21,7 +21,7 @@ - + From 62df8d900116272a94b92252fb179897fb450a1f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Jan 2022 11:24:30 +0000 Subject: [PATCH 020/202] Bump maven-compiler-plugin from 3.8.1 to 3.9.0 Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.8.1 to 3.9.0. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.8.1...maven-compiler-plugin-3.9.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 93a59b253..1987422df 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.9.0 11 11 From 31eb35752034ac880d5ff4a048ce0bb0baaa7f8e Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 14 Jan 2022 17:35:08 +0100 Subject: [PATCH 021/202] Fixed wrong condition (it was inverted accidentally I guess) --- .../main/java/org/eclipse/tm4e/core/grammar/StackElement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java index 72a5993d8..4b2250b23 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java @@ -88,7 +88,7 @@ private static boolean structuralEquals(StackElement a, StackElement b) { if (a == null || b == null) { return false; } - return a.depth == b.depth && a.ruleId == b.ruleId && !Objects.equals(a.endRule, b.endRule) && structuralEquals(a.parent, b.parent); + return a.depth == b.depth && a.ruleId == b.ruleId && Objects.equals(a.endRule, b.endRule) && structuralEquals(a.parent, b.parent); } @Override From a544710aae00a7e903dd19a48542e08d6d697349 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 21 Jan 2022 11:20:53 +0000 Subject: [PATCH 022/202] Bump tycho-version from 2.5.0 to 2.6.0 Bumps `tycho-version` from 2.5.0 to 2.6.0. Updates `tycho-buildtimestamp-jgit` from 2.5.0 to 2.6.0 Updates `tycho-sourceref-jgit` from 2.5.0 to 2.6.0 Updates `tycho-maven-plugin` from 2.5.0 to 2.6.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.5.0...tycho-2.6.0) Updates `target-platform-configuration` from 2.5.0 to 2.6.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.5.0...tycho-2.6.0) Updates `tycho-source-plugin` from 2.5.0 to 2.6.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.5.0...tycho-2.6.0) Updates `tycho-p2-plugin` from 2.5.0 to 2.6.0 Updates `tycho-packaging-plugin` from 2.5.0 to 2.6.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.5.0...tycho-2.6.0) Updates `tycho-p2-extras-plugin` from 2.5.0 to 2.6.0 Updates `tycho-surefire-plugin` from 2.5.0 to 2.6.0 --- updated-dependencies: - dependency-name: org.eclipse.tycho.extras:tycho-buildtimestamp-jgit dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho.extras:tycho-sourceref-jgit dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:target-platform-configuration dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-source-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-p2-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-packaging-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho.extras:tycho-p2-extras-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1987422df..a723c7139 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ UTF-8 - 2.5.0 + 2.6.0 ../target/jacoco.exec scm:git:https://github.com/eclipse/tm4e.git true From 3591385051f082fddf74fe7ea4709ee682515d87 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Fri, 11 Feb 2022 18:44:43 +0200 Subject: [PATCH 023/202] Use gson 2.8.9 as it's in latest Orbit S-build --- target-platform/tm4e-target.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target-platform/tm4e-target.target b/target-platform/tm4e-target.target index 7f5441bb8..5165b79a3 100644 --- a/target-platform/tm4e-target.target +++ b/target-platform/tm4e-target.target @@ -7,7 +7,7 @@ - + From e4c3db21a4a4cda3646abc51498ab03c5b1fa0d4 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Fri, 11 Feb 2022 19:00:42 +0200 Subject: [PATCH 024/202] Make more JUnit 5 in TMinGenericEditorTest --- .../tm4e/ui/TMinGenericEditorTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java index cae38c362..5cccad572 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015, 2021 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -35,7 +35,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class TMinGenericEditorTest { +class TMinGenericEditorTest { private IEditorDescriptor editorDescriptor; private File f; @@ -77,11 +77,11 @@ public void tearDown() { } @Test - public void testTMHighlightInGenericEditor() throws IOException, PartInitException { + void testTMHighlightInGenericEditor() throws IOException, PartInitException { f = File.createTempFile("test" + System.currentTimeMillis(), ".ts"); - FileOutputStream fileOutputStream = new FileOutputStream(f); - fileOutputStream.write("let a = '';\nlet b = 10;\nlet c = true;".getBytes()); - fileOutputStream.close(); + try (FileOutputStream fileOutputStream = new FileOutputStream(f)) { + fileOutputStream.write("let a = '';\nlet b = 10;\nlet c = true;".getBytes()); + } f.deleteOnExit(); editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), f.toURI(), editorDescriptor.getId(), true); @@ -95,11 +95,11 @@ protected boolean condition() { } @Test - public void testTMHighlightInGenericEditorEdit() throws IOException, PartInitException { + void testTMHighlightInGenericEditorEdit() throws IOException, PartInitException { f = File.createTempFile("test" + System.currentTimeMillis(), ".ts"); - FileOutputStream fileOutputStream = new FileOutputStream(f); - fileOutputStream.write("let a = '';".getBytes()); - fileOutputStream.close(); + try (FileOutputStream fileOutputStream = new FileOutputStream(f)) { + fileOutputStream.write("let a = '';".getBytes()); + } f.deleteOnExit(); editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), f.toURI(), editorDescriptor.getId(), true); @@ -120,7 +120,7 @@ protected boolean condition() { } @Test - public void testReconcilierStartsAndDisposeThread() throws Exception { + void testReconcilierStartsAndDisposeThread() throws Exception { testTMHighlightInGenericEditor(); editor.getEditorSite().getPage().closeEditor(editor, false); Thread.sleep(500); // give time to dispose From bfe5debad8748fe0a7a55550731390305145e426 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Feb 2022 17:21:07 +0000 Subject: [PATCH 025/202] Bump maven-javadoc-plugin from 3.3.1 to 3.3.2 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.1 to 3.3.2. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.1...maven-javadoc-plugin-3.3.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a723c7139..39b663e44 100644 --- a/pom.xml +++ b/pom.xml @@ -205,7 +205,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.1 + 3.3.2 true From b33a83b9a86989865991f2ff4d370d35eb3c6229 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Fri, 11 Feb 2022 19:37:54 +0200 Subject: [PATCH 026/202] Junit5-ify ui.tests --- .../java/org/eclipse/tm4e/ui/RegistryTest.java | 6 +++--- .../org/eclipse/tm4e/ui/TMinGenericEditorTest.java | 7 +++---- .../ui/internal/model/DocumentLineListTest.java | 4 ++-- .../ui/internal/model/DocumentTMModelTest.java | 4 ++-- .../java/org/eclipse/tm4e/ui/text/TMEditor.java | 3 +-- .../TMPresentationReconcilerTypeScriptTest.java | 14 +++++++------- .../eclipse/tm4e/ui/themes/TMEditorColorTest.java | 10 +++++----- .../eclipse/tm4e/ui/themes/ThemeManagerTest.java | 8 ++++---- 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/RegistryTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/RegistryTest.java index 87fbde3c1..cbc7efe43 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/RegistryTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/RegistryTest.java @@ -18,17 +18,17 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class RegistryTest { +class RegistryTest { @Test - public void testGrammarRegistered() { + void testGrammarRegistered() { IContentType contentType = Platform.getContentTypeManager().getContentType("org.eclipse.tm4e.ui.tests.testContentType"); IGrammar grammar = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(new IContentType[] { contentType }); Assertions.assertNotNull(grammar); } @Test - public void testThemeAppliesToSubtypes() { + void testThemeAppliesToSubtypes() { IContentType contentType = Platform.getContentTypeManager().getContentType("org.eclipse.tm4e.ui.tests.testContentType.child"); IGrammar grammar = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(new IContentType[] { contentType }); Assertions.assertNotNull(grammar); diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java index 5cccad572..13326d6e7 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2021 Angelo ZERR and others. + * Copyright (c) 2015, 2022 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,13 +11,12 @@ */ package org.eclipse.tm4e.ui; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -124,7 +123,7 @@ void testReconcilierStartsAndDisposeThread() throws Exception { testTMHighlightInGenericEditor(); editor.getEditorSite().getPage().closeEditor(editor, false); Thread.sleep(500); // give time to dispose - assertEquals(Collections.emptySet(), getTM4EThreads()); + assertTrue(getTM4EThreads().isEmpty()); } } diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java index b60b9f800..f0e81dd51 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java @@ -17,10 +17,10 @@ import org.eclipse.jface.text.Document; import org.junit.jupiter.api.Test; -public class DocumentLineListTest { +class DocumentLineListTest { @Test - public void testMultiLineChange() { + void testMultiLineChange() { Document document = new Document(); DocumentLineList lineList = new DocumentLineList(document); diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java index e8d9e34b1..6a3c01c6e 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java @@ -15,10 +15,10 @@ import org.eclipse.tm4e.core.registry.Registry; import org.junit.jupiter.api.Test; -public class DocumentTMModelTest { +class DocumentTMModelTest { @Test - public void testMultiLineChange() throws Exception { + void testMultiLineChange() throws Exception { Document document = new Document(); TMDocumentModel model = new TMDocumentModel(document); try { diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java index 9e0e37c8a..e5b0b6691 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import java.util.List; -import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.TextViewer; import org.eclipse.swt.SWT; @@ -66,7 +65,7 @@ private void setAndExecute(String text) { collector.setCommand(command); } - public void replace(int pos, int length, String text) throws BadLocationException { + public void replace(int pos, int length, String text) { commands.add(new DocumentReplaceCommand(pos, length, text, document)); } diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java index 342f6e89d..fe7827862 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java @@ -28,7 +28,7 @@ public class TMPresentationReconcilerTypeScriptTest { @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") @Test - public void colorizeTypescript() throws Exception { + void colorizeTypescript() throws Exception { TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); List commands = editor.execute(); @@ -68,7 +68,7 @@ public void colorizeTypescript() throws Exception { @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") @Test - public void colorizeTypescriptWithInvalidate1() throws Exception { + void colorizeTypescriptWithInvalidate1() throws Exception { TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); editor.invalidateTextPresentation(0, 3); @@ -117,7 +117,7 @@ public void colorizeTypescriptWithInvalidate1() throws Exception { @Disabled @Test - public void colorizeTypescriptWithInvalidate2() throws Exception { + void colorizeTypescriptWithInvalidate2() throws Exception { TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); editor.invalidateTextPresentation(0, 2); @@ -166,7 +166,7 @@ public void colorizeTypescriptWithInvalidate2() throws Exception { @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") @Test - public void colorizeTypescriptWithInvalidate3() throws Exception { + void colorizeTypescriptWithInvalidate3() throws Exception { TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); editor.invalidateTextPresentation(1, 2); @@ -215,7 +215,7 @@ public void colorizeTypescriptWithInvalidate3() throws Exception { @Disabled @Test - public void colorizeTypescriptWithInvalidate4() throws Exception { + void colorizeTypescriptWithInvalidate4() throws Exception { TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); editor.invalidateTextPresentation(1, 1); @@ -264,7 +264,7 @@ public void colorizeTypescriptWithInvalidate4() throws Exception { @Disabled @Test - public void colorizeTypescriptWithInvalidate8() throws Exception { + void colorizeTypescriptWithInvalidate8() throws Exception { TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "let a = '';\nlet b = 10;\nlet c = true;"); editor.invalidateTextPresentation(1, 8); @@ -313,7 +313,7 @@ public void colorizeTypescriptWithInvalidate8() throws Exception { @Disabled ("Remove this annotation when org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] will be fixed") @Test - public void colorizeTypescriptWithInvalidateAndSeveralLines() throws Exception { + void colorizeTypescriptWithInvalidateAndSeveralLines() throws Exception { TMEditor editor = new TMEditor(getGrammar(), getTokenProvider(), "a\r\n\r\nb"); editor.invalidateTextPresentation(0, 6); diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java index e29454ee9..77b00fb93 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java @@ -35,7 +35,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class TMEditorColorTest implements ThemeIdConstants { +class TMEditorColorTest implements ThemeIdConstants { private static final String EDITOR_CURRENTLINE_HIGHLIGHT = "currentLineColor"; @@ -65,7 +65,7 @@ public void tearDown() { } @Test - public void systemDefaultEditorColorTest() throws IOException, PartInitException { + void systemDefaultEditorColorTest() throws IOException, PartInitException { f = File.createTempFile("test" + System.currentTimeMillis(), ".ts"); editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), f.toURI(), @@ -75,7 +75,7 @@ public void systemDefaultEditorColorTest() throws IOException, PartInitException String themeId = manager.getDefaultTheme().getId(); ITheme theme = manager.getThemeById(themeId); - assertEquals(themeId, SolarizedLight, "Default light theme isn't set"); + assertEquals(SolarizedLight, themeId, "Default light theme isn't set"); assertEquals(theme.getEditorBackground(), styledText.getBackground(), "Background colors isn't equals"); assertEquals(theme.getEditorForeground(), styledText.getForeground(), "Foreground colors isn't equals"); assertNull(theme.getEditorSelectionBackground(), "System default selection background should be null"); @@ -89,7 +89,7 @@ public void systemDefaultEditorColorTest() throws IOException, PartInitException } @Test - public void userDefinedEditorColorTest() throws Exception { + void userDefinedEditorColorTest() throws Exception { String testColorVal = "255,128,0"; Color testColor = new Color(Display.getCurrent(), 255, 128, 0); IPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.editors"); @@ -108,7 +108,7 @@ public void userDefinedEditorColorTest() throws Exception { String themeId = manager.getDefaultTheme().getId(); ITheme theme = manager.getThemeById(themeId); - assertEquals(themeId, SolarizedLight, "Default light theme isn't set"); + assertEquals(SolarizedLight, themeId, "Default light theme isn't set"); assertEquals(styledText.getBackground(), testColor, "Background color should be user defined"); assertEquals(theme.getEditorForeground(), styledText.getForeground(), "Foreground colors should be "); diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java index 7b41dd3de..d4af15ea7 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java @@ -20,7 +20,7 @@ * Test for theme manager. * */ -public class ThemeManagerTest implements ThemeIdConstants { +class ThemeManagerTest implements ThemeIdConstants { private IThemeManager manager; @@ -37,7 +37,7 @@ public void init() { @Test - public void themes() { + void themes() { // All themes ITheme[] themes = manager.getThemes(); assertNotNull(themes); @@ -45,7 +45,7 @@ public void themes() { } @Test - public void defaultThemeAssociation() { + void defaultThemeAssociation() { // Default theme ITheme theme = manager.getDefaultTheme(); assertNotNull(theme); @@ -53,7 +53,7 @@ public void defaultThemeAssociation() { } @Test - public void darkThemes() { + void darkThemes() { // All themes for Dark E4 CSS Theme ITheme[] darkThemes = manager.getThemes(true); assertNotNull(darkThemes); From dc9bec757cfdaebc9089aa73fab32a9844fd6e1d Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Fri, 11 Feb 2022 19:45:30 +0200 Subject: [PATCH 027/202] Add licensecheck verification. --- .github/workflows/licensecheck.yml | 35 ++++++++++++++++++++++++++++++ pom.xml | 7 ++++++ 2 files changed, 42 insertions(+) create mode 100644 .github/workflows/licensecheck.yml diff --git a/.github/workflows/licensecheck.yml b/.github/workflows/licensecheck.yml new file mode 100644 index 000000000..955428c45 --- /dev/null +++ b/.github/workflows/licensecheck.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: License check + +on: + push: + branches: + - '*' + pull_request: + branches: + - '*' + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: License check + run: | + mvn -U -V -e -B -ntp org.eclipse.dash:license-tool-plugin:license-check --file pom.xml -Ddash.fail=true diff --git a/pom.xml b/pom.xml index 39b663e44..f0d42f239 100644 --- a/pom.xml +++ b/pom.xml @@ -287,6 +287,13 @@ true + + dash-licenses-snapshots + https://repo.eclipse.org/content/repositories/dash-licenses-snapshots/ + + true + + From be6bd6eaf44f42772445a9dca49be41fca4b58b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 11:33:18 +0000 Subject: [PATCH 028/202] Bump maven-compiler-plugin from 3.9.0 to 3.10.0 Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.9.0 to 3.10.0. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.9.0...maven-compiler-plugin-3.10.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f0d42f239..6e65a07d3 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.9.0 + 3.10.0 11 11 From c081ad04b3aed0691e39944b5ec3b62b7ddb5c0e Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 21 Feb 2022 16:57:19 +0100 Subject: [PATCH 029/202] Use try-with-resources with JsonReader --- .../internal/parser/json/JSONPListParser.java | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java index 9126bbdb6..00bb3f1f7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java @@ -30,57 +30,57 @@ public JSONPListParser(boolean theme) { public T parse(InputStream contents) throws Exception { PList pList = new PList<>(theme); - JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8)); - // reader.setLenient(true); - boolean parsing = true; - while (parsing) { - JsonToken nextToken = reader.peek(); - switch (nextToken) { - case BEGIN_ARRAY: - pList.startElement(null, "array", null, null); - reader.beginArray(); - break; - case END_ARRAY: - pList.endElement(null, "array", null); - reader.endArray(); - break; - case BEGIN_OBJECT: - pList.startElement(null, "dict", null, null); - reader.beginObject(); - break; - case END_OBJECT: - pList.endElement(null, "dict", null); - reader.endObject(); - break; - case NAME: - String lastName = reader.nextName(); - pList.startElement(null, "key", null, null); - pList.characters(lastName.toCharArray(), 0, lastName.length()); - pList.endElement(null, "key", null); - break; - case NULL: - reader.nextNull(); - break; - case BOOLEAN: - reader.nextBoolean(); - break; - case NUMBER: - reader.nextLong(); - break; - case STRING: - String value = reader.nextString(); - pList.startElement(null, "string", null, null); - pList.characters(value.toCharArray(), 0, value.length()); - pList.endElement(null, "string", null); - break; - case END_DOCUMENT: - parsing = false; - break; - default: - break; + try (JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8))) { + // reader.setLenient(true); + boolean parsing = true; + while (parsing) { + JsonToken nextToken = reader.peek(); + switch (nextToken) { + case BEGIN_ARRAY: + pList.startElement(null, "array", null, null); + reader.beginArray(); + break; + case END_ARRAY: + pList.endElement(null, "array", null); + reader.endArray(); + break; + case BEGIN_OBJECT: + pList.startElement(null, "dict", null, null); + reader.beginObject(); + break; + case END_OBJECT: + pList.endElement(null, "dict", null); + reader.endObject(); + break; + case NAME: + String lastName = reader.nextName(); + pList.startElement(null, "key", null, null); + pList.characters(lastName.toCharArray(), 0, lastName.length()); + pList.endElement(null, "key", null); + break; + case NULL: + reader.nextNull(); + break; + case BOOLEAN: + reader.nextBoolean(); + break; + case NUMBER: + reader.nextLong(); + break; + case STRING: + String value = reader.nextString(); + pList.startElement(null, "string", null, null); + pList.characters(value.toCharArray(), 0, value.length()); + pList.endElement(null, "string", null); + break; + case END_DOCUMENT: + parsing = false; + break; + default: + break; + } } } - reader.close(); return pList.getResult(); } From cf7385e2e810f145ffe688a7a9e115a3edca6c49 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 21 Feb 2022 17:08:38 +0100 Subject: [PATCH 030/202] Replace usage of deprecated Class#newInstance() method --- .../tm4e/core/internal/css/SACParserFactoryImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java index 72e4b301b..4cc60ec01 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.tm4e.core.internal.css; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; @@ -47,7 +48,11 @@ public Parser makeParser(String name) throws ClassNotFoundException, IllegalAcce String classNameParser = parsers.get(name); if (classNameParser != null) { Class classParser = super.getClass().getClassLoader().loadClass(classNameParser); - return (Parser) classParser.newInstance(); + try { + return (Parser) classParser.getDeclaredConstructor().newInstance(); + } catch (InvocationTargetException|NoSuchMethodException ex) { + throw (InstantiationException)((new InstantiationException()).initCause(ex)); + } } throw new IllegalAccessException("SAC parser with name=" + name + " was not registered into SAC parser factory."); From 968acfe77ea30e0bffe295d01b883b8ede653712 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 21 Feb 2022 17:09:44 +0100 Subject: [PATCH 031/202] Remove redundant super interface --- .../java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java index 7a3bbe3a9..72ab8e148 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java @@ -13,12 +13,11 @@ import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import org.w3c.dom.css.Counter; import org.w3c.dom.css.RGBColor; import org.w3c.dom.css.Rect; -public abstract class CSSValueImpl implements CSSPrimitiveValue, CSSValue { +public abstract class CSSValueImpl implements CSSPrimitiveValue { // W3C CSSValue API methods From 9b79be4154ae198ab8de1f2ddc586792a01ed0b4 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 21 Feb 2022 17:12:07 +0100 Subject: [PATCH 032/202] add missing hashCode() method --- .../tm4e/core/grammar/internal/RawToken.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java index d7eda0a25..be1447b1b 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.grammar.internal; @@ -45,4 +45,13 @@ public boolean equals(Object obj) { } return this.scopes.equals(other.scopes); } + + @Override + public int hashCode() { + final var prime = 31; + var result = 1; + result = prime * result + (scopes == null ? 0 : scopes.hashCode()); + result = prime * result + (value == null ? 0 : value.hashCode()); + return result; + } } From 3d3f6a2814fc2efb313ad635bd83d3782c6c24be Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 21 Feb 2022 17:18:09 +0100 Subject: [PATCH 033/202] Fix potential resource leak --- .../src/main/java/org/eclipse/tm4e/registry/TMResource.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index 8d4f21d52..b5e93ec14 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -79,8 +79,7 @@ public InputStream getInputStream() throws IOException { } protected String getResourceContent() { - try { - InputStream in = this.getInputStream(); + try (InputStream in = this.getInputStream()) { if (in == null) { return null; } From 4142caab6923cf2708b07d4b35a2f0499e1029ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Feb 2022 11:26:05 +0000 Subject: [PATCH 034/202] Bump tycho-version from 2.6.0 to 2.7.0 Bumps `tycho-version` from 2.6.0 to 2.7.0. Updates `tycho-buildtimestamp-jgit` from 2.6.0 to 2.7.0 Updates `tycho-sourceref-jgit` from 2.6.0 to 2.7.0 Updates `tycho-maven-plugin` from 2.6.0 to 2.7.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.6.0...tycho-2.7.0) Updates `target-platform-configuration` from 2.6.0 to 2.7.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.6.0...tycho-2.7.0) Updates `tycho-source-plugin` from 2.6.0 to 2.7.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.6.0...tycho-2.7.0) Updates `tycho-p2-plugin` from 2.6.0 to 2.7.0 Updates `tycho-packaging-plugin` from 2.6.0 to 2.7.0 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.6.0...tycho-2.7.0) Updates `tycho-p2-extras-plugin` from 2.6.0 to 2.7.0 Updates `tycho-surefire-plugin` from 2.6.0 to 2.7.0 --- updated-dependencies: - dependency-name: org.eclipse.tycho.extras:tycho-buildtimestamp-jgit dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho.extras:tycho-sourceref-jgit dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:target-platform-configuration dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-source-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-p2-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-packaging-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho.extras:tycho-p2-extras-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.eclipse.tycho:tycho-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6e65a07d3..7b8dfe03f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ UTF-8 - 2.6.0 + 2.7.0 ../target/jacoco.exec scm:git:https://github.com/eclipse/tm4e.git true From b144034ac44f246564fdc790b7054b7e9d141053 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:22:16 +0000 Subject: [PATCH 035/202] Bump maven-compiler-plugin from 3.10.0 to 3.10.1 Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.0 to 3.10.1. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.0...maven-compiler-plugin-3.10.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7b8dfe03f..62d3128a0 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.0 + 3.10.1 11 11 From dcf7076d4bf9e166d4f1f11daea1be30f555f551 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:22:58 +0000 Subject: [PATCH 036/202] Bump maven-surefire-plugin from 3.0.0-M5 to 3.0.0-M6 Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.0.0-M5 to 3.0.0-M6. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.0.0-M5...surefire-3.0.0-M6) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 62d3128a0..189148a5e 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M5 + 3.0.0-M6 test From af3e5d3886b9eef7f177863b3b993bfd5bc7084b Mon Sep 17 00:00:00 2001 From: Sebastian Thomschke Date: Mon, 4 Apr 2022 19:38:15 +0200 Subject: [PATCH 037/202] Clear snippet preview if none provided When switching from a grammar that provides a snippet to a grammar that does not. The snippet preview is not cleared and still shows the snippet from the unrelated grammar and wrong syntax highlighing is applied. This PR clears the snippet preview text field in case a grammar is selected that does not provide snippets. --- .../tm4e/ui/internal/preferences/GrammarPreferencePage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index a1a1a1412..bc9d281cf 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -301,7 +301,9 @@ private void fillPreview(String scopeName, IThemeAssociation selectedAssociation // Snippet ISnippet[] snippets = snippetManager.getSnippets(scopeName); - if (snippets != null && snippets.length > 0) { + if (snippets == null || snippets.length == 0) { + previewViewer.setText(""); + } else { // TODO: manage list of snippet for the given scope. previewViewer.setText(snippets[0].getContent()); } From e45944efe5a86d9c9e114781fdbad9347562bbab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Apr 2022 11:19:56 +0000 Subject: [PATCH 038/202] Bump jacoco-maven-plugin from 0.8.7 to 0.8.8 Bumps [jacoco-maven-plugin](https://github.com/jacoco/jacoco) from 0.8.7 to 0.8.8. - [Release notes](https://github.com/jacoco/jacoco/releases) - [Commits](https://github.com/jacoco/jacoco/compare/v0.8.7...v0.8.8) --- updated-dependencies: - dependency-name: org.jacoco:jacoco-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 189148a5e..4b611f387 100644 --- a/pom.xml +++ b/pom.xml @@ -213,7 +213,7 @@ org.jacoco jacoco-maven-plugin - 0.8.7 + 0.8.8 prepare-agent From 7bad3536a07f7e469e2b966b096815e645c7f8fa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 11:32:02 +0000 Subject: [PATCH 039/202] Bump tycho-version from 2.7.0 to 2.7.1 Bumps `tycho-version` from 2.7.0 to 2.7.1. Updates `tycho-buildtimestamp-jgit` from 2.7.0 to 2.7.1 Updates `tycho-sourceref-jgit` from 2.7.0 to 2.7.1 Updates `tycho-maven-plugin` from 2.7.0 to 2.7.1 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.0...tycho-2.7.1) Updates `target-platform-configuration` from 2.7.0 to 2.7.1 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.0...tycho-2.7.1) Updates `tycho-source-plugin` from 2.7.0 to 2.7.1 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.0...tycho-2.7.1) Updates `tycho-p2-plugin` from 2.7.0 to 2.7.1 Updates `tycho-packaging-plugin` from 2.7.0 to 2.7.1 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.0...tycho-2.7.1) Updates `tycho-p2-extras-plugin` from 2.7.0 to 2.7.1 Updates `tycho-surefire-plugin` from 2.7.0 to 2.7.1 --- updated-dependencies: - dependency-name: org.eclipse.tycho.extras:tycho-buildtimestamp-jgit dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho.extras:tycho-sourceref-jgit dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:target-platform-configuration dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-source-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-p2-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-packaging-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho.extras:tycho-p2-extras-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4b611f387..54ae4657e 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ UTF-8 - 2.7.0 + 2.7.1 ../target/jacoco.exec scm:git:https://github.com/eclipse/tm4e.git true From 0d22b683284f60949eb30e826a7564d80d8f031e Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 11 Apr 2022 23:59:55 +0200 Subject: [PATCH 040/202] Cleanup JSONPlistParserTest and XMLPlistParserTest - use try-with-resources to fix resource leak - use proper name for test methods - add some assertions to test methods - remove duplicate test plist resources --- .../parser/json/JSONPListParserTest.java | 22 +- .../parser/xml/XMLPlistParserTest.java | 21 +- .../internal/grammar/parser/json/csharp.json | 641 ----- .../grammar/parser/xml/JavaScript.tmLanguage | 2205 ----------------- 4 files changed, 31 insertions(+), 2858 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/json/csharp.json delete mode 100644 org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/xml/JavaScript.tmLanguage diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java index 3fd2f5e4e..70fa76ef9 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java @@ -1,27 +1,37 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.grammar.parser.json; +import static org.junit.jupiter.api.Assertions.*; + +import java.io.InputStream; + +import org.eclipse.tm4e.core.Data; import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser; import org.eclipse.tm4e.core.internal.types.IRawGrammar; + import org.junit.jupiter.api.Test; public class JSONPListParserTest { @Test - public void testCsharp() throws Exception { + public void testParseJSONPList() throws Exception { IGrammarParser parser = GrammarReader.JSON_PARSER; - IRawGrammar grammar = parser.parse(JSONPListParserTest.class.getResourceAsStream("csharp.json")); - System.err.println(grammar); + try (InputStream is = Data.class.getResourceAsStream("csharp.json")) { + IRawGrammar grammar = parser.parse(is); + assertNotNull(grammar); + assertFalse(grammar.getFileTypes().isEmpty()); + System.err.println(grammar); + } } } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java index 6f3ccc4a1..bcd165812 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java @@ -1,16 +1,21 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.grammar.parser.xml; +import static org.junit.jupiter.api.Assertions.*; + +import java.io.InputStream; + +import org.eclipse.tm4e.core.Data; import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser; import org.eclipse.tm4e.core.internal.types.IRawGrammar; @@ -19,9 +24,13 @@ public class XMLPlistParserTest { @Test - public void testCsharp() throws Exception { + public void testParseXMLPlist() throws Exception { IGrammarParser parser = GrammarReader.XML_PARSER; - IRawGrammar grammar = parser.parse(XMLPlistParserTest.class.getResourceAsStream("JavaScript.tmLanguage")); - System.err.println(grammar); + try (InputStream is = Data.class.getResourceAsStream("JavaScript.tmLanguage")) { + IRawGrammar grammar = parser.parse(is); + assertNotNull(grammar); + assertFalse(grammar.getFileTypes().isEmpty()); + System.err.println(grammar); + } } } diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/json/csharp.json b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/json/csharp.json deleted file mode 100644 index 3621982a8..000000000 --- a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/json/csharp.json +++ /dev/null @@ -1,641 +0,0 @@ -{ - "scopeName": "source.cs", - "name": "C#", - "fileTypes": [ - "cs" - ], - "foldingStartMarker": "^\\s*#\\s*region|^\\s*/\\*|^(?![^{]*?//|[^{]*?/\\*(?!.*?\\*/.*?\\{)).*?\\{\\s*($|//|/\\*(?!.*?\\*/.*\\S))", - "foldingStopMarker": "^\\s*#\\s*endregion|^\\s*\\*/|^\\s*\\}", - "patterns": [ - { - "include": "#using" - }, - { - "include": "#namespace" - }, - { - "include": "#code" - } - ], - "repository": { - "using": { - "begin": "^\\s*(using)\\b\\s*", - "captures": { - "1": { - "name": "keyword.other.using.cs" - } - }, - "end": "\\s*(?:$|;)" - }, - "namespace": { - "begin": "^\\s*[^@]?((namespace)\\s+([\\w.]+))", - "beginCaptures": { - "1": { - "name": "meta.namespace.identifier.cs" - }, - "2": { - "name": "keyword.other.namespace.cs" - }, - "3": { - "name": "entity.name.type.namespace.cs" - } - }, - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.namespace.end.cs" - } - }, - "name": "meta.namespace.cs", - "patterns": [ - { - "begin": "{", - "beginCaptures": { - "0": { - "name": "punctuation.section.namespace.begin.cs" - } - }, - "end": "(?=})", - "name": "meta.namespace.body.cs", - "patterns": [ - { - "include": "#using" - }, - { - "include": "#namespace" - }, - { - "include": "#code" - } - ] - } - ] - }, - "variable": { - "patterns": [ - { - "match": "\\b(var)\\s+(.*?)(?=(=|;))", - "captures": { - "1": { - "name": "keyword.other.var.cs" - } - } - }, - { - "match": "\\b(?!var|return|yield|throw)([\\w<>*?\\[\\]]+)\\s+([\\w]+)\\s*(?=(=(?!=)|;))", - "captures": { - "1": { - "name": "storage.type.variable.cs" - } - } - } - ] - }, - "block": { - "patterns": [ - { - "begin": "{", - "beginCaptures": { - "0": { - "name": "punctuation.section.block.begin.cs" - } - }, - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.block.end.cs" - } - }, - "name": "meta.block.cs", - "patterns": [ - { - "include": "#code" - } - ] - } - ] - }, - "builtinTypes": { - "patterns": [ - { - "match": "\\b(bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|object|short|ushort|string|void|class|struct|enum|interface)\\b", - "name": "storage.type.cs" - } - ] - }, - "class": { - "begin": "(?=\\w?[\\w\\s]*[^@]?(?:class|struct|interface|enum)\\s+\\w+)", - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.class.end.cs" - } - }, - "name": "meta.class.cs", - "patterns": [ - { - "include": "#storage-modifiers" - }, - { - "include": "#comments" - }, - { - "captures": { - "1": { - "name": "storage.modifier.cs" - }, - "2": { - "name": "entity.name.type.class.cs" - } - }, - "match": "(class|struct|interface|enum)\\s+(\\w+)", - "name": "meta.class.identifier.cs" - }, - { - "begin": ":", - "end": "(?={)", - "patterns": [ - { - "captures": { - "1": { - "name": "storage.type.cs" - } - }, - "match": "\\s*,?([A-Za-z_]\\w*)\\b" - } - ] - }, - { - "begin": "{", - "beginCaptures": { - "0": { - "name": "punctuation.section.class.begin.cs" - } - }, - "end": "(?=})", - "name": "meta.class.body.cs", - "patterns": [ - { - "include": "#method" - }, - { - "include": "#code" - } - ] - } - ] - }, - "code": { - "patterns": [ - { - "include": "#block" - }, - { - "include": "#comments" - }, - { - "include": "#class" - }, - { - "include": "#variable" - }, - { - "include": "#constants" - }, - { - "include": "#storage-modifiers" - }, - { - "include": "#keywords" - }, - { - "include": "#preprocessor" - }, - { - "include": "#method-call" - }, - { - "include": "#builtinTypes" - }, - { - "include": "#documentation" - } - ] - }, - "comments": { - "patterns": [ - { - "begin": "///", - "captures": { - "0": { - "name": "punctuation.definition.comment.cs" - } - }, - "end": "$\\n?", - "name": "comment.block.documentation.cs", - "patterns": [ - { - "include": "text.xml" - } - ] - }, - { - "begin": "/\\*", - "captures": { - "0": { - "name": "punctuation.definition.comment.cs" - } - }, - "end": "\\*/\\n?", - "name": "comment.block.cs" - }, - { - "begin": "//", - "captures": { - "1": { - "name": "punctuation.definition.comment.cs" - } - }, - "end": "$\\n?", - "name": "comment.line.double-slash.cs" - } - ] - }, - "constants": { - "patterns": [ - { - "match": "\\b(true|false|null|this|base)\\b", - "name": "constant.language.cs" - }, - { - "match": "\\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b", - "name": "constant.numeric.cs" - }, - { - "captures": { - "0": { - "name": "punctuation.definition.string.begin.cs" - } - }, - "match": "@\"([^\"]|\"\")*\"", - "name": "string.quoted.double.literal.cs" - }, - { - "begin": "\"", - "beginCaptures": { - "0": { - "name": "punctuation.definition.string.begin.cs" - } - }, - "end": "\"", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.end.cs" - } - }, - "name": "string.quoted.double.cs", - "patterns": [ - { - "match": "\\\\.", - "name": "constant.character.escape.cs" - } - ] - }, - { - "begin": "'", - "beginCaptures": { - "0": { - "name": "punctuation.definition.string.begin.cs" - } - }, - "end": "'", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.end.cs" - } - }, - "name": "string.quoted.single.cs", - "patterns": [ - { - "match": "\\\\.", - "name": "constant.character.escape.cs" - } - ] - } - ] - }, - "keywords": { - "patterns": [ - { - "match": "\\b(if|else|while|for|foreach|in|do|return|continue|break|switch|case|default|goto|throw|try|catch|finally|lock|yield|await|when)\\b", - "name": "keyword.control.cs" - }, - { - "match": "\\b(from|where|select|group|into|orderby|join|let|on|equals|by|ascending|descending)\\b", - "name": "keyword.linq.cs" - }, - { - "match": "\\b(event|delegate|fixed|add|remove|set|get|value|new|is|as|using|checked|unchecked|typeof|sizeof|stackalloc|nameof)\\b", - "name": "keyword.other.cs" - }, - { - "match": "[@]\\b(namespace|class|var|event|delegate|add|remove|set|get|value|new|is|as|using|checked|unchecked|typeof|sizeof|nameof|when|override|readonly|stackalloc|from|where|select|group|into|orderby|join|let|on|equals|by|ascending|descending|if|else|while|for|foreach|in|do|return|continue|break|switch|case|default|goto|throw|try|catch|finally|lock|yield|await|internal|public|protected|private|static|const|sealed|abstract|virtual|extern|unsafe|volatile|implicit|explicit|operator|async|partial|bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|object|short|ushort|string|void|struct|enum|interface)\\b", - "name": "meta.class.body.cs" - } - ] - }, - "method": { - "patterns": [ - { - "begin": "\\[", - "end": "\\]", - "name": "meta.method.annotation.cs", - "patterns": [ - { - "include": "#constants" - }, - { - "include": "#preprocessor" - }, - { - "include": "#builtinTypes" - } - ] - }, - { - "begin": "(?=\\bnew\\s+)(?=[\\w<].*\\s+)(?=[^=]+\\()", - "end": "(?={|;)", - "name": "meta.new-object.cs", - "patterns": [ - { - "include": "#code" - } - ] - }, - { - "begin": "(?\\s,`?]*>)?)\\s*\\(", - "beginCaptures": { - "1": { - "name": "entity.name.function.cs" - } - }, - "end": "\\)", - "name": "meta.method.identifier.cs", - "patterns": [ - { - "include": "#parameters" - }, - { - "include": "#constants" - } - ] - }, - { - "begin": "(?=\\w.*\\s+[\\w.]+\\s*\\()", - "end": "(?=[\\w.]+\\s*\\()", - "name": "meta.method.return-type.cs", - "patterns": [ - { - "include": "#builtinTypes" - } - ] - }, - { - "begin": ":\\s*(this|base)\\s*\\(", - "beginCaptures": { - "1": { - "name": "constant.language.cs" - } - }, - "end": "\\)", - "name": "meta.method.base-call.cs", - "patterns": [ - { - "include": "#builtinTypes" - } - ] - }, - { - "begin": "=>", - "beginCaptures": { - "0": { - "name": "punctuation.section.method.begin.cs" - } - }, - "end": "(?=;)", - "name": "meta.method.body.cs", - "patterns": [ - { - "include": "#code" - } - ] - }, - { - "begin": "{", - "beginCaptures": { - "0": { - "name": "punctuation.section.method.begin.cs" - } - }, - "end": "(?=})", - "name": "meta.method.body.cs", - "patterns": [ - { - "include": "#code" - } - ] - } - ] - }, - { - "begin": "(?!new)(?=[\\w<].*\\s+)(?=[^\\(]+=>)", - "end": ";", - "endCaptures": { - "0": { - "name": "punctuation.section.property.end.cs" - } - }, - "name": "meta.property.cs", - "patterns": [ - { - "include": "#storage-modifiers" - }, - { - "begin": "(?=([\\w.]+)\\s*=>)", - "captures": { - "1": { - "name": "entity.name.function.cs" - } - }, - "end": "(?==>)", - "name": "meta.method.identifier.cs" - }, - { - "begin": "(?=\\w.*\\s+[\\w.]+\\s*=>)", - "end": "(?=[\\w.]+\\s*=>)", - "name": "meta.method.return-type.cs", - "patterns": [ - { - "include": "#builtinTypes" - } - ] - }, - { - "begin": "=>", - "beginCaptures": { - "0": { - "name": "punctuation.section.property.begin.cs" - } - }, - "end": "(?=;)", - "name": "meta.method.body.cs", - "patterns": [ - { - "include": "#code" - } - ] - } - ] - }, - { - "begin": "(?!new)(?=[\\w<].*\\s+)(?=[^=\\(]+\\{)", - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.property.end.cs" - } - }, - "name": "meta.property.cs", - "patterns": [ - { - "include": "#storage-modifiers" - }, - { - "begin": "([\\w.]+)\\s*(?={)", - "captures": { - "1": { - "name": "entity.name.function.cs" - } - }, - "end": "(?={)", - "name": "meta.method.identifier.cs" - }, - { - "begin": "(?=\\w.*\\s+[\\w.]+\\s*\\{)", - "end": "(?=[\\w.]+\\s*\\{)", - "name": "meta.method.return-type.cs", - "patterns": [ - { - "include": "#builtinTypes" - } - ] - }, - { - "begin": "{", - "beginCaptures": { - "0": { - "name": "punctuation.section.property.begin.cs" - } - }, - "end": "(?=})", - "name": "meta.method.body.cs", - "patterns": [ - { - "include": "#code" - } - ] - } - ] - } - ] - }, - "method-call": { - "begin": "([\\w$]+)\\s*(\\()", - "beginCaptures": { - "1": { - "name": "meta.method.cs" - }, - "2": { - "name": "punctuation.definition.method-parameters.begin.cs" - } - }, - "end": "\\)", - "endCaptures": { - "0": { - "name": "punctuation.definition.method-parameters.end.cs" - } - }, - "name": "meta.method-call.cs", - "patterns": [ - { - "match": ",", - "name": "punctuation.definition.seperator.parameter.cs" - }, - { - "include": "#code" - } - ] - }, - "parameters": { - "begin": "\\b(ref|params|out)?\\s*\\b(\\w+(?:\\s*<.*?>)?(?:\\s*\\*)*(?:\\s*\\?)?(?:\\s*\\[.*?\\])?)\\s+(@?\\w+)\\s*(=)?", - "beginCaptures": { - "1": { - "name": "storage.type.modifier.cs" - }, - "2": { - "name": "storage.type.generic.cs" - }, - "3": { - "name": "variable.parameter.function.cs" - }, - "4": { - "name": "keyword.operator.assignment.cs" - } - }, - "end": "(?:(,)|(?=[\\)]))", - "endCaptures": { - "1": { - "name": "punctuation.definition.separator.parameter.cs" - } - }, - "patterns": [ - { - "include": "#constants" - }, - { - "include": "#block" - } - ] - }, - "preprocessor": { - "patterns": [ - { - "captures": { - "2": { - "name": "entity.name.function.preprocessor.cs" - } - }, - "match": "^\\s*#\\s*(if|else|elif|endif|define|undef|warning|error|line|pragma|region|endregion)\\b\\s*(.*?)(?=$|\\/\\/)", - "name": "meta.preprocessor.cs" - } - ] - }, - "storage-modifiers": { - "match": "\\b(event|delegate|internal|public|protected|private|static|const|new|sealed|abstract|virtual|override|extern|unsafe|readonly|volatile|implicit|explicit|operator|async|partial)\\b", - "name": "storage.modifier.cs" - } - } -} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/xml/JavaScript.tmLanguage b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/xml/JavaScript.tmLanguage deleted file mode 100644 index 389da2c6f..000000000 --- a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/internal/grammar/parser/xml/JavaScript.tmLanguage +++ /dev/null @@ -1,2205 +0,0 @@ - - - - fileTypes - - js - jsx - - name - JavaScript (with React support) - patterns - - - include - #expression - - - repository - - access-modifier - - match - \b(public|protected|private)\b - name - storage.modifier.js - - arithmetic-operator - - match - \*|/|\-\-|\-|\+\+|\+|% - name - keyword.operator.arithmetic.js - - array-literal - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.js - - - end - \] - endCaptures - - 0 - - name - meta.brace.square.js - - - name - meta.array.literal.js - patterns - - - include - #expression - - - - assignment-operator - - match - <<=|>>=|>>>=|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^= - name - keyword.operator.assignment.js - - await-modifier - - match - \bawait\b - name - storage.modifier.js - - block - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.js - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.js - - - name - meta.block.js - patterns - - - include - #object-member - - - include - #expression - - - - boolean-literal - - match - \b(false|true)\b - name - constant.language.boolean.js - - case-clause - - begin - (?<!\.)\b(case|default)\b - beginCaptures - - 1 - - name - keyword.control.js - - - end - : - name - case-clause.expr.js - patterns - - - include - #expression - - - - comment - - name - comment.js - patterns - - - include - #comment-block-doc - - - include - #comment-block - - - include - #comment-line - - - - comment-block - - begin - /\* - end - \*/ - name - comment.block.js - - comment-block-doc - - begin - /\*\*(?!/) - end - \*/ - name - comment.block.documentation.js - - comment-line - - match - (//).*$\n? - name - comment.line.js - - control-statement - - match - (?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default)\b - name - keyword.control.js - - decl-block - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.js - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.js - - - name - meta.decl.block.js - patterns - - - include - #expression - - - - declaration - - name - meta.declaration.js - patterns - - - include - #function-declaration - - - include - #object-declaration - - - include - #type-declaration - - - include - #enum-declaration - - - - enum-declaration - - captures - - 1 - - name - storage.modifier.js - - 2 - - name - storage.type.js - - 3 - - name - entity.name.class.js - - - match - (?:\b(const)\s+)?\b(enum)\s+([a-zA-Z_$][\w$]*) - name - meta.enum.declaration.js - - expression - - name - meta.expression.js - patterns - - - include - #jsx - - - include - #for-in-simple - - - include - #string - - - include - #regex - - - include - #template - - - include - #comment - - - include - #literal - - - include - #paren-expression - - - include - #var-expr - - - include - #declaration - - - include - #new-expr - - - include - #switch-statement - - - include - #block - - - include - #expression-operator - - - include - #relational-operator - - - include - #arithmetic-operator - - - include - #logic-operator - - - include - #assignment-operator - - - include - #storage-keyword - - - include - #function-call - - - include - #case-clause - - - include - #control-statement - - - - expression-operator - - match - =>|\b(delete|export|import|from|in|instanceof|new|typeof|void|as)\b - name - keyword.operator.js - - field-declaration - - begin - (?<!\()\s*((?:\b[a-zA-Z_$][\w$]*)|(?:\'[^']*\')|(?:\"[^"]*\"))\s*(\?\s*)?(?=(=|:)) - beginCaptures - - 1 - - name - variable.js - - 2 - - name - keyword.operator.js - - - end - (?=\}|;|,|$)|(?<=\}) - name - meta.field.declaration.js - patterns - - - include - #expression - - - - for-in-simple - - captures - - 1 - - name - storage.type.js - - 3 - - name - keyword.operator.js - - - match - (?<=\()\s*\b(var|let|const)\s+([a-zA-Z_$][\w$]*)\s+(in|of)\b - name - forin.expr.js - - function-call - - name - functioncall.expr.js - patterns - - - include - #await-modifier - - - include - #type-parameters - - - include - #paren-expression - - - - function-declaration - - begin - \b(?:(export)\s+)?(?:(async)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s* - beginCaptures - - 1 - - name - storage.modifier.js - - 2 - - name - storage.modifier.js - - 3 - - name - storage.type.function.js - - 4 - - name - entity.name.function.js - - - end - (?=;|\})|(?<=\}) - name - meta.function.js - patterns - - - include - #comment - - - include - #type-parameters - - - include - #function-type-parameters - - - include - #return-type - - - include - #function-overload-declaration - - - include - #decl-block - - - - function-overload-declaration - - captures - - 1 - - name - storage.modifier.js - - 2 - - name - storage.type.function.js - - 3 - - name - entity.name.function.js - - - match - \b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s* - name - meta.function.overload.js - - function-type-parameters - - begin - \( - beginCaptures - - 0 - - name - meta.brace.round.js - - - end - \) - endCaptures - - 0 - - name - meta.brace.round.js - - - name - meta.function.type.parameter.js - patterns - - - include - #comment - - - include - #parameter-name - - - include - #type-annotation - - - include - #variable-initializer - - - - indexer-declaration - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.js - - - end - (\])\s*(\?\s*)?|$ - endCaptures - - 1 - - name - meta.brace.square.js - - 2 - - name - keyword.operator.js - - - name - meta.indexer.declaration.js - patterns - - - include - #type-annotation - - - include - #indexer-parameter - - - include - #expression - - - - indexer-parameter - - captures - - 1 - - name - variable.parameter.js - - - match - ([a-zA-Z_$][\w$]*)(?=\:) - name - meta.indexer.parameter.js - - jsx - - name - meta.jsx.js - patterns - - - include - #jsx-tag-without-attributes - - - include - #jsx-tag-open - - - include - #jsx-tag-close - - - include - #jsx-tag-invalid - - - begin - (?<=(?:'|"|})>) - end - (?=</) - name - meta.jsx.children.js - patterns - - - include - #jsx-children - - - - - - jsx-children - - patterns - - - include - #jsx-tag-without-attributes - - - include - #jsx-tag-open - - - include - #jsx-tag-close - - - include - #jsx-tag-invalid - - - include - #jsx-evaluated-code - - - include - #jsx-entities - - - - jsx-entities - - patterns - - - captures - - 1 - - name - punctuation.definition.entity.js - - 3 - - name - punctuation.definition.entity.js - - - match - (&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;) - name - constant.character.entity.js - - - match - & - name - invalid.illegal.bad-ampersand.js - - - - jsx-evaluated-code - - begin - { - beginCaptures - - 0 - - name - punctuation.definition.brace.curly.start.js - - - end - } - endCaptures - - 0 - - name - punctuation.definition.brace.curly.end.js - - - name - meta.brace.curly.js - patterns - - - include - #expression - - - - jsx-string-double-quoted - - begin - " - beginCaptures - - 0 - - name - punctuation.definition.string.begin.js - - - end - " - endCaptures - - 0 - - name - punctuation.definition.string.end.js - - - name - string.quoted.double.js - patterns - - - include - #jsx-entities - - - - jsx-string-single-quoted - - begin - ' - beginCaptures - - 0 - - name - punctuation.definition.string.begin.js - - - end - ' - endCaptures - - 0 - - name - punctuation.definition.string.end.js - - - name - string.quoted.single.js - patterns - - - include - #jsx-entities - - - - jsx-tag-attribute-assignment - - match - =(?=\s*(?:'|"|{|/\*|//|\n)) - name - keyword.operator.assignment.js - - jsx-tag-attribute-name - - captures - - 1 - - name - entity.other.attribute-name.js - - - match - (?x) - \s* - ([_$a-zA-Z][-$\w]*) - (?=\s|=|/?>|/\*|//) - name - meta.tag.attribute-name.js - - jsx-tag-attributes - - patterns - - - include - #jsx-tag-attribute-name - - - include - #jsx-tag-attribute-assignment - - - include - #jsx-string-double-quoted - - - include - #jsx-string-single-quoted - - - include - #jsx-evaluated-code - - - - jsx-tag-attributes-illegal - - match - \S+ - name - invalid.illegal.attribute.js - - jsx-tag-close - - begin - (</)([_$a-zA-Z][-$\w.]*(?<!\.|-)) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.js - - 2 - - name - entity.name.tag.js - - - end - (>) - endCaptures - - 1 - - name - punctuation.definition.tag.end.js - - - name - tag.close.js - patterns - - - include - #comment - - - - jsx-tag-invalid - - match - <\s*> - name - invalid.illegal.tag.incomplete.js - - jsx-tag-open - - begin - (?x) - (<) - ([_$a-zA-Z][-$\w.]*(?<!\.|-)) - (?=\s+(?!\?)|/?>) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.js - - 2 - - name - entity.name.tag.js - - - end - (/?>) - endCaptures - - 1 - - name - punctuation.definition.tag.end.js - - - name - tag.open.js - patterns - - - include - #comment - - - include - #jsx-tag-attributes - - - include - #jsx-tag-attributes-illegal - - - - jsx-tag-without-attributes - - begin - (<)([_$a-zA-Z][-$\w.]*(?<!\.|-))(>) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.js - - 2 - - name - entity.name.tag.js - - 3 - - name - punctuation.definition.tag.end.js - - - end - (</)([_$a-zA-Z][-$\w.]*(?<!\.|-))(>) - endCaptures - - 1 - - name - punctuation.definition.tag.begin.js - - 2 - - name - entity.name.tag.js - - 3 - - name - punctuation.definition.tag.end.js - - - name - tag.without-attributes.js - patterns - - - include - #jsx-children - - - - literal - - name - literal.js - patterns - - - include - #numeric-literal - - - include - #boolean-literal - - - include - #null-literal - - - include - #undefined-literal - - - include - #array-literal - - - include - #this-literal - - - - logic-operator - - match - \!|&|~|\||&&|\|\| - name - keyword.operator.arithmetic.js - - method-declaration - - begin - \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<) - beginCaptures - - 1 - - name - storage.modifier.js - - 2 - - name - storage.modifier.js - - 3 - - name - storage.modifier.js - - 4 - - name - storage.type.property.js - - 5 - - name - keyword.operator.js - - 6 - - name - entity.name.function.js - - 7 - - name - keyword.operator.js - - - end - (?=\}|;|,)|(?<=\}) - name - meta.method.declaration.js - patterns - - - include - #comment - - - include - #type-parameters - - - include - #function-type-parameters - - - include - #type-annotation - - - include - #method-overload-declaration - - - include - #decl-block - - - - method-overload-declaration - - captures - - 1 - - name - storage.modifier.js - - 2 - - name - storage.modifier.js - - 3 - - name - storage.modifier.js - - 4 - - name - storage.type.property.js - - 5 - - name - keyword.operator.js - - 6 - - name - entity.name.function.js - - 7 - - name - keyword.operator.js - - - match - \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<) - name - meta.method.overload.declaration.js - - new-expr - - begin - \b(new)\b - beginCaptures - - 1 - - name - keyword.operator.js - - - end - (?=[(;]|$) - name - new.expr.js - patterns - - - include - #type - - - include - #comment - - - - null-literal - - match - \b(null)\b - name - constant.language.null.js - - numeric-literal - - match - \b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b - name - constant.numeric.js - - object-body - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.js - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.js - - - name - meta.object.body.js - patterns - - - include - #string - - - include - #comment - - - include - #field-declaration - - - include - #method-declaration - - - include - #indexer-declaration - - - include - #type-annotation - - - include - #variable-initializer - - - include - #access-modifier - - - include - #static-modifier - - - include - #property-accessor - - - - object-declaration - - begin - \b(?:(export)\s+)?\b(?:(abstract)\s+)?\b(?<!\.)(class|interface)\b - beginCaptures - - 1 - - name - storage.modifier.js - - 2 - - name - storage.modifier.js - - 3 - - name - storage.type.js - - - end - (?<=\}) - endCaptures - - 1 - - name - brace.curly.js - - - name - meta.declaration.object.js - patterns - - - include - #comment - - - include - #object-heritage - - - include - #object-name - - - include - #type-parameters - - - include - #object-body - - - - object-heritage - - begin - (?:\b(extends|implements)) - beginCaptures - - 1 - - name - keyword.other.js - - - end - (?=\{) - endCaptures - - 1 - - name - brace.curly.js - - - name - meta.object.heritage.js - patterns - - - include - #comment - - - include - #object-heritage - - - include - #type-parameters - - - include - #object-heritage-parent - - - - object-heritage-parent - - captures - - 1 - - name - storage.type.js - - - match - (?:\s*([a-zA-Z_$][\w$]*)) - name - meta.object.heritage.parent.js - - object-member - - begin - [a-zA-Z_$][\w$]*\s*: - end - (?=,|\}) - name - meta.object.member.js - patterns - - - include - #expression - - - - object-name - - captures - - 0 - - name - entity.name.class.js - - - match - [a-zA-Z_$][\w$]* - name - meta.object.name.js - - parameter-name - - captures - - 1 - - name - storage.modifier.js - - 2 - - name - keyword.operator.js - - 3 - - name - variable.parameter.js - - 4 - - name - keyword.operator.js - - - match - (?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\??) - name - parameter.name.js - - paren-expression - - begin - \( - beginCaptures - - 0 - - name - meta.brace.paren.js - - - end - \) - endCaptures - - 0 - - name - meta.brace.paren.js - - - patterns - - - include - #expression - - - - property-accessor - - match - \b(get|set)\b - name - storage.type.property.js - - qstring-double - - begin - " - end - "|(?=$) - name - string.double.js - patterns - - - include - #string-character-escape - - - - qstring-single - - begin - ' - end - '|(?=$) - name - string.single.js - patterns - - - include - #string-character-escape - - - - regex - - begin - (?<=[=(:,\[]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?]) - end - $|(/)[igm]* - name - string.regex.js - patterns - - - match - \\. - name - constant.character.escape.js - - - match - \[(\\\]|[^\]])*\] - name - constant.character.class.js - - - - relational-operator - - match - ===|==|=|!=|!==|<=|>=|<>|<|> - name - keyword.operator.comparison.js - - return-type - - begin - (?<=\))\s*: - end - (?=$)|(?=\{|;|//) - name - meta.return.type.js - patterns - - - include - #type - - - - static-modifier - - match - \b(static)\b - name - keyword.other.js - - storage-keyword - - match - \b(number|boolean|string|any|var|let|function|const|module|namespace)\b - name - storage.type.js - - string - - name - string.js - patterns - - - include - #qstring-single - - - include - #qstring-double - - - - string-character-escape - - match - \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$) - name - constant.character.escape - - switch-block - - begin - { - end - (?=\}) - name - switch-block.expr.js - patterns - - - include - #expression - - - - switch-expression - - begin - \b(switch)\b\s*\( - beginCaptures - - 1 - - name - keyword.operator.js - - - end - \) - name - switch-expression.expr.js - patterns - - - include - #expression - - - - switch-statement - - begin - (?=\bswitch\b\s*\() - end - } - name - switch-statement.expr.js - patterns - - - include - #switch-expression - - - include - #switch-block - - - - template - - begin - ` - beginCaptures - - 0 - - name - string.template.js - - - end - ` - endCaptures - - 0 - - name - string.template.js - - - name - meta.template.js - patterns - - - include - #template-substitution-element - - - include - #template-string-contents - - - - template-string-contents - - begin - .*? - end - (?=(\$\{|`)) - name - string.template.js - patterns - - - include - #string-character-escape - - - - template-substitution-element - - begin - \$\{ - beginCaptures - - 0 - - name - keyword.operator.js - - - end - \} - endCaptures - - 0 - - name - keyword.operator.js - - - name - template.element.js - patterns - - - include - #expression - - - - this-literal - - match - \b(this)\b - name - constant.language.this.js - - type - - name - meta.type.js - patterns - - - include - #type-primitive - - - include - #type-parameters - - - include - #type-tuple - - - include - #type-object - - - include - #type-operator - - - include - #type-paren-or-function-type-parameters - - - include - #type-function-return-type - - - include - #type-name - - - - type-annotation - - begin - : - end - (?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[a-zA-Z_$])\s*(?=\{) - name - meta.type.annotation.js - patterns - - - include - #type - - - include - #string - - - include - #comment - - - - type-declaration - - begin - \b(type)\b\s+([a-zA-Z_$][\w$]*)\s*=\s* - beginCaptures - - 1 - - name - keyword.other.js - - 2 - - name - storage.type.js - - - end - (?=$|[,);>]|var|type|function|class|interface) - name - meta.type.declaration.js - patterns - - - include - #type - - - - type-function-return-type - - begin - => - beginCaptures - - 0 - - name - keyword.operator.js - - - end - (?=\s*[,\)\{=;>]|//|$) - name - meta.type.function.return.js - patterns - - - include - #type - - - - type-name - - captures - - 1 - - name - entity.name.type.js - - - match - [a-zA-Z_$][.\w$]* - name - meta.type.name.js - - type-object - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.js - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.js - - - name - meta.object.type.js - patterns - - - include - #comment - - - include - #field-declaration - - - include - #method-declaration - - - include - #indexer-declaration - - - include - #type-annotation - - - - type-operator - - match - [.|] - name - keyword.operator.type.js - - type-parameters - - begin - ([a-zA-Z_$][\w$]*)?(<) - beginCaptures - - 1 - - name - entity.name.type.js - - 2 - - name - meta.brace.angle.js - - - end - (?=$)|(>) - endCaptures - - 2 - - name - meta.brace.angle.js - - - name - meta.type.parameters.js - patterns - - - match - \b(extends)\b - name - keyword.other.js - - - include - #comment - - - include - #type - - - - type-paren-or-function-type-parameters - - begin - (?:\b(new)\b)?\s*\( - beginCaptures - - 1 - - name - keyword.control.js - - - end - \) - name - meta.type.paren.cover.js - patterns - - - include - #comment - - - include - #type - - - include - #function-type-parameters - - - - type-primitive - - captures - - 1 - - name - storage.type.js - - - match - \b(string|number|boolean|symbol|any|void)\b - name - meta.type.primitive.js - - type-tuple - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.js - - - end - \] - endCaptures - - 0 - - name - meta.brace.square.js - - - name - meta.type.tuple.js - patterns - - - include - #type - - - include - #comment - - - - undefined-literal - - match - \b(undefined)\b - name - constant.language.js - - var-expr - - begin - (?<!\()\s*\b(var|let|const(?!\s+enum)\b) - beginCaptures - - 1 - - name - storage.type.js - - - end - (?=$|;) - name - meta.var.expr.js - patterns - - - include - #var-single-variable - - - include - #comment - - - - var-single-variable - - begin - \b([a-zA-Z_$][\w$]*)\s*(=?) - beginCaptures - - 1 - - name - variable.js - - - end - (?=$|[;,]) - name - meta.var-single-variable.expr.js - patterns - - - include - #type-annotation - - - include - #string - - - include - #comment - - - include - #expression - - - - variable-initializer - - begin - (=) - beginCaptures - - 1 - - name - keyword.operator.js - - - end - (?=$|[,);=]) - patterns - - - include - #expression - - - - - scopeName - source.js - uuid - 805375ec-d614-41f5-8993-5843fe63ea82 - - - From 3c4f64c0c28805d2e1d9eecde29c2a9c061baad9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 12 Apr 2022 16:22:12 +0200 Subject: [PATCH 041/202] Include fileTypes field in hashCode/equals methods --- .../core/internal/grammar/parser/Raw.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java index a06e669a9..79bc06b27 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java @@ -302,4 +302,28 @@ public Object clone() { return CloneUtils.clone(this); } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + Raw other = (Raw) obj; + if (fileTypes == null) { + if (other.fileTypes != null) + return false; + } else if (!fileTypes.equals(other.fileTypes)) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((fileTypes == null) ? 0 : fileTypes.hashCode()); + return result; + } } \ No newline at end of file From 31418880c8cfa37e5499e41482b466f78e2531ba Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 12 Apr 2022 17:38:27 +0200 Subject: [PATCH 042/202] Support loading of TextMate Grammars in YAML format --- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 3 +- .../grammar/reader/GrammarReader.java | 32 +- .../internal/parser/yaml/YamlPListParser.java | 83 + .../grammar/parser/PlistFormatsTest.java | 41 + .../parser/yaml/YamlPlistParserTest.java | 37 + .../tm4e/core/JavaScript.tmLanguage.json | 1415 +++++++++++++++++ .../tm4e/core/JavaScript.tmLanguage.yaml | 791 +++++++++ .../schema/grammars.exsd | 2 +- .../tm4e/ui/internal/TMUIMessages.properties | 16 +- .../wizards/SelectGrammarWizardPage.java | 4 +- target-platform/tm4e-target.target | 1 + 11 files changed, 2408 insertions(+), 17 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PlistFormatsTest.java create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java create mode 100644 org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/JavaScript.tmLanguage.json create mode 100644 org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/JavaScript.tmLanguage.yaml diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index 7af9b5720..305ed92be 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -9,7 +9,8 @@ Require-Bundle: org.apache.batik.css;bundle-version="1.9.1";resolution:=optional org.apache.batik.util;bundle-version="1.9.1";resolution:=optional, com.google.gson;resolution:=optional, org.jcodings;bundle-version="1.0.18", - org.joni;bundle-version="2.1.11" + org.joni;bundle-version="2.1.11", + org.yaml.snakeyaml;bundle-version="1.27.0" Import-Package: org.w3c.css.sac;resolution:=optional, org.w3c.css.sac.helpers;resolution:=optional, org.w3c.dom.css diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java index 2d6027958..097a3757e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.grammar.reader; @@ -20,6 +20,7 @@ import org.eclipse.tm4e.core.internal.parser.json.JSONPListParser; import org.eclipse.tm4e.core.internal.parser.xml.XMLPListParser; +import org.eclipse.tm4e.core.internal.parser.yaml.YamlPListParser; import org.eclipse.tm4e.core.internal.types.IRawGrammar; /** @@ -55,15 +56,36 @@ public IRawGrammar parse(InputStream contents) throws Exception { } }; + public static final IGrammarParser YAML_PARSER = new IGrammarParser() { + + private final YamlPListParser parser = new YamlPListParser<>(false); + + @Override + public IRawGrammar parse(InputStream contents) throws Exception { + return parser.parse(contents); + } + }; + public static IRawGrammar readGrammarSync(String filePath, InputStream in) throws Exception { SyncGrammarReader reader = new SyncGrammarReader(in, getGrammarParser(filePath)); return reader.load(); } private static IGrammarParser getGrammarParser(String filePath) { - if (filePath.endsWith(".json")) { + String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); + + switch (extension) { + + case "json": return JSON_PARSER; + + case "yaml": + case "yaml-tmlanguage": + case "yml": + return YAML_PARSER; + + default: + return XML_PARSER; } - return XML_PARSER; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java new file mode 100644 index 000000000..80b87ec5a --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.parser.yaml; + +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.tm4e.core.internal.parser.PList; +import org.xml.sax.SAXException; +import org.yaml.snakeyaml.Yaml; + +/** + * Parses TextMate Grammar file in YAML format. + */ +public class YamlPListParser { + + private final boolean theme; + + public YamlPListParser(boolean theme) { + this.theme = theme; + } + + @SuppressWarnings("unchecked") + private void addListToPList(PList pList, List list) throws SAXException { + pList.startElement(null, "array", null, null); + + for (Object item : list) { + if (item instanceof List) { + addListToPList(pList, (List) item); + } else if (item instanceof Map) { + addMapToPList(pList, (Map) item); + } else { + addStringToPList(pList, item.toString()); + } + } + + pList.endElement(null, "array", null); + } + + @SuppressWarnings("unchecked") + private void addMapToPList(PList pList, Map map) throws SAXException { + pList.startElement(null, "dict", null, null); + + for (Entry entry : map.entrySet()) { + pList.startElement(null, "key", null, null); + pList.characters(entry.getKey().toCharArray(), 0, entry.getKey().length()); + pList.endElement(null, "key", null); + if (entry.getValue() instanceof List) { + addListToPList(pList, (List) entry.getValue()); + } else if (entry.getValue() instanceof Map) { + addMapToPList(pList, (Map) entry.getValue()); + } else { + addStringToPList(pList, entry.getValue().toString()); + } + } + + pList.endElement(null, "dict", null); + } + + private void addStringToPList(PList pList, String value) throws SAXException { + pList.startElement(null, "string", null, null); + pList.characters(value.toCharArray(), 0, value.length()); + pList.endElement(null, "string", null); + } + + public T parse(InputStream contents) throws Exception { + PList pList = new PList<>(theme); + addMapToPList(pList, new Yaml().loadAs(contents, Map.class)); + return pList.getResult(); + } +} diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PlistFormatsTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PlistFormatsTest.java new file mode 100644 index 000000000..c783e189a --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PlistFormatsTest.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.grammar.parser; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.InputStream; + +import org.eclipse.tm4e.core.Data; +import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; +import org.eclipse.tm4e.core.internal.types.IRawGrammar; +import org.junit.jupiter.api.Test; + +public class PlistFormatsTest { + + private IRawGrammar loadGrammar(String path) throws Exception { + try (InputStream is = Data.class.getResourceAsStream(path)) { + return GrammarReader.readGrammarSync(path, is); + } + } + + @Test + public void testPlistFormats() throws Exception { + IRawGrammar grammarFromXML = loadGrammar("JavaScript.tmLanguage"); + IRawGrammar grammarFromJSON = loadGrammar("JavaScript.tmLanguage.json"); + IRawGrammar grammarFromYAML = loadGrammar("JavaScript.tmLanguage.yaml"); + + assertEquals(grammarFromXML, grammarFromJSON); + assertEquals(grammarFromXML, grammarFromYAML); + } +} diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java new file mode 100644 index 000000000..c833ba296 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.grammar.parser.yaml; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.InputStream; + +import org.eclipse.tm4e.core.Data; +import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; +import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser; +import org.eclipse.tm4e.core.internal.types.IRawGrammar; +import org.junit.jupiter.api.Test; + +public class YamlPlistParserTest { + + @Test + public void testParsePlistYaml() throws Exception { + IGrammarParser parser = GrammarReader.YAML_PARSER; + try (InputStream is = Data.class.getResourceAsStream("JavaScript.tmLanguage.yaml")) { + IRawGrammar grammar = parser.parse(is); + assertNotNull(grammar); + assertFalse(grammar.getFileTypes().isEmpty()); + System.err.println(grammar); + } + } +} diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/JavaScript.tmLanguage.json b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/JavaScript.tmLanguage.json new file mode 100644 index 000000000..7bc39946d --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/JavaScript.tmLanguage.json @@ -0,0 +1,1415 @@ +{ + "fileTypes": [ + "js", + "jsx" + ], + "name": "JavaScript (with React support)", + "patterns": [ + { + "include": "#expression" + } + ], + "repository": { + "access-modifier": { + "match": "\\b(public|protected|private)\\b", + "name": "storage.modifier.js" + }, + "arithmetic-operator": { + "match": "\\*|\/|\\-\\-|\\-|\\+\\+|\\+|%", + "name": "keyword.operator.arithmetic.js" + }, + "array-literal": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.js" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "meta.brace.square.js" + } + }, + "name": "meta.array.literal.js", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "assignment-operator": { + "match": "<<=|>>=|>>>=|\\*=|(?|\\b(delete|export|import|from|in|instanceof|new|typeof|void|as)\\b", + "name": "keyword.operator.js" + }, + "field-declaration": { + "begin": "(?)", + "end": "(?=<\/)", + "name": "meta.jsx.children.js", + "patterns": [ + { + "include": "#jsx-children" + } + ] + } + ] + }, + "jsx-children": { + "patterns": [ + { + "include": "#jsx-tag-without-attributes" + }, + { + "include": "#jsx-tag-open" + }, + { + "include": "#jsx-tag-close" + }, + { + "include": "#jsx-tag-invalid" + }, + { + "include": "#jsx-evaluated-code" + }, + { + "include": "#jsx-entities" + } + ] + }, + "jsx-entities": { + "patterns": [ + { + "captures": { + "1": { + "name": "punctuation.definition.entity.js" + }, + "3": { + "name": "punctuation.definition.entity.js" + } + }, + "match": "(&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;)", + "name": "constant.character.entity.js" + }, + { + "match": "&", + "name": "invalid.illegal.bad-ampersand.js" + } + ] + }, + "jsx-evaluated-code": { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.definition.brace.curly.start.js" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.definition.brace.curly.end.js" + } + }, + "name": "meta.brace.curly.js", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "jsx-string-double-quoted": { + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.js" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.js" + } + }, + "name": "string.quoted.double.js", + "patterns": [ + { + "include": "#jsx-entities" + } + ] + }, + "jsx-string-single-quoted": { + "begin": "'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.js" + } + }, + "end": "'", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.js" + } + }, + "name": "string.quoted.single.js", + "patterns": [ + { + "include": "#jsx-entities" + } + ] + }, + "jsx-tag-attribute-assignment": { + "match": "=(?=\\s*(?:'|\"|{|\/\\*|\/\/|\\n))", + "name": "keyword.operator.assignment.js" + }, + "jsx-tag-attribute-name": { + "captures": { + "1": { + "name": "entity.other.attribute-name.js" + } + }, + "match": "(?x)\n \\s*\n ([_$a-zA-Z][-$\\w]*)\n (?=\\s|=|\/?>|\/\\*|\/\/)", + "name": "meta.tag.attribute-name.js" + }, + "jsx-tag-attributes": { + "patterns": [ + { + "include": "#jsx-tag-attribute-name" + }, + { + "include": "#jsx-tag-attribute-assignment" + }, + { + "include": "#jsx-string-double-quoted" + }, + { + "include": "#jsx-string-single-quoted" + }, + { + "include": "#jsx-evaluated-code" + } + ] + }, + "jsx-tag-attributes-illegal": { + "match": "\\S+", + "name": "invalid.illegal.attribute.js" + }, + "jsx-tag-close": { + "begin": "(<\/)([_$a-zA-Z][-$\\w.]*(?)", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.end.js" + } + }, + "name": "tag.close.js", + "patterns": [ + { + "include": "#comment" + } + ] + }, + "jsx-tag-invalid": { + "match": "<\\s*>", + "name": "invalid.illegal.tag.incomplete.js" + }, + "jsx-tag-open": { + "begin": "(?x)\n (<)\n ([_$a-zA-Z][-$\\w.]*(?)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.tag.begin.js" + }, + "2": { + "name": "entity.name.tag.js" + } + }, + "end": "(\/?>)", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.end.js" + } + }, + "name": "tag.open.js", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#jsx-tag-attributes" + }, + { + "include": "#jsx-tag-attributes-illegal" + } + ] + }, + "jsx-tag-without-attributes": { + "begin": "(<)([_$a-zA-Z][-$\\w.]*(?)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.tag.begin.js" + }, + "2": { + "name": "entity.name.tag.js" + }, + "3": { + "name": "punctuation.definition.tag.end.js" + } + }, + "end": "(<\/)([_$a-zA-Z][-$\\w.]*(?)", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.begin.js" + }, + "2": { + "name": "entity.name.tag.js" + }, + "3": { + "name": "punctuation.definition.tag.end.js" + } + }, + "name": "tag.without-attributes.js", + "patterns": [ + { + "include": "#jsx-children" + } + ] + }, + "literal": { + "name": "literal.js", + "patterns": [ + { + "include": "#numeric-literal" + }, + { + "include": "#boolean-literal" + }, + { + "include": "#null-literal" + }, + { + "include": "#undefined-literal" + }, + { + "include": "#array-literal" + }, + { + "include": "#this-literal" + } + ] + }, + "logic-operator": { + "match": "\\!|&|~|\\||&&|\\|\\|", + "name": "keyword.operator.arithmetic.js" + }, + "method-declaration": { + "begin": "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)", + "beginCaptures": { + "1": { + "name": "storage.modifier.js" + }, + "2": { + "name": "storage.modifier.js" + }, + "3": { + "name": "storage.modifier.js" + }, + "4": { + "name": "storage.type.property.js" + }, + "5": { + "name": "keyword.operator.js" + }, + "6": { + "name": "entity.name.function.js" + }, + "7": { + "name": "keyword.operator.js" + } + }, + "end": "(?=\\}|;|,)|(?<=\\})", + "name": "meta.method.declaration.js", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-parameters" + }, + { + "include": "#function-type-parameters" + }, + { + "include": "#type-annotation" + }, + { + "include": "#method-overload-declaration" + }, + { + "include": "#decl-block" + } + ] + }, + "method-overload-declaration": { + "captures": { + "1": { + "name": "storage.modifier.js" + }, + "2": { + "name": "storage.modifier.js" + }, + "3": { + "name": "storage.modifier.js" + }, + "4": { + "name": "storage.type.property.js" + }, + "5": { + "name": "keyword.operator.js" + }, + "6": { + "name": "entity.name.function.js" + }, + "7": { + "name": "keyword.operator.js" + } + }, + "match": "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)", + "name": "meta.method.overload.declaration.js" + }, + "new-expr": { + "begin": "\\b(new)\\b", + "beginCaptures": { + "1": { + "name": "keyword.operator.js" + } + }, + "end": "(?=[(;]|$)", + "name": "new.expr.js", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, + "null-literal": { + "match": "\\b(null)\\b", + "name": "constant.language.null.js" + }, + "numeric-literal": { + "match": "\\b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|([0-9]+(\\.[0-9]+)?))\\b", + "name": "constant.numeric.js" + }, + "object-body": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "meta.brace.curly.js" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "meta.brace.curly.js" + } + }, + "name": "meta.object.body.js", + "patterns": [ + { + "include": "#string" + }, + { + "include": "#comment" + }, + { + "include": "#field-declaration" + }, + { + "include": "#method-declaration" + }, + { + "include": "#indexer-declaration" + }, + { + "include": "#type-annotation" + }, + { + "include": "#variable-initializer" + }, + { + "include": "#access-modifier" + }, + { + "include": "#static-modifier" + }, + { + "include": "#property-accessor" + } + ] + }, + "object-declaration": { + "begin": "\\b(?:(export)\\s+)?\\b(?:(abstract)\\s+)?\\b(?=|<>|<|>", + "name": "keyword.operator.comparison.js" + }, + "return-type": { + "begin": "(?<=\\))\\s*:", + "end": "(?=$)|(?=\\{|;|\/\/)", + "name": "meta.return.type.js", + "patterns": [ + { + "include": "#type" + } + ] + }, + "static-modifier": { + "match": "\\b(static)\\b", + "name": "keyword.other.js" + }, + "storage-keyword": { + "match": "\\b(number|boolean|string|any|var|let|function|const|module|namespace)\\b", + "name": "storage.type.js" + }, + "string": { + "name": "string.js", + "patterns": [ + { + "include": "#qstring-single" + }, + { + "include": "#qstring-double" + } + ] + }, + "string-character-escape": { + "match": "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)", + "name": "constant.character.escape" + }, + "switch-block": { + "begin": "{", + "end": "(?=\\})", + "name": "switch-block.expr.js", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "switch-expression": { + "begin": "\\b(switch)\\b\\s*\\(", + "beginCaptures": { + "1": { + "name": "keyword.operator.js" + } + }, + "end": "\\)", + "name": "switch-expression.expr.js", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "switch-statement": { + "begin": "(?=\\bswitch\\b\\s*\\()", + "end": "}", + "name": "switch-statement.expr.js", + "patterns": [ + { + "include": "#switch-expression" + }, + { + "include": "#switch-block" + } + ] + }, + "template": { + "begin": "`", + "beginCaptures": { + "0": { + "name": "string.template.js" + } + }, + "end": "`", + "endCaptures": { + "0": { + "name": "string.template.js" + } + }, + "name": "meta.template.js", + "patterns": [ + { + "include": "#template-substitution-element" + }, + { + "include": "#template-string-contents" + } + ] + }, + "template-string-contents": { + "begin": ".*?", + "end": "(?=(\\$\\{|`))", + "name": "string.template.js", + "patterns": [ + { + "include": "#string-character-escape" + } + ] + }, + "template-substitution-element": { + "begin": "\\$\\{", + "beginCaptures": { + "0": { + "name": "keyword.operator.js" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "keyword.operator.js" + } + }, + "name": "template.element.js", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "this-literal": { + "match": "\\b(this)\\b", + "name": "constant.language.this.js" + }, + "type": { + "name": "meta.type.js", + "patterns": [ + { + "include": "#type-primitive" + }, + { + "include": "#type-parameters" + }, + { + "include": "#type-tuple" + }, + { + "include": "#type-object" + }, + { + "include": "#type-operator" + }, + { + "include": "#type-paren-or-function-type-parameters" + }, + { + "include": "#type-function-return-type" + }, + { + "include": "#type-name" + } + ] + }, + "type-annotation": { + "begin": ":", + "end": "(?=$|[,);\\}\\]]|\/\/)|(?==[^>])|(?<=[\\}>\\]\\)]|[a-zA-Z_$])\\s*(?=\\{)", + "name": "meta.type.annotation.js", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#string" + }, + { + "include": "#comment" + } + ] + }, + "type-declaration": { + "begin": "\\b(type)\\b\\s+([a-zA-Z_$][\\w$]*)\\s*=\\s*", + "beginCaptures": { + "1": { + "name": "keyword.other.js" + }, + "2": { + "name": "storage.type.js" + } + }, + "end": "(?=$|[,);>]|var|type|function|class|interface)", + "name": "meta.type.declaration.js", + "patterns": [ + { + "include": "#type" + } + ] + }, + "type-function-return-type": { + "begin": "=>", + "beginCaptures": { + "0": { + "name": "keyword.operator.js" + } + }, + "end": "(?=\\s*[,\\)\\{=;>]|\/\/|$)", + "name": "meta.type.function.return.js", + "patterns": [ + { + "include": "#type" + } + ] + }, + "type-name": { + "captures": { + "1": { + "name": "entity.name.type.js" + } + }, + "match": "[a-zA-Z_$][.\\w$]*", + "name": "meta.type.name.js" + }, + "type-object": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "meta.brace.curly.js" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "meta.brace.curly.js" + } + }, + "name": "meta.object.type.js", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#field-declaration" + }, + { + "include": "#method-declaration" + }, + { + "include": "#indexer-declaration" + }, + { + "include": "#type-annotation" + } + ] + }, + "type-operator": { + "match": "[.|]", + "name": "keyword.operator.type.js" + }, + "type-parameters": { + "begin": "([a-zA-Z_$][\\w$]*)?(<)", + "beginCaptures": { + "1": { + "name": "entity.name.type.js" + }, + "2": { + "name": "meta.brace.angle.js" + } + }, + "end": "(?=$)|(>)", + "endCaptures": { + "2": { + "name": "meta.brace.angle.js" + } + }, + "name": "meta.type.parameters.js", + "patterns": [ + { + "match": "\\b(extends)\\b", + "name": "keyword.other.js" + }, + { + "include": "#comment" + }, + { + "include": "#type" + } + ] + }, + "type-paren-or-function-type-parameters": { + "begin": "(?:\\b(new)\\b)?\\s*\\(", + "beginCaptures": { + "1": { + "name": "keyword.control.js" + } + }, + "end": "\\)", + "name": "meta.type.paren.cover.js", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type" + }, + { + "include": "#function-type-parameters" + } + ] + }, + "type-primitive": { + "captures": { + "1": { + "name": "storage.type.js" + } + }, + "match": "\\b(string|number|boolean|symbol|any|void)\\b", + "name": "meta.type.primitive.js" + }, + "type-tuple": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.js" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "meta.brace.square.js" + } + }, + "name": "meta.type.tuple.js", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, + "undefined-literal": { + "match": "\\b(undefined)\\b", + "name": "constant.language.js" + }, + "var-expr": { + "begin": "(?>=|>>>=|\\*=|(?|\\b(delete|export|import|from|in|instanceof|new|typeof|void|as)\\b" + name: keyword.operator.js + field-declaration: + begin: (?) + end: "(?=|/\*|//) + name: meta.tag.attribute-name.js + jsx-tag-attributes: + patterns: + - include: "#jsx-tag-attribute-name" + - include: "#jsx-tag-attribute-assignment" + - include: "#jsx-string-double-quoted" + - include: "#jsx-string-single-quoted" + - include: "#jsx-evaluated-code" + jsx-tag-attributes-illegal: + match: "\\S+" + name: invalid.illegal.attribute.js + jsx-tag-close: + begin: "()" + endCaptures: + '1': + name: punctuation.definition.tag.end.js + name: tag.close.js + patterns: + - include: "#comment" + jsx-tag-invalid: + match: "<\\s*>" + name: invalid.illegal.tag.incomplete.js + jsx-tag-open: + begin: |- + (?x) + (<) + ([_$a-zA-Z][-$\w.]*(?) + beginCaptures: + '1': + name: punctuation.definition.tag.begin.js + '2': + name: entity.name.tag.js + end: "(/?>)" + endCaptures: + '1': + name: punctuation.definition.tag.end.js + name: tag.open.js + patterns: + - include: "#comment" + - include: "#jsx-tag-attributes" + - include: "#jsx-tag-attributes-illegal" + jsx-tag-without-attributes: + begin: "(<)([_$a-zA-Z][-$\\w.]*(?)" + beginCaptures: + '1': + name: punctuation.definition.tag.begin.js + '2': + name: entity.name.tag.js + '3': + name: punctuation.definition.tag.end.js + end: "()" + endCaptures: + '1': + name: punctuation.definition.tag.begin.js + '2': + name: entity.name.tag.js + '3': + name: punctuation.definition.tag.end.js + name: tag.without-attributes.js + patterns: + - include: "#jsx-children" + literal: + name: literal.js + patterns: + - include: "#numeric-literal" + - include: "#boolean-literal" + - include: "#null-literal" + - include: "#undefined-literal" + - include: "#array-literal" + - include: "#this-literal" + logic-operator: + match: "\\!|&|~|\\||&&|\\|\\|" + name: keyword.operator.arithmetic.js + method-declaration: + begin: "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)" + beginCaptures: + '1': + name: storage.modifier.js + '2': + name: storage.modifier.js + '3': + name: storage.modifier.js + '4': + name: storage.type.property.js + '5': + name: keyword.operator.js + '6': + name: entity.name.function.js + '7': + name: keyword.operator.js + end: "(?=\\}|;|,)|(?<=\\})" + name: meta.method.declaration.js + patterns: + - include: "#comment" + - include: "#type-parameters" + - include: "#function-type-parameters" + - include: "#type-annotation" + - include: "#method-overload-declaration" + - include: "#decl-block" + method-overload-declaration: + captures: + '1': + name: storage.modifier.js + '2': + name: storage.modifier.js + '3': + name: storage.modifier.js + '4': + name: storage.type.property.js + '5': + name: keyword.operator.js + '6': + name: entity.name.function.js + '7': + name: keyword.operator.js + match: "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)" + name: meta.method.overload.declaration.js + new-expr: + begin: "\\b(new)\\b" + beginCaptures: + '1': + name: keyword.operator.js + end: "(?=[(;]|$)" + name: new.expr.js + patterns: + - include: "#type" + - include: "#comment" + null-literal: + match: "\\b(null)\\b" + name: constant.language.null.js + numeric-literal: + match: "\\b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|([0-9]+(\\.[0-9]+)?))\\b" + name: constant.numeric.js + object-body: + begin: "\\{" + beginCaptures: + '0': + name: meta.brace.curly.js + end: "\\}" + endCaptures: + '0': + name: meta.brace.curly.js + name: meta.object.body.js + patterns: + - include: "#string" + - include: "#comment" + - include: "#field-declaration" + - include: "#method-declaration" + - include: "#indexer-declaration" + - include: "#type-annotation" + - include: "#variable-initializer" + - include: "#access-modifier" + - include: "#static-modifier" + - include: "#property-accessor" + object-declaration: + begin: "\\b(?:(export)\\s+)?\\b(?:(abstract)\\s+)?\\b(?=|<>|<|>" + name: keyword.operator.comparison.js + return-type: + begin: "(?<=\\))\\s*:" + end: "(?=$)|(?=\\{|;|//)" + name: meta.return.type.js + patterns: + - include: "#type" + static-modifier: + match: "\\b(static)\\b" + name: keyword.other.js + storage-keyword: + match: "\\b(number|boolean|string|any|var|let|function|const|module|namespace)\\b" + name: storage.type.js + string: + name: string.js + patterns: + - include: "#qstring-single" + - include: "#qstring-double" + string-character-escape: + match: "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)" + name: constant.character.escape + switch-block: + begin: "{" + end: "(?=\\})" + name: switch-block.expr.js + patterns: + - include: "#expression" + switch-expression: + begin: "\\b(switch)\\b\\s*\\(" + beginCaptures: + '1': + name: keyword.operator.js + end: "\\)" + name: switch-expression.expr.js + patterns: + - include: "#expression" + switch-statement: + begin: "(?=\\bswitch\\b\\s*\\()" + end: "}" + name: switch-statement.expr.js + patterns: + - include: "#switch-expression" + - include: "#switch-block" + template: + begin: "`" + beginCaptures: + '0': + name: string.template.js + end: "`" + endCaptures: + '0': + name: string.template.js + name: meta.template.js + patterns: + - include: "#template-substitution-element" + - include: "#template-string-contents" + template-string-contents: + begin: ".*?" + end: "(?=(\\$\\{|`))" + name: string.template.js + patterns: + - include: "#string-character-escape" + template-substitution-element: + begin: "\\$\\{" + beginCaptures: + '0': + name: keyword.operator.js + end: "\\}" + endCaptures: + '0': + name: keyword.operator.js + name: template.element.js + patterns: + - include: "#expression" + this-literal: + match: "\\b(this)\\b" + name: constant.language.this.js + type: + name: meta.type.js + patterns: + - include: "#type-primitive" + - include: "#type-parameters" + - include: "#type-tuple" + - include: "#type-object" + - include: "#type-operator" + - include: "#type-paren-or-function-type-parameters" + - include: "#type-function-return-type" + - include: "#type-name" + type-annotation: + begin: ":" + end: "(?=$|[,);\\}\\]]|//)|(?==[^>])|(?<=[\\}>\\]\\)]|[a-zA-Z_$])\\s*(?=\\{)" + name: meta.type.annotation.js + patterns: + - include: "#type" + - include: "#string" + - include: "#comment" + type-declaration: + begin: "\\b(type)\\b\\s+([a-zA-Z_$][\\w$]*)\\s*=\\s*" + beginCaptures: + '1': + name: keyword.other.js + '2': + name: storage.type.js + end: "(?=$|[,);>]|var|type|function|class|interface)" + name: meta.type.declaration.js + patterns: + - include: "#type" + type-function-return-type: + begin: "=>" + beginCaptures: + '0': + name: keyword.operator.js + end: "(?=\\s*[,\\)\\{=;>]|//|$)" + name: meta.type.function.return.js + patterns: + - include: "#type" + type-name: + captures: + '1': + name: entity.name.type.js + match: "[a-zA-Z_$][.\\w$]*" + name: meta.type.name.js + type-object: + begin: "\\{" + beginCaptures: + '0': + name: meta.brace.curly.js + end: "\\}" + endCaptures: + '0': + name: meta.brace.curly.js + name: meta.object.type.js + patterns: + - include: "#comment" + - include: "#field-declaration" + - include: "#method-declaration" + - include: "#indexer-declaration" + - include: "#type-annotation" + type-operator: + match: "[.|]" + name: keyword.operator.type.js + type-parameters: + begin: "([a-zA-Z_$][\\w$]*)?(<)" + beginCaptures: + '1': + name: entity.name.type.js + '2': + name: meta.brace.angle.js + end: "(?=$)|(>)" + endCaptures: + '2': + name: meta.brace.angle.js + name: meta.type.parameters.js + patterns: + - match: "\\b(extends)\\b" + name: keyword.other.js + - include: "#comment" + - include: "#type" + type-paren-or-function-type-parameters: + begin: "(?:\\b(new)\\b)?\\s*\\(" + beginCaptures: + '1': + name: keyword.control.js + end: "\\)" + name: meta.type.paren.cover.js + patterns: + - include: "#comment" + - include: "#type" + - include: "#function-type-parameters" + type-primitive: + captures: + '1': + name: storage.type.js + match: "\\b(string|number|boolean|symbol|any|void)\\b" + name: meta.type.primitive.js + type-tuple: + begin: "\\[" + beginCaptures: + '0': + name: meta.brace.square.js + end: "\\]" + endCaptures: + '0': + name: meta.brace.square.js + name: meta.type.tuple.js + patterns: + - include: "#type" + - include: "#comment" + undefined-literal: + match: "\\b(undefined)\\b" + name: constant.language.js + var-expr: + begin: "(? - Extension point to register TextMate grammars *.tmLanguage, *.json (VSCode format). + Extension point to register TextMate grammars *.tmLanguage, *.json (VSCode format), *.YAML-tmLanguage, *.yaml, *.yml. diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties index 0066ccf12..f132b9914 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties @@ -6,7 +6,7 @@ # http://www.eclipse.org/legal/epl-v10.html # # Contributors: -# Angelo Zerr - Initial API and implementation +# Angelo Zerr - Initial API and implementation ############################################################################### # Buttons @@ -18,7 +18,7 @@ Button_browse_Workspace=Browse Workspace... # preference page TextMatePreferencePage_GrammarRelatedLink=See ''{0}'' for associating editors with grammars. -TextMatePreferencePage_LanguageConfigurationRelatedLink=See ''{0}'' for associating editors with language configurations. +TextMatePreferencePage_LanguageConfigurationRelatedLink=See ''{0}'' for associating editors with language configurations. TextMatePreferencePage_ThemeRelatedLink=See ''{0}'' for associating editors with themes. GrammarPreferencePage_title=TextMate grammars @@ -52,19 +52,19 @@ ThemeAssociationLabelProvider_dark=Use ''{0}'' theme with Eclipse 'Dark' theme. GrammarInfoWidget_name_text=Name: GrammarInfoWidget_scopeName_text=Scope: GrammarInfoWidget_fileTypes_text=File types: - + # Wizards SelectGrammarWizardPage_title=Specify the TextMate grammar file -SelectGrammarWizardPage_description=Specify the TextMate grammar file *.tmLanguage, *.json (VSCode format) to import. +SelectGrammarWizardPage_description=Specify the TextMate grammar file *.tmLanguage, *.json (VSCode format), *.YAML-tmLanguage, *.yaml, *.yml to import. SelectGrammarWizardPage_file_label=File: -SelectGrammarWizardPage_file_error_required=TextMate grammar file is required. +SelectGrammarWizardPage_file_error_required=TextMate grammar file is required. SelectGrammarWizardPage_file_error_load=Error while loading the TextMate grammar file: "{0}". SelectGrammarWizardPage_file_error_invalid=The file is not a TextMate grammar file. It cannot retrieve the scope name. -CreateThemeAssociationWizardPage_title=Specify the theme to use with a given grammar +CreateThemeAssociationWizardPage_title=Specify the theme to use with a given grammar CreateThemeAssociationWizardPage_description=Choose the theme to use for your grammar when an E4 Theme is activated. -CreateThemeAssociationWizardPage_theme_text=Use the theme: -CreateThemeAssociationWizardPage_grammar_text= with the grammar: +CreateThemeAssociationWizardPage_theme_text=Use the theme: +CreateThemeAssociationWizardPage_grammar_text= with the grammar: CreateThemeAssociationWizardPage_theme_error_required=Theme is required CreateThemeAssociationWizardPage_grammar_error_required=Grammar is required CreateThemeAssociationWizardPage_whenDark_text=when Eclipse Dark theme is activated? diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java index b7566ae81..1b26f1629 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java @@ -45,7 +45,7 @@ public class SelectGrammarWizardPage extends AbstractWizardPage { private static final String PAGE_NAME = SelectGrammarWizardPage.class.getName(); - protected static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json"}; + protected static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json","*.YAML-tmLanguage","*.yaml","*.yml"}; private Button browseFileSystemButton; private Button browseWorkspaceButton; @@ -104,7 +104,7 @@ public void widgetSelected(SelectionEvent e) { // TODO } }); - + grammarInfoWidget = new GrammarInfoWidget(parent, SWT.NONE); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; diff --git a/target-platform/tm4e-target.target b/target-platform/tm4e-target.target index 5165b79a3..bab68d0a4 100644 --- a/target-platform/tm4e-target.target +++ b/target-platform/tm4e-target.target @@ -11,6 +11,7 @@ + From 9904414492416253daf4d2577240e7a289ddead0 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 12 Apr 2022 19:16:33 +0200 Subject: [PATCH 043/202] Remove hashCode/equals override again The fileTypes field is a mutable field only used for caching purposes. It's value is derived from the underlying map's "fileType" entry. --- .../core/internal/grammar/parser/Raw.java | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java index 79bc06b27..92457d050 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java @@ -1,14 +1,14 @@ /** - * Copyright (c) 2015-2019 Angelo ZERR. + * Copyright (c) 2015-2019 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes */ package org.eclipse.tm4e.core.internal.grammar.parser; @@ -53,7 +53,8 @@ public class Raw extends HashMap implements IRawRepository, IRaw private static final String DOLLAR_SELF = "$self"; private static final String DOLLAR_BASE = "$base"; private static final long serialVersionUID = -2306714541728887963L; - private List fileTypes; + + private transient List fileTypes; @Override public IRawRule getProp(String name) { @@ -264,20 +265,20 @@ public String getScopeName() { @Override public Collection getFileTypes() { - if(fileTypes==null) { - List list=new ArrayList<>(); + if (fileTypes == null) { + List list = new ArrayList<>(); Collection unparsedFileTypes = (Collection) super.get(FILE_TYPES); if (unparsedFileTypes != null) { - for(Object o: unparsedFileTypes) { - String str=o.toString(); + for (Object o : unparsedFileTypes) { + String str = o.toString(); // #202 - if(str.startsWith(".")) { - str=str.substring(1); + if (str.startsWith(".")) { + str = str.substring(1); } list.add(str); } } - fileTypes=list; + fileTypes = list; } return fileTypes; } @@ -303,27 +304,17 @@ public Object clone() { } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - Raw other = (Raw) obj; - if (fileTypes == null) { - if (other.fileTypes != null) - return false; - } else if (!fileTypes.equals(other.fileTypes)) - return false; - return true; + public Object put(String key, Object value) { + if (FILE_TYPES.equals(key)) + fileTypes = null; + return super.put(key, value); } @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((fileTypes == null) ? 0 : fileTypes.hashCode()); - return result; + @SuppressWarnings("unlikely-arg-type") + public void putAll(Map m) { + if (m != null && m.containsKey(FILE_TYPES)) + fileTypes = null; + super.putAll(m); } } \ No newline at end of file From 7a1554befd4f5bca34f4ae93d0adb7476a4917c7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 12 Apr 2022 19:17:52 +0200 Subject: [PATCH 044/202] Rename PlistFormatsTest to GrammarReaderTest Renames/moves the `internal.grammar.parser.PListFormatsTest` to `internal.grammar.reader.GrammarReaderTest`, since the test mainly uses the GrammarReader from this package. --- .../GrammarReaderTest.java} | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) rename org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/{parser/PlistFormatsTest.java => reader/GrammarReaderTest.java} (70%) diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PlistFormatsTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReaderTest.java similarity index 70% rename from org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PlistFormatsTest.java rename to org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReaderTest.java index c783e189a..a461cc2aa 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PlistFormatsTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReaderTest.java @@ -10,18 +10,17 @@ * Contributors: * Sebastian Thomschke - initial implementation */ -package org.eclipse.tm4e.core.internal.grammar.parser; +package org.eclipse.tm4e.core.internal.grammar.reader; import static org.junit.jupiter.api.Assertions.*; import java.io.InputStream; import org.eclipse.tm4e.core.Data; -import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.junit.jupiter.api.Test; -public class PlistFormatsTest { +public class GrammarReaderTest { private IRawGrammar loadGrammar(String path) throws Exception { try (InputStream is = Data.class.getResourceAsStream(path)) { @@ -29,13 +28,20 @@ private IRawGrammar loadGrammar(String path) throws Exception { } } + /** + * Loads the same TextMate grammar in different formats and checks + * loading them results in equal IRawGrammar objects. + */ @Test - public void testPlistFormats() throws Exception { + public void testLoadDifferentPlistFormats() throws Exception { IRawGrammar grammarFromXML = loadGrammar("JavaScript.tmLanguage"); IRawGrammar grammarFromJSON = loadGrammar("JavaScript.tmLanguage.json"); IRawGrammar grammarFromYAML = loadGrammar("JavaScript.tmLanguage.yaml"); + assertNotNull(grammarFromXML); + assertFalse(grammarFromXML.getFileTypes().isEmpty()); + assertEquals(grammarFromXML, grammarFromJSON); - assertEquals(grammarFromXML, grammarFromYAML); + assertEquals(grammarFromJSON, grammarFromYAML); } } From 8e8c9edbf8b5db3e8149e00d4cb614e2b5ed42bd Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 12 Apr 2022 20:16:21 +0200 Subject: [PATCH 045/202] Fix NPE when loading language-configuration (#323) --- .../internal/LanguageConfiguration.java | 16 ++-- .../internal/supports/ParsingTest.java | 34 +++++--- .../resources/php-language-configuration.json | 81 +++++++++++++++++++ 3 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 org.eclipse.tm4e.languageconfiguration/src/test/resources/php-language-configuration.json diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java index acd02ea40..91b605342 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal; @@ -58,11 +58,11 @@ public static LanguageConfiguration load(Reader reader) { JsonElement actionElement = object.get("action"); //$NON-NLS-1$ if (actionElement != null && actionElement.isJsonObject()) { JsonObject actionObject = actionElement.getAsJsonObject(); - IndentAction indentAction = IndentAction - .valueOf(getAsString(actionObject.get("indentAction"))); //$NON-NLS-1$ - Integer removeText = getAsInt(actionObject.get("removeText")); //$NON-NLS-1$ - String appendText = getAsString(actionObject.get("appendText")); //$NON-NLS-1$ - if (indentAction != null) { + String indentActionString = getAsString(actionObject.get("indentAction")); //$NON-NLS-1$ + if (indentActionString != null) { + IndentAction indentAction = IndentAction.valueOf(indentActionString); + Integer removeText = getAsInt(actionObject.get("removeText")); //$NON-NLS-1$ + String appendText = getAsString(actionObject.get("appendText")); //$NON-NLS-1$ action = new EnterAction(indentAction); action.setAppendText(appendText); action.setRemoveText(removeText); diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java index 652ca29fb..b0bfb2e6a 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java @@ -1,16 +1,18 @@ /********************************************************************* -* Copyright (c) 2018 Red Hat Inc., and others -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* SPDX-License-Identifier: EPL-2.0 -**********************************************************************/ + * Copyright (c) 2018 Red Hat Inc., and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ package org.eclipse.tm4e.languageconfiguration.internal.supports; import static org.junit.jupiter.api.Assertions.assertNotNull; +import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfiguration; @@ -18,10 +20,22 @@ public class ParsingTest { + private LanguageConfiguration loadLanguageConfiguration(String path) throws IOException { + try (InputStream is = getClass().getResourceAsStream(path)) { + assertNotNull(is); + return LanguageConfiguration.load(new InputStreamReader(is)); + } + } + @Test - public void testCanLoadRustLanguageConfig() throws Exception { - LanguageConfiguration languageConfiguration = LanguageConfiguration.load(new InputStreamReader(getClass().getResourceAsStream("/rust-language-configuration.json"))); + public void testCanLoadPhpLanguageConfig() throws Exception { + LanguageConfiguration languageConfiguration = loadLanguageConfiguration("/php-language-configuration.json"); assertNotNull(languageConfiguration); } + @Test + public void testCanLoadRustLanguageConfig() throws Exception { + LanguageConfiguration languageConfiguration = loadLanguageConfiguration("/rust-language-configuration.json"); + assertNotNull(languageConfiguration); + } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/resources/php-language-configuration.json b/org.eclipse.tm4e.languageconfiguration/src/test/resources/php-language-configuration.json new file mode 100644 index 000000000..e02f24bd1 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/test/resources/php-language-configuration.json @@ -0,0 +1,81 @@ +{ + "comments": { + "lineComment": "//", // "#" + "blockComment": [ "/*", "*/" ] + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + "autoClosingPairs": [ + { "open": "{", "close": "}", "notIn": ["string"] }, + { "open": "[", "close": "]", "notIn": ["string"] }, + { "open": "(", "close": ")", "notIn": ["string"] }, + { "open": "'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "\"", "close": "\"", "notIn": ["string", "comment"] }, + { "open": "/**", "close": " */", "notIn": ["string"] } + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["'", "'"], + ["\"", "\""], + ["`", "`"] + ], + "indentationRules": { + "increaseIndentPattern": "({(?!.*}).*|\\(|\\[|((else(\\s)?)?if|else|for(each)?|while|switch|case).*:)\\s*((/[/*].*|)?$|\\?>)", + "decreaseIndentPattern": "^(.*\\*\\/)?\\s*((\\})|(\\)+[;,])|(\\]\\)*[;,])|\\b(else:)|\\b((end(if|for(each)?|while|switch));))" + }, + "folding": { + "markers": { + "start": "^\\s*(#|\/\/)region\\b", + "end": "^\\s*(#|\/\/)endregion\\b" + } + }, + "wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\-\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)", + "onEnterRules": [ + { + // e.g. /** | */ + "beforeText": "^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", + "afterText": "^\\s*\\*\\/$", + "action": { + "indent": "indentOutdent", + "appendText": " * " + } + }, + { + // e.g. /** ...| + "beforeText": "^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", + "action": { + "indent": "none", + "appendText": " * " + } + }, + { + // e.g. * ...| + "beforeText": "^(\\t|(\\ \\ ))*\\ \\*(\\ ([^\\*]|\\*(?!\\/))*)?$", + "action": { + "indent": "none", + "appendText": "* " + } + }, + { + // e.g. */| + "beforeText": "^(\\t|(\\ \\ ))*\\ \\*\\/\\s*$", + "action": { + "indent": "none", + "removeText": 1 + } + }, + { + // e.g. *-----*/| + "beforeText": "^(\\t|(\\ \\ ))*\\ \\*[^/]*\\*\\/\\s*$", + "action": { + "indent": "none", + "removeText": 1 + } + } + ] +} From 8a770d8ca29374bff4f3090fb67152b2c16e876f Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 12 Apr 2022 20:49:51 +0200 Subject: [PATCH 046/202] Use try-with-resources --- .../eclipse/tm4e/core/registry/Registry.java | 10 ++++---- .../wizards/SelectGrammarWizardPage.java | 5 ++-- .../org/eclipse/tm4e/ui/themes/Theme.java | 3 +-- .../tm4e/ui/utils/ContentTypeHelper.java | 24 +++++++------------ 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index 264c0fe5e..964a0e1ec 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.registry; @@ -122,7 +122,9 @@ private IGrammar _loadGrammar(String initialScopeName) { } public IGrammar loadGrammarFromPathSync(File file) throws Exception { - return loadGrammarFromPathSync(file.getPath(), new FileInputStream(file)); + try (InputStream is = new FileInputStream(file)) { + return loadGrammarFromPathSync(file.getPath(), is); + } } public IGrammar loadGrammarFromPathSync(String path, InputStream in) throws Exception { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java index 1b26f1629..e3f815d62 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java @@ -13,6 +13,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -135,8 +136,8 @@ protected IStatus validatePage(Event event) { } File f = new File(path); Registry registry = new Registry(); - try { - IGrammar grammar = registry.loadGrammarFromPathSync(f.getName(), new FileInputStream(f)); + try(InputStream is = new FileInputStream(f)) { + IGrammar grammar = registry.loadGrammarFromPathSync(f.getName(), is); if (grammar == null || grammar.getScopeName() == null) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.SelectGrammarWizardPage_file_error_invalid); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java index 0d3b175a6..ae6145cba 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java @@ -127,8 +127,7 @@ public Color getEditorCurrentLineHighlight() { private ITokenProvider getTokenProvider() { if (tokenProvider == null) { - try { - InputStream in = super.getInputStream(); + try(InputStream in = super.getInputStream()) { if (in == null) { return null; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java index b8fee9325..5f8229eec 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.utils; @@ -109,7 +109,7 @@ private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws Co if (buffer.isDirty()) { // Buffer is dirty (content of the filesystem is not synch with // the editor content), use IDocument content. - try (InputStream input = new DocumentInputStream(buffer.getDocument())){ + try (InputStream input = new DocumentInputStream(buffer.getDocument())) { IContentType[] contentTypesForInput = Platform.getContentTypeManager().findContentTypesFor(input, fileName); if (contentTypesForInput != null) { contentTypes.addAll(Arrays.asList(contentTypesForInput)); @@ -119,7 +119,7 @@ private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws Co } // Buffer is synchronized with filesystem content - try (InputStream contents = getContents(buffer)){ + try (InputStream contents = getContents(buffer)) { contentTypes.addAll(Arrays.asList(Platform.getContentTypeManager().findContentTypesFor(contents, fileName))); return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new)); } catch (Throwable e) { @@ -164,21 +164,15 @@ private static ContentTypeInfo findContentTypesFromEditorInput(IDocument documen IEditorInput editorInput = getEditorInput(document); if (editorInput != null) { if (editorInput instanceof IStorageEditorInput) { - InputStream input = null; try { IStorage storage = ((IStorageEditorInput) editorInput).getStorage(); String fileName = storage.getName(); - input = storage.getContents(); - return new ContentTypeInfo(fileName, - Platform.getContentTypeManager().findContentTypesFor(input, fileName)); + try (InputStream input = storage.getContents()) { + return new ContentTypeInfo(fileName, + Platform.getContentTypeManager().findContentTypesFor(input, fileName)); + } } catch (Exception e) { return null; - } finally { - try { - if (input != null) - input.close(); - } catch (IOException x) { - } } } else { // TODO: manage other type of IEditorInput From f5c455cbc38c31e5d286d2b1885a4f5ab68e9e1b Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 12 Apr 2022 21:33:39 +0200 Subject: [PATCH 047/202] Fix incomplete listeners synchronization in TMPresentationReconciler Doing unsynchronized null-checks has the known issues of Double Checked Locking, where the current field value may not be visible in other threads. Even without that issue concurrent calls to addTMPresentationReconcilerListener() can result in race-conditions because of the lazy initialized unsynchronized assignment of the listeners variable. --- .../ui/text/TMPresentationReconciler.java | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index acb1e378a..794e1b9fd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -111,7 +111,7 @@ public class TMPresentationReconciler implements IPresentationReconciler { private IPreferenceChangeListener themeChangeListener; - private List listeners; + private final List listeners = new ArrayList<>(); private boolean initializeViewerColors; @@ -133,7 +133,6 @@ public TMPresentationReconciler() { this.defaultToken = new Token(null); this.internalListener = new InternalListener(); this.fDefaultTextAttribute = new TextAttribute(null); - listeners = null; if (TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/GenerateTest")) { addTMPresentationReconcilerListener(new TMPresentationReconcilerTestGenerator()); } @@ -178,9 +177,6 @@ private void preferenceThemeChange(String eclipseThemeId, IThemeManager themeMan class InternalListener implements ITextInputListener, IModelTokensChangedListener, ITextListener { private void fireInstall(ITextViewer viewer, IDocument document) { - if (listeners == null) { - return; - } synchronized (listeners) { for (ITMPresentationReconcilerListener listener : listeners) { listener.install(viewer, document); @@ -189,9 +185,6 @@ private void fireInstall(ITextViewer viewer, IDocument document) { } private void fireUninstall() { - if (listeners == null) { - return; - } synchronized (listeners) { for (ITMPresentationReconcilerListener listener : listeners) { listener.uninstall(); @@ -680,9 +673,6 @@ private void applyTextRegionCollection(TextPresentation presentation) { * the TextMate presentation reconciler listener to add. */ public void addTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { - if (listeners == null) { - listeners = new ArrayList<>(); - } synchronized (listeners) { if (!listeners.contains(listener)) { listeners.add(listener); @@ -697,9 +687,6 @@ public void addTMPresentationReconcilerListener(ITMPresentationReconcilerListene * the TextMate presentation reconciler listener to remove. */ public void removeTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { - if (listeners == null) { - return; - } synchronized (listeners) { listeners.remove(listener); } @@ -712,9 +699,6 @@ public void removeTMPresentationReconcilerListener(ITMPresentationReconcilerList * @param error */ private void fireColorize(TextPresentation presentation, Throwable error) { - if (listeners == null) { - return; - } synchronized (listeners) { for (ITMPresentationReconcilerListener listener : listeners) { listener.colorize(presentation, error); @@ -726,7 +710,8 @@ public static TMPresentationReconciler getTMPresentationReconciler(IEditorPart e if (editorPart == null) { return null; } - @Nullable ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); + @Nullable + ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); if (target instanceof ITextViewer) { ITextViewer textViewer = ((ITextViewer) target); return TMPresentationReconciler.getTMPresentationReconciler(textViewer); @@ -747,7 +732,7 @@ public static TMPresentationReconciler getTMPresentationReconciler(ITextViewer t Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); if (field != null) { field.setAccessible(true); - Object presentationReconciler = field.get(textViewer); + Object presentationReconciler = field.get(textViewer); //field is IPresentationRecounciler, looking for TMPresentationReconciler implementation return presentationReconciler instanceof TMPresentationReconciler ? (TMPresentationReconciler) presentationReconciler From b68b135bfd9c0e766f4ef33f45f6ae75bf7a1131 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 13 Apr 2022 15:27:50 +0200 Subject: [PATCH 048/202] Use String.equals for string comparison instead of identity check --- .../org/eclipse/tm4e/ui/themes/ColorManager.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java index eacd5a860..abdd069a8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java @@ -53,7 +53,7 @@ public void dispose() { /** * Get the color from preferences store using a token. - * + * * @param tokenId * name of the token * @return Color matching token @@ -64,7 +64,7 @@ public Color getPreferenceEditorColor(String tokenId) { /** * The method verifies that a color is defined in a preferences store using a token. - * + * * @param tokenId * name of the token * @return color is user defined or not @@ -72,16 +72,15 @@ public Color getPreferenceEditorColor(String tokenId) { public boolean isColorUserDefined(String tokenId) { String systemDefaultToken = getSystemDefaultToken(tokenId); - return systemDefaultToken != "" - ? !PreferenceUtils.getEditorsPreferenceStore().getBoolean(systemDefaultToken, true) - : true; // if system default token doesn't exists + return "".equals(systemDefaultToken) || // returns true if system default token doesn't exists + !PreferenceUtils.getEditorsPreferenceStore().getBoolean(systemDefaultToken, true); } /** * Get high priority color in text editors. * See Issue #176 * Priority: User defined > TM defined > Eclipse color - * + * * @param themeColor * color defined in TM theme * @param tokenId @@ -100,7 +99,7 @@ public Color getPriorityColor(Color themeColor, String tokenId) { /** * Returns a token for the system default value of the given token. - * + * * @param tokenId * name of the token * @return system default token or empty string if doesn't exist @@ -122,7 +121,7 @@ private String getSystemDefaultToken(String tokenId) { /** * Convert String to RGB. - * + * * @param value * string value of rgb * @return RGB value From 72d98dc7cd070d0f0cb18238f9d4bb653192e093 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 13 Apr 2022 20:34:18 +0200 Subject: [PATCH 049/202] Replace if-string-equals statements with switch(string) statements --- .../core/internal/css/CSSDocumentHandler.java | 25 ++++++---- .../grammar/ScopeMetadataProvider.java | 11 +++-- .../tm4e/core/internal/parser/PList.java | 49 +++++++++++++------ .../org/eclipse/tm4e/core/theme/Theme.java | 16 +++--- .../core/grammar/GrammarInjectionTest.java | 30 ++++++------ .../internal/GrammarRegistryManager.java | 21 +++++--- .../tm4e/ui/internal/themes/ThemeManager.java | 34 +++++++------ .../ui/text/TMPresentationReconciler.java | 25 +++++----- 8 files changed, 126 insertions(+), 85 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java index 07044d2b0..522109a7e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.css; @@ -89,17 +89,21 @@ public void namespaceDeclaration(String arg0, String arg1) throws CSSException { @Override public void property(String name, LexicalUnit value, boolean arg2) throws CSSException { - if (currentStyle != null) { - if ("color".equals(name)) { + if (currentStyle != null && name != null) { + switch (name) { + case "color": currentStyle.setColor(createRGB(value)); - } else if ("background-color".equals(name)) { + break; + case "background-color": currentStyle.setBackgroundColor(createRGB(value)); - } else if ("font-weight".equals(name)) { + break; + case "font-weight": currentStyle.setBold(value.getStringValue().toUpperCase().contains("BOLD")); - } else if ("font-style".equals(name)) { + break; + case "font-style": currentStyle.setItalic(value.getStringValue().toUpperCase().contains("ITALIC")); - } - if ("text-decoration".equals(name)) { + break; + case "text-decoration": String decoration = value.getStringValue().toUpperCase(); if (decoration.contains("UNDERLINE")) { currentStyle.setUnderline(true); @@ -107,6 +111,7 @@ public void property(String name, LexicalUnit value, boolean arg2) throws CSSExc if (decoration.contains("LINE-THROUGH")) { currentStyle.setStrikeThrough(true); } + break; } } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java index 8a26a2dc3..a5bfd0f1b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java @@ -164,14 +164,15 @@ private static int toStandardTokenType(String tokenType) { return StandardTokenType.Other; } String group = m.group(); - if (COMMENT_TOKEN_TYPE.equals(group)) { + switch (group) { + case COMMENT_TOKEN_TYPE: return StandardTokenType.Comment; - } else if (STRING_TOKEN_TYPE.equals(group)) { + case STRING_TOKEN_TYPE: return StandardTokenType.String; - } - if (REGEX_TOKEN_TYPE.equals(group)) { + case REGEX_TOKEN_TYPE: return StandardTokenType.RegEx; + default: + throw new TMException("Unexpected match for standard token type: " + group); } - throw new TMException("Unexpected match for standard token type!"); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java index 8732e8cfb..458896a8c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.parser; @@ -36,15 +36,20 @@ public PList(boolean theme) { @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - if ("dict".equals(localName)) { + switch (localName) { + case "dict": this.currObject = create(currObject, false); - } else if ("array".equals(localName)) { + break; + case "array": this.currObject = create(currObject, true); - } else if ("key".equals(localName)) { + break; + case "key": if (currObject != null) { currObject.setLastKey(null); } + break; } + this.text = new StringBuilder(""); super.startElement(uri, localName, qName, attributes); } @@ -65,48 +70,60 @@ public void endElement(String uri, String localName, String qName) throws SAXExc private void endElement(String tagName) { Object value = null; String text = this.text.toString(); - if ("key".equals(tagName)) { + + switch (tagName) { + case "key": if (currObject == null || currObject.isValueAsArray()) { errors.add("key can only be used inside an open dict element"); return; } currObject.setLastKey(text); return; - } else if ("dict".equals(tagName) || "array".equals(tagName)) { + case "dict": + case "array": if (currObject == null) { errors.add(tagName + " closing tag found, without opening tag"); return; } value = currObject.getValue(); currObject = currObject.parent; - } else if ("string".equals(tagName) || "data".equals(tagName)) { + break; + case "string": + case "data": value = text; - } else if ("date".equals(tagName)) { + break; + case "date": // TODO : parse date - } else if ("integer".equals(tagName)) { + break; + case "integer": try { value = Integer.parseInt(text); } catch (NumberFormatException e) { errors.add(text + " is not a integer"); return; } - } else if ("real".equals(tagName)) { + break; + case "real": try { value = Float.parseFloat(text); } catch (NumberFormatException e) { errors.add(text + " is not a float"); return; } - } else if ("true".equals(tagName)) { + break; + case "true": value = true; - } else if ("false".equals(tagName)) { + break; + case "false": value = false; - } else if ("plist".equals(tagName)) { + break; + case "plist": return; - } else { + default: errors.add("Invalid tag name: " + tagName); return; } + if (currObject == null) { result = (T) value; } else if (currObject.isValueAsArray()) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index 312f8e2c1..17e91f10d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; @@ -85,12 +85,16 @@ public static List parseTheme(IRawTheme source) { String[] segments = ((String) settingsFontStyle).split(" "); for (String segment : segments) { - if ("italic".equals(segment)) { + switch (segment) { + case "italic": fontStyle = fontStyle | FontStyle.Italic; - } else if ("bold".equals(segment)) { + break; + case "bold": fontStyle = fontStyle | FontStyle.Bold; - } else if ("underline".equals(segment)) { + break; + case "underline": fontStyle = fontStyle | FontStyle.Underline; + break; } } } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java index 41b6a2cad..e8a379627 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.grammar; @@ -41,7 +41,6 @@ public class GrammarInjectionTest { "Token from 39 to 40 with scopes [source.ts, meta.decorator.ts, meta.object-literal.ts, punctuation.definition.block.ts]", "Token from 40 to 41 with scopes [source.ts, meta.decorator.ts, meta.brace.round.ts]" }; - @Test public void angular2TokenizeLine() throws Exception { Registry registry = new Registry(new IRegistryOptions() { @@ -58,16 +57,19 @@ public Collection getInjections(String scopeName) { @Override public String getFilePath(String scopeName) { - if ("source.js".equals(scopeName)) { - return "JavaScript.tmLanguage.json"; - } else if ("text.html.basic".equals(scopeName)) { - return "html.json"; - } else if ("source.ts".equals(scopeName)) { - return "TypeScript.tmLanguage.json"; - } else if ("template.ng".equals(scopeName)) { - return "template.ng.json"; - } else if ("styles.ng".equals(scopeName)) { - return "styles.ng.json"; + if (scopeName != null) { + switch (scopeName) { + case "source.js": + return "JavaScript.tmLanguage.json"; + case "text.html.basic": + return "html.json"; + case "source.ts": + return "TypeScript.tmLanguage.json"; + case "template.ng": + return "template.ng.json"; + case "styles.ng": + return "styles.ng.json"; + } } return null; } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java index 358bb3039..d5552aecf 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry.internal; @@ -66,21 +66,28 @@ private void loadGrammarsFromExtensionPoints() { .getConfigurationElementsFor(TMEclipseRegistryPlugin.PLUGIN_ID, EXTENSION_GRAMMARS); for (IConfigurationElement ce : cf) { String extensionName = ce.getName(); - if (XMLConstants.GRAMMAR_ELT.equals(extensionName)) { + switch (extensionName) { + case XMLConstants.GRAMMAR_ELT: super.registerGrammarDefinition(new GrammarDefinition(ce)); - } else if (XMLConstants.INJECTION_ELT.equals(extensionName)) { + break; + case XMLConstants.INJECTION_ELT: { String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); String injectTo = ce.getAttribute(XMLConstants.INJECT_TO_ATTR); super.registerInjection(scopeName, injectTo); - } else if (XMLConstants.SCOPE_NAME_CONTENT_TYPE_BINDING_ELT.equals(extensionName)) { + break; + } + case XMLConstants.SCOPE_NAME_CONTENT_TYPE_BINDING_ELT: { String contentTypeId = ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR); IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId); if (contentType == null) { - Platform.getLog(getClass()).warn("No content-type found with id='" + contentTypeId + "', ignoring TM4E association."); + Platform.getLog(getClass()) + .warn("No content-type found with id='" + contentTypeId + "', ignoring TM4E association."); } else { String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); super.registerContentTypeBinding(contentType, scopeName); } + break; + } } } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java index 4a20edd8e..70e213890 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java @@ -1,17 +1,16 @@ /** - * Copyright (c) 2015, 2021 Angelo ZERR and others. + * Copyright (c) 2015, 2021 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.themes; - import java.util.Arrays; import java.util.stream.Collectors; @@ -82,10 +81,13 @@ private void loadThemesFromExtensionPoints() { EXTENSION_THEMES); for (IConfigurationElement ce : cf) { String name = ce.getName(); - if (THEME_ELT.equals(name)) { + switch (name) { + case THEME_ELT: super.registerTheme(new Theme(ce)); - } else if (THEME_ASSOCIATION_ELT.equals(name)) { + break; + case THEME_ASSOCIATION_ELT: super.registerThemeAssociation(new ThemeAssociation(ce)); + break; } } } @@ -120,15 +122,15 @@ public void save() throws BackingStoreException { // Save Themes in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" prefs.put(PreferenceConstants.THEMES, Arrays.stream(getThemes()) // - .filter(t -> t.getPluginId() == null) // - .map(theme -> { - JsonObject json = new JsonObject(); - json.addProperty("id", theme.getId()); - json.addProperty("path", theme.getPath()); - json.addProperty("dark", theme.isDark()); - return json; + .filter(t -> t.getPluginId() == null) // + .map(theme -> { + JsonObject json = new JsonObject(); + json.addProperty("id", theme.getId()); + json.addProperty("path", theme.getPath()); + json.addProperty("dark", theme.isDark()); + return json; }).collect(JsonArray::new, (JsonArray array, JsonObject object) -> array.add(object), (r,r1) -> {}) - .toString()); + .toString()); // Save Theme associations in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" @@ -143,7 +145,7 @@ public void save() throws BackingStoreException { /** * Add preference change listener to observe changed of Eclipse E4 Theme and * TextMate theme association with grammar. - * + * * @param themeChangeListener */ public void addPreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { @@ -162,7 +164,7 @@ public void addPreferenceChangeListener(IPreferenceChangeListener themeChangeLis /** * Remove preference change listener to observe changed of Eclipse E4 Theme and * TextMate theme association with grammar. - * + * * @param themeChangeListener */ public void removePreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index 794e1b9fd..beb6beb05 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -1,15 +1,15 @@ /** - * Copyright (c) 2015-2019 Angelo ZERR. + * Copyright (c) 2015-2019 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #220 Switch to theme only works once for open editor - * IBM Corporation Gerald Mitchell - bug fix + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #220 Switch to theme only works once for open editor + * IBM Corporation Gerald Mitchell - bug fix */ package org.eclipse.tm4e.ui.text; @@ -149,10 +149,13 @@ private class ThemeChangeListener implements IPreferenceChangeListener { @Override public void preferenceChange(PreferenceChangeEvent event) { IThemeManager themeManager = TMUIPlugin.getThemeManager(); - if (PreferenceConstants.E4_THEME_ID.equals(event.getKey())) { + switch (event.getKey()) { + case PreferenceConstants.E4_THEME_ID: preferenceThemeChange((String) event.getNewValue(), themeManager); - } else if (PreferenceConstants.THEME_ASSOCIATIONS.equals(event.getKey())) { + break; + case PreferenceConstants.THEME_ASSOCIATIONS: preferenceThemeChange(PreferenceUtils.getE4PreferenceCSSThemeId(), themeManager); + break; } } @@ -367,14 +370,14 @@ private void colorize(ModelTokensChangedEvent event) { return; } ITMModel model = event.model; - if (! (model instanceof TMDocumentModel)) { + if (!(model instanceof TMDocumentModel)) { return; } TMDocumentModel docModel = (TMDocumentModel) model; for (Range range : event.ranges) { try { int length = document.getLineOffset(range.toLineNumber - 1) + document.getLineLength(range.toLineNumber - 1) - document.getLineOffset(range.fromLineNumber - 1); - IRegion region = new Region(document.getLineOffset(range.fromLineNumber -1), length); + IRegion region = new Region(document.getLineOffset(range.fromLineNumber - 1), length); TMPresentationReconciler.this.colorize(region, docModel); } catch (BadLocationException ex) { TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); @@ -431,7 +434,7 @@ public void setTheme(final ITokenProvider newTheme) { applyThemeEditor(); IDocument document = viewer.getDocument(); ITMModel model = getTMModelManager().connect(document); - if (! (model instanceof TMDocumentModel)) { + if (!(model instanceof TMDocumentModel)) { return; } TMDocumentModel docModel = (TMDocumentModel) model; @@ -483,7 +486,7 @@ private ITMModelManager getTMModelManager() { return TMUIPlugin.getTMModelManager(); } - void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws BadLocationException{ + void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws BadLocationException { IDocument document = model.getDocument(); final int fromLineNumber = document.getLineOfOffset(damage.getOffset()); final int toLineNumber = document.getLineOfOffset(damage.getOffset() + damage.getLength()); From 2cc5e8b663d4f61544632ccdbca33ea833688e0d Mon Sep 17 00:00:00 2001 From: Victor Rubezhny Date: Thu, 14 Apr 2022 12:36:46 +0200 Subject: [PATCH 050/202] Fix StringIndexOutOfBoundsException in LineTokens An error message appears in log due to StringIndexOutOfBoundsException exception occuring in TMModel.TokenizerThread: !ENTRY org.eclipse.tm4e.core 4 0 2022-04-14 13:10:05.298 !MESSAGE begin -1, end 1, length 1 The cause of the error logged is the following exception: Apr 14, 2022 1:10:05 PM org.eclipse.tm4e.core.model.TMModel$TokenizerThread updateTokensInRange SEVERE: begin -1, end 1, length 1 java.lang.StringIndexOutOfBoundsException: begin -1, end 1, length 1 at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4601) at java.base/java.lang.String.substring(String.java:2704) at org.eclipse.tm4e.core.internal.grammar.LineTokens.produceFromScopes(LineTokens.java:88) at org.eclipse.tm4e.core.internal.grammar.LineTokens.produce(LineTokens.java:62) at org.eclipse.tm4e.core.internal.grammar.LineTokens.getResult(LineTokens.java:106) at org.eclipse.tm4e.core.internal.grammar.Grammar.tokenize(Grammar.java:248) at org.eclipse.tm4e.core.internal.grammar.Grammar.tokenizeLine(Grammar.java:194) at org.eclipse.tm4e.core.model.Tokenizer.tokenize(Tokenizer.java:65) at org.eclipse.tm4e.core.model.TMModel$TokenizerThread.updateTokensInRange(TMModel.java:191) at org.eclipse.tm4e.core.model.TMModel$TokenizerThread.lambda$0(Unknown Source) at org.eclipse.tm4e.core.model.TMModel.buildEventWithCallback(Unknown Source) at org.eclipse.tm4e.core.model.TMModel$TokenizerThread.revalidateTokensNow(Unknown Source) at org.eclipse.tm4e.core.model.TMModel$TokenizerThread.run(Unknown Source) Signed-off-by: Victor Rubezhny --- .../org/eclipse/tm4e/core/internal/grammar/LineTokens.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index d7f0bfd28..b96e8887b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2022 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -85,12 +85,12 @@ public void produceFromScopes(ScopeListElement scopesList, int endIndex) { List scopes = scopesList.generateScopes(); if (this.lineText != null) { - LOGGER.info(" token: |" + this.lineText.substring(this.lastTokenEndIndex, endIndex).replaceAll("\n", "\\n") + '|'); + LOGGER.info(" token: |" + this.lineText.substring(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex).replaceAll("\n", "\\n") + '|'); for (String scope : scopes) { LOGGER.info(" * " + scope); } } - this.tokens.add(new Token(this.lastTokenEndIndex, endIndex, scopes)); + this.tokens.add(new Token(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex, scopes)); this.lastTokenEndIndex = endIndex; } From e67293312a96813569d56cc5abb035257f542b9a Mon Sep 17 00:00:00 2001 From: Victor Rubezhny Date: Thu, 14 Apr 2022 14:24:45 +0200 Subject: [PATCH 051/202] Syntax colouring lost after file compare #321 Signed-off-by: Victor Rubezhny --- .../tm4e/ui/text/TMPresentationReconciler.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index beb6beb05..f5ee1a4d7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2019 Angelo ZERR. + * Copyright (c) 2015-2022 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -302,6 +302,18 @@ public void textChanged(TextEvent e) { if (model == null) { return; } + + // It's possible that there are two or more SourceViewers opened for the same document, + // so when one of them is closed the existing TMModel is also "closed" and its TokenizerThread + // is interrupted and terminated. + // In this case, in order to let the others Source Viewers to continue working a new + // TMModel object is to be created for the document, so it should be initialized + // with the existing grammar as well as new ModelTokenListener is to be added + if (TMPresentationReconciler.this.grammar != null) { + model.setGrammar(TMPresentationReconciler.this.grammar); + model.addModelTokensChangedListener(this); + } + try { TMPresentationReconciler.this.colorize(region, (TMDocumentModel) model); } catch (BadLocationException e1) { From 1da3bfee0c65b01d56271ed317d3cea88ed0d740 Mon Sep 17 00:00:00 2001 From: Sebastian Thomschke Date: Fri, 15 Apr 2022 15:09:31 +0100 Subject: [PATCH 052/202] Improve logging performance (#338) * Check if log-level is enabled before creating log message object * Log LineTokens at level FINEST instead of INFO * Replace java.util.logging.Logger with java.lang.System.Logger --- .../core/internal/grammar/LineTokenizer.java | 28 +++++++++++-------- .../core/internal/grammar/LineTokens.java | 25 +++++++++-------- .../tm4e/core/model/AbstractLineList.java | 11 ++++---- .../org/eclipse/tm4e/core/model/TMModel.java | 18 ++++++------ .../tm4e/core/theme/css/SACParserFactory.java | 11 ++++---- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index ce888e5c1..08d87fa1e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,14 +11,16 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.grammar; +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; import org.eclipse.tm4e.core.grammar.GrammarHelper; import org.eclipse.tm4e.core.grammar.Injection; @@ -37,7 +39,7 @@ class LineTokenizer { - private static final Logger LOGGER = Logger.getLogger(LineTokenizer.class.getName()); + private static final Logger LOGGER = System.getLogger(LineTokenizer.class.getName()); static class WhileStack { @@ -104,12 +106,12 @@ public StackElement scan() { } private void scanNext() { - LOGGER.finest("@@scanNext: |" + lineText.string.replaceAll("\n", "\\n").substring(linePos) + '|'); + LOGGER.log(TRACE, () -> "@@scanNext: |" + lineText.string.replaceAll("\n", "\\n").substring(linePos) + '|'); IMatchResult r = matchRuleOrInjections(grammar, lineText, isFirstLine, linePos, stack, anchorPosition); if (r == null) { - LOGGER.finest(" no more matches."); + LOGGER.log(TRACE, " no more matches."); // No match lineTokens.produce(stack, lineLength); stop = true; @@ -143,7 +145,8 @@ private void scanNext() { if (!hasAdvanced && popped.getEnterPos() == linePos) { // Grammar pushed & popped a rule without advancing - LOGGER.info("[1] - Grammar is in an endless loop - Grammar pushed & popped a rule without advancing"); + LOGGER.log(INFO, + "[1] - Grammar is in an endless loop - Grammar pushed & popped a rule without advancing"); // See https://github.com/Microsoft/vscode-textmate/issues/12 // Let's assume this was a mistake by the grammar author and the // intent was to continue in this state @@ -189,7 +192,8 @@ private void scanNext() { if (!hasAdvanced && beforePush.hasSameRuleAs(stack)) { // Grammar pushed the same rule without advancing - LOGGER.info("[2] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); + LOGGER.log(INFO, + "[2] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); stack = stack.pop(); lineTokens.produce(stack, lineLength); stop = true; @@ -217,7 +221,8 @@ private void scanNext() { if (!hasAdvanced && beforePush.hasSameRuleAs(stack)) { // Grammar pushed the same rule without advancing - LOGGER.info("[3] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); + LOGGER.log(INFO, + "[3] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); stack = stack.pop(); lineTokens.produce(stack, lineLength); stop = true; @@ -239,7 +244,8 @@ private void scanNext() { if (!hasAdvanced) { // Grammar is not advancing, nor is it pushing/popping - LOGGER.info("[4] - Grammar is in an endless loop - Grammar is not advancing, nor is it pushing/popping"); + LOGGER.log(INFO, + "[4] - Grammar is in an endless loop - Grammar is not advancing, nor is it pushing/popping"); stack = stack.safePop(); lineTokens.produce(stack, lineLength); stop = true; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index b96e8887b..c90d94248 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2022 Angelo ZERR. + * Copyright (c) 2015-2022 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,22 +11,23 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.grammar; +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import org.eclipse.tm4e.core.grammar.IToken; import org.eclipse.tm4e.core.grammar.StackElement; class LineTokens { - private static final Logger LOGGER = Logger.getLogger(LineTokens.class.getName()); + private static final Logger LOGGER = System.getLogger(LineTokens.class.getName()); private final String lineText; @@ -35,7 +36,6 @@ class LineTokens { */ private final List tokens; - private final boolean emitBinaryTokens; /** @@ -47,7 +47,7 @@ class LineTokens { LineTokens(boolean emitBinaryTokens, String lineText) { this.emitBinaryTokens = emitBinaryTokens; - this.lineText = LOGGER.isLoggable(Level.FINEST) ? lineText : null; // store line only if it's logged + this.lineText = LOGGER.isLoggable(TRACE) ? lineText : null; // store line only if it's logged if (this.emitBinaryTokens) { this.tokens = null; this.binaryTokens = new ArrayList<>(); @@ -84,10 +84,13 @@ public void produceFromScopes(ScopeListElement scopesList, int endIndex) { List scopes = scopesList.generateScopes(); - if (this.lineText != null) { - LOGGER.info(" token: |" + this.lineText.substring(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex).replaceAll("\n", "\\n") + '|'); + if (this.lineText != null && LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, + " token: |" + this.lineText + .substring(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex) + .replaceAll("\n", "\\n") + '|'); for (String scope : scopes) { - LOGGER.info(" * " + scope); + LOGGER.log(TRACE, " * " + scope); } } this.tokens.add(new Token(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex, scopes)); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java index 8b4827962..7a8bf76f0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java @@ -11,12 +11,13 @@ */ package org.eclipse.tm4e.core.model; +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Abstract class for Model lines used by the TextMate model. Implementation @@ -30,7 +31,7 @@ */ public abstract class AbstractLineList implements IModelLines { - private static final Logger LOGGER = Logger.getLogger(AbstractLineList.class.getName()); + private static final Logger LOGGER = System.getLogger(AbstractLineList.class.getName()); private final List list = Collections.synchronizedList(new ArrayList<>()); @@ -61,8 +62,8 @@ public void removeLine(int line) { public void updateLine(int line) { try { // this.list.get(line).text = this.lineToTextResolver.apply(line); - } catch (Exception e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + } catch (Exception ex) { + LOGGER.log(ERROR, ex.getMessage(), ex); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index 782e24ea3..52ea912ef 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -11,13 +11,15 @@ */ package org.eclipse.tm4e.core.model; +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.PriorityBlockingQueue; import java.util.function.Consumer; -import java.util.logging.Logger; import org.eclipse.tm4e.core.grammar.IGrammar; @@ -27,7 +29,7 @@ */ public class TMModel implements ITMModel { - private static final Logger LOGGER = Logger.getLogger(TMModel.class.getName()); + private static final Logger LOGGER = System.getLogger(TMModel.class.getName()); /** * The TextMate grammar to use to parse for each lines of the document the @@ -93,8 +95,8 @@ public void run() { if (model.lines.get(toProcess).isInvalid) { try { this.revalidateTokensNow(toProcess, null); - } catch (Exception t) { - LOGGER.severe(t.getMessage()); + } catch (Exception ex) { + LOGGER.log(ERROR, ex.getMessage()); if (toProcess < model.lines.getNumberOfLines()) { model.invalidateLine(toProcess); } @@ -141,8 +143,8 @@ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { // Compute how many characters will be tokenized for this line try { currentCharsToTokenize = model.lines.getLineLength(lineIndex); - } catch (Exception e) { - LOGGER.severe(e.getMessage()); + } catch (Exception ex) { + LOGGER.log(ERROR, ex.getMessage()); } if (tokenizedChars > 0) { @@ -186,8 +188,8 @@ private int updateTokensInRange(ModelTokensChangedEventBuilder eventBuilder, int text = model.lines.getLineText(lineIndex); // Tokenize only the first X characters r = model.tokenizer.tokenize(text, modeLine.getState(), 0, stopLineTokenizationAfter); - } catch (Exception e) { - LOGGER.severe(e.getMessage()); + } catch (Exception ex) { + LOGGER.log(ERROR, ex.getMessage()); } if (r != null && r.tokens != null && !r.tokens.isEmpty()) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java index a4c3c9b0b..fab0277cd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java @@ -10,8 +10,9 @@ *******************************************************************************/ package org.eclipse.tm4e.core.theme.css; -import java.util.logging.Level; -import java.util.logging.Logger; +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; import org.eclipse.tm4e.core.internal.css.SACParserFactoryImpl; import org.w3c.css.sac.Parser; @@ -22,7 +23,7 @@ */ public abstract class SACParserFactory extends ParserFactory implements ISACParserFactory { - private static final Logger LOGGER = Logger.getLogger(SACParserFactory.class.getName()); + private static final Logger LOGGER = System.getLogger(SACParserFactory.class.getName()); private String preferredParserName; @@ -39,8 +40,8 @@ public Parser makeParser() throws ClassNotFoundException, IllegalAccessException if (preferredParserName != null) { return makeParser(preferredParserName); } - } catch (Throwable e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + } catch (Throwable ex) { + LOGGER.log(ERROR, ex.getMessage(), ex); } return super.makeParser(); } From 7b7f3fe08f2992fec032e1faa6fbd5ad0fb535da Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 15 Apr 2022 17:46:51 +0200 Subject: [PATCH 053/202] Use Guava Splitter for string splitting --- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 1 + .../internal/grammar/ScopeListElement.java | 15 ++++------ .../eclipse/tm4e/core/model/DecodeMap.java | 6 +++- .../org/eclipse/tm4e/core/theme/Theme.java | 23 ++++++++------- org.eclipse.tm4e.ui/META-INF/MANIFEST.MF | 1 + .../eclipse/tm4e/ui/themes/ColorManager.java | 28 +++++++++++-------- .../tm4e/ui/themes/css/CSSTokenProvider.java | 14 ++++++---- target-platform/tm4e-target.target | 1 + 8 files changed, 52 insertions(+), 37 deletions(-) diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index 305ed92be..26bfdaad6 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-Version: 0.4.4.qualifier Require-Bundle: org.apache.batik.css;bundle-version="1.9.1";resolution:=optional, org.apache.batik.util;bundle-version="1.9.1";resolution:=optional, com.google.gson;resolution:=optional, + com.google.guava;bundle-version="30.1.0", org.jcodings;bundle-version="1.0.18", org.joni;bundle-version="2.1.11", org.yaml.snakeyaml;bundle-version="1.27.0" diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index 6120bee96..029f2295b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -12,7 +12,6 @@ package org.eclipse.tm4e.core.internal.grammar; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -20,8 +19,12 @@ import org.eclipse.tm4e.core.theme.FontStyle; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; +import com.google.common.base.Splitter; + public class ScopeListElement { + private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' '); + public final ScopeListElement parent; public final String scope; public final int metadata; @@ -115,7 +118,7 @@ public static int mergeMetadata(int metadata, ScopeListElement scopesList, Scope background); } - private static ScopeListElement push(ScopeListElement target, Grammar grammar, List scopes) { + private static ScopeListElement push(ScopeListElement target, Grammar grammar, Iterable scopes) { for (String scope : scopes) { ScopeMetadata rawMetadata = grammar.getMetadataForScope(scope); int metadata = ScopeListElement.mergeMetadata(target.metadata, target, rawMetadata); @@ -128,13 +131,7 @@ public ScopeListElement push(Grammar grammar, String scope) { if (scope == null) { return this; } - if (scope.indexOf(' ') >= 0) { - // there are multiple scopes to push - return ScopeListElement.push(this, grammar, Arrays.asList(scope.split(" ")));// scope.split(/ - // /g)); - } - // there is a single scope to push - return ScopeListElement.push(this, grammar, Arrays.asList(scope)); + return ScopeListElement.push(this, grammar, BY_SPACE_SPLITTER.split(scope)); } private static List generateScopes(ScopeListElement scopesList) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java index ca1fe6fea..148478ae0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java @@ -19,8 +19,12 @@ import java.util.LinkedHashMap; import java.util.Map; +import com.google.common.base.Splitter; + class DecodeMap { + private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); + int lastAssignedId; Map scopeToTokenIds; Map tokenToTokenId; @@ -40,7 +44,7 @@ public int[] getTokenIds(String scope) { if (tokens != null) { return tokens; } - String[] tmpTokens = scope.split("[.]"); + String[] tmpTokens = BY_DOT_SPLITTER.splitToStream(scope).toArray(String[]::new); tokens = new int[tmpTokens.length]; for (int i = 0; i < tmpTokens.length; i++) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index 17e91f10d..e548ae35d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -24,12 +24,18 @@ import org.eclipse.tm4e.core.internal.utils.CompareUtils; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; + /** * TextMate theme. * */ public class Theme { + private static final Splitter BY_COMMA_SPLITTER = Splitter.on(','); + private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' '); + private static final Pattern rrggbb = Pattern.compile("^#[0-9a-f]{6}", Pattern.CASE_INSENSITIVE); private static final Pattern rrggbbaa = Pattern.compile("^#[0-9a-f]{8}", Pattern.CASE_INSENSITIVE); private static final Pattern rgb = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE); @@ -61,7 +67,7 @@ public static List parseTheme(IRawTheme source) { } Object settingScope = entry.getScope(); - List scopes = new ArrayList<>(); + List scopes; if (settingScope instanceof String) { String scope = (String) settingScope; @@ -71,11 +77,11 @@ public static List parseTheme(IRawTheme source) { // remove trailing commans scope = scope.replaceAll("[,]+$", ""); - scopes = Arrays.asList(scope.split(",")); + scopes = BY_COMMA_SPLITTER.splitToList(scope); } else if (settingScope instanceof List) { scopes = (List) settingScope; } else { - scopes.add(""); + scopes = Arrays.asList(""); } int fontStyle = FontStyle.NotSet; @@ -83,7 +89,7 @@ public static List parseTheme(IRawTheme source) { if (settingsFontStyle instanceof String) { fontStyle = FontStyle.None; - String[] segments = ((String) settingsFontStyle).split(" "); + Iterable segments = BY_SPACE_SPLITTER.split((String) settingsFontStyle); for (String segment : segments) { switch (segment) { case "italic": @@ -113,16 +119,13 @@ public static List parseTheme(IRawTheme source) { for (int j = 0, lenJ = scopes.size(); j < lenJ; j++) { String _scope = scopes.get(j).trim(); - List segments = Arrays.asList(_scope.split(" ")); + List segments = BY_SPACE_SPLITTER.splitToList(_scope); String scope = segments.get(segments.size() - 1); List parentScopes = null; if (segments.size() > 1) { - parentScopes = segments.subList(0, segments.size() - 1);// slice(0, - // segments.length - // - - // 1); - Collections.reverse(parentScopes); // parentScopes.reverse(); + parentScopes = segments.subList(0, segments.size() - 1); + parentScopes = Lists.reverse(parentScopes); } ParsedThemeRule t = new ParsedThemeRule(scope, parentScopes, i, fontStyle, foreground, background); diff --git a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF index f18dbd9e7..15fbf14b3 100644 --- a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF @@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.tm4e.core, org.eclipse.tm4e.registry, org.eclipse.ui.ide;resolution:=optional, com.google.gson, + com.google.guava, org.eclipse.e4.ui.css.swt.theme, org.eclipse.core.expressions, org.eclipse.ui.workbench.texteditor, diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java index abdd069a8..e3953b81d 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.themes; @@ -21,8 +21,12 @@ import org.eclipse.tm4e.ui.utils.PreferenceUtils; import org.eclipse.ui.texteditor.AbstractTextEditor; +import com.google.common.base.Splitter; + public class ColorManager { + private static final Splitter BY_COMMA_SPLITTER = Splitter.on(','); + private static final ColorManager INSTANCE = new ColorManager(); public static ColorManager getInstance() { @@ -55,7 +59,7 @@ public void dispose() { * Get the color from preferences store using a token. * * @param tokenId - * name of the token + * name of the token * @return Color matching token */ public Color getPreferenceEditorColor(String tokenId) { @@ -66,7 +70,7 @@ public Color getPreferenceEditorColor(String tokenId) { * The method verifies that a color is defined in a preferences store using a token. * * @param tokenId - * name of the token + * name of the token * @return color is user defined or not */ public boolean isColorUserDefined(String tokenId) { @@ -82,9 +86,9 @@ public boolean isColorUserDefined(String tokenId) { * Priority: User defined > TM defined > Eclipse color * * @param themeColor - * color defined in TM theme + * color defined in TM theme * @param tokenId - * name of the token for preferences store + * name of the token for preferences store * @return Highest priority color */ public Color getPriorityColor(Color themeColor, String tokenId) { @@ -101,7 +105,7 @@ public Color getPriorityColor(Color themeColor, String tokenId) { * Returns a token for the system default value of the given token. * * @param tokenId - * name of the token + * name of the token * @return system default token or empty string if doesn't exist */ private String getSystemDefaultToken(String tokenId) { @@ -123,14 +127,14 @@ private String getSystemDefaultToken(String tokenId) { * Convert String to RGB. * * @param value - * string value of rgb + * string value of rgb * @return RGB value */ private RGB stringToRGB(String value) { - String[] rgbValues = value.split(","); + String[] rgbValues = BY_COMMA_SPLITTER.splitToStream(value).toArray(String[]::new); return rgbValues.length == 3 - ? new RGB(Integer.parseInt(rgbValues[0]), Integer.parseInt(rgbValues[1]), Integer.parseInt(rgbValues[2])) - : new RGB(255, 255, 255); + ? new RGB(Integer.parseInt(rgbValues[0]), Integer.parseInt(rgbValues[1]), Integer.parseInt(rgbValues[2])) + : new RGB(255, 255, 255); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java index 7d9eebf26..6b8317b5e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.themes.css; @@ -29,8 +29,12 @@ import org.eclipse.tm4e.ui.themes.AbstractTokenProvider; import org.eclipse.tm4e.ui.themes.ColorManager; +import com.google.common.base.Splitter; + public class CSSTokenProvider extends AbstractTokenProvider { + private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); + private final Map tokenMaps; private CSSParser parser; @@ -68,7 +72,7 @@ public IToken getToken(String type) { if (type == null) { return null; } - IStyle style = parser.getBestStyle(type.split("[.]")); + IStyle style = parser.getBestStyle(BY_DOT_SPLITTER.splitToStream(type).toArray(String[]::new)); if (style != null) { IToken t = tokenMaps.get(style); if (t != null) { @@ -113,7 +117,7 @@ public Color getEditorSelectionBackground() { } return null; } - + @Override public Color getEditorCurrentLineHighlight() { IStyle style = parser.getBestStyle("editor", "lineHighlight"); diff --git a/target-platform/tm4e-target.target b/target-platform/tm4e-target.target index bab68d0a4..2c27c03f5 100644 --- a/target-platform/tm4e-target.target +++ b/target-platform/tm4e-target.target @@ -8,6 +8,7 @@ + From 8a6821ce025894d5e3218727440cfd5a79987d70 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 16 Apr 2022 18:50:47 +0200 Subject: [PATCH 054/202] Upgrade org.joni from 2.1.11 to 2.1.43 --- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 4 +- target-platform/tm4e-target.target | 69 ++++++++++++++-------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index 26bfdaad6..119a38e8c 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -9,8 +9,8 @@ Require-Bundle: org.apache.batik.css;bundle-version="1.9.1";resolution:=optional org.apache.batik.util;bundle-version="1.9.1";resolution:=optional, com.google.gson;resolution:=optional, com.google.guava;bundle-version="30.1.0", - org.jcodings;bundle-version="1.0.18", - org.joni;bundle-version="2.1.11", + org.jcodings;bundle-version="1.0.57", + org.joni;bundle-version="2.1.43", org.yaml.snakeyaml;bundle-version="1.27.0" Import-Package: org.w3c.css.sac;resolution:=optional, org.w3c.css.sac.helpers;resolution:=optional, diff --git a/target-platform/tm4e-target.target b/target-platform/tm4e-target.target index 2c27c03f5..b4c3269eb 100644 --- a/target-platform/tm4e-target.target +++ b/target-platform/tm4e-target.target @@ -1,30 +1,47 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + org.jruby.joni + joni + 2.1.43 + jar + + + + + + \ No newline at end of file From 737c0529777f96d27552c4616995a962d74bb6cb Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 16 Apr 2022 21:56:07 +0200 Subject: [PATCH 055/202] Update github actions with dependabot --- .github/dependabot.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f71fb86bf..a795f29a6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,20 @@ +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates version: 2 updates: +- package-ecosystem: github-actions + directory: / + schedule: + interval: daily + commit-message: + prefix: fix + prefix-development: chore + include: scope - package-ecosystem: maven directory: "/" schedule: interval: daily - open-pull-requests-limit: 10 \ No newline at end of file + commit-message: + prefix: fix + prefix-development: chore + include: scope + open-pull-requests-limit: 10 From 89d37eb0d0bbbb955f27b18cd22895459182a2e7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 16 Apr 2022 22:59:56 +0200 Subject: [PATCH 056/202] Remove redundant abstract method already defined in interface --- .../tm4e/core/theme/css/SACParserFactory.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java index fab0277cd..26b780ed0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java @@ -74,20 +74,4 @@ public static ISACParserFactory newInstance() { // SAXParserFactory. return new SACParserFactoryImpl(); } - - /** - * Return instance of SAC Parser registered into the factory with name - * name. - * - * @param name - * @return - * @throws ClassNotFoundException - * @throws IllegalAccessException - * @throws InstantiationException - * @throws NullPointerException - * @throws ClassCastException - */ - @Override - public abstract Parser makeParser(String name) throws ClassNotFoundException, IllegalAccessException, - InstantiationException, NullPointerException, ClassCastException; } From 088602f33f5449c6d24bf8d7a36ad88f8f3118e3 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 16 Apr 2022 21:46:56 +0200 Subject: [PATCH 057/202] Fix warning 'Statement unnecessarily nested within else clause' --- .../core/internal/oniguruma/OnigResult.java | 7 +-- .../core/internal/oniguruma/OnigString.java | 3 +- .../tm4e/core/internal/rule/RegExpSource.java | 13 ++-- .../core/internal/rule/RegExpSourceList.java | 62 +++++++++---------- .../tm4e/core/internal/utils/RegexSource.java | 9 ++- .../LanguageConfigurationRegistryManager.java | 20 +++--- .../internal/text/StyleRangesCollector.java | 3 +- .../ui/text/TMPresentationReconciler.java | 10 ++- 8 files changed, 57 insertions(+), 70 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java index 172ff5449..d79fd7cd9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java @@ -41,9 +41,8 @@ public int locationAt(int index) { int bytes = region.beg[index]; if (bytes > 0) { return bytes; - } else { - return 0; } + return 0; } public int count() { @@ -54,9 +53,7 @@ public int lengthAt(int index) { int bytes = region.end[index] - region.beg[index]; if (bytes > 0) { return bytes; - } else { - return 0; } + return 0; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java index 989c430b5..e6d620712 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java @@ -69,9 +69,8 @@ public int convertUtf16OffsetToUtf8(int posInChars) { if (last < posInChars) { if (last == posInChars - 1) { return charsLenInBytes.length; - } else { - throw new ArrayIndexOutOfBoundsException(posInChars); } + throw new ArrayIndexOutOfBoundsException(posInChars); } int index = Arrays.binarySearch(charsLenInBytes, posInChars); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index 1a627c2f8..f2ebc3993 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -218,16 +218,13 @@ public String resolveAnchors(boolean allowA, boolean allowG) { if (allowA) { if (allowG) { return this.anchorCache.A1_G1; - } else { - return this.anchorCache.A1_G0; - } - } else { - if (allowG) { - return this.anchorCache.A0_G1; - } else { - return this.anchorCache.A0_G0; } + return this.anchorCache.A1_G0; + } + if (allowG) { + return this.anchorCache.A0_G1; } + return this.anchorCache.A0_G0; } public boolean hasAnchor() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index dee558941..088a2307e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; @@ -87,38 +87,36 @@ public ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allo this._cached = new ICompiledRule(createOnigScanner(regexps.toArray(new String[0])), getRules()); } return this._cached; - } else { - if (this._anchorCache.A0_G0 == null) { - this._anchorCache.A0_G0 = (allowA == false && allowG == false) ? this._resolveAnchors(allowA, allowG) - : null; - } - if (this._anchorCache.A0_G1 == null) { - this._anchorCache.A0_G1 = (allowA == false && allowG == true) ? this._resolveAnchors(allowA, allowG) - : null; - } - if (this._anchorCache.A1_G0 == null) { - this._anchorCache.A1_G0 = (allowA == true && allowG == false) ? this._resolveAnchors(allowA, allowG) - : null; - } - if (this._anchorCache.A1_G1 == null) { - this._anchorCache.A1_G1 = (allowA == true && allowG == true) ? this._resolveAnchors(allowA, allowG) - : null; - } - if (allowA) { - if (allowG) { - return this._anchorCache.A1_G1; - } else { - return this._anchorCache.A1_G0; - } - } else { - if (allowG) { - return this._anchorCache.A0_G1; - } else { - return this._anchorCache.A0_G0; - } + } + + if (this._anchorCache.A0_G0 == null) { + this._anchorCache.A0_G0 = (allowA == false && allowG == false) ? this._resolveAnchors(allowA, allowG) + : null; + } + if (this._anchorCache.A0_G1 == null) { + this._anchorCache.A0_G1 = (allowA == false && allowG == true) ? this._resolveAnchors(allowA, allowG) + : null; + } + if (this._anchorCache.A1_G0 == null) { + this._anchorCache.A1_G0 = (allowA == true && allowG == false) ? this._resolveAnchors(allowA, allowG) + : null; + } + if (this._anchorCache.A1_G1 == null) { + this._anchorCache.A1_G1 = (allowA == true && allowG == true) ? this._resolveAnchors(allowA, allowG) + : null; + } + + if (allowA) { + if (allowG) { + return this._anchorCache.A1_G1; } + return this._anchorCache.A1_G0; } + if (allowG) { + return this._anchorCache.A0_G1; + } + return this._anchorCache.A0_G0; } private ICompiledRule _resolveAnchors(boolean allowA, boolean allowG) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index 2c91ffd14..02e56a696 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -70,13 +70,12 @@ private static String getReplacement(String match, String captureSource, IOnigCa } if ("downcase".equals(command)) { return result.toLowerCase(); - } else if ("upcase".equals(command)) { + } + if ("upcase".equals(command)) { return result.toUpperCase(); - } else { - return result; } - } else { - return match; + return result; } + return match; } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java index 5b2b1077f..09bb29237 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java @@ -186,16 +186,16 @@ public EnterActionAndIndent getEnterAction(IDocument document, int offset, ICont if (enterResult == null) { return null; - } else { - // Here we add `\t` to appendText first because enterAction is leveraging - // appendText and removeText to change indentation. - if (enterResult.getAppendText() == null) { - if ((enterResult.getIndentAction() == IndentAction.Indent) - || (enterResult.getIndentAction() == IndentAction.IndentOutdent)) { - enterResult.setAppendText("\t"); //$NON-NLS-1$ - } else { - enterResult.setAppendText(""); //$NON-NLS-1$ - } + } + + // Here we add `\t` to appendText first because enterAction is leveraging + // appendText and removeText to change indentation. + if (enterResult.getAppendText() == null) { + if ((enterResult.getIndentAction() == IndentAction.Indent) + || (enterResult.getIndentAction() == IndentAction.IndentOutdent)) { + enterResult.setAppendText("\t"); //$NON-NLS-1$ + } else { + enterResult.setAppendText(""); //$NON-NLS-1$ } } diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java index 536c556e5..692539154 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java @@ -54,9 +54,8 @@ public void colorize(TextPresentation presentation, Throwable error) { try { if (waitForToLineNumber != document.getLineOfOffset(offset)) { return; - } else { - waitForToLineNumber = null; } + waitForToLineNumber = null; } catch (BadLocationException e) { e.printStackTrace(); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index f5ee1a4d7..ac539ffc7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -304,9 +304,9 @@ public void textChanged(TextEvent e) { } // It's possible that there are two or more SourceViewers opened for the same document, - // so when one of them is closed the existing TMModel is also "closed" and its TokenizerThread + // so when one of them is closed the existing TMModel is also "closed" and its TokenizerThread // is interrupted and terminated. - // In this case, in order to let the others Source Viewers to continue working a new + // In this case, in order to let the others Source Viewers to continue working a new // TMModel object is to be created for the document, so it should be initialized // with the existing grammar as well as new ModelTokenListener is to be added if (TMPresentationReconciler.this.grammar != null) { @@ -537,11 +537,9 @@ void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws Ba // The token is before the damage region if (nextToken != null) { if (isBeforeRegion(nextToken, startLineOffset, damage)) { - // ignore it - continue; - } else { - tokenStartIndex = damage.getOffset() - startLineOffset; + continue; // ignore it } + tokenStartIndex = damage.getOffset() - startLineOffset; } else { tokenStartIndex = damage.getOffset() - startLineOffset; IToken token = toToken(currentToken); From a34a7af03fe6d88508188245f16a1c01e2abeccd Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 16 Apr 2022 17:08:39 +0200 Subject: [PATCH 058/202] Log regex pattern if parsing fails --- .../tm4e/core/internal/oniguruma/OnigRegExp.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java index 98ce14a3d..0d63aea7a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; +import org.eclipse.tm4e.core.TMException; import org.jcodings.specific.UTF8Encoding; import org.joni.Matcher; import org.joni.Option; @@ -28,6 +29,7 @@ import org.joni.Region; import org.joni.Syntax; import org.joni.WarnCallback; +import org.joni.exception.SyntaxException; /** * @@ -46,8 +48,12 @@ public OnigRegExp(String source) { lastSearchPosition = -1; lastSearchResult = null; byte[] pattern = source.getBytes(StandardCharsets.UTF_8); - this.regex = new Regex(pattern, 0, pattern.length, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, Syntax.DEFAULT, - WarnCallback.DEFAULT); + try { + this.regex = new Regex(pattern, 0, pattern.length, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, + Syntax.DEFAULT, WarnCallback.DEFAULT); + } catch (SyntaxException ex) { + throw new TMException("Parsing regex pattern \"" + source + "\" failed with " + ex, ex); + } } public OnigResult search(OnigString str, int position) { From 507241eeb5fbe64894bff71d2be711f3ad22be97 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 16 Apr 2022 16:47:53 +0200 Subject: [PATCH 059/202] Fix "SWT Resource was not properly disposed" --- .../widgets/AutoClosingPairConditionalTableWidget.java | 3 +++ .../internal/widgets/CharacterPairsTableWidget.java | 2 ++ .../internal/widgets/OnEnterRuleTableWidget.java | 2 ++ 3 files changed, 7 insertions(+) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java index ab65db884..43335bc76 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java @@ -26,6 +26,7 @@ public class AutoClosingPairConditionalTableWidget extends CharacterPairsTableWi public AutoClosingPairConditionalTableWidget(Table table) { super(table); setLabelProvider(new AutoClosingPairConditionalLabelProvider()); + GC gc = new GC(table.getShell()); gc.setFont(JFaceResources.getDialogFont()); TableColumnLayout columnLayout = new TableColumnLayout(); @@ -35,6 +36,8 @@ public AutoClosingPairConditionalTableWidget(Table table) { int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.AutoClosingPairConditionalTableWidget_notIn); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); + + gc.dispose(); } protected class AutoClosingPairConditionalLabelProvider extends CharacterPairLabelProvider { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java index be45d13f4..ffae47cd4 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java @@ -50,6 +50,8 @@ public CharacterPairsTableWidget(Table table) { column2.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_end); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_end); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); + + gc.dispose(); } protected int computeMinimumColumnWidth(GC gc, String string) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java index 8c380b346..a8883cbe2 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java @@ -66,6 +66,8 @@ public OnEnterRuleTableWidget(Table table) { column5.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); columnLayout.setColumnData(column5, new ColumnWeightData(1, minWidth, true)); + + gc.dispose(); } protected int computeMinimumColumnWidth(GC gc, String string) { From 44164f12e6ca3d6fd9fb93672303200b0ba28e23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 17 Apr 2022 21:20:12 +0000 Subject: [PATCH 060/202] fix(deps): bump stCarolas/setup-maven from 4.2 to 4.3 Bumps [stCarolas/setup-maven](https://github.com/stCarolas/setup-maven) from 4.2 to 4.3. - [Release notes](https://github.com/stCarolas/setup-maven/releases) - [Commits](https://github.com/stCarolas/setup-maven/compare/v4.2...v4.3) --- updated-dependencies: - dependency-name: stCarolas/setup-maven dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c52987a8..66fa98b27 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,7 +51,7 @@ jobs: ${{ runner.os }}-mvnrepo- - name: Set up Maven - uses: stCarolas/setup-maven@v4.2 + uses: stCarolas/setup-maven@v4.3 with: maven-version: 3.8.2 From b13dc2985edab471a1729999099dfdadb995ad4c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 17 Apr 2022 21:20:10 +0000 Subject: [PATCH 061/202] fix(deps): bump actions/cache from 2 to 3 Bumps [actions/cache](https://github.com/actions/cache) from 2 to 3. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 2 +- .github/workflows/licensecheck.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66fa98b27..f454824e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: run: sudo apt-get install -o Acquire::Retries=3 --no-install-recommends -y xvfb - name: "Cache: Local Maven Repository" - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.m2/repository diff --git a/.github/workflows/licensecheck.yml b/.github/workflows/licensecheck.yml index 955428c45..e776e7c8e 100644 --- a/.github/workflows/licensecheck.yml +++ b/.github/workflows/licensecheck.yml @@ -24,7 +24,7 @@ jobs: java-version: '11' distribution: 'adopt' - name: Cache local Maven repository - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} From 9b15d6471723497753d0a13b2b8230cfde0034b9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 17 Apr 2022 21:20:08 +0000 Subject: [PATCH 062/202] fix(deps): bump actions/setup-java from 2 to 3 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2 to 3. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 2 +- .github/workflows/licensecheck.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f454824e9..bee3a72d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,7 +32,7 @@ jobs: uses: actions/checkout@v2 #https://github.com/actions/checkout - name: Set up JDK 11 - uses: actions/setup-java@v2 # https://github.com/actions/setup-java + uses: actions/setup-java@v3 # https://github.com/actions/setup-java with: distribution: 'zulu' java-version: 11 diff --git a/.github/workflows/licensecheck.yml b/.github/workflows/licensecheck.yml index e776e7c8e..8112ffd21 100644 --- a/.github/workflows/licensecheck.yml +++ b/.github/workflows/licensecheck.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '11' distribution: 'adopt' From e43206b5df26e32151d7425770e13514313ab8d1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 04:41:23 +0000 Subject: [PATCH 063/202] fix(deps): bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 2 +- .github/workflows/licensecheck.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bee3a72d5..f3f17ad41 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Git Checkout - uses: actions/checkout@v2 #https://github.com/actions/checkout + uses: actions/checkout@v3 #https://github.com/actions/checkout - name: Set up JDK 11 uses: actions/setup-java@v3 # https://github.com/actions/setup-java diff --git a/.github/workflows/licensecheck.yml b/.github/workflows/licensecheck.yml index 8112ffd21..bfde8fa5f 100644 --- a/.github/workflows/licensecheck.yml +++ b/.github/workflows/licensecheck.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 11 uses: actions/setup-java@v3 with: From b1821808e187caa9afb72aa9e1f0d035386f4e6d Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 18 Apr 2022 13:24:44 +0200 Subject: [PATCH 064/202] Use .isEmpty() instead of .size() or .length() for emptiness check --- .../org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java | 4 ++-- .../org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java | 2 +- .../org/eclipse/tm4e/core/internal/utils/RegexSource.java | 2 +- .../src/main/java/org/eclipse/tm4e/core/theme/Theme.java | 4 ++-- .../internal/supports/OnEnterSupport.java | 4 ++-- .../wizards/SelectLanguageConfigurationWizardPage.java | 4 ++-- .../main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java | 2 +- .../main/java/org/eclipse/tm4e/markdown/marked/Helpers.java | 2 +- .../src/main/java/org/eclipse/tm4e/registry/TMResource.java | 2 +- .../org/eclipse/tm4e/ui/internal/model/DocumentHelper.java | 2 +- .../eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java | 2 +- .../tm4e/ui/internal/wizards/SelectGrammarWizardPage.java | 4 ++-- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java index 85d293116..964932827 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java @@ -119,9 +119,9 @@ private static StackElement assertLineTokenization(IGrammar grammar, RawTestLine List expectedTokens = testCase.getTokens(); // // TODO@Alex: fix tests instead of working around - if (testCase.getLine().length() > 0) { + if (!testCase.getLine().isEmpty()) { // Remove empty tokens... - expectedTokens = testCase.getTokens().stream().filter(token -> token.getValue().length() > 0) + expectedTokens = testCase.getTokens().stream().filter(token -> !token.getValue().isEmpty()) .collect(Collectors.toList()); } deepEqual(actualTokens, expectedTokens, "Tokenizing line '" + testCase.getLine() + "'"); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 08d87fa1e..da1acef75 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -291,7 +291,7 @@ private IMatchResult matchRuleOrInjections(Grammar grammar, OnigString lineText, // Look for injected rules List injections = grammar.getInjections(); - if (injections.size() == 0) { + if (injections.isEmpty()) { // No injections whatsoever => early return return matchResult; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index 02e56a696..c0b2b283d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -65,7 +65,7 @@ private static String getReplacement(String match, String captureSource, IOnigCa if (capture != null) { String result = captureSource.substring(capture.getStart(), capture.getEnd()); // Remove leading dots that would make the selector invalid - while (result.length() > 0 && result.charAt(0) == '.') { + while (!result.isEmpty() && result.charAt(0) == '.') { result = result.substring(1); } if ("downcase".equals(command)) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index e548ae35d..b1512b79b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -138,7 +138,7 @@ public static List parseTheme(IRawTheme source) { } private static boolean isValidHexColor(String hex) { - if (hex == null || hex.length() < 1) { + if (hex == null || hex.isEmpty()) { return false; } @@ -190,7 +190,7 @@ public static Theme resolveParsedThemeRules(List parsedThemeRul int defaultFontStyle = FontStyle.None; String defaultForeground = "#000000"; String defaultBackground = "#ffffff"; - while (parsedThemeRules.size() >= 1 && "".equals(parsedThemeRules.get(0).scope)) { + while (!parsedThemeRules.isEmpty() && "".equals(parsedThemeRules.get(0).scope)) { ParsedThemeRule incomingDefaults = parsedThemeRules.remove(0); // shift(); if (incomingDefaults.fontStyle != FontStyle.NotSet) { defaultFontStyle = incomingDefaults.fontStyle; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java index df80b97c1..467f9cf74 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java @@ -55,7 +55,7 @@ public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, Stri } // (2): Special indent-outdent - if (beforeEnterText.length() > 0 && afterEnterText.length() > 0) { + if (!beforeEnterText.isEmpty() && !afterEnterText.isEmpty()) { for (ProcessedBracketPair bracket : brackets) { if (bracket.matchOpen(beforeEnterText) && bracket.matchClose(afterEnterText)) { return new EnterAction(IndentAction.IndentOutdent); @@ -64,7 +64,7 @@ public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, Stri } // (3): Open bracket based logic - if (beforeEnterText.length() > 0) { + if (!beforeEnterText.isEmpty()) { for (ProcessedBracketPair bracket : brackets) { if (bracket.matchOpen(beforeEnterText)) { return new EnterAction(IndentAction.Indent); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java index 4431de68f..d53e66b13 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java @@ -123,7 +123,7 @@ private static void applyToStatusLine(DialogPage page, IStatus status) { page.setErrorMessage(null); break; default: - if (message != null && message.length() == 0) { + if (message != null && message.isEmpty()) { message = null; } page.setMessage(null); @@ -163,7 +163,7 @@ public void widgetSelected(SelectionEvent e) { dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); dialog.setFilterPath(fileText.getText()); String result = dialog.open(); - if (result != null && result.length() > 0) { + if (result != null && !result.isEmpty()) { fileText.setText(result); } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java index 7e42b57c4..86c96a18e 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java @@ -89,7 +89,7 @@ private TMState tokenizeLine(String line, ITokenizationSupport tokenizationSuppo String className = "token"; String safeType = token.type.replaceAll("[^a-z0-9\\-]", " "); - if (safeType.length() > 0) { + if (!safeType.isEmpty()) { className += ' ' + safeType; } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java index 44aabea84..cc57daf51 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java @@ -32,7 +32,7 @@ public static String escape(String html, boolean encode) { } public static boolean isEmpty(String s) { - return s == null || s.length() < 1; + return s == null || s.isEmpty(); } } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index b5e93ec14..fdbc4da39 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -68,7 +68,7 @@ public String getPluginId() { @Override public InputStream getInputStream() throws IOException { - if (path == null || path.length() < 0) { + if (path == null || path.isEmpty()) { return null; } if (pluginId != null) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java index 769b794fb..f0f41d53f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java @@ -33,7 +33,7 @@ public static int getEndLine(DocumentEvent event, boolean documentAboutToBeChang } public static boolean isRemove(DocumentEvent event) { - return event.getText() == null || event.getText().length() == 0; + return event.getText() == null || event.getText().isEmpty(); } public static boolean isInsert(DocumentEvent event) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java index 14aaa1181..3e2d806d2 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java @@ -91,7 +91,7 @@ private static void applyToStatusLine(DialogPage page, IStatus status) { page.setErrorMessage(null); break; default: - if (message != null && message.length() == 0) { + if (message != null && message.isEmpty()) { message = null; } page.setMessage(null); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java index e3f815d62..9b996b1e0 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java @@ -91,7 +91,7 @@ public void widgetSelected(SelectionEvent e) { dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); dialog.setFilterPath(grammarFileText.getText()); String result = dialog.open(); - if (result != null && result.length() > 0) { + if (result != null && !result.isEmpty()) { grammarFileText.setText(result); } } @@ -130,7 +130,7 @@ protected void initializeDefaultValues() { protected IStatus validatePage(Event event) { grammarInfoWidget.refresh(null); String path = grammarFileText.getText(); - if (path.length() == 0) { + if (path.isEmpty()) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.SelectGrammarWizardPage_file_error_required); } From 74a8e741906d61efd8d44ea6b2d2454d47f5b416 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 18 Apr 2022 17:21:58 +0200 Subject: [PATCH 065/202] Use String#replace" instead of String#replaceAll See https://rules.sonarsource.com/java/RSPEC-5361 --- .../eclipse/tm4e/core/internal/grammar/LineTokenizer.java | 2 +- .../eclipse/tm4e/core/internal/grammar/LineTokens.java | 2 +- .../java/org/eclipse/tm4e/markdown/marked/Helpers.java | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index da1acef75..ddb042162 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -106,7 +106,7 @@ public StackElement scan() { } private void scanNext() { - LOGGER.log(TRACE, () -> "@@scanNext: |" + lineText.string.replaceAll("\n", "\\n").substring(linePos) + '|'); + LOGGER.log(TRACE, () -> "@@scanNext: |" + lineText.string.replace("\n", "\\n").substring(linePos) + '|'); IMatchResult r = matchRuleOrInjections(grammar, lineText, isFirstLine, linePos, stack, anchorPosition); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index c90d94248..7e1a79a2c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -88,7 +88,7 @@ public void produceFromScopes(ScopeListElement scopesList, int endIndex) { LOGGER.log(TRACE, " token: |" + this.lineText .substring(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex) - .replaceAll("\n", "\\n") + '|'); + .replace("\n", "\\n") + '|'); for (String scope : scopes) { LOGGER.log(TRACE, " * " + scope); } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java index cc57daf51..d9dce131a 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java @@ -25,10 +25,10 @@ public static String escape(String html) { public static String escape(String html, boolean encode) { return html .replaceAll(!encode ? "&(?!#?\\w+;)" : "&", "&") - .replaceAll("<", "<") - .replaceAll(">", ">") - .replaceAll("\"", """) - .replaceAll("'", "'"); + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("'", "'"); } public static boolean isEmpty(String s) { From 1ace936ee0491496f61008c01658ff4b11cc0026 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 18 Apr 2022 17:49:43 +0200 Subject: [PATCH 066/202] Make internal instance fields final --- .../eclipse/tm4e/core/internal/rule/BeginEndRule.java | 10 +++++----- .../java/org/eclipse/tm4e/core/model/DecodeMap.java | 6 +++--- .../java/org/eclipse/tm4e/core/model/LineTokens.java | 2 +- .../org/eclipse/tm4e/markdown/marked/InlineLexer.java | 7 ++++--- .../java/org/eclipse/tm4e/markdown/marked/Lexer.java | 5 +++-- .../java/org/eclipse/tm4e/markdown/marked/Parser.java | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index d89bf5a24..ca37f521c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -23,13 +23,13 @@ public class BeginEndRule extends Rule { private final RegExpSource begin; - public List beginCaptures; + public final List beginCaptures; private final RegExpSource end; - public boolean endHasBackReferences; - public List endCaptures; - public boolean applyEndPatternLast; + public final boolean endHasBackReferences; + public final List endCaptures; + public final boolean applyEndPatternLast; public final boolean hasMissingPatterns; - public Integer[] patterns; + public final Integer[] patterns; private RegExpSourceList cachedCompiledPatterns; public BeginEndRule(int id, String name, String contentName, String begin, List beginCaptures, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java index 148478ae0..2e3d8d338 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java @@ -26,9 +26,9 @@ class DecodeMap { private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); int lastAssignedId; - Map scopeToTokenIds; - Map tokenToTokenId; - Map tokenIdToToken; + final Map scopeToTokenIds; + final Map tokenToTokenId; + final Map tokenIdToToken; TMTokenDecodeData prevToken; public DecodeMap() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java index 905e4ab83..50cc95a9d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java @@ -20,7 +20,7 @@ public class LineTokens { - List tokens; + final List tokens; int actualStopOffset; TMState endState; diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java index 428aba000..27dac2d50 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java @@ -23,14 +23,13 @@ public class InlineLexer { - private Options options; - private InlineRules rules; + private final Options options; + private final InlineRules rules; private final IRenderer renderer; public InlineLexer(Object links, Options options, IRenderer renderer) { this.options = options != null ? options : Options.DEFAULTS; // this.links = links; - this.rules = InlineRules.normal; this.renderer = renderer != null ? renderer : new HTMLRenderer(); // this.renderer = this.options.renderer || new Renderer; // this.renderer.options = this.options; @@ -48,6 +47,8 @@ public InlineLexer(Object links, Options options, IRenderer renderer) { } } else if (this.options.isPedantic()) { this.rules = InlineRules.pedantic; + } else { + this.rules = InlineRules.normal; } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java index 7be42c022..0e3b31825 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java @@ -22,14 +22,13 @@ public class Lexer { - private BlockRules rules; + private final BlockRules rules; private final Tokens tokens; private final Options options; public Lexer(Options options) { this.tokens = new Tokens(); this.options = options != null ? options : Options.DEFAULTS; - this.rules = BlockRules.normal; if (this.options.isGfm()) { if (this.options.isTables()) { @@ -37,6 +36,8 @@ public Lexer(Options options) { } else { this.rules = BlockRules.gfm; } + } else { + this.rules = BlockRules.normal; } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java index f066a947a..e8365dd7a 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java @@ -20,9 +20,9 @@ public class Parser { private Tokens tokens; private Token token; - private Options options; + private final Options options; private InlineLexer inline; - private IRenderer renderer; + private final IRenderer renderer; public Parser(Options options, IRenderer renderer) { this.tokens = new Tokens(); From 0acba7d51d2ac1469270d944e158102251c91fdf Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 18 Apr 2022 20:51:20 +0200 Subject: [PATCH 067/202] Define jgit.dirtyWorkingTree as configurable Maven property --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 54ae4657e..6e21c5827 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ ../target/jacoco.exec scm:git:https://github.com/eclipse/tm4e.git true + error Eclipse TM4E project @@ -181,6 +182,7 @@ jgit pom.xml + ${jgit.dirtyWorkingTree} From 15568e7531b41dbb572b72530b4469a71b82f21f Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 19 Apr 2022 15:26:16 +0200 Subject: [PATCH 068/202] Use JUnit5 instead of JUnit3 with maven-surefire-plugin --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6e21c5827..1da402fda 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,13 @@ + + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + + org.apache.maven.plugins @@ -297,5 +304,4 @@ - From fc6d66cb8d6ca684896c6d357bd59e525a923311 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 19 Apr 2022 18:15:56 +0200 Subject: [PATCH 069/202] Don't include src/test/resources in build artifact --- org.eclipse.tm4e.ui/build.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.ui/build.properties b/org.eclipse.tm4e.ui/build.properties index 7daa50854..0b1c73d72 100644 --- a/org.eclipse.tm4e.ui/build.properties +++ b/org.eclipse.tm4e.ui/build.properties @@ -1,6 +1,5 @@ source.. = src/main/java/,\ - src/main/resources/,\ - src/test/resources + src/main/resources/ bin.includes = META-INF/,\ .,\ plugin.properties,\ From e436bfd3acc56ecc6990da4dc129e7fa508ddd3f Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 19 Apr 2022 18:24:50 +0200 Subject: [PATCH 070/202] Remove redundant super() constructor call --- .../tm4e/core/internal/css/Measure.java | 1 - .../LanguageConfigurationPreferencePage.java | 1 - .../supports/EnterActionAndIndent.java | 1 - .../tm4e/registry/GrammarDefinition.java | 1 - .../preferences/GrammarPreferencePage.java | 21 +++++++++---------- .../preferences/ThemePreferencePage.java | 3 +-- .../tm4e/ui/internal/snippets/Snippet.java | 1 - .../org/eclipse/tm4e/ui/themes/Theme.java | 1 - .../tm4e/ui/themes/ThemeAssociation.java | 1 - 9 files changed, 11 insertions(+), 20 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java index 0e7e6f552..1c41e86b8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java @@ -20,7 +20,6 @@ public class Measure extends CSSValueImpl { LexicalUnit value; public Measure(LexicalUnit value) { - super(); this.value = value; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java index dc5a7dd8d..bcfbb15a4 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java @@ -72,7 +72,6 @@ public class LanguageConfigurationPreferencePage extends PreferencePage implemen private LanguageConfigurationPreferencesWidget infoWidget; public LanguageConfigurationPreferencePage() { - super(); setDescription(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_description); manager = new WorkingCopyLanguageConfigurationRegistryManager( LanguageConfigurationRegistryManager.getInstance()); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java index 814723144..b97d24f85 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java @@ -22,7 +22,6 @@ public class EnterActionAndIndent { * @param indentation */ public EnterActionAndIndent(EnterAction enterAction, String indentation) { - super(); this.enterAction = enterAction; this.indentation = indentation; } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java index b5d9e2a45..66b5dea1a 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java @@ -36,7 +36,6 @@ public class GrammarDefinition extends TMResource implements IGrammarDefinition * Constructor for user preferences (loaded from Json with Gson). */ public GrammarDefinition() { - super(); } /** diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index bc9d281cf..e7706c853 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -96,7 +96,6 @@ public class GrammarPreferencePage extends PreferencePage implements IWorkbenchP private TMViewer previewViewer; public GrammarPreferencePage() { - super(); setDescription(TMUIMessages.GrammarPreferencePage_description); setGrammarRegistryManager( new WorkingCopyGrammarRegistryManager(TMEclipseRegistryPlugin.getGrammarRegistryManager())); @@ -106,7 +105,7 @@ public GrammarPreferencePage() { /** * Returns the grammar registry manager. - * + * * @return the grammar registry manager. */ public IGrammarRegistryManager getGrammarRegistryManager() { @@ -115,7 +114,7 @@ public IGrammarRegistryManager getGrammarRegistryManager() { /** * Set the grammar registry manager. - * + * * @param grammarRegistryManager */ public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { @@ -124,7 +123,7 @@ public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryMan /** * Returns the theme manager. - * + * * @return the theme manager. */ public IThemeManager getThemeManager() { @@ -133,7 +132,7 @@ public IThemeManager getThemeManager() { /** * Set the theme manager. - * + * * @param themeManager */ public void setThemeManager(IThemeManager themeManager) { @@ -182,7 +181,7 @@ protected Control createContents(Composite ancestor) { /** * Create grammar list content. - * + * * @param parent */ private void createGrammarListContent(Composite parent) { @@ -370,7 +369,7 @@ private void remove() { /** * Create detail grammar content which is filled when a grammar is selected in * the grammar list. - * + * * @param parent */ private void createGrammarDetailContent(Composite parent) { @@ -388,7 +387,7 @@ private void createGrammarDetailContent(Composite parent) { /** * Create "General" tab - * + * * @param folder */ private void createGeneralTab(TabFolder folder) { @@ -408,7 +407,7 @@ private void createGeneralTab(TabFolder folder) { /** * Create "Content type" tab - * + * * @param folder */ private void createContentTypeTab(TabFolder folder) { @@ -427,7 +426,7 @@ private void createContentTypeTab(TabFolder folder) { /** * Create "Theme" tab - * + * * @param folder */ private void createThemeTab(TabFolder folder) { @@ -474,7 +473,7 @@ private void setPreviewTheme(String themeId) { /** * Create "Injection" tab - * + * * @param folder */ private void createInjectionTab(TabFolder folder) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index e685ede86..7d986529b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -82,11 +82,10 @@ public class ThemePreferencePage extends PreferencePage implements IWorkbenchPre private Button darkThemeButton; private Button defaultThemeButton; - + private ITheme selectedTheme; public ThemePreferencePage() { - super(); setDescription(TMUIMessages.ThemePreferencePage_description); this.grammarRegistryManager = TMEclipseRegistryPlugin.getGrammarRegistryManager(); this.themeManager = TMUIPlugin.getThemeManager(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java index 125694382..a1efa6e19 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java @@ -25,7 +25,6 @@ public class Snippet extends TMResource implements ISnippet { * Constructor for user preferences (loaded from Json with Gson). */ public Snippet() { - super(); } /** diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java index ae6145cba..cb7760aeb 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java @@ -43,7 +43,6 @@ public class Theme extends TMResource implements ITheme { * Constructor for user preferences (loaded from Json with Gson). */ public Theme() { - super(); } /** diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java index d0ad5d810..fe4c65bf7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java @@ -54,7 +54,6 @@ public class ThemeAssociation implements IThemeAssociation { * Constructor for user preferences (loaded from Json with Gson). */ public ThemeAssociation() { - super(); } /** From 2a7ecf04435bf9a35d56eb62669daa79815693fe Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 19 Apr 2022 17:11:07 +0200 Subject: [PATCH 071/202] Reduce accessibility of internal code --- .../css/AbstractAttributeCondition.java | 2 +- .../css/AbstractCombinatorCondition.java | 4 +- .../internal/css/AbstractElementSelector.java | 4 +- .../core/internal/css/CSSAndCondition.java | 8 +-- .../internal/css/CSSAttributeCondition.java | 12 ++--- .../core/internal/css/CSSClassCondition.java | 4 +- .../internal/css/CSSConditionFactory.java | 2 +- .../internal/css/CSSConditionalSelector.java | 10 ++-- .../core/internal/css/CSSDocumentHandler.java | 12 +---- .../core/internal/css/CSSElementSelector.java | 8 +-- .../core/internal/css/CSSSelectorFactory.java | 2 +- .../tm4e/core/internal/css/CSSValueImpl.java | 2 +- .../core/internal/css/ExtendedCondition.java | 2 +- .../tm4e/core/internal/css/Measure.java | 6 +-- .../tm4e/core/internal/css/RGBColorImpl.java | 4 +- .../internal/css/SACParserFactoryImpl.java | 6 +-- .../tm4e/core/internal/grammar/Grammar.java | 8 +-- .../core/internal/grammar/LineTokenizer.java | 28 +++++----- .../core/internal/grammar/LineTokens.java | 10 ++-- .../internal/grammar/LocalStackElement.java | 8 +-- .../core/internal/grammar/MetadataConsts.java | 44 +++++++-------- .../internal/grammar/ScopeListElement.java | 15 +++--- .../core/internal/grammar/ScopeMetadata.java | 10 ++-- .../grammar/ScopeMetadataProvider.java | 27 +++++----- .../grammar/StackElementMetadata.java | 14 ++--- .../internal/grammar/StandardTokenType.java | 10 ++-- .../tm4e/core/internal/grammar/Token.java | 6 +-- .../internal/grammar/TokenizeLineResult.java | 6 +-- .../internal/grammar/TokenizeLineResult2.java | 7 ++- .../internal/grammar/parser/PListGrammar.java | 2 +- .../core/internal/grammar/parser/Raw.java | 54 +++++++++---------- .../grammar/reader/GrammarReader.java | 2 +- .../grammar/reader/SyncGrammarReader.java | 4 +- .../core/internal/grammars/SyncRegistry.java | 2 +- .../matcher/IMatchInjectionsResult.java | 1 - .../core/internal/matcher/IMatchesName.java | 2 +- .../tm4e/core/internal/matcher/Matcher.java | 10 ++-- .../internal/matcher/MatcherWithPriority.java | 4 +- .../oniguruma/OnigNextMatchResult.java | 8 +-- .../core/internal/oniguruma/OnigRegExp.java | 6 +-- .../core/internal/oniguruma/OnigResult.java | 14 ++--- .../core/internal/oniguruma/OnigScanner.java | 4 +- .../core/internal/oniguruma/OnigSearcher.java | 7 ++- .../core/internal/oniguruma/OnigString.java | 8 ++- .../tm4e/core/internal/parser/PList.java | 4 +- .../core/internal/parser/PListObject.java | 14 ++--- .../internal/parser/json/JSONPListParser.java | 2 +- .../internal/parser/xml/XMLPListParser.java | 2 +- .../internal/parser/yaml/YamlPListParser.java | 2 +- .../tm4e/core/internal/rule/BeginEndRule.java | 12 ++--- .../core/internal/rule/BeginWhileRule.java | 10 ++-- .../tm4e/core/internal/rule/CaptureRule.java | 10 ++-- .../internal/rule/ICompilePatternsResult.java | 8 +-- .../core/internal/rule/ICompiledRule.java | 4 +- .../core/internal/rule/IGrammarRegistry.java | 2 +- .../rule/IRegExpSourceAnchorCache.java | 12 ++--- .../core/internal/rule/IncludeOnlyRule.java | 10 ++-- .../tm4e/core/internal/rule/MatchRule.java | 6 +-- .../tm4e/core/internal/rule/RegExpSource.java | 22 ++++---- .../core/internal/rule/RegExpSourceList.java | 24 ++++----- .../eclipse/tm4e/core/internal/rule/Rule.java | 6 +-- .../tm4e/core/internal/rule/RuleFactory.java | 4 +- .../tm4e/core/internal/theme/PListTheme.java | 2 +- .../tm4e/core/internal/theme/ThemeRaw.java | 2 +- .../theme/reader/SyncThemeReader.java | 4 +- .../internal/theme/reader/ThemeReader.java | 6 +-- .../tm4e/core/internal/types/IBaseRaw.java | 2 +- .../tm4e/core/internal/utils/CloneUtils.java | 2 +- .../core/internal/utils/CompareUtils.java | 2 +- .../tm4e/core/internal/utils/RegexSource.java | 2 +- .../tm4e/core/model/AbstractLineList.java | 2 +- .../org/eclipse/tm4e/core/model/TMModel.java | 2 +- .../core/internal}/grammar/GrammarTest.java | 18 +++---- .../oniguruma}/OnigStringTest.java | 6 +-- .../oniguruma}/TestOngurama.java | 5 +- ...tLanguageConfigurationRegistryManager.java | 2 +- .../internal/LanguageConfiguration.java | 2 +- .../LanguageConfigurationDefinition.java | 8 +-- .../LanguageConfigurationMessages.java | 2 +- .../internal/LanguageConfigurationPlugin.java | 10 ++-- .../LanguageConfigurationRegistryManager.java | 2 +- .../LanguageConfigurationContentProvider.java | 2 +- .../LanguageConfigurationLabelProvider.java | 2 +- .../LanguageConfigurationPreferencePage.java | 4 +- .../preferences/PreferenceConstants.java | 2 +- .../preferences/PreferenceHelper.java | 2 +- .../supports/AutoClosingPairConditional.java | 2 +- .../supports/CharacterPairSupport.java | 2 +- .../internal/supports/CommentSupport.java | 4 +- .../internal/supports/Comments.java | 2 +- .../internal/supports/EnterAction.java | 6 +-- .../supports/EnterActionAndIndent.java | 2 +- .../internal/supports/Folding.java | 2 +- .../internal/supports/IndentationRule.java | 5 +- .../internal/supports/OnEnterRule.java | 2 +- .../internal/supports/OnEnterSupport.java | 8 +-- .../internal/utils/RegExpUtils.java | 2 +- .../internal/utils/TabSpacesInfo.java | 8 +-- .../internal/utils/TextUtils.java | 4 +- ...AutoClosingPairConditionalTableWidget.java | 6 +-- .../widgets/CharacterPairsTableWidget.java | 6 +-- .../widgets/ColumnSelectionAdapter.java | 2 +- .../widgets/ColumnViewerComparator.java | 2 +- .../LanguageConfigurationInfoWidget.java | 18 +++---- ...anguageConfigurationPreferencesWidget.java | 14 ++--- .../widgets/OnEnterRuleTableWidget.java | 10 ++-- .../LanguageConfigurationImportWizard.java | 4 +- ...SelectLanguageConfigurationWizardPage.java | 24 ++++----- .../AbstractGrammarRegistryManager.java | 20 +++---- .../tm4e/registry/internal/GrammarCache.java | 36 ++++++------- .../internal/GrammarRegistryManager.java | 2 +- .../preferences/PreferenceConstants.java | 10 ++-- .../preferences/PreferenceHelper.java | 4 +- .../tm4e/ui/internal/text/Command.java | 4 +- org.eclipse.tm4e.ui/.classpath | 8 +-- .../tm4e/ui/internal/TMPropertyTester.java | 2 +- .../tm4e/ui/internal/TMUIMessages.java | 2 +- .../ui/internal/menus/ThemeContribution.java | 2 +- .../ui/internal/model/DocumentHelper.java | 14 ++--- .../internal/model/DocumentInputStream.java | 14 ++--- .../ui/internal/model/DocumentLineList.java | 6 +-- .../ui/internal/model/TMDocumentModel.java | 2 +- .../ui/internal/model/TMModelManager.java | 2 +- .../preferences/GrammarPreferencePage.java | 18 +++---- .../preferences/PreferenceConstants.java | 2 +- .../preferences/PreferenceHelper.java | 4 +- .../preferences/TextMatePreferencePage.java | 2 +- .../preferences/ThemePreferencePage.java | 6 +-- .../tm4e/ui/internal/snippets/Snippet.java | 8 +-- .../ui/internal/snippets/SnippetManager.java | 4 +- ...TMPresentationReconcilerTestGenerator.java | 12 ++--- .../internal/themes/AbstractThemeManager.java | 4 +- .../themes/BaseThemeAssociationRegistry.java | 21 ++++---- .../themes/ThemeAssociationRegistry.java | 26 ++++----- .../tm4e/ui/internal/themes/ThemeManager.java | 2 +- .../themes/WorkingCopyThemeManager.java | 2 +- .../widgets/ColumnSelectionAdapter.java | 2 +- .../widgets/ColumnViewerComparator.java | 2 +- .../widgets/ContentTypeLabelProvider.java | 2 +- .../widgets/ContentTypesBindingWidget.java | 2 +- .../GrammarDefinitionContentProvider.java | 2 +- .../GrammarDefinitionLabelProvider.java | 2 +- .../internal/widgets/GrammarInfoWidget.java | 2 +- .../tm4e/ui/internal/widgets/TMViewer.java | 4 +- .../widgets/TableAndButtonsWidget.java | 8 +-- .../ThemeAssociationLabelProvider.java | 2 +- .../widgets/ThemeAssociationsWidget.java | 2 +- .../widgets/ThemeContentProvider.java | 2 +- .../internal/widgets/ThemeLabelProvider.java | 2 +- .../internal/wizards/AbstractWizardPage.java | 4 +- .../wizards/CreateThemeAssociationWizard.java | 8 +-- .../CreateThemeAssociationWizardPage.java | 4 +- .../wizards/SelectGrammarWizardPage.java | 6 +-- .../wizards/TextMateGrammarImportWizard.java | 2 +- .../ui/text/TMPresentationReconciler.java | 2 +- .../tm4e/ui/themes/AbstractTokenProvider.java | 1 + .../internal/model/DocumentLineListTest.java | 0 157 files changed, 540 insertions(+), 551 deletions(-) rename {org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core => org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal}/grammar/GrammarTest.java (93%) rename org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/{ => internal/oniguruma}/OnigStringTest.java (91%) rename org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/{ => internal/oniguruma}/TestOngurama.java (82%) rename {org.eclipse.tm4e.ui.tests => org.eclipse.tm4e.ui}/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java (100%) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java index 4740854fb..387336b2c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java @@ -18,7 +18,7 @@ public abstract class AbstractAttributeCondition implements AttributeCondition, /** * The attribute value. */ - protected String value; + private final String value; /** * Creates a new AbstractAttributeCondition object. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java index 1b0dabb2d..ff0c3a0e1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java @@ -15,9 +15,9 @@ import org.w3c.css.sac.Condition; public abstract class AbstractCombinatorCondition implements CombinatorCondition, ExtendedCondition { - protected Condition firstCondition; - protected Condition secondCondition; + private final Condition firstCondition; + private final Condition secondCondition; /** * Creates a new CombinatorCondition object. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java index b871e8021..7aa0b081c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java @@ -18,12 +18,12 @@ public abstract class AbstractElementSelector implements ElementSelector, Extend /** * The namespace URI. */ - protected String namespaceURI; + private final String namespaceURI; /** * The local name. */ - protected String localName; + private final String localName; /** * Creates a new ElementSelector object. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java index e3672007e..278f569bd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java @@ -13,12 +13,12 @@ import org.w3c.css.sac.Condition; -public class CSSAndCondition extends AbstractCombinatorCondition { +final class CSSAndCondition extends AbstractCombinatorCondition { /** * Creates a new CombinatorCondition object. */ - public CSSAndCondition(Condition c1, Condition c2) { + CSSAndCondition(Condition c1, Condition c2) { super(c1, c2); } @@ -32,8 +32,8 @@ public int nbMatch(String... names) { return ((ExtendedCondition) getFirstCondition()).nbMatch(names) + ((ExtendedCondition) getSecondCondition()).nbMatch(names); } - - @Override + + @Override public int nbClass() { return ((ExtendedCondition) getFirstCondition()).nbClass() + ((ExtendedCondition) getSecondCondition()).nbClass(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java index c1f6f3e67..068a47f1c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java @@ -11,24 +11,24 @@ */ package org.eclipse.tm4e.core.internal.css; -public class CSSAttributeCondition extends AbstractAttributeCondition { +class CSSAttributeCondition extends AbstractAttributeCondition { /** * The attribute's local name. */ - protected String localName; + private final String localName; /** * The attribute's namespace URI. */ - protected String namespaceURI; + private final String namespaceURI; /** * Whether this condition applies to specified attributes. */ - protected boolean specified; + private final boolean specified; - public CSSAttributeCondition(String localName, String namespaceURI, boolean specified, String value) { + protected CSSAttributeCondition(String localName, String namespaceURI, boolean specified, String value) { super(value); this.localName = localName; this.namespaceURI = namespaceURI; @@ -64,7 +64,7 @@ public int nbMatch(String... names) { // return e.getAttribute(getLocalName()).equals(val); return 0; } - + @Override public int nbClass() { return 0; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java index 40b1cce42..672cee5f7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java @@ -11,9 +11,9 @@ */ package org.eclipse.tm4e.core.internal.css; -public class CSSClassCondition extends CSSAttributeCondition { +final class CSSClassCondition extends CSSAttributeCondition { - public CSSClassCondition(String localName, String namespaceURI, String value) { + CSSClassCondition(String localName, String namespaceURI, String value) { super(localName, namespaceURI, true, value); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java index cf39c75c1..ed63ea1ea 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java @@ -21,7 +21,7 @@ import org.w3c.css.sac.NegativeCondition; import org.w3c.css.sac.PositionalCondition; -public class CSSConditionFactory implements ConditionFactory { +public final class CSSConditionFactory implements ConditionFactory { public static final ConditionFactory INSTANCE = new CSSConditionFactory(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java index 5dd1c2641..d18700e04 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java @@ -15,22 +15,22 @@ import org.w3c.css.sac.ConditionalSelector; import org.w3c.css.sac.SimpleSelector; -public class CSSConditionalSelector implements ConditionalSelector, ExtendedSelector { +final class CSSConditionalSelector implements ConditionalSelector, ExtendedSelector { /** * The simple selector. */ - protected SimpleSelector simpleSelector; + private final SimpleSelector simpleSelector; /** * The condition. */ - protected Condition condition; + private final Condition condition; /** * Creates a new ConditionalSelector object. */ - public CSSConditionalSelector(SimpleSelector simpleSelector, Condition condition) { + CSSConditionalSelector(SimpleSelector simpleSelector, Condition condition) { this.simpleSelector = simpleSelector; this.condition = condition; } @@ -61,7 +61,7 @@ public int nbMatch(String... names) { return ((ExtendedSelector)getSimpleSelector()).nbMatch(names) + ((ExtendedCondition)getCondition()).nbMatch(names); } - + @Override public int nbClass() { return ((ExtendedSelector) getSimpleSelector()).nbClass() diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java index 522109a7e..ae145a85f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java @@ -26,7 +26,7 @@ import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.RGBColor; -public class CSSDocumentHandler implements DocumentHandler { +public final class CSSDocumentHandler implements DocumentHandler { private final List list; private CSSStyle currentStyle; @@ -43,13 +43,11 @@ public void comment(String arg0) throws CSSException { @Override public void endDocument(InputSource arg0) throws CSSException { // TODO Auto-generated method stub - } @Override public void endFontFace() throws CSSException { // TODO Auto-generated method stub - } @Override @@ -61,7 +59,6 @@ public void endMedia(SACMediaList arg0) throws CSSException { @Override public void endPage(String arg0, String arg1) throws CSSException { // TODO Auto-generated method stub - } @Override @@ -72,19 +69,16 @@ public void endSelector(SelectorList selector) throws CSSException { @Override public void ignorableAtRule(String arg0) throws CSSException { // TODO Auto-generated method stub - } @Override public void importStyle(String arg0, SACMediaList arg1, String arg2) throws CSSException { // TODO Auto-generated method stub - } @Override public void namespaceDeclaration(String arg0, String arg1) throws CSSException { // TODO Auto-generated method stub - } @Override @@ -127,25 +121,21 @@ private RGB createRGB(LexicalUnit value) { @Override public void startDocument(InputSource arg0) throws CSSException { // TODO Auto-generated method stub - } @Override public void startFontFace() throws CSSException { // TODO Auto-generated method stub - } @Override public void startMedia(SACMediaList arg0) throws CSSException { // TODO Auto-generated method stub - } @Override public void startPage(String arg0, String arg1) throws CSSException { // TODO Auto-generated method stub - } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java index 619dfa21d..f100a5caf 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java @@ -11,9 +11,9 @@ */ package org.eclipse.tm4e.core.internal.css; -public class CSSElementSelector extends AbstractElementSelector { +final class CSSElementSelector extends AbstractElementSelector { - public CSSElementSelector(String uri, String name) { + CSSElementSelector(String uri, String name) { super(uri, name); } @@ -28,10 +28,10 @@ public int getSpecificity() { } @Override - public int nbMatch(String... names) { + public int nbMatch(String... names) { return 0; } - + @Override public int nbClass() { return 0; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java index 524c7defb..6899936c0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java @@ -25,7 +25,7 @@ import org.w3c.css.sac.SiblingSelector; import org.w3c.css.sac.SimpleSelector; -public class CSSSelectorFactory implements SelectorFactory { +public final class CSSSelectorFactory implements SelectorFactory { public static final SelectorFactory INSTANCE = new CSSSelectorFactory(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java index 72ab8e148..c044ba4ce 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java @@ -17,7 +17,7 @@ import org.w3c.dom.css.RGBColor; import org.w3c.dom.css.Rect; -public abstract class CSSValueImpl implements CSSPrimitiveValue { +abstract class CSSValueImpl implements CSSPrimitiveValue { // W3C CSSValue API methods diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java index 91b08cf66..3d2a574dd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.core.internal.css; -public interface ExtendedCondition { +interface ExtendedCondition { /** * Returns the specificity of this condition. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java index 1c41e86b8..48cf2ed59 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java @@ -15,11 +15,11 @@ import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSValue; -public class Measure extends CSSValueImpl { +final class Measure extends CSSValueImpl { LexicalUnit value; - public Measure(LexicalUnit value) { + Measure(LexicalUnit value) { this.value = value; } @@ -53,7 +53,7 @@ public float getFloatValue(short valueType) throws DOMException { * a short representing the value type, see * {@link CSSValue#getCssValueType()} */ - public int getIntegerValue(short valueType) throws DOMException { + private int getIntegerValue(short valueType) throws DOMException { return value.getIntegerValue(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java index 2ec162cd0..3a557b4f8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java @@ -16,13 +16,13 @@ import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.RGBColor; -public class RGBColorImpl extends CSSValueImpl implements RGBColor { +final class RGBColorImpl extends CSSValueImpl implements RGBColor { private final CSSPrimitiveValue red; private final CSSPrimitiveValue green; private final CSSPrimitiveValue blue; - public RGBColorImpl(LexicalUnit lexicalUnit) { + RGBColorImpl(LexicalUnit lexicalUnit) { LexicalUnit nextUnit = lexicalUnit.getParameters(); red = new Measure(nextUnit); nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java index 4cc60ec01..66f2eb23c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java @@ -22,7 +22,7 @@ * SAC Parser factory implementation. By default, this SAC FActory support * Flute, SteadyState and Batik SAC Parser. */ -public class SACParserFactoryImpl extends SACParserFactory { +public final class SACParserFactoryImpl extends SACParserFactory { private static Map parsers = new HashMap<>(); @@ -63,7 +63,7 @@ public Parser makeParser(String name) throws ClassNotFoundException, IllegalAcce * * @param parser */ - public static void registerSACParser(String parser) { + private static void registerSACParser(String parser) { registerSACParser(parser, parser); } @@ -74,7 +74,7 @@ public static void registerSACParser(String parser) { * @param name * @param classNameParser */ - public static void registerSACParser(String name, String classNameParser) { + private static void registerSACParser(String name, String classNameParser) { parsers.put(name, classNameParser); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 4a3f98552..7c7e67f3a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -52,7 +52,7 @@ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts * */ -public class Grammar implements IGrammar, IRuleFactoryHelper { +public final class Grammar implements IGrammar, IRuleFactoryHelper { private int rootId; private int lastRuleId; @@ -79,11 +79,11 @@ public void onDidChangeTheme() { this.scopeMetadataProvider.onDidChangeTheme(); } - public ScopeMetadata getMetadataForScope(String scope) { + ScopeMetadata getMetadataForScope(String scope) { return this.scopeMetadataProvider.getMetadataForScope(scope); } - public List getInjections() { + List getInjections() { if (this.injections == null) { this.injections = new ArrayList<>(); // add injections from the current grammar @@ -144,7 +144,7 @@ public Rule getRule(int patternId) { return this.ruleId2desc.get(patternId); } - public IRawGrammar getExternalGrammar(String scopeName) { + private IRawGrammar getExternalGrammar(String scopeName) { return getExternalGrammar(scopeName, null); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index ddb042162..4edc5ea30 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -37,29 +37,29 @@ import org.eclipse.tm4e.core.internal.rule.MatchRule; import org.eclipse.tm4e.core.internal.rule.Rule; -class LineTokenizer { +final class LineTokenizer { private static final Logger LOGGER = System.getLogger(LineTokenizer.class.getName()); - static class WhileStack { + private static final class WhileStack { - public final StackElement stack; - public final BeginWhileRule rule; + private final StackElement stack; + private final BeginWhileRule rule; - public WhileStack(StackElement stack, BeginWhileRule rule) { + private WhileStack(StackElement stack, BeginWhileRule rule) { this.stack = stack; this.rule = rule; } } - static class WhileCheckResult { + private static final class WhileCheckResult { - public final StackElement stack; - public final int linePos; - public final int anchorPosition; - public final boolean isFirstLine; + private final StackElement stack; + private final int linePos; + private final int anchorPosition; + private final boolean isFirstLine; - public WhileCheckResult(StackElement stack, int linePos, int anchorPosition, boolean isFirstLine) { + private WhileCheckResult(StackElement stack, int linePos, int anchorPosition, boolean isFirstLine) { this.stack = stack; this.linePos = linePos; this.anchorPosition = anchorPosition; @@ -77,7 +77,7 @@ public WhileCheckResult(StackElement stack, int linePos, int anchorPosition, boo private boolean stop; private final int lineLength; - public LineTokenizer(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, StackElement stack, + private LineTokenizer(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, StackElement stack, LineTokens lineTokens) { this.grammar = grammar; this.lineText = lineText; @@ -88,7 +88,7 @@ public LineTokenizer(Grammar grammar, OnigString lineText, boolean isFirstLine, this.lineTokens = lineTokens; } - public StackElement scan() { + private StackElement scan() { stop = false; WhileCheckResult whileCheckResult = checkWhileConditions(grammar, lineText, isFirstLine, linePos, stack, @@ -522,7 +522,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe return new WhileCheckResult(stack, linePos, currentanchorPosition, isFirstLine); } - public static StackElement tokenizeString(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, + static StackElement tokenizeString(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, StackElement stack, LineTokens lineTokens) { return new LineTokenizer(grammar, lineText, isFirstLine, linePos, stack, lineTokens).scan(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 7e1a79a2c..028d38a7e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -25,7 +25,7 @@ import org.eclipse.tm4e.core.grammar.IToken; import org.eclipse.tm4e.core.grammar.StackElement; -class LineTokens { +final class LineTokens { private static final Logger LOGGER = System.getLogger(LineTokens.class.getName()); @@ -58,11 +58,11 @@ class LineTokens { this.lastTokenEndIndex = 0; } - public void produce(StackElement stack, int endIndex) { + void produce(StackElement stack, int endIndex) { this.produceFromScopes(stack.contentNameScopesList, endIndex); } - public void produceFromScopes(ScopeListElement scopesList, int endIndex) { + void produceFromScopes(ScopeListElement scopesList, int endIndex) { if (this.lastTokenEndIndex >= endIndex) { return; } @@ -98,7 +98,7 @@ public void produceFromScopes(ScopeListElement scopesList, int endIndex) { this.lastTokenEndIndex = endIndex; } - public IToken[] getResult(StackElement stack, int lineLength) { + IToken[] getResult(StackElement stack, int lineLength) { if (!this.tokens.isEmpty() && this.tokens.get(this.tokens.size() - 1).getStartIndex() == lineLength - 1) { // pop produced token for newline this.tokens.remove(this.tokens.size() - 1); @@ -113,7 +113,7 @@ public IToken[] getResult(StackElement stack, int lineLength) { return this.tokens.toArray(new IToken[0]); } - public int[] getBinaryResult(StackElement stack, int lineLength) { + int[] getBinaryResult(StackElement stack, int lineLength) { if (!this.binaryTokens.isEmpty() && this.binaryTokens.get(this.binaryTokens.size() - 2) == lineLength - 1) { // pop produced token for newline this.binaryTokens.remove(this.binaryTokens.size() - 1); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java index 37770d867..62a1493fc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java @@ -16,21 +16,21 @@ */ package org.eclipse.tm4e.core.internal.grammar; -class LocalStackElement { +final class LocalStackElement { private final ScopeListElement scopes; private final int endPos; - public LocalStackElement(ScopeListElement scopes, int endPos) { + LocalStackElement(ScopeListElement scopes, int endPos) { this.scopes = scopes; this.endPos = endPos; } - public ScopeListElement getScopes() { + ScopeListElement getScopes() { return scopes; } - public int getEndPos() { + int getEndPos() { return endPos; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java index e6d2709bb..6c624002b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java @@ -14,24 +14,24 @@ /** * Helpers to manage the "collapsed" metadata of an entire StackElement stack. * The following assumptions have been made: - * - languageId < 256 => needs 8 bits - * - unique color count < 512 => needs 9 bits + * - languageId < 256 => needs 8 bits + * - unique color count < 512 => needs 9 bits * * The binary format is: * - ------------------------------------------- - * 3322 2222 2222 1111 1111 1100 0000 0000 - * 1098 7654 3210 9876 5432 1098 7654 3210 + * 3322 2222 2222 1111 1111 1100 0000 0000 + * 1098 7654 3210 9876 5432 1098 7654 3210 * - ------------------------------------------- - * xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - * bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL + * xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx + * bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL * - ------------------------------------------- - * - L = LanguageId (8 bits) - * - T = StandardTokenType (3 bits) - * - F = FontStyle (3 bits) - * - f = foreground color (9 bits) - * - b = background color (9 bits) + * - L = LanguageId (8 bits) + * - T = StandardTokenType (3 bits) + * - F = FontStyle (3 bits) + * - f = foreground color (9 bits) + * - b = background color (9 bits) */ -public class MetadataConsts { +final class MetadataConsts { /** * content should be accessed statically @@ -39,15 +39,15 @@ public class MetadataConsts { private MetadataConsts() { } - public static final int LANGUAGEID_MASK = 0b00000000000000000000000011111111; - public static final int TOKEN_TYPE_MASK = 0b00000000000000000000011100000000; - public static final int FONT_STYLE_MASK = 0b00000000000000000011100000000000; - public static final int FOREGROUND_MASK = 0b00000000011111111100000000000000; - public static final int BACKGROUND_MASK = 0b11111111100000000000000000000000; + static final int LANGUAGEID_MASK = 0b00000000000000000000000011111111; + static final int TOKEN_TYPE_MASK = 0b00000000000000000000011100000000; + static final int FONT_STYLE_MASK = 0b00000000000000000011100000000000; + static final int FOREGROUND_MASK = 0b00000000011111111100000000000000; + static final int BACKGROUND_MASK = 0b11111111100000000000000000000000; - public static final int LANGUAGEID_OFFSET = 0; - public static final int TOKEN_TYPE_OFFSET = 8; - public static final int FONT_STYLE_OFFSET = 11; - public static final int FOREGROUND_OFFSET = 14; - public static final int BACKGROUND_OFFSET = 23; + static final int LANGUAGEID_OFFSET = 0; + static final int TOKEN_TYPE_OFFSET = 8; + static final int FONT_STYLE_OFFSET = 11; + static final int FOREGROUND_OFFSET = 14; + static final int BACKGROUND_OFFSET = 23; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index 029f2295b..a18b05ea1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -21,13 +21,13 @@ import com.google.common.base.Splitter; -public class ScopeListElement { +public final class ScopeListElement { private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' '); - public final ScopeListElement parent; - public final String scope; - public final int metadata; + private final ScopeListElement parent; + private final String scope; + final int metadata; public ScopeListElement(ScopeListElement parent, String scope, int metadata) { this.parent = parent; @@ -59,7 +59,8 @@ public boolean equals(Object other) { return ScopeListElement.equals(this, (ScopeListElement)other); } - @Override public int hashCode() { + @Override + public int hashCode() { return Objects.hash(scope, metadata, parent); } @@ -127,7 +128,7 @@ private static ScopeListElement push(ScopeListElement target, Grammar grammar, I return target; } - public ScopeListElement push(Grammar grammar, String scope) { + ScopeListElement push(Grammar grammar, String scope) { if (scope == null) { return this; } @@ -144,7 +145,7 @@ private static List generateScopes(ScopeListElement scopesList) { return result; } - public List generateScopes() { + List generateScopes() { return ScopeListElement.generateScopes(this); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java index 08f07f409..308a46a44 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java @@ -15,12 +15,12 @@ import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; -public class ScopeMetadata { +public final class ScopeMetadata { - public final String scopeName; - public final int languageId; - public final int tokenType; - public final List themeData; + private final String scopeName; + final int languageId; + final int tokenType; + final List themeData; public ScopeMetadata(String scopeName, int languageId, int tokenType, List themeData) { this.scopeName = scopeName; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java index a5bfd0f1b..020627e07 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java @@ -25,7 +25,7 @@ import org.eclipse.tm4e.core.theme.IThemeProvider; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; -public class ScopeMetadataProvider { +final class ScopeMetadataProvider { private static final ScopeMetadata _NULL_SCOPE_METADATA = new ScopeMetadata("", 0, StandardTokenType.Other, null); @@ -41,7 +41,7 @@ public class ScopeMetadataProvider { private final Map embeddedLanguages; private Pattern embeddedLanguagesRegex; - public ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider, + ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider, Map embeddedLanguages) { this.initialLanguage = initialLanguage; this.themeProvider = themeProvider; @@ -84,17 +84,16 @@ public ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider, } } -public void onDidChangeTheme() { - this.cache.clear(); - this.defaultMetaData = new ScopeMetadata( - "", - this.initialLanguage, - StandardTokenType.Other, - Arrays.asList(this.themeProvider.getDefaults()) - ); -} + void onDidChangeTheme() { + this.cache.clear(); + this.defaultMetaData = new ScopeMetadata( + "", + this.initialLanguage, + StandardTokenType.Other, + Arrays.asList(this.themeProvider.getDefaults())); + } - public ScopeMetadata getDefaultMetadata() { + ScopeMetadata getDefaultMetadata() { return this.defaultMetaData; } @@ -103,10 +102,10 @@ public ScopeMetadata getDefaultMetadata() { */ private static String escapeRegExpCharacters(String value) { // TODO!!! - return value; //value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&'); + return value; // value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&'); } - public ScopeMetadata getMetadataForScope(String scopeName) { + ScopeMetadata getMetadataForScope(String scopeName) { if (scopeName == null) { return ScopeMetadataProvider._NULL_SCOPE_METADATA; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index 1cf7b1d74..e71a46bcc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -19,7 +19,7 @@ * Metadata for {@link StackElement}. * */ -public class StackElementMetadata { +public final class StackElementMetadata { /** * Content should be referenced statically @@ -27,7 +27,7 @@ public class StackElementMetadata { private StackElementMetadata() { } - public static String toBinaryStr(int metadata) { + static String toBinaryStr(int metadata) { /* * let r = metadata.toString(2); while (r.length < 32) { r = '0' + r; } * return r; @@ -36,15 +36,15 @@ public static String toBinaryStr(int metadata) { return null; } - public static int getLanguageId(int metadata) { + static int getLanguageId(int metadata) { return (metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET; } - public static int getTokenType(int metadata) { + static int getTokenType(int metadata) { return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET; } - public static int getFontStyle(int metadata) { + static int getFontStyle(int metadata) { return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET; } @@ -52,11 +52,11 @@ public static int getForeground(int metadata) { return (metadata & MetadataConsts.FOREGROUND_MASK) >>> MetadataConsts.FOREGROUND_OFFSET; } - public static int getBackground(int metadata) { + static int getBackground(int metadata) { return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET; } - public static int set(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { + static int set(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { languageId = languageId == 0 ? StackElementMetadata.getLanguageId(metadata) : languageId; tokenType = tokenType == StandardTokenType.Other ? StackElementMetadata.getTokenType(metadata) : tokenType; fontStyle = fontStyle == FontStyle.NotSet ? StackElementMetadata.getFontStyle(metadata) : fontStyle; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java index cccb08ddd..47f8669e8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java @@ -15,7 +15,7 @@ * Standard TextMate token type. * */ -public class StandardTokenType { +final class StandardTokenType { /** * Content should be accessed statically @@ -23,9 +23,9 @@ public class StandardTokenType { private StandardTokenType() { } - public static final int Other = 0; - public static final int Comment = 1; - public static final int String = 2; - public static final int RegEx = 4; + static final int Other = 0; + static final int Comment = 1; + static final int String = 2; + static final int RegEx = 4; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java index 83da86459..520a7cba3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java @@ -20,7 +20,7 @@ import org.eclipse.tm4e.core.grammar.IToken; -class Token implements IToken { +final class Token implements IToken { private int startIndex; @@ -28,7 +28,7 @@ class Token implements IToken { private final List scopes; - public Token(int startIndex, int endIndex, List scopes) { + Token(int startIndex, int endIndex, List scopes) { this.startIndex = startIndex; this.endIndex = endIndex; this.scopes = scopes; @@ -53,7 +53,7 @@ public int getEndIndex() { public List getScopes() { return scopes; } - + @Override public String toString() { StringBuilder s = new StringBuilder(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java index 0f17e7191..050b30775 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java @@ -21,16 +21,16 @@ import org.eclipse.tm4e.core.grammar.StackElement; /** - * + * * Result of the line tokenization implementation. * */ -public class TokenizeLineResult implements ITokenizeLineResult { +final class TokenizeLineResult implements ITokenizeLineResult { private final IToken[] tokens; private final StackElement ruleStack; - public TokenizeLineResult(IToken[] tokens, StackElement ruleStack) { + TokenizeLineResult(IToken[] tokens, StackElement ruleStack) { this.tokens = tokens; this.ruleStack = ruleStack; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java index a7a20fbc2..2d5a2186e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java @@ -20,16 +20,16 @@ import org.eclipse.tm4e.core.grammar.StackElement; /** - * + * * Result of the line tokenization2 implementation. * */ -public class TokenizeLineResult2 implements ITokenizeLineResult2 { +final class TokenizeLineResult2 implements ITokenizeLineResult2 { private final int[] tokens; private final StackElement ruleStack; - public TokenizeLineResult2(int[] tokens, StackElement ruleStack) { + TokenizeLineResult2(int[] tokens, StackElement ruleStack) { this.tokens = tokens; this.ruleStack = ruleStack; } @@ -43,5 +43,4 @@ public int[] getTokens() { public StackElement getRuleStack() { return ruleStack; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java index e4eb0176f..f8d6220f4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java @@ -15,7 +15,7 @@ import org.eclipse.tm4e.core.internal.parser.PListObject; -public class PListGrammar extends PListObject { +public final class PListGrammar extends PListObject { public PListGrammar(PListObject parent, boolean valueAsArray) { super(parent, valueAsArray); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java index 92457d050..46aae559c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java @@ -29,32 +29,32 @@ * Raw * */ -public class Raw extends HashMap implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { - private static final String FIRST_LINE_MATCH = "firstLineMatch"; - private static final String FILE_TYPES = "fileTypes"; - private static final String SCOPE_NAME = "scopeName"; - private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast"; - private static final String REPOSITORY = "repository"; - private static final String INJECTION_SELECTOR = "injectionSelector"; - private static final String INJECTIONS = "injections"; - private static final String PATTERNS = "patterns"; - private static final String WHILE_CAPTURES = "whileCaptures"; - private static final String END_CAPTURES = "endCaptures"; - private static final String INCLUDE = "include"; - private static final String WHILE = "while"; - private static final String END = "end"; - private static final String BEGIN = "begin"; - private static final String CAPTURES = "captures"; - private static final String MATCH = "match"; - private static final String BEGIN_CAPTURES = "beginCaptures"; - private static final String CONTENT_NAME = "contentName"; - private static final String NAME = "name"; - private static final String ID = "id"; - private static final String DOLLAR_SELF = "$self"; - private static final String DOLLAR_BASE = "$base"; - private static final long serialVersionUID = -2306714541728887963L; - - private transient List fileTypes; +public final class Raw extends HashMap implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { + public static final String FIRST_LINE_MATCH = "firstLineMatch"; + public static final String FILE_TYPES = "fileTypes"; + public static final String SCOPE_NAME = "scopeName"; + public static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast"; + public static final String REPOSITORY = "repository"; + public static final String INJECTION_SELECTOR = "injectionSelector"; + public static final String INJECTIONS = "injections"; + public static final String PATTERNS = "patterns"; + public static final String WHILE_CAPTURES = "whileCaptures"; + public static final String END_CAPTURES = "endCaptures"; + public static final String INCLUDE = "include"; + public static final String WHILE = "while"; + public static final String END = "end"; + public static final String BEGIN = "begin"; + public static final String CAPTURES = "captures"; + public static final String MATCH = "match"; + public static final String BEGIN_CAPTURES = "beginCaptures"; + public static final String CONTENT_NAME = "contentName"; + public static final String NAME = "name"; + public static final String ID = "id"; + public static final String DOLLAR_SELF = "$self"; + public static final String DOLLAR_BASE = "$base"; + public static final long serialVersionUID = -2306714541728887963L; + + public transient List fileTypes; @Override public IRawRule getProp(String name) { @@ -127,7 +127,7 @@ public IRawCaptures getCaptures() { return (IRawCaptures) super.get(CAPTURES); } - private void updateCaptures(String name) { + public void updateCaptures(String name) { Object captures = super.get(name); if (captures instanceof List) { Raw rawCaptures = new Raw(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java index 097a3757e..3f83c1cd7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java @@ -27,7 +27,7 @@ * TextMate Grammar reader utilities. * */ -public class GrammarReader { +public final class GrammarReader { /** * methods should be accessed statically diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java index d22843f33..d36dec4b3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java @@ -20,7 +20,7 @@ import org.eclipse.tm4e.core.internal.types.IRawGrammar; -public class SyncGrammarReader { +final class SyncGrammarReader { private final InputStream in; private final IGrammarParser parser; @@ -30,7 +30,7 @@ public class SyncGrammarReader { this.parser = parser; } - public IRawGrammar load() throws Exception { + IRawGrammar load() throws Exception { return this.parser.parse(in); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java index 6ba91f8f8..41f321baf 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java @@ -36,7 +36,7 @@ import org.eclipse.tm4e.core.theme.Theme; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; -public class SyncRegistry implements IGrammarRepository, IThemeProvider { +public final class SyncRegistry implements IGrammarRepository, IThemeProvider { private final Map grammars; private final Map rawGrammars; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java index 1af543828..37ecd5cf2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java @@ -20,5 +20,4 @@ public interface IMatchInjectionsResult extends IMatchResult { boolean isPriorityMatch(); - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java index 9da15570a..006fbc936 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -public interface IMatchesName { +interface IMatchesName { IMatchesName> NAME_MATCHER = new IMatchesName<>() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java index 06b418c3b..7557ebe4a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java @@ -28,7 +28,7 @@ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/matcher.ts * */ -public class Matcher implements Predicate { +public final class Matcher implements Predicate { private static final Pattern IDENTIFIER_REGEXP = Pattern.compile("[\\w\\.:]+"); @@ -45,7 +45,7 @@ private static Collection> createMatchers(String sele private final IMatchesName matchesName; private String token; - public Matcher(String expression, IMatchesName matchesName) { + private Matcher(String expression, IMatchesName matchesName) { this.results = new ArrayList<>(); this.tokenizer = new Tokenizer(expression); this.matchesName = matchesName; @@ -160,17 +160,17 @@ public boolean test(T matcherInput) { return false; } - private static class Tokenizer { + private static final class Tokenizer { private static final Pattern REGEXP = Pattern.compile("([LR]:|[\\w\\.:]+|[\\,\\|\\-\\(\\)])"); private final java.util.regex.Matcher regex; - public Tokenizer(String input) { + private Tokenizer(String input) { this.regex = REGEXP.matcher(input); } - public String next() { + private String next() { if (regex.find()) { return regex.group(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java index 2211cb0ee..0cbea1228 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java @@ -18,7 +18,7 @@ import java.util.function.Predicate; -public class MatcherWithPriority { +public final class MatcherWithPriority { public final Predicate matcher; public final int priority; @@ -27,7 +27,7 @@ public class MatcherWithPriority { * @param matcher * @param priority */ - public MatcherWithPriority(Predicate matcher, int priority) { + MatcherWithPriority(Predicate matcher, int priority) { this.matcher = matcher; this.priority = priority; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java index 9e5c7d3cb..150068747 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java @@ -16,13 +16,13 @@ */ package org.eclipse.tm4e.core.internal.oniguruma; -class OnigNextMatchResult implements IOnigNextMatchResult { +final class OnigNextMatchResult implements IOnigNextMatchResult { private final int index; private final IOnigCaptureIndex[] captureIndices; - public OnigNextMatchResult(OnigResult result, OnigString source) { + OnigNextMatchResult(OnigResult result, OnigString source) { this.index = result.getIndex(); this.captureIndices = captureIndicesForMatch(result, source); } @@ -71,13 +71,13 @@ private static IOnigCaptureIndex[] captureIndicesForMatch(OnigResult result, Oni return captures; } - private static class OnigCaptureIndex implements IOnigCaptureIndex { + private static final class OnigCaptureIndex implements IOnigCaptureIndex { private final int index; private final int start; private final int end; - public OnigCaptureIndex(int index, int start, int end) { + private OnigCaptureIndex(int index, int start, int end) { this.index = index; this.start = start >= 0 ? start : 0; this.end = end >= 0 ? end : 0; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java index 0d63aea7a..3423114da 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java @@ -36,14 +36,14 @@ * @see https://github.com/atom/node-oniguruma/blob/master/src/onig-reg-exp.cc * */ -public class OnigRegExp { +final class OnigRegExp { private OnigString lastSearchString; private int lastSearchPosition; private OnigResult lastSearchResult; private final Regex regex; - public OnigRegExp(String source) { + OnigRegExp(String source) { lastSearchString = null; lastSearchPosition = -1; lastSearchResult = null; @@ -56,7 +56,7 @@ public OnigRegExp(String source) { } } - public OnigResult search(OnigString str, int position) { + OnigResult search(OnigString str, int position) { if (lastSearchString == str && lastSearchPosition <= position && (lastSearchResult == null || lastSearchResult.locationAt(0) >= position)) { return lastSearchResult; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java index d79fd7cd9..4bb1c3b13 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java @@ -19,25 +19,25 @@ import org.joni.Region; -public class OnigResult { +final class OnigResult { private int indexInScanner; private final Region region; - public OnigResult(Region region, int indexInScanner) { + OnigResult(Region region, int indexInScanner) { this.region = region; this.indexInScanner = indexInScanner; } - public int getIndex() { + int getIndex() { return indexInScanner; } - public void setIndex(int index) { + void setIndex(int index) { this.indexInScanner = index; } - public int locationAt(int index) { + int locationAt(int index) { int bytes = region.beg[index]; if (bytes > 0) { return bytes; @@ -45,11 +45,11 @@ public int locationAt(int index) { return 0; } - public int count() { + int count() { return region.numRegs; } - public int lengthAt(int index) { + int lengthAt(int index) { int bytes = region.end[index] - region.beg[index]; if (bytes > 0) { return bytes; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java index 428ac584e..0a3de09a5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java @@ -17,7 +17,7 @@ package org.eclipse.tm4e.core.internal.oniguruma; -public class OnigScanner { +public final class OnigScanner { private final OnigSearcher searcher; @@ -33,7 +33,7 @@ public IOnigNextMatchResult findNextMatchSync(OnigString source, int charOffset) return null; } - public IOnigNextMatchResult findNextMatchSync(String lin, int pos) { + IOnigNextMatchResult findNextMatchSync(String lin, int pos) { return findNextMatchSync(new OnigString(lin), pos); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java index cbbcd4dbd..7dd66d328 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java @@ -14,22 +14,21 @@ * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ - package org.eclipse.tm4e.core.internal.oniguruma; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -public class OnigSearcher { +final class OnigSearcher { private final List regExps; - public OnigSearcher(String[] regexps) { + OnigSearcher(String[] regexps) { this.regExps = Arrays.stream(regexps).map(OnigRegExp::new).collect(Collectors.toList()); } - public OnigResult search(OnigString source, int charOffset) { + OnigResult search(OnigString source, int charOffset) { int byteOffset = source.convertUtf16OffsetToUtf8(charOffset); int bestLocation = 0; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java index e6d620712..77d28d89a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java @@ -16,7 +16,6 @@ * - Fabio Zadrozny - Convert uniqueId to Object (for identity compare) * - Fabio Zadrozny - Utilities to convert between utf-8 and utf-16 */ - package org.eclipse.tm4e.core.internal.oniguruma; import java.nio.charset.StandardCharsets; @@ -30,7 +29,7 @@ * @see https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc * */ -public class OnigString { +public final class OnigString { public final String string; public final byte[] utf8_value; @@ -38,13 +37,12 @@ public class OnigString { private int[] charsPosFromBytePos; private boolean computedOffsets; - public OnigString(String str) { this.string = str; this.utf8_value = str.getBytes(StandardCharsets.UTF_8); } - public int convertUtf16OffsetToUtf8(int posInChars) { + int convertUtf16OffsetToUtf8(int posInChars) { if(!computedOffsets) { computeOffsets(); } @@ -84,7 +82,7 @@ public int convertUtf16OffsetToUtf8(int posInChars) { return index; } - public int convertUtf8OffsetToUtf16(int posInBytes) { + int convertUtf8OffsetToUtf16(int posInBytes) { if(!computedOffsets) { computeOffsets(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java index 458896a8c..cb69ee2f9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java @@ -20,7 +20,7 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; -public class PList extends DefaultHandler { +public final class PList extends DefaultHandler { private final boolean theme; private final List errors; @@ -67,7 +67,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc super.endElement(uri, localName, qName); } - private void endElement(String tagName) { + public void endElement(String tagName) { Object value = null; String text = this.text.toString(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java index b35f26f39..7c520ab1e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java @@ -17,13 +17,13 @@ public abstract class PListObject { - public final PListObject parent; + final PListObject parent; private final List arrayValues; private final Map mapValues; private String lastKey; - public PListObject(PListObject parent, boolean valueAsArray) { + protected PListObject(PListObject parent, boolean valueAsArray) { this.parent = parent; if (valueAsArray) { this.arrayValues = new ArrayList<>(); @@ -34,15 +34,15 @@ public PListObject(PListObject parent, boolean valueAsArray) { } } - public String getLastKey() { + String getLastKey() { return lastKey; } - public void setLastKey(String lastKey) { + void setLastKey(String lastKey) { this.lastKey = lastKey; } - public void addValue(Object value) { + void addValue(Object value) { if (isValueAsArray()) { arrayValues.add(value); } else { @@ -50,11 +50,11 @@ public void addValue(Object value) { } } - public boolean isValueAsArray() { + boolean isValueAsArray() { return arrayValues != null; } - public Object getValue() { + Object getValue() { if (isValueAsArray()) { return arrayValues; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java index 00bb3f1f7..4b455d1fa 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java @@ -20,7 +20,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; -public class JSONPListParser { +public final class JSONPListParser { private final boolean theme; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java index 4503ea0cd..a30e6214a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java @@ -21,7 +21,7 @@ import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -public class XMLPListParser { +public final class XMLPListParser { private final boolean theme; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java index 80b87ec5a..a0fde87f2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java @@ -24,7 +24,7 @@ /** * Parses TextMate Grammar file in YAML format. */ -public class YamlPListParser { +public final class YamlPListParser { private final boolean theme; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index ca37f521c..8f879e51b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -20,19 +20,19 @@ import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; -public class BeginEndRule extends Rule { +public final class BeginEndRule extends Rule { private final RegExpSource begin; public final List beginCaptures; private final RegExpSource end; public final boolean endHasBackReferences; public final List endCaptures; - public final boolean applyEndPatternLast; - public final boolean hasMissingPatterns; - public final Integer[] patterns; + private final boolean applyEndPatternLast; + final boolean hasMissingPatterns; + final Integer[] patterns; private RegExpSourceList cachedCompiledPatterns; - public BeginEndRule(int id, String name, String contentName, String begin, List beginCaptures, + BeginEndRule(int id, String name, String contentName, String begin, List beginCaptures, String end, List endCaptures, boolean applyEndPatternLast, ICompilePatternsResult patterns) { super(id, name, contentName); this.begin = new RegExpSource(begin, this.id); @@ -51,7 +51,7 @@ public String getEndWithResolvedBackReferences(String lineText, IOnigCaptureInde } @Override - public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { if (isFirst) { for (Integer pattern : this.patterns) { Rule rule = grammar.getRule(pattern); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index f602717e2..dd5dd7fc4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -20,19 +20,19 @@ import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; -public class BeginWhileRule extends Rule { +public final class BeginWhileRule extends Rule { private final RegExpSource begin; public final List beginCaptures; public final List whileCaptures; private final RegExpSource _while; public final boolean whileHasBackReferences; - public final boolean hasMissingPatterns; - public final Integer[] patterns; + final boolean hasMissingPatterns; + final Integer[] patterns; private RegExpSourceList cachedCompiledPatterns; private RegExpSourceList cachedCompiledWhilePatterns; - public BeginWhileRule(/* $location:ILocation, */ int id, String name, String contentName, String begin, + BeginWhileRule(/* $location:ILocation, */ int id, String name, String contentName, String begin, List beginCaptures, String _while, List whileCaptures, ICompilePatternsResult patterns) { super(/* $location, */id, name, contentName); @@ -52,7 +52,7 @@ public String getWhileWithResolvedBackReferences(String lineText, IOnigCaptureIn } @Override - public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { if (isFirst) { Rule rule; for (Integer pattern : patterns) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java index c98c39560..4ff8b6ac4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java @@ -16,20 +16,22 @@ */ package org.eclipse.tm4e.core.internal.rule; -public class CaptureRule extends Rule { +public final class CaptureRule extends Rule { public final Integer retokenizeCapturedWithRuleId; - public CaptureRule(int id, String name, String contentName, Integer retokenizeCapturedWithRuleId) { + CaptureRule(int id, String name, String contentName, Integer retokenizeCapturedWithRuleId) { super(id, name, contentName); this.retokenizeCapturedWithRuleId = retokenizeCapturedWithRuleId; } - @Override public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + @Override + void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { throw new UnsupportedOperationException(); } - @Override public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + @Override + public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { throw new UnsupportedOperationException(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java index 3b5fa2b39..cc8b48b05 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java @@ -18,12 +18,12 @@ import java.util.Collection; -public class ICompilePatternsResult { +final class ICompilePatternsResult { - public final Integer[] patterns; - public final boolean hasMissingPatterns; + final Integer[] patterns; + final boolean hasMissingPatterns; - public ICompilePatternsResult(Collection patterns, boolean hasMissingPatterns) { + ICompilePatternsResult(Collection patterns, boolean hasMissingPatterns) { this.hasMissingPatterns = hasMissingPatterns; this.patterns = patterns.toArray(new Integer[patterns.size()]); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java index 393325cdf..ff829e011 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java @@ -18,12 +18,12 @@ import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner; -public class ICompiledRule { +public final class ICompiledRule { public final OnigScanner scanner; public final Integer[] rules; - public ICompiledRule(OnigScanner scanner, Integer[] rules) { + ICompiledRule(OnigScanner scanner, Integer[] rules) { this.scanner = scanner; this.rules = rules; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java index 924fe071f..8cedf4fa8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java @@ -19,7 +19,7 @@ import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; -public interface IGrammarRegistry { +interface IGrammarRegistry { IRawGrammar getExternalGrammar(String scopeName, IRawRepository repository); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java index f08dc3a30..940b5d79a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java @@ -16,14 +16,14 @@ */ package org.eclipse.tm4e.core.internal.rule; -public class IRegExpSourceAnchorCache { +final class IRegExpSourceAnchorCache { - public final String A0_G0; - public final String A0_G1; - public final String A1_G0; - public final String A1_G1; + final String A0_G0; + final String A0_G1; + final String A1_G0; + final String A1_G1; - public IRegExpSourceAnchorCache(String A0_G0, String A0_G1, String A1_G0, String A1_G1) { + IRegExpSourceAnchorCache(String A0_G0, String A0_G1, String A1_G0, String A1_G1) { this.A0_G0 = A0_G0; this.A0_G1 = A0_G1; this.A1_G0 = A1_G0; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java index 077dab5ca..05ee778fe 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java @@ -16,13 +16,13 @@ */ package org.eclipse.tm4e.core.internal.rule; -public class IncludeOnlyRule extends Rule { +final class IncludeOnlyRule extends Rule { - public final boolean hasMissingPatterns; - public final Integer[] patterns; + final boolean hasMissingPatterns; + final Integer[] patterns; private RegExpSourceList cachedCompiledPatterns; - public IncludeOnlyRule(int id, String name, String contentName, ICompilePatternsResult patterns) { + IncludeOnlyRule(int id, String name, String contentName, ICompilePatternsResult patterns) { super(id, name, contentName); this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; @@ -30,7 +30,7 @@ public IncludeOnlyRule(int id, String name, String contentName, ICompilePatterns } @Override - public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { for (Integer pattern : this.patterns) { Rule rule = grammar.getRule(pattern); rule.collectPatternsRecursive(grammar, out, false); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java index 2d1aa9ab5..e40e69167 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java @@ -18,13 +18,13 @@ import java.util.List; -public class MatchRule extends Rule { +public final class MatchRule extends Rule { private final RegExpSource match; public final List captures; private RegExpSourceList cachedCompiledPatterns; - public MatchRule(int id, String name, String match, List captures) { + MatchRule(int id, String name, String match, List captures) { super(id, name, null); this.match = new RegExpSource(match, this.id); this.captures = captures; @@ -32,7 +32,7 @@ public MatchRule(int id, String name, String match, List captures) } @Override - public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { out.push(this.match); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index f2ebc3993..1d342c5fb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -29,7 +29,7 @@ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts * */ -public class RegExpSource { +final class RegExpSource { private static final Pattern HAS_BACK_REFERENCES = Pattern.compile("\\\\(\\d+)"); private static final Pattern BACK_REFERENCING_END = Pattern.compile("\\\\(\\d+)"); @@ -42,11 +42,11 @@ public class RegExpSource { private IRegExpSourceAnchorCache anchorCache; private String source; - public RegExpSource(String regExpSource, int ruleId) { + RegExpSource(String regExpSource, int ruleId) { this(regExpSource, ruleId, true); } - public RegExpSource(String regExpSource, int ruleId, boolean handleAnchors) { + private RegExpSource(String regExpSource, int ruleId, boolean handleAnchors) { if (handleAnchors) { this._handleAnchors(regExpSource); } else { @@ -66,11 +66,11 @@ public RegExpSource(String regExpSource, int ruleId, boolean handleAnchors) { } @Override - public RegExpSource clone() { + protected RegExpSource clone() { return new RegExpSource(this.source, this.ruleId, true); } - public void setSource(String newSource) { + void setSource(String newSource) { if (this.source.equals(newSource)) { return; } @@ -122,7 +122,7 @@ private void _handleAnchors(String regExpSource) { } } - public String resolveBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) { + String resolveBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) { try { List capturedValues = Arrays.stream(captureIndices) .map(capture -> lineText.substring(capture.getStart(), capture.getEnd())).collect(Collectors.toList()); @@ -210,7 +210,7 @@ private IRegExpSourceAnchorCache _buildAnchorCache() { ); } - public String resolveAnchors(boolean allowA, boolean allowG) { + String resolveAnchors(boolean allowA, boolean allowG) { if (!this._hasAnchor) { return this.source; } @@ -227,19 +227,19 @@ public String resolveAnchors(boolean allowA, boolean allowG) { return this.anchorCache.A0_G0; } - public boolean hasAnchor() { + boolean hasAnchor() { return this._hasAnchor; } - public String getSource() { + String getSource() { return this.source; } - public Integer getRuleId() { + Integer getRuleId() { return this.ruleId; } - public boolean hasBackReferences() { + boolean hasBackReferences() { return this._hasBackReferences; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index 088a2307e..5930343f5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -27,14 +27,14 @@ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts * */ -public class RegExpSourceList { +final class RegExpSourceList { - private static class RegExpSourceListAnchorCache { + private static final class RegExpSourceListAnchorCache { - public ICompiledRule A0_G0; - public ICompiledRule A0_G1; - public ICompiledRule A1_G0; - public ICompiledRule A1_G1; + private ICompiledRule A0_G0; + private ICompiledRule A0_G1; + private ICompiledRule A1_G0; + private ICompiledRule A1_G1; } @@ -43,28 +43,28 @@ private static class RegExpSourceListAnchorCache { private ICompiledRule _cached; private final RegExpSourceListAnchorCache _anchorCache; - public RegExpSourceList() { + RegExpSourceList() { this._items = new ArrayList<>(); this._hasAnchors = false; this._cached = null; this._anchorCache = new RegExpSourceListAnchorCache(); } - public void push(RegExpSource item) { + void push(RegExpSource item) { this._items.add(item); this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor(); } - public void unshift(RegExpSource item) { + void unshift(RegExpSource item) { this._items.add(0, item); this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor(); } - public int length() { + int length() { return this._items.size(); } - public void setSource(int index, String newSource) { + void setSource(int index, String newSource) { RegExpSource r = this._items.get(index); if (!r.getSource().equals(newSource)) { // bust the cache @@ -77,7 +77,7 @@ public void setSource(int index, String newSource) { } } - public ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) { + ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) { if (!this._hasAnchors) { if (this._cached == null) { List regexps = new ArrayList<>(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java index 437576d15..c4618ce61 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java @@ -21,7 +21,7 @@ public abstract class Rule { - public final int id; + final int id; private final boolean nameIsCapturing; private final String name; @@ -29,7 +29,7 @@ public abstract class Rule { private final boolean contentNameIsCapturing; private final String contentName; - public Rule(int id, String name, String contentName) { + Rule(int id, String name, String contentName) { this.id = id; this.name = name; this.nameIsCapturing = RegexSource.hasCaptures(this.name); @@ -51,7 +51,7 @@ public String getContentName(String lineText, IOnigCaptureIndex[] captureIndices return RegexSource.replaceCaptures(this.contentName, lineText, captureIndices); } - public abstract void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst); + abstract void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst); public abstract ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index dfd1d1b59..03b52473f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -31,9 +31,9 @@ * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts * */ -public class RuleFactory { +public final class RuleFactory { - public static CaptureRule createCaptureRule(IRuleFactoryHelper helper, final String name, final String contentName, + private static CaptureRule createCaptureRule(IRuleFactoryHelper helper, final String name, final String contentName, final Integer retokenizeCapturedWithRuleId) { return (CaptureRule) helper.registerRule(id -> new CaptureRule(id, name, contentName, retokenizeCapturedWithRuleId)); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java index 8a37c89ea..04cb2ff56 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java @@ -15,7 +15,7 @@ import org.eclipse.tm4e.core.internal.parser.PListObject; -public class PListTheme extends PListObject { +public final class PListTheme extends PListObject { public PListTheme(PListObject parent, boolean valueAsArray) { super(parent, valueAsArray); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index 9dabdd447..027081e88 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -18,7 +18,7 @@ import org.eclipse.tm4e.core.theme.IRawThemeSetting; import org.eclipse.tm4e.core.theme.IThemeSetting; -public class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting { +final class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting { private static final long serialVersionUID = -3622927264735492387L; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java index 8e4b14641..3514997a7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java @@ -20,7 +20,7 @@ import org.eclipse.tm4e.core.theme.IRawTheme; -public class SyncThemeReader { +final class SyncThemeReader { private final InputStream in; private final IThemeParser parser; @@ -30,7 +30,7 @@ public class SyncThemeReader { this.parser = parser; } - public IRawTheme load() throws Exception { + IRawTheme load() throws Exception { return this.parser.parse(in); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java index 5742efd95..604b0ac05 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java @@ -26,7 +26,7 @@ * TextMate Theme reader utilities. * */ -public class ThemeReader { +public final class ThemeReader { /** * Helper class, use methods statically @@ -34,7 +34,7 @@ public class ThemeReader { private ThemeReader() { } - public static final IThemeParser XML_PARSER = new IThemeParser() { + private static final IThemeParser XML_PARSER = new IThemeParser() { private final XMLPListParser parser = new XMLPListParser<>(true); @@ -54,7 +54,7 @@ public IRawTheme parse(InputStream contents) throws Exception { } }; - public static IRawTheme readThemeSync(String filePath, InputStream in) throws Exception { + private static IRawTheme readThemeSync(String filePath, InputStream in) throws Exception { SyncThemeReader reader = new SyncThemeReader(in, getThemeParser(filePath)); return reader.load(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java index 8ecb1a356..d532ea21e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java @@ -16,6 +16,6 @@ */ package org.eclipse.tm4e.core.internal.types; -public interface IBaseRaw extends Iterable{ +interface IBaseRaw extends Iterable{ } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java index 40d31d890..87d903881 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java @@ -24,7 +24,7 @@ * Clone utilities. * */ -public class CloneUtils { +public final class CloneUtils { /** * Helper class, use methods statically diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java index 2beb8ef28..c661aff3f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java @@ -2,7 +2,7 @@ import java.util.List; -public class CompareUtils { +public final class CompareUtils { public static int strcmp(String a, String b) { if (a == null && b == null) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index c0b2b283d..dd2bc9587 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -21,7 +21,7 @@ import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; -public class RegexSource { +public final class RegexSource { /** * Helper class, access members statically diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java index 7a8bf76f0..73e9f8dfd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java @@ -37,7 +37,7 @@ public abstract class AbstractLineList implements IModelLines { private TMModel model; - public AbstractLineList() { + protected AbstractLineList() { } void setModel(TMModel model) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index 52ea912ef..d1e9fe2e6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -65,7 +65,7 @@ public TMModel(IModelLines lines) { * {@link TMModel#addModelTokensChangedListener(IModelTokensChangedListener)}. * */ - static class TokenizerThread extends Thread { + private static final class TokenizerThread extends Thread { private final TMModel model; private TMState lastState; diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java similarity index 93% rename from org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarTest.java rename to org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java index 225556c9e..e25529ba9 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java @@ -9,17 +9,15 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.grammar; +package org.eclipse.tm4e.core.internal.grammar; -import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata; -import org.eclipse.tm4e.core.internal.grammar.StandardTokenType; import org.eclipse.tm4e.core.theme.FontStyle; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** * {@link StackElementMetadata} tests same than vscode-textmate. - * + * * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/grammar.test.ts * */ @@ -94,24 +92,24 @@ public void testCanWorkAtMaxValues() { int value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground); assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground); } - + private static void assertEquals(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { - String actual = "{\n" + + String actual = "{\n" + "languageId: " + StackElementMetadata.getLanguageId(metadata) + ",\n" + "tokenType: " + StackElementMetadata.getTokenType(metadata) + ",\n" + "fontStyle: " + StackElementMetadata.getFontStyle(metadata) + ",\n" + "foreground: " + StackElementMetadata.getForeground(metadata) + ",\n" + - "background: " + StackElementMetadata.getBackground(metadata) + ",\n" + + "background: " + StackElementMetadata.getBackground(metadata) + ",\n" + "}"; - String expected = "{\n" + + String expected = "{\n" + "languageId: " + languageId + ",\n" + "tokenType: " + tokenType + ",\n" + "fontStyle: " + fontStyle + ",\n" + "foreground: " + foreground + ",\n" + - "background: " + background + ",\n" + + "background: " + background + ",\n" + "}"; - + Assertions.assertEquals(expected, actual, "equals for " + StackElementMetadata.toBinaryStr(metadata)); } } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/OnigStringTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigStringTest.java similarity index 91% rename from org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/OnigStringTest.java rename to org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigStringTest.java index 4cf0bc62a..277c7fec3 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/OnigStringTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigStringTest.java @@ -1,9 +1,7 @@ -package org.eclipse.tm4e.core; +package org.eclipse.tm4e.core.internal.oniguruma; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; -import org.eclipse.tm4e.core.internal.oniguruma.OnigString; import org.junit.jupiter.api.Test; public class OnigStringTest { diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestOngurama.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java similarity index 82% rename from org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestOngurama.java rename to org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java index b63b6ada4..6c3e2d6d9 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestOngurama.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java @@ -9,10 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core; - -import org.eclipse.tm4e.core.internal.oniguruma.IOnigNextMatchResult; -import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner; +package org.eclipse.tm4e.core.internal.oniguruma; public class TestOngurama { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java index f93a85b8e..1adf62bcb 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java @@ -25,7 +25,7 @@ public abstract class AbstractLanguageConfigurationRegistryManager implements IL protected final Map pluginDefinitions; protected final Map userDefinitions; - public AbstractLanguageConfigurationRegistryManager() { + protected AbstractLanguageConfigurationRegistryManager() { pluginDefinitions = new HashMap<>(); userDefinitions = new HashMap<>(); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java index 91b605342..2535188e8 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java @@ -35,7 +35,7 @@ * * @see https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages */ -public class LanguageConfiguration implements ILanguageConfiguration { +public final class LanguageConfiguration implements ILanguageConfiguration { /** * Returns an instance of {@link LanguageConfiguration} loaded from the VSCode diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java index 582cb42c6..55ec3230e 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java @@ -32,7 +32,7 @@ * Language configuration definition. * */ -public class LanguageConfigurationDefinition extends TMResource implements ILanguageConfigurationDefinition { +public final class LanguageConfigurationDefinition extends TMResource implements ILanguageConfigurationDefinition { private final IContentType contentType; private boolean onEnterEnabled = true; @@ -70,7 +70,7 @@ public LanguageConfigurationDefinition(IContentType contentType, String path, St * * @return the "character pair" support and null otherwise. */ - public CharacterPairSupport getCharacterPair() { + CharacterPairSupport getCharacterPair() { if (this.characterPair == null) { ILanguageConfiguration conf = getLanguageConfiguration(); if (conf != null) { @@ -86,7 +86,7 @@ public CharacterPairSupport getCharacterPair() { * * @return the "on enter" support and null otherwise. */ - public OnEnterSupport getOnEnter() { + OnEnterSupport getOnEnter() { if (this.onEnter == null) { ILanguageConfiguration conf = getLanguageConfiguration(); if (conf != null && (conf.getBrackets() != null || conf.getOnEnterRules() != null)) { @@ -101,7 +101,7 @@ public OnEnterSupport getOnEnter() { * * @return the "commment" support and null otherwise. */ - public CommentSupport getCommentSupport() { + CommentSupport getCommentSupport() { if (this.comment == null) { ILanguageConfiguration conf = getLanguageConfiguration(); if (conf != null) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java index b536acaec..23f14c9dc 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java @@ -17,7 +17,7 @@ * Helper class to get NLSed messages. * */ -public class LanguageConfigurationMessages extends NLS { +public final class LanguageConfigurationMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages"; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java index dcf44e9b8..c6469b25b 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java @@ -19,22 +19,24 @@ * language-configuration.json) Eclipse bundle. * */ -public class LanguageConfigurationPlugin extends AbstractUIPlugin { +public final class LanguageConfigurationPlugin extends AbstractUIPlugin { public static final String PLUGIN_ID = "org.eclipse.tm4e.languageconfiguration"; //$NON-NLS-1$ private static LanguageConfigurationPlugin INSTANCE = null; - public static LanguageConfigurationPlugin getInstance() { + static LanguageConfigurationPlugin getInstance() { return INSTANCE; } - @Override public void start(BundleContext context) throws Exception { + @Override + public void start(BundleContext context) throws Exception { super.start(context); INSTANCE = this; } - @Override public void stop(BundleContext context) throws Exception { + @Override + public void stop(BundleContext context) throws Exception { INSTANCE = null; super.stop(context); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java index 09bb29237..f14730886 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java @@ -37,7 +37,7 @@ import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils; import org.osgi.service.prefs.BackingStoreException; -public class LanguageConfigurationRegistryManager extends AbstractLanguageConfigurationRegistryManager { +public final class LanguageConfigurationRegistryManager extends AbstractLanguageConfigurationRegistryManager { private static final String EXTENSION_LANGUAGE_CONFIGURATIONS = "languageConfigurations"; //$NON-NLS-1$ private static final String LANGUAGE_CONFIGURATION_ELT = "languageConfiguration"; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java index 647b3db7a..1941fecef 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java @@ -15,7 +15,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; -public class LanguageConfigurationContentProvider implements IStructuredContentProvider { +final class LanguageConfigurationContentProvider implements IStructuredContentProvider { private ILanguageConfigurationRegistryManager registry; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java index 777cef524..6f3f575b4 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java @@ -16,7 +16,7 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; -public class LanguageConfigurationLabelProvider extends LabelProvider implements ITableLabelProvider { +final class LanguageConfigurationLabelProvider extends LabelProvider implements ITableLabelProvider { @Override public Image getColumnImage(Object element, int columnIndex) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java index bcfbb15a4..08cc3948e 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java @@ -59,9 +59,9 @@ * configuration It provides controls for adding, removing and changing language * configuration as well as enablement, default management. */ -public class LanguageConfigurationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { +public final class LanguageConfigurationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - public final static String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$ + final static String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$ private final ILanguageConfigurationRegistryManager manager; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java index fd5ff7218..9e29e4d25 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceConstants.java @@ -15,7 +15,7 @@ * Preferences constants for language configurations. * */ -public class PreferenceConstants { +public final class PreferenceConstants { public static final String LANGUAGE_CONFIGURATIONS = "org.eclipse.tm4e.languageConfigurations"; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java index 1646d870f..1160b6cf8 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java @@ -28,7 +28,7 @@ * Helper class load, save language configuration preferences with Json format. * */ -public class PreferenceHelper { +public final class PreferenceHelper { private static final Gson DEFAULT_GSON; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java index f2b5dd9b2..2caea279e 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java @@ -14,7 +14,7 @@ import java.util.List; @SuppressWarnings("serial") -public class AutoClosingPairConditional extends CharacterPair { +public final class AutoClosingPairConditional extends CharacterPair { private final List notIn; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java index bc624d655..624b2401f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java @@ -19,7 +19,7 @@ * The "character pair" support. * */ -public class CharacterPairSupport { +public final class CharacterPairSupport { private List autoClosingPairs; private final List surroundingPairs; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java index b5edf1e3c..db7ff8b72 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java @@ -14,7 +14,7 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; -public class CommentSupport { +public final class CommentSupport { private final Comments comments; @@ -22,7 +22,7 @@ public CommentSupport(Comments comments) { this.comments = comments; } - public boolean isInComment(IDocument document, int offset) { + private boolean isInComment(IDocument document, int offset) { try { if (isInBlockComment(document.get(0, offset))) { return true; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java index ff8490c89..4559412a5 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.supports; -public class Comments { +public final class Comments { private final String lineComment; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java index aea6c899c..6755d6dd9 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java @@ -14,7 +14,7 @@ /** * Describes what to do when pressing Enter. */ -public class EnterAction { +public final class EnterAction { public enum IndentAction { /** @@ -67,7 +67,7 @@ public IndentAction getIndentAction() { /** * @return the outdentCurrentLine */ - public Boolean getOutdentCurrentLine() { + private Boolean getOutdentCurrentLine() { return outdentCurrentLine; } @@ -76,7 +76,7 @@ public Boolean getOutdentCurrentLine() { * the outdentCurrentLine to set * @return */ - public EnterAction setOutdentCurrentLine(Boolean outdentCurrentLine) { + private EnterAction setOutdentCurrentLine(Boolean outdentCurrentLine) { this.outdentCurrentLine = outdentCurrentLine; return this; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java index b97d24f85..beaf26c7d 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.supports; -public class EnterActionAndIndent { +public final class EnterActionAndIndent { private final EnterAction enterAction; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java index 3c2b8818a..ab6813371 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.supports; -public class Folding { +public final class Folding { private final Boolean offSide; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java index b50545b77..431210e72 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/IndentationRule.java @@ -11,6 +11,9 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.supports; -public class IndentationRule { +/** + * TODO unused class + */ +final class IndentationRule { } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java index 89666271b..8a8754fc3 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java @@ -18,7 +18,7 @@ /** * Describes a rule to be evaluated when pressing Enter. */ -public class OnEnterRule { +public final class OnEnterRule { /** * This rule will only execute if the text before the cursor matches this diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java index 467f9cf74..69c0f92c4 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java @@ -74,23 +74,23 @@ public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, Stri return null; } - private static class ProcessedBracketPair { + private static final class ProcessedBracketPair { private static final Pattern B_REGEXP = Pattern.compile("\\B"); //$NON-NLS-1$ private final Pattern openRegExp; private final Pattern closeRegExp; - public ProcessedBracketPair(String open, String close) { + private ProcessedBracketPair(String open, String close) { openRegExp = createOpenBracketRegExp(open); closeRegExp = createCloseBracketRegExp(close); } - public boolean matchOpen(String beforeEnterText) { + private boolean matchOpen(String beforeEnterText) { return openRegExp != null && openRegExp.matcher(beforeEnterText).find(); } - public boolean matchClose(String afterEnterText) { + private boolean matchClose(String afterEnterText) { return closeRegExp != null && closeRegExp.matcher(afterEnterText).find(); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java index 22da0ccd5..284ff8fac 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java @@ -17,7 +17,7 @@ * Regex utilities. * */ -public class RegExpUtils { +public final class RegExpUtils { /** * Escapes regular expression characters in a given string diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java index f89cad864..d0df375f0 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java @@ -11,20 +11,20 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.utils; -public class TabSpacesInfo { +public final class TabSpacesInfo { private final int tabSize; private final boolean insertSpaces; - public TabSpacesInfo(int tabSize, boolean insertSpaces) { + TabSpacesInfo(int tabSize, boolean insertSpaces) { this.tabSize = tabSize; this.insertSpaces = insertSpaces; } - + public int getTabSize() { return tabSize; } - + public boolean isInsertSpaces() { return insertSpaces; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java index 03efeaacf..380de6508 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java @@ -23,7 +23,7 @@ import org.eclipse.jface.text.TextViewer; import org.eclipse.tm4e.ui.utils.ClassHelper; -public class TextUtils { +public final class TextUtils { /** * Returns true if text of the command is an enter and false otherwise. @@ -94,7 +94,7 @@ public static int startIndexOfOffsetTouchingString(String text, int offset, Stri * Returns first index of the string that is not whitespace. If string is empty * or contains only whitespaces, returns -1 */ - public static int firstNonWhitespaceIndex(String str) { + private static int firstNonWhitespaceIndex(String str) { for (int i = 0, len = str.length(); i < len; i++) { char c = str.charAt(i); if (c != ' ' && c != '\t') { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java index 43335bc76..4f723d651 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java @@ -21,9 +21,9 @@ import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional; -public class AutoClosingPairConditionalTableWidget extends CharacterPairsTableWidget { +final class AutoClosingPairConditionalTableWidget extends CharacterPairsTableWidget { - public AutoClosingPairConditionalTableWidget(Table table) { + AutoClosingPairConditionalTableWidget(Table table) { super(table); setLabelProvider(new AutoClosingPairConditionalLabelProvider()); @@ -40,7 +40,7 @@ public AutoClosingPairConditionalTableWidget(Table table) { gc.dispose(); } - protected class AutoClosingPairConditionalLabelProvider extends CharacterPairLabelProvider { + private static final class AutoClosingPairConditionalLabelProvider extends CharacterPairLabelProvider { @Override public String getColumnText(Object element, int columnIndex) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java index ffae47cd4..81504513b 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java @@ -30,9 +30,9 @@ import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; -public class CharacterPairsTableWidget extends TableViewer { +class CharacterPairsTableWidget extends TableViewer { - public CharacterPairsTableWidget(Table table) { + CharacterPairsTableWidget(Table table) { super(table); setContentProvider(new CharacterPairContentProvider()); setLabelProvider(new CharacterPairLabelProvider()); @@ -58,7 +58,7 @@ protected int computeMinimumColumnWidth(GC gc, String string) { return gc.stringExtent(string).x + 10; } - protected static class CharacterPairContentProvider implements IStructuredContentProvider { + private static final class CharacterPairContentProvider implements IStructuredContentProvider { private List characterPairList; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java index f063baf69..76270d462 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java @@ -21,7 +21,7 @@ * Sort the selected column and refresh the viewer. * */ -public class ColumnSelectionAdapter extends SelectionAdapter { +public final class ColumnSelectionAdapter extends SelectionAdapter { private final TableColumn fTableColumn; private final TableViewer tableViewer; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java index f9833d9fd..b7a25c4b3 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java @@ -22,7 +22,7 @@ * Viewer compoarator which sort a given column. * */ -public class ColumnViewerComparator extends ViewerComparator { +public final class ColumnViewerComparator extends ViewerComparator { private int fSortColumn; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java index 2f893d13a..6c7c80120 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java @@ -44,12 +44,12 @@ public LanguageConfigurationInfoWidget(Composite parent, int style) { createUI(this); } - protected TabItem commentsTab; + private TabItem commentsTab; private Text lineCommentText; private Text blockCommentStartText; private Text blockCommentEndText; - protected TabItem bracketsTab; + private TabItem bracketsTab; private CharacterPairsTableWidget bracketsTable; protected TabItem autoClosingPairsTab; @@ -58,12 +58,12 @@ public LanguageConfigurationInfoWidget(Composite parent, int style) { protected TabItem surroundingPairsTab; private CharacterPairsTableWidget surroundingPairsTable; - protected TabItem foldingTab; + private TabItem foldingTab; private Text offsideText; private Text markersStartText; private Text markersEndText; - protected TabItem wordPatternTab; + private TabItem wordPatternTab; private Text wordPatternText; protected TabItem onEnterRulesTab; @@ -137,7 +137,7 @@ private List removeNullElements(List list) { return list.stream().filter(el -> el != null).collect(Collectors.toList()); } - protected void createCommentsTab(TabFolder folder) { + private void createCommentsTab(TabFolder folder) { commentsTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_comments); Composite parent = (Composite) commentsTab.getControl(); @@ -149,7 +149,7 @@ protected void createCommentsTab(TabFolder folder) { LanguageConfigurationMessages.LanguageConfigurationInfoWidget_blockCommentsEnd); } - protected void createBracketsTab(TabFolder folder) { + private void createBracketsTab(TabFolder folder) { bracketsTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_brackets); bracketsTable = new CharacterPairsTableWidget(createTable((Composite) bracketsTab.getControl())); } @@ -168,7 +168,7 @@ protected void createSurroundingPairsTab(TabFolder folder) { createTable((Composite) surroundingPairsTab.getControl())); } - protected void createFoldingTab(TabFolder folder) { + private void createFoldingTab(TabFolder folder) { foldingTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_folding_title); Composite parent = (Composite) foldingTab.getControl(); @@ -179,7 +179,7 @@ protected void createFoldingTab(TabFolder folder) { markersEndText = createText(parent, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_end); } - protected void createWordPatternTab(TabFolder folder) { + private void createWordPatternTab(TabFolder folder) { wordPatternTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_wordPattern_title); Composite parent = (Composite) wordPatternTab.getControl(); @@ -216,7 +216,7 @@ private TabItem createTab(TabFolder folder, String title) { return tab; } - protected Text createText(Composite parent, String s) { + private Text createText(Composite parent, String s) { Label label = new Label(parent, SWT.NONE); label.setText(s); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java index 5ed2cbff9..4162558e4 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java @@ -21,7 +21,7 @@ import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; -public class LanguageConfigurationPreferencesWidget extends LanguageConfigurationInfoWidget { +public final class LanguageConfigurationPreferencesWidget extends LanguageConfigurationInfoWidget { private Button toggleOnEnterButton; private Button toggleBracketAutoClosingButton; @@ -70,11 +70,11 @@ protected void createOnEnterRulesTab(TabFolder folder) { })); } - public boolean getToggleOnEnter() { + private boolean getToggleOnEnter() { return toggleOnEnterButton.getSelection(); } - public void setToggleOnEnter(Boolean selection) { + private void setToggleOnEnter(Boolean selection) { toggleOnEnterButton.setSelection(selection); } @@ -93,11 +93,11 @@ protected void createAutoClosingPairsTab(TabFolder folder) { })); } - public boolean getBracketAutoClosing() { + private boolean getBracketAutoClosing() { return toggleBracketAutoClosingButton.getSelection(); } - public void setBracketAutoClosing(Boolean selection) { + private void setBracketAutoClosing(Boolean selection) { toggleBracketAutoClosingButton.setSelection(selection); } @@ -116,11 +116,11 @@ protected void createSurroundingPairsTab(TabFolder folder) { })); } - public boolean getMatchingPairs() { + private boolean getMatchingPairs() { return toggleMatchingPairsButton.getSelection(); } - public void setMatchingPairs(Boolean selection) { + private void setMatchingPairs(Boolean selection) { toggleMatchingPairsButton.setSelection(selection); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java index a8883cbe2..a03d8252e 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java @@ -31,9 +31,9 @@ import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction; import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterRule; -public class OnEnterRuleTableWidget extends TableViewer { +final class OnEnterRuleTableWidget extends TableViewer { - public OnEnterRuleTableWidget(Table table) { + OnEnterRuleTableWidget(Table table) { super(table); setContentProvider(new OnEnterRuleContentProvider()); setLabelProvider(new OnEnterRuleLabelProvider()); @@ -70,11 +70,11 @@ public OnEnterRuleTableWidget(Table table) { gc.dispose(); } - protected int computeMinimumColumnWidth(GC gc, String string) { + private int computeMinimumColumnWidth(GC gc, String string) { return gc.stringExtent(string).x + 10; } - protected static class OnEnterRuleContentProvider implements IStructuredContentProvider { + private static final class OnEnterRuleContentProvider implements IStructuredContentProvider { private List onEnterRulesList; @@ -99,7 +99,7 @@ public void dispose() { } } - protected static class OnEnterRuleLabelProvider extends LabelProvider implements ITableLabelProvider { + private static final class OnEnterRuleLabelProvider extends LabelProvider implements ITableLabelProvider { @Override public Image getColumnImage(Object element, int columnIndex) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java index ca757e9aa..f66547ca8 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java @@ -24,7 +24,7 @@ * Wizard to import language configurations * */ -public class LanguageConfigurationImportWizard extends Wizard implements IImportWizard { +public final class LanguageConfigurationImportWizard extends Wizard implements IImportWizard { private SelectLanguageConfigurationWizardPage mainPage; @@ -34,7 +34,7 @@ public class LanguageConfigurationImportWizard extends Wizard implements IImport private final boolean save; - public LanguageConfigurationImportWizard() { + LanguageConfigurationImportWizard() { this(true); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java index d53e66b13..a7ae5b7fc 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java @@ -55,10 +55,10 @@ import org.eclipse.tm4e.ui.utils.ContentTypeHelper; import org.eclipse.ui.dialogs.ResourceSelectionDialog; -public class SelectLanguageConfigurationWizardPage extends WizardPage implements Listener { +final class SelectLanguageConfigurationWizardPage extends WizardPage implements Listener { private static final String PAGE_NAME = SelectLanguageConfigurationWizardPage.class.getName(); - protected static final String[] TEXTMATE_EXTENSIONS = { "*language-configuration.json" }; //$NON-NLS-1$ + private static final String[] TEXTMATE_EXTENSIONS = { "*language-configuration.json" }; //$NON-NLS-1$ private Button browseFileSystemButton; private Button browseWorkspaceButton; @@ -66,13 +66,9 @@ public class SelectLanguageConfigurationWizardPage extends WizardPage implements private Text contentTypeText; private LanguageConfigurationInfoWidget infoWidget; - private ILanguageConfigurationRegistryManager registryManager; + private final ILanguageConfigurationRegistryManager registryManager; - protected SelectLanguageConfigurationWizardPage(String pageName) { - super(pageName); - } - - public SelectLanguageConfigurationWizardPage(ILanguageConfigurationRegistryManager registryManager) { + SelectLanguageConfigurationWizardPage(ILanguageConfigurationRegistryManager registryManager) { super(PAGE_NAME); this.registryManager = registryManager; super.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_title); @@ -102,7 +98,7 @@ private void validateAndUpdateStatus(Event event) { statusChanged(status == null ? Status.OK_STATUS : status); } - public void statusChanged(IStatus status) { + private void statusChanged(IStatus status) { setPageComplete(!status.matches(IStatus.ERROR)); applyToStatusLine(this, status); } @@ -132,7 +128,7 @@ private static void applyToStatusLine(DialogPage page, IStatus status) { } } - protected void createBody(Composite ancestor) { + private void createBody(Composite ancestor) { Composite parent = new Composite(ancestor, SWT.NONE); parent.setFont(parent.getFont()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -208,7 +204,7 @@ private void createContentTypeTreeViewer(Composite composite) { .setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString())); } - private static class ContentTypesLabelProvider extends LabelProvider { + private static final class ContentTypesLabelProvider extends LabelProvider { @Override public String getText(Object element) { IContentType contentType = (IContentType) element; @@ -216,7 +212,7 @@ public String getText(Object element) { } } - private static class ContentTypesContentProvider implements ITreeContentProvider { + private static final class ContentTypesContentProvider implements ITreeContentProvider { private IContentTypeManager manager = Platform.getContentTypeManager(); @@ -265,7 +261,7 @@ private Text createText(Composite parent, String s) { return text; } - protected IStatus validatePage(Event event) { + private IStatus validatePage(Event event) { infoWidget.refresh(null); String path = fileText.getText(); if (path.length() == 0) { @@ -304,7 +300,7 @@ protected IStatus validatePage(Event event) { return null; } - public ILanguageConfigurationDefinition getDefinition() { + ILanguageConfigurationDefinition getDefinition() { IPath p = new Path(fileText.getText()); if (!p.isAbsolute()) { p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation(); diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java index 2ba622f50..5ffb87f0e 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java @@ -31,14 +31,14 @@ */ public abstract class AbstractGrammarRegistryManager extends Registry implements IGrammarRegistryManager { - protected final GrammarCache pluginCache; + private final GrammarCache pluginCache; protected final GrammarCache userCache; - private static class EclipseRegistryOptions implements IRegistryOptions { + private static final class EclipseRegistryOptions implements IRegistryOptions { private AbstractGrammarRegistryManager registry; - public void setRegistry(AbstractGrammarRegistryManager registry) { + private void setRegistry(AbstractGrammarRegistryManager registry) { this.registry = registry; } @@ -60,12 +60,12 @@ public InputStream getInputStream(String scopeName) throws IOException { } } - public AbstractGrammarRegistryManager() { + protected AbstractGrammarRegistryManager() { this(new EclipseRegistryOptions()); ((EclipseRegistryOptions) getLocator()).setRegistry(this); } - public AbstractGrammarRegistryManager(IRegistryOptions locator) { + protected AbstractGrammarRegistryManager(IRegistryOptions locator) { super(locator); this.pluginCache = new GrammarCache(); this.userCache = new GrammarCache(); @@ -140,7 +140,7 @@ public IGrammarDefinition[] getDefinitions() { * @return the loaded grammar from the given scopeName and null * otherwise. */ - public IGrammar getGrammar(String scopeName) { + private IGrammar getGrammar(String scopeName) { if (scopeName == null) { return null; } @@ -159,7 +159,7 @@ public IGrammar getGrammar(String scopeName) { * @return the grammar definition from the given scopeName and * null otherwise. */ - public IGrammarDefinition getDefinition(String scopeName) { + private IGrammarDefinition getDefinition(String scopeName) { IGrammarDefinition definition = userCache.getDefinition(scopeName); if (definition != null) { return definition; @@ -187,7 +187,7 @@ public Collection getInjections(String scopeName) { * @param scopeName * @param injectTo */ - public void registerInjection(String scopeName, String injectTo) { + protected void registerInjection(String scopeName, String injectTo) { pluginCache.registerInjection(scopeName, injectTo); } @@ -196,7 +196,7 @@ public void registerInjection(String scopeName, String injectTo) { * @return scope name bound with the given content type (or its base type) and * null otherwise. */ - public String getScopeNameForContentType(IContentType contentType) { + private String getScopeNameForContentType(IContentType contentType) { while (contentType != null) { String scopeName = pluginCache.getScopeNameForContentType(contentType); if (scopeName != null) { @@ -212,7 +212,7 @@ public List getContentTypesForScope(String scopeName) { return pluginCache.getContentTypesForScope(scopeName); } - public void registerContentTypeBinding(IContentType contentType, String scopeName) { + protected void registerContentTypeBinding(IContentType contentType, String scopeName) { pluginCache.registerContentTypeBinding(contentType, scopeName); } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java index db4a17286..76f64dc08 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java @@ -26,13 +26,13 @@ * Grammar cache. * */ -public class GrammarCache { +final class GrammarCache { private final Map definitions; private final Map> injections; private final Map scopeNameBindings; - public GrammarCache() { + GrammarCache() { this.definitions = new HashMap<>(); this.injections = new HashMap<>(); this.scopeNameBindings = new HashMap<>(); @@ -40,59 +40,59 @@ public GrammarCache() { /** * Register a grammar definition. - * + * * @param definition * the grammar definition to register. */ - public void registerGrammarDefinition(IGrammarDefinition definition) { + void registerGrammarDefinition(IGrammarDefinition definition) { definitions.put(definition.getScopeName(), definition); } - public void unregisterGrammarDefinition(IGrammarDefinition definition) { + void unregisterGrammarDefinition(IGrammarDefinition definition) { definitions.remove(definition.getScopeName()); } /** * Returns the whole registered grammar definition. - * + * * @return */ - public Collection getDefinitions() { + Collection getDefinitions() { return this.definitions.values(); } /** * Returns the grammar definition from the given scopeName and * null otherwise. - * + * * @param scopeName * @return the grammar definition from the given scopeName and * null otherwise. */ - public IGrammarDefinition getDefinition(String scopeName) { + IGrammarDefinition getDefinition(String scopeName) { return definitions.get(scopeName); } /** * Returns list of scope names to inject for the given * scopeName and null otheriwse. - * + * * @param scopeName * @return list of scope names to inject for the given * scopeName and null otheriwse. */ - public Collection getInjections(String scopeName) { + Collection getInjections(String scopeName) { return injections.get(scopeName); } /** * Register the given scopeName to inject to the given scope * name injectTo. - * + * * @param scopeName * @param injectTo */ - public void registerInjection(String scopeName, String injectTo) { + void registerInjection(String scopeName, String injectTo) { Collection injections = getInjections(injectTo); if (injections == null) { injections = new ArrayList<>(); @@ -103,15 +103,15 @@ public void registerInjection(String scopeName, String injectTo) { /** * Returns scope name bound with the given content type and null otherwise. - * - * @param contentType + * + * @param contentType * @return scope name bound with the given content type and null otherwise. */ - public String getScopeNameForContentType(IContentType contentType) { + String getScopeNameForContentType(IContentType contentType) { return scopeNameBindings.get(contentType); } - public List getContentTypesForScope(String scopeName) { + List getContentTypesForScope(String scopeName) { if (scopeName == null) { return List.of(); } @@ -119,7 +119,7 @@ public List getContentTypesForScope(String scopeName) { .map(Entry::getKey).collect(Collectors.toList()); } - public void registerContentTypeBinding(IContentType contentType, String scopeName) { + void registerContentTypeBinding(IContentType contentType, String scopeName) { scopeNameBindings.put(contentType, scopeName); } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java index d5552aecf..b5f8f1ec4 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java @@ -27,7 +27,7 @@ /** * Grammar registry manager singleton. */ -public class GrammarRegistryManager extends AbstractGrammarRegistryManager { +public final class GrammarRegistryManager extends AbstractGrammarRegistryManager { private static final String EXTENSION_GRAMMARS = "grammars"; diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java index aa25832f8..508902973 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry.internal.preferences; @@ -15,7 +15,7 @@ * Preferences constants for grammar. * */ -public class PreferenceConstants { +public final class PreferenceConstants { public static final String GRAMMARS = "org.eclipse.tm4e.registry.grammars"; @@ -23,4 +23,6 @@ public class PreferenceConstants { public static final String INJECTIONS = "org.eclipse.tm4e.registry.injections"; + private PreferenceConstants() { + } } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java index 9b4a92456..a809f35fa 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java @@ -24,7 +24,7 @@ * Helper class load, save grammar preferences with Json format. * */ -public class PreferenceHelper { +public final class PreferenceHelper { private static final Gson DEFAULT_GSON; @@ -42,4 +42,6 @@ public static String toJson(Collection definitions) { return DEFAULT_GSON.toJson(definitions); } + private PreferenceHelper() { + } } diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java index 306193777..7c3fa97c1 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java @@ -19,7 +19,7 @@ public abstract class Command implements ICommand { private String styleRanges; private boolean done; - public Command(String name) { + protected Command(String name) { this.name = name; this.done = false; } @@ -48,7 +48,7 @@ public void execute() { protected abstract void doExecute(); protected abstract Integer getLineTo(); - + public static String toText(String text) { StringBuilder newText = new StringBuilder(); for (int i = 0; i < text.length(); i++) { diff --git a/org.eclipse.tm4e.ui/.classpath b/org.eclipse.tm4e.ui/.classpath index 1ee1e0930..097e3264d 100644 --- a/org.eclipse.tm4e.ui/.classpath +++ b/org.eclipse.tm4e.ui/.classpath @@ -1,13 +1,15 @@ + + + + - - - + diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java index c0df882a7..fcc903a4d 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java @@ -20,7 +20,7 @@ * {@link TMPresentationReconciler}. * */ -public class TMPropertyTester extends PropertyTester { +public final class TMPropertyTester extends PropertyTester { private static final String CAN_SUPPORT_TEXT_MATE = "canSupportTextMate"; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java index 2f1ec1fe7..be527f177 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java @@ -17,7 +17,7 @@ * Helper class to get NLSed messages. * */ -public class TMUIMessages extends NLS { +public final class TMUIMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.tm4e.ui.internal.TMUIMessages"; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java index 85b5ab8d1..48adb6981 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java @@ -37,7 +37,7 @@ * Contribute "Switch to theme" menu item with list of available themes. * */ -public class ThemeContribution extends CompoundContributionItem implements IWorkbenchContribution { +public final class ThemeContribution extends CompoundContributionItem implements IWorkbenchContribution { private IHandlerService handlerService; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java index f0f41d53f..66c5fd0cf 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java @@ -21,26 +21,26 @@ * Utilities class for {@link IDocument}. * */ -public class DocumentHelper { +final class DocumentHelper { - public static int getStartLine(DocumentEvent event) throws BadLocationException { + static int getStartLine(DocumentEvent event) throws BadLocationException { return event.getDocument().getLineOfOffset(event.getOffset()); } - public static int getEndLine(DocumentEvent event, boolean documentAboutToBeChanged) throws BadLocationException { + static int getEndLine(DocumentEvent event, boolean documentAboutToBeChanged) throws BadLocationException { int length = documentAboutToBeChanged ? event.getLength() : event.getText().length(); return event.getDocument().getLineOfOffset(event.getOffset() + length); } - public static boolean isRemove(DocumentEvent event) { + static boolean isRemove(DocumentEvent event) { return event.getText() == null || event.getText().isEmpty(); } - public static boolean isInsert(DocumentEvent event) { + static boolean isInsert(DocumentEvent event) { return event.getLength() == 0 && event.getText() != null; } - public static String getLineText(IDocument document, int line, boolean withLineDelimiter) + static String getLineText(IDocument document, int line, boolean withLineDelimiter) throws BadLocationException { int lo = document.getLineOffset(line); int ll = document.getLineLength(line); @@ -51,7 +51,7 @@ public static String getLineText(IDocument document, int line, boolean withLineD return document.get(lo, ll); } - public static IRegion getRegion(IDocument document, int fromLine, int toLine) throws BadLocationException { + private static IRegion getRegion(IDocument document, int fromLine, int toLine) throws BadLocationException { int startOffset = document.getLineOffset(fromLine); int endOffset = document.getLineOffset(toLine) + document.getLineLength(toLine); return new Region(startOffset, endOffset - startOffset); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java index 917650471..d3e20071e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java @@ -19,24 +19,24 @@ /** * Input stream which reads from a document */ -public class DocumentInputStream extends InputStream { - +public final class DocumentInputStream extends InputStream { + private final IDocument fDocument; private int fCurrPos; - + public DocumentInputStream(IDocument document) { fDocument= document; fCurrPos= 0; } - + public IDocument getDocument() { return fDocument; } - + /** * {@inheritDoc} */ - @Override + @Override public int read() throws IOException { try { if (fCurrPos < fDocument.getLength()) { @@ -46,5 +46,5 @@ public int read() throws IOException { } return -1; } - + } \ No newline at end of file diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java index 6fac24261..b1deaee74 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java @@ -28,12 +28,12 @@ * TextMate model lines. * */ -public class DocumentLineList extends AbstractLineList { +final class DocumentLineList extends AbstractLineList { private final IDocument document; private final InternalListener listener; - public DocumentLineList(IDocument document) { + DocumentLineList(IDocument document) { this.document = document; this.listener = new InternalListener(); document.addDocumentListener(listener); @@ -42,7 +42,7 @@ public DocumentLineList(IDocument document) { } } - private class InternalListener implements IDocumentListener { + private final class InternalListener implements IDocumentListener { @Override public void documentAboutToBeChanged(DocumentEvent event) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java index 7bcda2b1e..1b8e379aa 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java @@ -14,7 +14,7 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.tm4e.core.model.TMModel; -public class TMDocumentModel extends TMModel { +public final class TMDocumentModel extends TMModel { private final IDocument document; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java index 72e895eab..b2bc3ad66 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java @@ -22,7 +22,7 @@ * TextMate model manager which connect/disconnect a TextModel model * {@link ITMModel} with an Eclipse {@link IDocument}. */ -public class TMModelManager implements ITMModelManager { +public final class TMModelManager implements ITMModelManager { private static final ITMModelManager INSTANCE = new TMModelManager(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index e7706c853..197d598b4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -72,9 +72,9 @@ * provides controls for adding, removing and changing grammar as well as * enablement, default management. */ -public class GrammarPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { +public final class GrammarPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - public final static String PAGE_ID = "org.eclipse.tm4e.ui.preferences.GrammarPreferencePage"; + static final String PAGE_ID = "org.eclipse.tm4e.ui.preferences.GrammarPreferencePage"; // Managers private IGrammarRegistryManager grammarRegistryManager; @@ -108,7 +108,7 @@ public GrammarPreferencePage() { * * @return the grammar registry manager. */ - public IGrammarRegistryManager getGrammarRegistryManager() { + IGrammarRegistryManager getGrammarRegistryManager() { return grammarRegistryManager; } @@ -117,7 +117,7 @@ public IGrammarRegistryManager getGrammarRegistryManager() { * * @param grammarRegistryManager */ - public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { + void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { this.grammarRegistryManager = grammarRegistryManager; } @@ -126,7 +126,7 @@ public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryMan * * @return the theme manager. */ - public IThemeManager getThemeManager() { + IThemeManager getThemeManager() { return themeManager; } @@ -135,15 +135,15 @@ public IThemeManager getThemeManager() { * * @param themeManager */ - public void setThemeManager(IThemeManager themeManager) { + void setThemeManager(IThemeManager themeManager) { this.themeManager = themeManager; } - public ISnippetManager getSnippetManager() { + ISnippetManager getSnippetManager() { return snippetManager; } - public void setSnippetManager(ISnippetManager snippetManager) { + void setSnippetManager(ISnippetManager snippetManager) { this.snippetManager = snippetManager; } @@ -542,7 +542,7 @@ private TMViewer doCreateViewer(Composite parent) { * the parent control * @return a configured source viewer */ - protected TMViewer createViewer(Composite parent) { + private TMViewer createViewer(Composite parent) { return new TMViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java index 1a3a282cd..656cf9129 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceConstants.java @@ -15,7 +15,7 @@ * Preferences constants for theme. * */ -public class PreferenceConstants { +public final class PreferenceConstants { public static final String THEMES = "org.eclipse.tm4e.ui.themes"; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java index 769363846..a0249815f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java @@ -24,7 +24,7 @@ * Helper class load, save theme preferences with Json format. * */ -public class PreferenceHelper { +public final class PreferenceHelper { private static final Gson DEFAULT_GSON; @@ -35,7 +35,7 @@ public class PreferenceHelper { public static IThemeAssociation[] loadThemeAssociations(String json) { return DEFAULT_GSON.fromJson(json, ThemeAssociation[].class); } - + public static String toJsonThemeAssociations(Collection themeAssociations) { return DEFAULT_GSON.toJson(themeAssociations); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java index c7024da96..e2d33d350 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java @@ -27,7 +27,7 @@ * TextMate Global preferences page. * */ -public class TextMatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { +public final class TextMatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { public TextMatePreferencePage() { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index 7d986529b..84b3f6e49 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -64,9 +64,9 @@ * provides controls for adding, removing and changing theme as well as * enablement, default management. */ -public class ThemePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { +public final class ThemePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - public final static String PAGE_ID = "org.eclipse.tm4e.ui.preferences.ThemePreferencePage"; + static final String PAGE_ID = "org.eclipse.tm4e.ui.preferences.ThemePreferencePage"; // Theme content private TableViewer themeViewer; @@ -373,7 +373,7 @@ private TMViewer doCreateViewer(Composite parent) { * the parent control * @return a configured source viewer */ - protected TMViewer createViewer(Composite parent) { + private TMViewer createViewer(Composite parent) { return new TMViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java index a1efa6e19..10f92cb1e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java @@ -16,7 +16,7 @@ import org.eclipse.tm4e.registry.XMLConstants; import org.eclipse.tm4e.ui.snippets.ISnippet; -public class Snippet extends TMResource implements ISnippet { +final class Snippet extends TMResource implements ISnippet { private String scopeName; private String name; @@ -24,7 +24,7 @@ public class Snippet extends TMResource implements ISnippet { /** * Constructor for user preferences (loaded from Json with Gson). */ - public Snippet() { + Snippet() { } /** @@ -32,13 +32,13 @@ public Snippet() { * * @param scopeName */ - public Snippet(String scopeName, String path, String name) { + Snippet(String scopeName, String path, String name) { super(path); this.scopeName = scopeName; this.name = name; } - public Snippet(IConfigurationElement ce) { + Snippet(IConfigurationElement ce) { super(ce); this.scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); this.name = ce.getAttribute(XMLConstants.NAME_ATTR); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java index 7877b3b41..a76c7cff6 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java @@ -22,7 +22,7 @@ import org.eclipse.tm4e.ui.snippets.ISnippet; import org.eclipse.tm4e.ui.snippets.ISnippetManager; -public class SnippetManager implements ISnippetManager { +public final class SnippetManager implements ISnippetManager { private static final ISnippet[] EMPTY_SNIPPETS = {}; @@ -52,7 +52,7 @@ private static synchronized ISnippetManager createInstance() { private final Map> snippets; - public SnippetManager() { + SnippetManager() { this.snippets = new HashMap<>(); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java index ad44fdb38..5747ce119 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java @@ -20,7 +20,7 @@ import org.eclipse.jface.text.TextPresentation; import org.eclipse.tm4e.ui.text.ITMPresentationReconcilerListener; -public class TMPresentationReconcilerTestGenerator +public final class TMPresentationReconcilerTestGenerator implements ITMPresentationReconcilerListener, IDocumentListener, ITextListener { private ITextViewer viewer; @@ -30,12 +30,12 @@ public class TMPresentationReconcilerTestGenerator /*private List commands; - private class Command { + private static final class Command { final String command; StyleRange[] ranges; Throwable error; - public Command(String command) { + Command(String command) { this.command = command; } }*/ @@ -93,7 +93,7 @@ public void install(ITextViewer viewer, IDocument document) { } - public String toText(String text) { + private String toText(String text) { StringBuilder newText = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); @@ -120,7 +120,7 @@ public void uninstall() { // for (Command command : commands) { // write(toString(command.ranges)); // } -// +// write("", true); write("\t\twhile (!shell.isDisposed()) {", true); write("\t\t}", true); @@ -151,7 +151,7 @@ public void uninstall() { document.removeDocumentListener(this); viewer.removeTextListener(this); //commands.clear(); - + } @Override diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index 60ac2e1bb..056bcd02b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -35,7 +35,7 @@ public abstract class AbstractThemeManager implements IThemeManager { private final Map themes; private final ThemeAssociationRegistry themeAssociationRegistry; - public AbstractThemeManager() { + protected AbstractThemeManager() { this.themes = new LinkedHashMap<>(); this.themeAssociationRegistry = new ThemeAssociationRegistry(); } @@ -67,7 +67,7 @@ public ITheme getDefaultTheme() { return getDefaultTheme(dark); } - public ITheme getDefaultTheme(boolean dark) { + ITheme getDefaultTheme(boolean dark) { for (ITheme theme : this.themes.values()) { if (theme.isDark() == dark && theme.isDefault()) { return theme; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java index bd985bd88..369824764 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java @@ -23,19 +23,20 @@ /** * Base Theme association registry. * + * TODO unused code */ -public class BaseThemeAssociationRegistry { +final class BaseThemeAssociationRegistry { private IThemeAssociation defaultAssociation; private final Map> eclipseThemeIds; private final List allAssociations; - public BaseThemeAssociationRegistry() { + BaseThemeAssociationRegistry() { eclipseThemeIds = new HashMap<>(); this.allAssociations = new ArrayList<>(); } - public void register(IThemeAssociation association) { + void register(IThemeAssociation association) { //String eclipseThemeId = association.getEclipseThemeId(); // when association is marked as default or scope name is defined, // update the default association or association for a given E4 Theme. @@ -51,7 +52,7 @@ public void register(IThemeAssociation association) { allAssociations.clear(); } - public void unregister(IThemeAssociation association) { + void unregister(IThemeAssociation association) { //String eclipseThemeId = association.getEclipseThemeId(); /*if (association.isDefault()) { if (eclipseThemeId == null) { @@ -70,7 +71,7 @@ public void unregister(IThemeAssociation association) { allAssociations.clear(); } - public IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { + IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { List associations = eclipseThemeIds.get(eclipseThemeId); if (associations != null) { if (associations.size() == 1) { @@ -85,7 +86,7 @@ public IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { return null; } - public IThemeAssociation[] getThemeAssociations(boolean isDefault) { + IThemeAssociation[] getThemeAssociations(boolean isDefault) { /*if (isDefault) { return getThemeAssociations().stream().filter(theme -> theme.isDefault()).collect(Collectors.toList()) .toArray(new IThemeAssociation[0]); @@ -93,16 +94,16 @@ public IThemeAssociation[] getThemeAssociations(boolean isDefault) { return getThemeAssociations().toArray(new IThemeAssociation[allAssociations.size()]); } - public IThemeAssociation getDefaultAssociation() { + IThemeAssociation getDefaultAssociation() { return defaultAssociation; } - public IThemeAssociation[] getThemeAssociationsForTheme(String themeId) { + IThemeAssociation[] getThemeAssociationsForTheme(String themeId) { return getThemeAssociations().stream().filter(themeAssociation -> themeId.equals(themeAssociation.getThemeId())) .collect(Collectors.toList()).toArray(new IThemeAssociation[0]); } - public boolean hasThemeAssociationsForTheme(String themeId, String eclipseThemeId) { + boolean hasThemeAssociationsForTheme(String themeId, String eclipseThemeId) { // Collection associations = eclipseThemeIds.get(eclipseThemeId); // if (associations != null) { // for (IThemeAssociation themeAssociation : associations) { @@ -124,7 +125,7 @@ public boolean hasThemeAssociationsForTheme(String themeId, String eclipseThemeI return true; } - public List getThemeAssociations() { + List getThemeAssociations() { if (allAssociations.isEmpty()) { if (defaultAssociation != null) { allAssociations.add(defaultAssociation); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java index 98171eb37..0cc94727f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java @@ -23,38 +23,38 @@ * Theme association registry. * */ -public class ThemeAssociationRegistry { +final class ThemeAssociationRegistry { private final Map scopes; - private static class EclipseThemeAssociation { + private static final class EclipseThemeAssociation { private IThemeAssociation light; private IThemeAssociation dark; - public IThemeAssociation getLight() { + IThemeAssociation getLight() { return light; } - public void setLight(IThemeAssociation light) { + void setLight(IThemeAssociation light) { this.light = light; } - public IThemeAssociation getDark() { + IThemeAssociation getDark() { return dark; } - public void setDark(IThemeAssociation dark) { + void setDark(IThemeAssociation dark) { this.dark = dark; } } - public ThemeAssociationRegistry() { + ThemeAssociationRegistry() { scopes = new HashMap<>(); } - public IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) { + IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) { // From theme assiocations IThemeAssociation userAssociation = null; EclipseThemeAssociation registry = scopes.get(scopeName); @@ -67,7 +67,7 @@ public IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) return null; } - public void register(IThemeAssociation association) { + void register(IThemeAssociation association) { String scopeName = association.getScopeName(); EclipseThemeAssociation registry = scopes.get(scopeName); if (registry == null) { @@ -82,7 +82,7 @@ public void register(IThemeAssociation association) { } } - public void unregister(IThemeAssociation association) { + void unregister(IThemeAssociation association) { String scopeName = association.getScopeName(); EclipseThemeAssociation registry = scopes.get(scopeName); if (registry != null) { @@ -95,7 +95,7 @@ public void unregister(IThemeAssociation association) { } } - // public IThemeAssociation getThemeAssociationFor(String scopeName, String + // IThemeAssociation getThemeAssociationFor(String scopeName, String // eclipseThemeId) { // IThemeAssociation association = null; // BaseThemeAssociationRegistry registry = scopes.get(scopeName); @@ -111,7 +111,7 @@ public void unregister(IThemeAssociation association) { // return association != null ? association : getDefaultAssociation(); // } - // public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { + // IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { // BaseThemeAssociationRegistry registry = scopes.get(scopeName); // if (registry != null) { // // Get the user associations (from preferences) @@ -150,7 +150,7 @@ public void unregister(IThemeAssociation association) { // } // // @Override - public List getThemeAssociations() { + List getThemeAssociations() { List associations = new ArrayList<>(); Collection eclipseAssociations = scopes.values(); for (EclipseThemeAssociation eclipseAssociation : eclipseAssociations) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java index 70e213890..f1091b2ce 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java @@ -35,7 +35,7 @@ /** * Theme manager singleton. */ -public class ThemeManager extends AbstractThemeManager { +public final class ThemeManager extends AbstractThemeManager { // "themes" extension point private static final String EXTENSION_THEMES = "themes"; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java index cb1561705..d2f99afc7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java @@ -23,7 +23,7 @@ * Working copy of theme manager. * */ -public class WorkingCopyThemeManager extends AbstractThemeManager { +public final class WorkingCopyThemeManager extends AbstractThemeManager { private final IThemeManager manager; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java index 2bd8ccd90..a52a02611 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java @@ -21,7 +21,7 @@ * Sort the selected column and refresh the viewer. * */ -public class ColumnSelectionAdapter extends SelectionAdapter { +public final class ColumnSelectionAdapter extends SelectionAdapter { private final TableColumn fTableColumn; private final TableViewer tableViewer; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java index 496b5858b..6a3bfee45 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java @@ -22,7 +22,7 @@ * Viewer compoarator which sort a given column. * */ -public class ColumnViewerComparator extends ViewerComparator { +public final class ColumnViewerComparator extends ViewerComparator { private int fSortColumn; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java index 2192a04e7..1a524d58f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java @@ -20,7 +20,7 @@ /** * Label provider for {@link IContentType}. */ -public class ContentTypeLabelProvider extends LabelProvider implements ITableLabelProvider { +public final class ContentTypeLabelProvider extends LabelProvider implements ITableLabelProvider { @Override public Image getColumnImage(Object element, int columnIndex) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java index 98ffbc9a9..626908a13 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java @@ -20,7 +20,7 @@ * buttons on the right. * */ -public class ContentTypesBindingWidget extends TableAndButtonsWidget { +public final class ContentTypesBindingWidget extends TableAndButtonsWidget { public ContentTypesBindingWidget(Composite parent, int style) { super(parent, style, TMUIMessages.ContentTypesBindingWidget_description); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java index 0580b891b..823427f00 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java @@ -19,7 +19,7 @@ * A content provider for the template grammar page's table viewer. * */ -public class GrammarDefinitionContentProvider implements IStructuredContentProvider { +public final class GrammarDefinitionContentProvider implements IStructuredContentProvider { private IGrammarRegistryManager registry; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java index 1df3925b5..931739324 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java @@ -19,7 +19,7 @@ /** * Label provider for grammar definition. */ -public class GrammarDefinitionLabelProvider extends LabelProvider implements ITableLabelProvider { +public final class GrammarDefinitionLabelProvider extends LabelProvider implements ITableLabelProvider { @Override public Image getColumnImage(Object element, int columnIndex) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java index 1e8df69db..3c90bcf84 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java @@ -28,7 +28,7 @@ * * Widget which display grammar information like name, scope, and file types. */ -public class GrammarInfoWidget extends Composite { +public final class GrammarInfoWidget extends Composite { private Text nameText; private Text scopeNameText; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java index 3df567c47..fc92b095a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java @@ -29,7 +29,7 @@ * Simple TextMate Viewer. * */ -public class TMViewer extends SourceViewer { +public final class TMViewer extends SourceViewer { private TMPresentationReconciler reconciler; @@ -50,7 +50,7 @@ private void init() { this.configure(configuration); } - private class TMSourceViewerConfiguration extends SourceViewerConfiguration { + private final class TMSourceViewerConfiguration extends SourceViewerConfiguration { @Override public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java index 83883d6d7..e0ef6899b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java @@ -30,8 +30,8 @@ public abstract class TableAndButtonsWidget extends Composite { private TableViewer viewer; - - public TableAndButtonsWidget(Composite parent, int style, String title) { + + protected TableAndButtonsWidget(Composite parent, int style, String title) { super(parent, style); GridLayout layout = new GridLayout(); layout.marginHeight = 0; @@ -51,7 +51,7 @@ private void createUI(String title, Composite ancestor) { layout.marginRight = 0; parent.setLayout(layout); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + // Title createTitle(title, parent); @@ -90,7 +90,7 @@ private void createTable(Composite parent) { viewer = new TableViewer(table); table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + } public void setInput(Object input) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java index 83a0a92d6..057456c20 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java @@ -24,7 +24,7 @@ /** * Label provider for TextMate theme association. */ -public class ThemeAssociationLabelProvider extends LabelProvider implements ITableLabelProvider { +public final class ThemeAssociationLabelProvider extends LabelProvider implements ITableLabelProvider { @Override public Image getColumnImage(Object element, int columnIndex) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java index 17456a469..a887a8466 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java @@ -34,7 +34,7 @@ * buttons on the right. * */ -public class ThemeAssociationsWidget extends TableAndButtonsWidget { +public final class ThemeAssociationsWidget extends TableAndButtonsWidget { private final IThemeManager themeManager; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java index b58f9074f..7c70c4595 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java @@ -19,7 +19,7 @@ * A content provider for the template theme page's table viewer. * */ -public class ThemeContentProvider implements IStructuredContentProvider { +public final class ThemeContentProvider implements IStructuredContentProvider { private IThemeManager registry; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java index 01dec2bc8..6a9b38504 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java @@ -19,7 +19,7 @@ /** * Label provider for TextMate theme. */ -public class ThemeLabelProvider extends LabelProvider implements ITableLabelProvider { +public final class ThemeLabelProvider extends LabelProvider implements ITableLabelProvider { @Override public Image getColumnImage(Object element, int columnIndex) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java index 3e2d806d2..e3a63159f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java @@ -29,7 +29,7 @@ * Abstract class for wizard page. * */ -public abstract class AbstractWizardPage extends WizardPage implements Listener { +abstract class AbstractWizardPage extends WizardPage implements Listener { protected AbstractWizardPage(String pageName) { super(pageName); @@ -67,7 +67,7 @@ private void validateAndUpdateStatus(Event event) { statusChanged(status == null ? Status.OK_STATUS : status); } - public void statusChanged(IStatus status) { + void statusChanged(IStatus status) { setPageComplete(!status.matches(IStatus.ERROR)); applyToStatusLine(this, status); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java index f5aaa9379..d1536ec86 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java @@ -20,9 +20,9 @@ /** * Wizard to create association between grammar and theme. - * + * */ -public class CreateThemeAssociationWizard extends Wizard { +public final class CreateThemeAssociationWizard extends Wizard { private CreateThemeAssociationWizardPage mainPage; @@ -36,7 +36,7 @@ public class CreateThemeAssociationWizard extends Wizard { private IThemeAssociation initialAssociation; - public CreateThemeAssociationWizard() { + private CreateThemeAssociationWizard() { this(true); } @@ -47,7 +47,7 @@ public CreateThemeAssociationWizard(boolean save) { /** * Set theme managerto use to add the created theme associations. - * + * * @param themeManager */ public void setThemeManager(IThemeManager themeManager) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java index 8bcd80fba..7e69fe259 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java @@ -38,7 +38,7 @@ * Wizard page to create association between grammar and theme. * */ -public class CreateThemeAssociationWizardPage extends AbstractWizardPage { +final class CreateThemeAssociationWizardPage extends AbstractWizardPage { private static final String PAGE_NAME = CreateThemeAssociationWizardPage.class.getName(); @@ -120,7 +120,7 @@ protected IStatus validatePage(Event event) { return null; } - public IThemeAssociation getThemeAssociation() { + IThemeAssociation getThemeAssociation() { String themeId = ((ITheme) themeViewer.getStructuredSelection().getFirstElement()).getId(); String scopeName = ((IGrammarDefinition) grammarViewer.getStructuredSelection().getFirstElement()) .getScopeName(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java index 9b996b1e0..bc2591ec8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java @@ -42,11 +42,11 @@ * registry. * */ -public class SelectGrammarWizardPage extends AbstractWizardPage { +final class SelectGrammarWizardPage extends AbstractWizardPage { private static final String PAGE_NAME = SelectGrammarWizardPage.class.getName(); - protected static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json","*.YAML-tmLanguage","*.yaml","*.yml"}; + private static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json","*.YAML-tmLanguage","*.yaml","*.yml"}; private Button browseFileSystemButton; private Button browseWorkspaceButton; @@ -150,7 +150,7 @@ protected IStatus validatePage(Event event) { return null; } - public IGrammarDefinition getGrammarDefinition() { + IGrammarDefinition getGrammarDefinition() { return new GrammarDefinition(grammarInfoWidget.getScopeNameText().getText(), grammarFileText.getText()); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java index 379c47282..ff81015c2 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java @@ -24,7 +24,7 @@ * Wizard to import TextMate grammar. * */ -public class TextMateGrammarImportWizard extends Wizard implements IImportWizard { +public final class TextMateGrammarImportWizard extends Wizard implements IImportWizard { private SelectGrammarWizardPage mainPage; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index ac539ffc7..e571e8db7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -144,7 +144,7 @@ public TMPresentationReconciler() { * preferences changed or TextMate theme changed.. * */ - private class ThemeChangeListener implements IPreferenceChangeListener { + private final class ThemeChangeListener implements IPreferenceChangeListener { @Override public void preferenceChange(PreferenceChangeEvent event) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java index 4352a9e41..a3d067b02 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/AbstractTokenProvider.java @@ -14,6 +14,7 @@ /** * Abstract class for {@link ITokenProvider}. * + * TODO remove? */ public abstract class AbstractTokenProvider implements ITokenProvider { diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java b/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java rename to org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentLineListTest.java From c5bb14ac696c9ac34f24d4588942d562e242cdd3 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 11:54:10 +0200 Subject: [PATCH 072/202] Replace StringBuilder with String concatenation --- .../tm4e/core/internal/grammar/Token.java | 20 +++++++--------- .../oniguruma/OnigNextMatchResult.java | 23 ++++++++----------- .../org/eclipse/tm4e/registry/TMResource.java | 2 +- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java index 520a7cba3..163f6fc5e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.grammar; @@ -56,14 +56,10 @@ public List getScopes() { @Override public String toString() { - StringBuilder s = new StringBuilder(); - s.append("{startIndex: "); - s.append(startIndex); - s.append(", endIndex: "); - s.append(endIndex); - s.append(", scopes: "); - s.append(scopes); - s.append("}"); - return s.toString(); + return "{" + + "startIndex: " + startIndex + + ", endIndex: " + endIndex + + ", scopes: " + scopes + + "}"; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java index 150068747..104081669 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.oniguruma; @@ -105,17 +105,12 @@ public int getLength() { @Override public String toString() { - StringBuilder result = new StringBuilder(); - result.append("{\"index\": "); - result.append(getIndex()); - result.append(", \"start\": "); - result.append(getStart()); - result.append(", \"end\": "); - result.append(getEnd()); - result.append(", \"length\": "); - result.append(getLength()); - result.append("}"); - return result.toString(); + return "{" + + "\"index\": " + index + + ", \"start\": " + start + + ", \"end\": " + end + + ", \"length\": " + getLength() + + "}"; } } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index fdbc4da39..e637f5d45 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -72,7 +72,7 @@ public InputStream getInputStream() throws IOException { return null; } if (pluginId != null) { - URL url = new URL(new StringBuilder(PLATFORM_PLUGIN).append(pluginId).append("/").append(path).toString()); + URL url = new URL(PLATFORM_PLUGIN + pluginId + "/" + path); return url.openStream(); } return new FileInputStream(new File(path)); From cd93d4db5c15b2813cdcee61bfecf3f8b9b12c4c Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 11:54:24 +0200 Subject: [PATCH 073/202] Use default StringBuilder constructor --- .../main/java/org/eclipse/tm4e/core/internal/parser/PList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java index cb69ee2f9..0f452118f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java @@ -50,7 +50,7 @@ public void startElement(String uri, String localName, String qName, Attributes break; } - this.text = new StringBuilder(""); + this.text = new StringBuilder(); super.startElement(uri, localName, qName, attributes); } From dccbe51934edb6b13c397e6a5208915b4f2a1bba Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 12:00:09 +0200 Subject: [PATCH 074/202] Make local StringBuilder variables final --- .../tm4e/core/internal/oniguruma/OnigNextMatchResult.java | 2 +- .../org/eclipse/tm4e/core/internal/rule/RegExpSource.java | 2 +- .../src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java | 2 +- .../LanguageConfigurationCharacterPairMatcher.java | 4 ++-- .../internal/supports/OnEnterSupport.java | 4 ++-- .../tm4e/languageconfiguration/internal/utils/TextUtils.java | 2 +- .../test/java/org/eclipse/tm4e/ui/internal/text/Command.java | 2 +- .../internal/text/TMPresentationReconcilerTestGenerator.java | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java index 104081669..8c02d97f8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java @@ -39,7 +39,7 @@ public IOnigCaptureIndex[] getCaptureIndices() { @Override public String toString() { - StringBuilder result = new StringBuilder(); + final StringBuilder result = new StringBuilder(); result.append("{\n"); result.append(" \"index\": "); result.append(getIndex()); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index 1d342c5fb..a2ff9ae61 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -87,7 +87,7 @@ private void _handleAnchors(String regExpSource) { char ch; char nextCh; int lastPushedPos = 0; - StringBuilder output = new StringBuilder(); + final StringBuilder output = new StringBuilder(); boolean hasAnchor = false; for (int pos = 0; pos < len; pos++) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java index 2e3d8d338..b2142d8f5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java @@ -63,7 +63,7 @@ public int[] getTokenIds(String scope) { } public String getToken(Map tokenMap) { - StringBuilder result = new StringBuilder(); + final StringBuilder result = new StringBuilder(); boolean isFirst = true; for (int i = 1; i <= this.lastAssignedId; i++) { if (tokenMap.containsKey(i)) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java index 74bdf13cb..c4d5765ac 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java @@ -97,7 +97,7 @@ public void clear() { /** * Returns the matcher from the document. - * + * * @param document * @return */ @@ -108,7 +108,7 @@ private DefaultCharacterPairMatcher getMatcher(IDocument document) { if (matcher == null) { // initizalize a DefaultCharacterPairMatcher by using character pairs of the // language configuration. - StringBuilder chars = new StringBuilder(); + final StringBuilder chars = new StringBuilder(); this.document = document; IContentType[] contentTypes = findContentTypes(document); if (contentTypes != null) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java index 69c0f92c4..799b6175f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java @@ -95,7 +95,7 @@ private boolean matchClose(String afterEnterText) { } private static Pattern createOpenBracketRegExp(String bracket) { - StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); + final StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); String c = String.valueOf(str.charAt(0)); if (!B_REGEXP.matcher(c).find()) { str.insert(0, "\\b"); //$NON-NLS-1$ @@ -105,7 +105,7 @@ private static Pattern createOpenBracketRegExp(String bracket) { } private static Pattern createCloseBracketRegExp(String bracket) { - StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); + final StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); String c = String.valueOf(str.charAt(str.length() - 1)); if (!B_REGEXP.matcher(c).find()) { str.append("\\b"); //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java index 380de6508..e2e4fd38a 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java @@ -55,7 +55,7 @@ private static String normalizeIndentationFromWhitespace(String str, int tabSize } } - StringBuilder result = new StringBuilder(); + final StringBuilder result = new StringBuilder(); if (!insertSpaces) { long tabsCnt = Math.round(Math.floor(spacesCnt / tabSize)); spacesCnt = spacesCnt % tabSize; diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java index 7c3fa97c1..434730d62 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java @@ -50,7 +50,7 @@ public void execute() { protected abstract Integer getLineTo(); public static String toText(String text) { - StringBuilder newText = new StringBuilder(); + final StringBuilder newText = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java index 5747ce119..a70cbcd91 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java @@ -94,7 +94,7 @@ public void install(ITextViewer viewer, IDocument document) { } private String toText(String text) { - StringBuilder newText = new StringBuilder(); + final StringBuilder newText = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { From a5951ebdcaa1173ef3531933fc1ab88cfc887160 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 12:03:19 +0200 Subject: [PATCH 075/202] Construct StringBuilder with initial value --- .../tm4e/core/internal/oniguruma/OnigNextMatchResult.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java index 8c02d97f8..9a78bdfac 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java @@ -39,8 +39,7 @@ public IOnigCaptureIndex[] getCaptureIndices() { @Override public String toString() { - final StringBuilder result = new StringBuilder(); - result.append("{\n"); + final StringBuilder result = new StringBuilder("{\n"); result.append(" \"index\": "); result.append(getIndex()); result.append(",\n"); From ce8ef33a4e4401cefbe7f4d322e4bc248299dc9c Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 16:21:12 +0200 Subject: [PATCH 076/202] Refactor constructors/object initialization --- .../tm4e/core/internal/grammar/Grammar.java | 13 +++----- .../core/internal/grammar/LineTokens.java | 3 +- .../grammar/ScopeMetadataProvider.java | 6 ++-- .../core/internal/grammars/SyncRegistry.java | 9 ++---- .../tm4e/core/internal/matcher/Matcher.java | 3 +- .../core/internal/oniguruma/OnigRegExp.java | 5 +-- .../tm4e/core/internal/parser/PList.java | 4 +-- .../tm4e/core/internal/rule/BeginEndRule.java | 1 - .../core/internal/rule/BeginWhileRule.java | 2 -- .../core/internal/rule/IncludeOnlyRule.java | 1 - .../tm4e/core/internal/rule/MatchRule.java | 1 - .../core/internal/rule/RegExpSourceList.java | 5 +-- .../eclipse/tm4e/core/model/DecodeMap.java | 26 ++++++---------- .../eclipse/tm4e/core/model/ModelLine.java | 5 --- .../model/ModelTokensChangedEventBuilder.java | 3 +- .../org/eclipse/tm4e/core/model/TMModel.java | 3 +- .../eclipse/tm4e/core/model/Tokenizer.java | 3 +- .../org/eclipse/tm4e/core/theme/ColorMap.java | 9 ++---- .../org/eclipse/tm4e/core/theme/Theme.java | 3 +- ...tLanguageConfigurationRegistryManager.java | 8 ++--- .../LanguageConfigurationPreferencePage.java | 13 ++++---- .../widgets/ColumnViewerComparator.java | 10 ++---- .../LanguageConfigurationImportWizard.java | 4 --- .../tm4e/registry/internal/GrammarCache.java | 12 ++----- .../internal/model/DocumentInputStream.java | 7 ++--- .../ui/internal/model/DocumentLineList.java | 3 +- .../ui/internal/model/TMModelManager.java | 3 +- .../preferences/GrammarPreferencePage.java | 31 ++++++++++--------- .../preferences/TextMatePreferencePage.java | 4 --- .../preferences/ThemePreferencePage.java | 6 ++-- .../ui/internal/snippets/SnippetManager.java | 5 ++- ...TMPresentationReconcilerTestGenerator.java | 6 +--- .../internal/themes/AbstractThemeManager.java | 9 ++---- .../themes/BaseThemeAssociationRegistry.java | 9 ++---- .../themes/ThemeAssociationRegistry.java | 5 +-- .../widgets/ColumnViewerComparator.java | 14 +++------ .../wizards/CreateThemeAssociationWizard.java | 11 ++----- .../wizards/TextMateGrammarImportWizard.java | 9 ++---- .../eclipse/tm4e/ui/themes/ColorManager.java | 5 ++- .../tm4e/ui/themes/css/CSSTokenProvider.java | 3 +- 40 files changed, 84 insertions(+), 198 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 7c7e67f3a..c31b8a2dd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -54,10 +54,10 @@ */ public final class Grammar implements IGrammar, IRuleFactoryHelper { - private int rootId; - private int lastRuleId; - private final Map ruleId2desc; - private final Map includedGrammars; + private int rootId = -1; + private int lastRuleId = 0; + private final Map ruleId2desc = new HashMap<>(); + private final Map includedGrammars = new HashMap<>(); private final IGrammarRepository grammarRepository; private final IRawGrammar grammar; private List injections; @@ -66,13 +66,8 @@ public final class Grammar implements IGrammar, IRuleFactoryHelper { public Grammar(IRawGrammar grammar, int initialLanguage, Map embeddedLanguages, IGrammarRepository grammarRepository, IThemeProvider themeProvider) { this.scopeMetadataProvider = new ScopeMetadataProvider(initialLanguage, themeProvider, embeddedLanguages); - this.rootId = -1; - this.lastRuleId = 0; - this.includedGrammars = new HashMap<>(); this.grammarRepository = grammarRepository; this.grammar = initGrammar(grammar, null); - this.ruleId2desc = new HashMap<>(); - this.injections = null; } public void onDidChangeTheme() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 028d38a7e..04eee18fe 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -43,7 +43,7 @@ final class LineTokens { */ private final List binaryTokens; - private int lastTokenEndIndex; + private int lastTokenEndIndex = 0; LineTokens(boolean emitBinaryTokens, String lineText) { this.emitBinaryTokens = emitBinaryTokens; @@ -55,7 +55,6 @@ final class LineTokens { this.tokens = new ArrayList<>(); this.binaryTokens = null; } - this.lastTokenEndIndex = 0; } void produce(StackElement stack, int endIndex) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java index 020627e07..3cb3b9aa8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java @@ -36,20 +36,18 @@ final class ScopeMetadataProvider { private final int initialLanguage; private final IThemeProvider themeProvider; - private final Map cache; + private final Map cache = new HashMap<>(); private ScopeMetadata defaultMetaData; - private final Map embeddedLanguages; + private final Map embeddedLanguages = new HashMap<>(); private Pattern embeddedLanguagesRegex; ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider, Map embeddedLanguages) { this.initialLanguage = initialLanguage; this.themeProvider = themeProvider; - this.cache = new HashMap<>(); this.onDidChangeTheme(); // embeddedLanguages handling - this.embeddedLanguages = new HashMap<>(); if (embeddedLanguages != null) { // If embeddedLanguages are configured, fill in // `this._embeddedLanguages` diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java index 41f321baf..c0aa0e9d0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java @@ -38,16 +38,13 @@ public final class SyncRegistry implements IGrammarRepository, IThemeProvider { - private final Map grammars; - private final Map rawGrammars; - private final Map> injectionGrammars; + private final Map grammars = new HashMap<>(); + private final Map rawGrammars = new HashMap<>(); + private final Map> injectionGrammars = new HashMap<>(); private Theme theme; public SyncRegistry(Theme theme) { this.theme = theme; - this.grammars = new HashMap<>(); - this.rawGrammars = new HashMap<>(); - this.injectionGrammars = new HashMap<>(); } public void setTheme(Theme theme) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java index 7557ebe4a..d630f5a65 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java @@ -40,13 +40,12 @@ private static Collection> createMatchers(String sele return new Matcher<>(selector, matchesName).results; } - private final List> results; + private final List> results = new ArrayList<>(); private final Tokenizer tokenizer; private final IMatchesName matchesName; private String token; private Matcher(String expression, IMatchesName matchesName) { - this.results = new ArrayList<>(); this.tokenizer = new Tokenizer(expression); this.matchesName = matchesName; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java index 3423114da..871439175 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java @@ -39,14 +39,11 @@ final class OnigRegExp { private OnigString lastSearchString; - private int lastSearchPosition; + private int lastSearchPosition = -1; private OnigResult lastSearchResult; private final Regex regex; OnigRegExp(String source) { - lastSearchString = null; - lastSearchPosition = -1; - lastSearchResult = null; byte[] pattern = source.getBytes(StandardCharsets.UTF_8); try { this.regex = new Regex(pattern, 0, pattern.length, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java index 0f452118f..fc7af4ca7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java @@ -23,15 +23,13 @@ public final class PList extends DefaultHandler { private final boolean theme; - private final List errors; + private final List errors = new ArrayList<>(); private PListObject currObject; private T result; private StringBuilder text; public PList(boolean theme) { this.theme = theme; - this.errors = new ArrayList<>(); - this.currObject = null; } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index 8f879e51b..392359de2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -43,7 +43,6 @@ public final class BeginEndRule extends Rule { this.applyEndPatternLast = applyEndPatternLast; this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; - this.cachedCompiledPatterns = null; } public String getEndWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index dd5dd7fc4..07477ed4e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -43,8 +43,6 @@ public final class BeginWhileRule extends Rule { this.whileHasBackReferences = this._while.hasBackReferences(); this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; - this.cachedCompiledPatterns = null; - this.cachedCompiledWhilePatterns = null; } public String getWhileWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java index 05ee778fe..fa71ed9b0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java @@ -26,7 +26,6 @@ final class IncludeOnlyRule extends Rule { super(id, name, contentName); this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; - this.cachedCompiledPatterns = null; } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java index e40e69167..59111415f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java @@ -28,7 +28,6 @@ public final class MatchRule extends Rule { super(id, name, null); this.match = new RegExpSource(match, this.id); this.captures = captures; - this.cachedCompiledPatterns = null; } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index 5930343f5..8aac88867 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -38,15 +38,12 @@ private static final class RegExpSourceListAnchorCache { } - private final List _items; + private final List _items = new ArrayList<>(); private boolean _hasAnchors; private ICompiledRule _cached; private final RegExpSourceListAnchorCache _anchorCache; RegExpSourceList() { - this._items = new ArrayList<>(); - this._hasAnchors = false; - this._cached = null; this._anchorCache = new RegExpSourceListAnchorCache(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java index b2142d8f5..bfe31aac0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.model; @@ -23,21 +23,15 @@ class DecodeMap { + private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); - int lastAssignedId; - final Map scopeToTokenIds; - final Map tokenToTokenId; - final Map tokenIdToToken; - TMTokenDecodeData prevToken; - - public DecodeMap() { - this.lastAssignedId = 0; - this.scopeToTokenIds = new LinkedHashMap<>(); - this.tokenToTokenId = new LinkedHashMap<>(); - this.tokenIdToToken = new LinkedHashMap<>(); - this.prevToken = new TMTokenDecodeData(new String[0], new LinkedHashMap>()); - } + int lastAssignedId = 0; + final Map scopeToTokenIds = new LinkedHashMap<>(); + final Map tokenToTokenId = new LinkedHashMap<>(); + final Map tokenIdToToken = new LinkedHashMap<>(); + TMTokenDecodeData prevToken = new TMTokenDecodeData(EMPTY_STRING_ARRAY, + new LinkedHashMap<>()); public int[] getTokenIds(String scope) { int[] tokens = this.scopeToTokenIds.get(scope); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java index 5c0df7fcf..b38a8fde2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java @@ -15,15 +15,10 @@ public class ModelLine { - //String text; boolean isInvalid; TMState state; List tokens; - public ModelLine(/*String text*/) { - //this.text = text; - } - public void resetTokenizationState() { this.state = null; this.tokens = null; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java index d32b9d92c..d5ac5d872 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java @@ -22,11 +22,10 @@ class ModelTokensChangedEventBuilder { private final ITMModel model; - private final List ranges; + private final List ranges = new ArrayList<>(); public ModelTokensChangedEventBuilder(ITMModel model) { this.model = model; - this.ranges = new ArrayList<>(); } public void registerChangedTokens(int lineNumber) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index d1e9fe2e6..447f38b0f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -38,7 +38,7 @@ public class TMModel implements ITMModel { private IGrammar grammar; /** Listener when TextMate model tokens changed **/ - private final List listeners; + private final List listeners = new ArrayList<>(); Tokenizer tokenizer; @@ -49,7 +49,6 @@ public class TMModel implements ITMModel { private final PriorityBlockingQueue invalidLines = new PriorityBlockingQueue<>(); public TMModel(IModelLines lines) { - this.listeners = new ArrayList<>(); this.lines = lines; ((AbstractLineList)lines).setModel(this); lines.forEach(ModelLine::resetTokenizationState); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java index 355e9e1fd..f5fbc8e16 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java @@ -28,11 +28,10 @@ public class Tokenizer implements ITokenizationSupport { private final IGrammar grammar; - private final DecodeMap decodeMap; + private final DecodeMap decodeMap = new DecodeMap(); public Tokenizer(IGrammar grammar) { this.grammar = grammar; - this.decodeMap = new DecodeMap(); } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java index 5e1f60577..ee95a3431 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java @@ -19,13 +19,8 @@ public class ColorMap { - private int lastColorId; - private final Map color2id; - - public ColorMap() { - this.lastColorId = 0; - this.color2id = new HashMap<>(); - } + private int lastColorId = 0; + private final Map color2id = new HashMap<>(); public int getId(String color) { if (color == null) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index b1512b79b..dbe9bfd6e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -44,7 +44,7 @@ public class Theme { private final ColorMap colorMap; private final ThemeTrieElement root; private final ThemeTrieElementRule defaults; - private final Map> cache; + private final Map> cache = new HashMap<>(); public static Theme createFromRawTheme(IRawTheme source) { return createFromParsedTheme(parseTheme(source)); @@ -220,7 +220,6 @@ public Theme(ColorMap colorMap, ThemeTrieElementRule defaults, ThemeTrieElement this.colorMap = colorMap; this.root = root; this.defaults = defaults; - this.cache = new HashMap<>(); } public Set getColorMap() { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java index 1adf62bcb..8b7bc06f1 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java @@ -22,13 +22,9 @@ import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; public abstract class AbstractLanguageConfigurationRegistryManager implements ILanguageConfigurationRegistryManager { - protected final Map pluginDefinitions; - protected final Map userDefinitions; - protected AbstractLanguageConfigurationRegistryManager() { - pluginDefinitions = new HashMap<>(); - userDefinitions = new HashMap<>(); - } + protected final Map pluginDefinitions = new HashMap<>(); + protected final Map userDefinitions = new HashMap<>(); @Override public ILanguageConfigurationDefinition[] getDefinitions() { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java index 08cc3948e..fb0301934 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java @@ -1,14 +1,14 @@ /** - * Copyright (c) 2015-2018 Angelo ZERR and others. + * Copyright (c) 2015-2018 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation - * Lucas Bullen (Red Hat Inc.) - configuration viewing and editing + * Contributors: + * Angelo Zerr - initial API and implementation + * Lucas Bullen (Red Hat Inc.) - configuration viewing and editing */ package org.eclipse.tm4e.languageconfiguration.internal.preferences; @@ -63,7 +63,8 @@ public final class LanguageConfigurationPreferencePage extends PreferencePage im final static String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$ - private final ILanguageConfigurationRegistryManager manager; + private final ILanguageConfigurationRegistryManager manager = new WorkingCopyLanguageConfigurationRegistryManager( + LanguageConfigurationRegistryManager.getInstance()); private TableViewer definitionViewer; @@ -73,8 +74,6 @@ public final class LanguageConfigurationPreferencePage extends PreferencePage im public LanguageConfigurationPreferencePage() { setDescription(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_description); - manager = new WorkingCopyLanguageConfigurationRegistryManager( - LanguageConfigurationRegistryManager.getInstance()); } @Override diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java index b7a25c4b3..43e8c0a7b 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java @@ -24,14 +24,8 @@ */ public final class ColumnViewerComparator extends ViewerComparator { - private int fSortColumn; - - private int fSortOrder; // 1 = asc, -1 = desc - - public ColumnViewerComparator() { - fSortColumn = 0; - fSortOrder = 1; - } + private int fSortColumn = 0; + private int fSortOrder = 1; // 1 = asc, -1 = desc /** * Returns the {@linkplain SWT} style constant for the sort direction. diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java index f66547ca8..d24354e20 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java @@ -34,10 +34,6 @@ public final class LanguageConfigurationImportWizard extends Wizard implements I private final boolean save; - LanguageConfigurationImportWizard() { - this(true); - } - public LanguageConfigurationImportWizard(boolean save) { this.save = save; setRegistryManager(LanguageConfigurationRegistryManager.getInstance()); diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java index 76f64dc08..45b8497b4 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java @@ -28,15 +28,9 @@ */ final class GrammarCache { - private final Map definitions; - private final Map> injections; - private final Map scopeNameBindings; - - GrammarCache() { - this.definitions = new HashMap<>(); - this.injections = new HashMap<>(); - this.scopeNameBindings = new HashMap<>(); - } + private final Map definitions = new HashMap<>(); + private final Map> injections = new HashMap<>(); + private final Map scopeNameBindings = new HashMap<>(); /** * Register a grammar definition. diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java index d3e20071e..61aa9053a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java @@ -22,20 +22,16 @@ public final class DocumentInputStream extends InputStream { private final IDocument fDocument; - private int fCurrPos; + private int fCurrPos = 0; public DocumentInputStream(IDocument document) { fDocument= document; - fCurrPos= 0; } public IDocument getDocument() { return fDocument; } - /** - * {@inheritDoc} - */ @Override public int read() throws IOException { try { @@ -43,6 +39,7 @@ public int read() throws IOException { return fDocument.getChar(fCurrPos++); } } catch (BadLocationException e) { + // ignore } return -1; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java index b1deaee74..71363ae0c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java @@ -31,11 +31,10 @@ final class DocumentLineList extends AbstractLineList { private final IDocument document; - private final InternalListener listener; + private final InternalListener listener = new InternalListener(); DocumentLineList(IDocument document) { this.document = document; - this.listener = new InternalListener(); document.addDocumentListener(listener); for (int i = 0; i < document.getNumberOfLines(); i++) { addLine(i); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java index b2bc3ad66..a8c17ab4f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java @@ -30,10 +30,9 @@ public static ITMModelManager getInstance() { return INSTANCE; } - private final Map models; + private final Map models = new HashMap<>(); private TMModelManager() { - models = new HashMap<>(); } @Override diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index 197d598b4..d65495139 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -6,9 +6,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation - * Nicolaj Hoess - Editor templates pref page: Allow to sort by column - https://bugs.eclipse.org/203722 - * Angelo Zerr - Adapt org.eclipse.ui.texteditor.templates.TemplatePreferencePage for TextMate grammar + * IBM Corporation - initial API and implementation + * Nicolaj Hoess - Editor templates pref page: Allow to sort by column - + * https://bugs.eclipse.org/203722 + * Angelo Zerr - Adapt org.eclipse.ui.texteditor.templates.TemplatePreferencePage for TextMate + * grammar *******************************************************************************/ package org.eclipse.tm4e.ui.internal.preferences; @@ -77,9 +79,10 @@ public final class GrammarPreferencePage extends PreferencePage implements IWork static final String PAGE_ID = "org.eclipse.tm4e.ui.preferences.GrammarPreferencePage"; // Managers - private IGrammarRegistryManager grammarRegistryManager; - private IThemeManager themeManager; - private ISnippetManager snippetManager; + private IGrammarRegistryManager grammarRegistryManager = new WorkingCopyGrammarRegistryManager( + TMEclipseRegistryPlugin.getGrammarRegistryManager()); + private IThemeManager themeManager = new WorkingCopyThemeManager(TMUIPlugin.getThemeManager()); + private ISnippetManager snippetManager = TMUIPlugin.getSnippetManager(); // Grammar list private TableViewer grammarViewer; @@ -97,10 +100,6 @@ public final class GrammarPreferencePage extends PreferencePage implements IWork public GrammarPreferencePage() { setDescription(TMUIMessages.GrammarPreferencePage_description); - setGrammarRegistryManager( - new WorkingCopyGrammarRegistryManager(TMEclipseRegistryPlugin.getGrammarRegistryManager())); - setThemeManager(new WorkingCopyThemeManager(TMUIPlugin.getThemeManager())); - setSnippetManager(TMUIPlugin.getSnippetManager()); } /** @@ -359,9 +358,10 @@ public void handleEvent(Event e) { } private void remove() { - IGrammarDefinition definition = (IGrammarDefinition) ((IStructuredSelection) grammarViewer.getSelection()).getFirstElement(); - grammarRegistryManager.unregisterGrammarDefinition(definition); - grammarViewer.refresh(); + IGrammarDefinition definition = (IGrammarDefinition) ((IStructuredSelection) grammarViewer + .getSelection()).getFirstElement(); + grammarRegistryManager.unregisterGrammarDefinition(definition); + grammarViewer.refresh(); } }); } @@ -491,7 +491,7 @@ private void createInjectionTab(TabFolder folder) { private int computeMinimumColumnWidth(GC gc, String string) { return gc.stringExtent(string).x + 10; // pad 10 to accommodate table - // header trimmings + // header trimmings } private void updateButtons() { @@ -539,7 +539,8 @@ private TMViewer doCreateViewer(Composite parent) { * source viewer featuring e.g. syntax coloring. * * @param parent - * the parent control + * the parent control + * * @return a configured source viewer */ private TMViewer createViewer(Composite parent) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java index e2d33d350..9f7bbe40a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java @@ -29,10 +29,6 @@ */ public final class TextMatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - public TextMatePreferencePage() { - - } - @Override protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index 84b3f6e49..d6e4833b4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -76,8 +76,8 @@ public final class ThemePreferencePage extends PreferencePage implements IWorkbe private ComboViewer grammarViewer; private TMViewer previewViewer; - private final IGrammarRegistryManager grammarRegistryManager; - private final IThemeManager themeManager; + private final IGrammarRegistryManager grammarRegistryManager = TMEclipseRegistryPlugin.getGrammarRegistryManager(); + private final IThemeManager themeManager = TMUIPlugin.getThemeManager(); private Button darkThemeButton; @@ -87,8 +87,6 @@ public final class ThemePreferencePage extends PreferencePage implements IWorkbe public ThemePreferencePage() { setDescription(TMUIMessages.ThemePreferencePage_description); - this.grammarRegistryManager = TMEclipseRegistryPlugin.getGrammarRegistryManager(); - this.themeManager = TMUIPlugin.getThemeManager(); } @Override diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java index a76c7cff6..9384f0f46 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java @@ -50,10 +50,9 @@ private static synchronized ISnippetManager createInstance() { return manager; } - private final Map> snippets; + private final Map> snippets = new HashMap<>(); - SnippetManager() { - this.snippets = new HashMap<>(); + private SnippetManager() { } private void load() { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java index a70cbcd91..d8ffdd0f1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java @@ -28,7 +28,7 @@ public final class TMPresentationReconcilerTestGenerator private final StringBuilder code = new StringBuilder(); - /*private List commands; + /*private List commands = new ArrayList<>(); private static final class Command { final String command; @@ -40,10 +40,6 @@ private static final class Command { } }*/ - public TMPresentationReconcilerTestGenerator() { - //this.commands = new ArrayList<>(); - } - @Override public void install(ITextViewer viewer, IDocument document) { this.viewer = viewer; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index 056bcd02b..bd5d3b648 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -32,13 +32,8 @@ */ public abstract class AbstractThemeManager implements IThemeManager { - private final Map themes; - private final ThemeAssociationRegistry themeAssociationRegistry; - - protected AbstractThemeManager() { - this.themes = new LinkedHashMap<>(); - this.themeAssociationRegistry = new ThemeAssociationRegistry(); - } + private final Map themes = new LinkedHashMap<>(); + private final ThemeAssociationRegistry themeAssociationRegistry = new ThemeAssociationRegistry(); @Override public void registerTheme(ITheme theme) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java index 369824764..11bcffb67 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java @@ -28,13 +28,8 @@ final class BaseThemeAssociationRegistry { private IThemeAssociation defaultAssociation; - private final Map> eclipseThemeIds; - private final List allAssociations; - - BaseThemeAssociationRegistry() { - eclipseThemeIds = new HashMap<>(); - this.allAssociations = new ArrayList<>(); - } + private final Map> eclipseThemeIds = new HashMap<>(); + private final List allAssociations = new ArrayList<>(); void register(IThemeAssociation association) { //String eclipseThemeId = association.getEclipseThemeId(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java index 0cc94727f..f5ec6c7cf 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java @@ -25,7 +25,7 @@ */ final class ThemeAssociationRegistry { - private final Map scopes; + private final Map scopes = new HashMap<>(); private static final class EclipseThemeAssociation { @@ -50,9 +50,6 @@ void setDark(IThemeAssociation dark) { } - ThemeAssociationRegistry() { - scopes = new HashMap<>(); - } IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) { // From theme assiocations diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java index 6a3bfee45..1a04a3181 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java @@ -24,18 +24,12 @@ */ public final class ColumnViewerComparator extends ViewerComparator { - private int fSortColumn; - - private int fSortOrder; // 1 = asc, -1 = desc - - public ColumnViewerComparator() { - fSortColumn = 0; - fSortOrder = 1; - } + private int fSortColumn = 0; + private int fSortOrder = 1; // 1 = asc, -1 = desc /** * Returns the {@linkplain SWT} style constant for the sort direction. - * + * * @return {@link SWT#DOWN} for asc sorting, {@link SWT#UP} otherwise */ public int getDirection() { @@ -45,7 +39,7 @@ public int getDirection() { /** * Sets the sort column. If the newly set sort column equals the previous * set sort column, the sort direction changes. - * + * * @param column * New sort column */ diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java index d1536ec86..ac3622dfb 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java @@ -28,7 +28,7 @@ public final class CreateThemeAssociationWizard extends Wizard { private IThemeAssociation createdThemeAssociation; - private IThemeManager themeManager; + private IThemeManager themeManager = TMUIPlugin.getThemeManager(); private final boolean save; @@ -36,17 +36,12 @@ public final class CreateThemeAssociationWizard extends Wizard { private IThemeAssociation initialAssociation; - private CreateThemeAssociationWizard() { - this(true); - } - public CreateThemeAssociationWizard(boolean save) { this.save = save; - setThemeManager(TMUIPlugin.getThemeManager()); } /** - * Set theme managerto use to add the created theme associations. + * Set theme manager to use to add the created theme associations. * * @param themeManager */ @@ -86,7 +81,5 @@ public void setInitialDefinition(IGrammarDefinition definition) { public void setInitialAssociation(IThemeAssociation association) { this.initialAssociation = association; - } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java index ff81015c2..4be8b371f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java @@ -30,22 +30,17 @@ public final class TextMateGrammarImportWizard extends Wizard implements IImport private IGrammarDefinition createdDefinition; - private IGrammarRegistryManager grammarRegistryManager; + private IGrammarRegistryManager grammarRegistryManager = TMEclipseRegistryPlugin.getGrammarRegistryManager(); private final boolean save; - public TextMateGrammarImportWizard() { - this(true); - } - public TextMateGrammarImportWizard(boolean save) { this.save = save; - setGrammarRegistryManager(TMEclipseRegistryPlugin.getGrammarRegistryManager()); } /** * Set grammar registry to use to add the created grammar definitions. - * + * * @param grammarRegistryManager */ public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java index e3953b81d..a08cc15f2 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java @@ -23,7 +23,7 @@ import com.google.common.base.Splitter; -public class ColorManager { +public final class ColorManager { private static final Splitter BY_COMMA_SPLITTER = Splitter.on(','); @@ -33,10 +33,9 @@ public static ColorManager getInstance() { return INSTANCE; } - private final Map fColorTable; + private final Map fColorTable = new HashMap<>(10); private ColorManager() { - fColorTable = new HashMap<>(10); } public Color getColor(RGB rgb) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java index 6b8317b5e..3463a01b2 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java @@ -35,11 +35,10 @@ public class CSSTokenProvider extends AbstractTokenProvider { private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); - private final Map tokenMaps; + private final Map tokenMaps = new HashMap<>(); private CSSParser parser; public CSSTokenProvider(InputStream in) { - tokenMaps = new HashMap<>(); try { parser = new CSSParser(in); for (IStyle style : parser.getStyles()) { From c743138b222ed59ab22d1c7e397f967e06460e0a Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 18:55:49 +0200 Subject: [PATCH 077/202] Use .toArray(TYPE[]::new) --- .../eclipse/tm4e/core/internal/grammar/LineTokens.java | 2 +- .../tm4e/core/internal/rule/ICompilePatternsResult.java | 2 +- .../eclipse/tm4e/core/internal/rule/RegExpSourceList.java | 6 +++--- .../main/java/org/eclipse/tm4e/core/model/Tokenizer.java | 2 +- .../AbstractLanguageConfigurationRegistryManager.java | 2 +- .../internal/widgets/CharacterPairsTableWidget.java | 2 +- .../internal/widgets/OnEnterRuleTableWidget.java | 2 +- .../registry/internal/AbstractGrammarRegistryManager.java | 2 +- .../eclipse/tm4e/ui/internal/menus/ThemeContribution.java | 2 +- .../eclipse/tm4e/ui/internal/snippets/SnippetManager.java | 2 +- .../tm4e/ui/internal/themes/AbstractThemeManager.java | 8 ++++---- .../ui/internal/themes/BaseThemeAssociationRegistry.java | 6 +++--- .../tm4e/ui/internal/themes/ThemeAssociationRegistry.java | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 04eee18fe..c6c61c867 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -109,7 +109,7 @@ IToken[] getResult(StackElement stack, int lineLength) { this.tokens.get(this.tokens.size() - 1).setStartIndex(0); } - return this.tokens.toArray(new IToken[0]); + return this.tokens.toArray(IToken[]::new); } int[] getBinaryResult(StackElement stack, int lineLength) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java index cc8b48b05..fa1fd9210 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java @@ -25,7 +25,7 @@ final class ICompilePatternsResult { ICompilePatternsResult(Collection patterns, boolean hasMissingPatterns) { this.hasMissingPatterns = hasMissingPatterns; - this.patterns = patterns.toArray(new Integer[patterns.size()]); + this.patterns = patterns.toArray(Integer[]::new); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index 8aac88867..5007d07f9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -81,7 +81,7 @@ ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) { for (RegExpSource regExpSource : _items) { regexps.add(regExpSource.getSource()); } - this._cached = new ICompiledRule(createOnigScanner(regexps.toArray(new String[0])), getRules()); + this._cached = new ICompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); } return this._cached; } @@ -121,7 +121,7 @@ private ICompiledRule _resolveAnchors(boolean allowA, boolean allowG) { for (RegExpSource regExpSource : _items) { regexps.add(regExpSource.resolveAnchors(allowA, allowG)); } - return new ICompiledRule(createOnigScanner(regexps.toArray(new String[0])), getRules()); + return new ICompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); } private OnigScanner createOnigScanner(String[] regexps) { @@ -133,7 +133,7 @@ private Integer[] getRules() { for (RegExpSource item : this._items) { ruleIds.add(item.getRuleId()); } - return ruleIds.toArray(new Integer[0]); + return ruleIds.toArray(Integer[]::new); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java index f5fbc8e16..1392785a9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java @@ -70,7 +70,7 @@ public LineTokens tokenize(String line, TMState state, Integer offsetDelta, Inte for (int tokenIndex = 0, len = textMateResult.getTokens().length; tokenIndex < len; tokenIndex++) { IToken token = textMateResult.getTokens()[tokenIndex]; int tokenStartIndex = token.getStartIndex(); - String tokenType = decodeTextMateToken(this.decodeMap, token.getScopes().toArray(new String[0])); + String tokenType = decodeTextMateToken(this.decodeMap, token.getScopes().toArray(String[]::new)); // do not push a new token if the type is exactly the same (also // helps with ligatures) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java index 8b7bc06f1..0fa5f69d4 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java @@ -31,7 +31,7 @@ public ILanguageConfigurationDefinition[] getDefinitions() { Set definitions = new HashSet<>(); userDefinitions.values().forEach(definition -> definitions.add(definition)); pluginDefinitions.values().forEach(definition -> definitions.add(definition)); - return definitions.toArray(new ILanguageConfigurationDefinition[definitions.size()]); + return definitions.toArray(ILanguageConfigurationDefinition[]::new); } @Override diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java index 81504513b..a25667452 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java @@ -64,7 +64,7 @@ private static final class CharacterPairContentProvider implements IStructuredCo @Override public Object[] getElements(Object input) { - return characterPairList.toArray(new CharacterPair[characterPairList.size()]); + return characterPairList.toArray(CharacterPair[]::new); } @SuppressWarnings("unchecked") diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java index a03d8252e..93020382e 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java @@ -80,7 +80,7 @@ private static final class OnEnterRuleContentProvider implements IStructuredCont @Override public Object[] getElements(Object input) { - return onEnterRulesList.toArray(new OnEnterRule[onEnterRulesList.size()]); + return onEnterRulesList.toArray(OnEnterRule[]::new); } @SuppressWarnings("unchecked") diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java index 5ffb87f0e..d68580c54 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java @@ -129,7 +129,7 @@ public IGrammarDefinition[] getDefinitions() { Collection userDefinitions = userCache.getDefinitions(); Collection definitions = new ArrayList<>(pluginDefinitions); definitions.addAll(userDefinitions); - return definitions.toArray(new IGrammarDefinition[definitions.size()]); + return definitions.toArray(IGrammarDefinition[]::new); } /** diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java index 48adb6981..93d59932c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java @@ -71,7 +71,7 @@ protected IContributionItem[] getContributionItems() { } } - return items.toArray(new IContributionItem[items.size()]); + return items.toArray(IContributionItem[]::new); } private Action createAction(final String scopeName, final ITheme theme, boolean whenDark) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java index 9384f0f46..7c99b1fce 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java @@ -86,6 +86,6 @@ private void registerSnippet(Snippet snippet) { @Override public ISnippet[] getSnippets(String scopeName) { Collection snippets = this.snippets.get(scopeName); - return snippets != null ? snippets.toArray(new ISnippet[snippets.size()]) : EMPTY_SNIPPETS; + return snippets != null ? snippets.toArray(ISnippet[]::new) : EMPTY_SNIPPETS; } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index bd5d3b648..d789c75a9 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -53,7 +53,7 @@ public ITheme getThemeById(String themeId) { @Override public ITheme[] getThemes() { Collection themes = this.themes.values(); - return themes.toArray(new ITheme[themes.size()]); + return themes.toArray(ITheme[]::new); } @Override @@ -75,7 +75,7 @@ ITheme getDefaultTheme(boolean dark) { public ITheme[] getThemes(boolean dark) { Collection themes = this.themes.values(); return themes.stream().filter(theme -> (theme.isDark() == dark)) - .collect(Collectors.toList()).toArray(new ITheme[0]); + .collect(Collectors.toList()).toArray(ITheme[]::new); } @Override @@ -116,7 +116,7 @@ public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { dark = new ThemeAssociation(getDefaultTheme(true).getId(), scopeName, true); } associations.add(dark); - return associations.toArray(new IThemeAssociation[associations.size()]); + return associations.toArray(IThemeAssociation[]::new); } @Override @@ -132,7 +132,7 @@ public void unregisterThemeAssociation(IThemeAssociation association) { @Override public IThemeAssociation[] getAllThemeAssociations() { List associations = themeAssociationRegistry.getThemeAssociations(); - return associations.toArray(new IThemeAssociation[associations.size()]); + return associations.toArray(IThemeAssociation[]::new); } @Override diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java index 11bcffb67..9d6f38ffd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java @@ -84,9 +84,9 @@ IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { IThemeAssociation[] getThemeAssociations(boolean isDefault) { /*if (isDefault) { return getThemeAssociations().stream().filter(theme -> theme.isDefault()).collect(Collectors.toList()) - .toArray(new IThemeAssociation[0]); + .toArray(IThemeAssociation[]::new); }*/ - return getThemeAssociations().toArray(new IThemeAssociation[allAssociations.size()]); + return getThemeAssociations().toArray(IThemeAssociation[]::new); } IThemeAssociation getDefaultAssociation() { @@ -95,7 +95,7 @@ IThemeAssociation getDefaultAssociation() { IThemeAssociation[] getThemeAssociationsForTheme(String themeId) { return getThemeAssociations().stream().filter(themeAssociation -> themeId.equals(themeAssociation.getThemeId())) - .collect(Collectors.toList()).toArray(new IThemeAssociation[0]); + .collect(Collectors.toList()).toArray(IThemeAssociation[]::new); } boolean hasThemeAssociationsForTheme(String themeId, String eclipseThemeId) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java index f5ec6c7cf..a08a34b4f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java @@ -123,7 +123,7 @@ void unregister(IThemeAssociation association) { // userAssociations.add(defaultAssociation); // } // }*/ - // return userAssociations.toArray(new IThemeAssociation[0]); + // return userAssociations.toArray(IThemeAssociation[]::new); // } // return getThemeAssociations(true); // } From 974942d0b8a9d04711b6f6c25c6c80e0130aa212 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 19:24:50 +0200 Subject: [PATCH 078/202] Replace lambdas with method references --- .../tm4e/core/grammar/GrammarSuiteTest.java | 14 +++++++------- ...tLanguageConfigurationRegistryManager.java | 4 ++-- .../LanguageConfigurationRegistryManager.java | 2 +- .../supports/CharacterPairSupport.java | 7 ++++--- .../internal/supports/OnEnterSupport.java | 19 ++++++++++--------- .../LanguageConfigurationInfoWidget.java | 3 ++- .../org/eclipse/tm4e/ui/text/TMEditor.java | 2 +- .../internal/themes/AbstractThemeManager.java | 3 +-- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java index d5df4ae72..2f1a32d53 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java @@ -33,7 +33,7 @@ /** * VSCode TextMate grammar tests which uses same vscode-textmate tests located * at src\test\resources\test-cases - * + * * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts * */ @@ -42,19 +42,19 @@ public class GrammarSuiteTest { private static final File REPO_ROOT = new File("src/test/resources"); // TODO: fix thoses tests: - // It seems that problem comes from with encoding. OnigString should support UTF-16 like https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc + // It seems that problem comes from with encoding. OnigString should support UTF-16 like https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66"); @TestFactory @DisplayName("Tokenization /first-mate/") Collection firstMate() throws Exception { return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/first-mate/tests.json")); } - + @TestFactory @DisplayName("Tokenization /suite1/ tests.json") Collection testsJSon() throws Exception { return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/tests.json")); } - + @TestFactory @DisplayName("Tokenization /suite1/ whileTests.json") Collection whileTests() throws Exception { return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/whileTests.json")); @@ -69,12 +69,12 @@ private List createVSCodeTestSuite(File testLocation) throws Excep for (RawTestImpl test : tests) { if (!IGNORE_TESTS.contains(test.getDesc())) { test.setTestLocation(testLocation); - dynamicTests.add(DynamicTest.dynamicTest(test.getDesc(), () -> test.executeTest())); + dynamicTests.add(DynamicTest.dynamicTest(test.getDesc(), test::executeTest)); } } return dynamicTests; } - + @TestFactory @DisplayName("Matcher tests") Collection dynamicTestsWithCollection() throws JsonIOException, JsonSyntaxException, FileNotFoundException { Type listType = new TypeToken>() { @@ -84,7 +84,7 @@ Collection dynamicTestsWithCollection() throws JsonIOException, Jso List dynamicTests = new ArrayList<>(); int i = 0; for (MatcherTestImpl test : tests) { - dynamicTests.add(DynamicTest.dynamicTest("Test #" + (i++), () -> test.executeTest())); + dynamicTests.add(DynamicTest.dynamicTest("Test #" + (i++), test::executeTest)); } return dynamicTests; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java index 0fa5f69d4..b762408ac 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java @@ -29,8 +29,8 @@ public abstract class AbstractLanguageConfigurationRegistryManager implements IL @Override public ILanguageConfigurationDefinition[] getDefinitions() { Set definitions = new HashSet<>(); - userDefinitions.values().forEach(definition -> definitions.add(definition)); - pluginDefinitions.values().forEach(definition -> definitions.add(definition)); + userDefinitions.values().forEach(definitions::add); + pluginDefinitions.values().forEach(definitions::add); return definitions.toArray(ILanguageConfigurationDefinition[]::new); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java index f14730886..52ced048c 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java @@ -272,7 +272,7 @@ public void save() throws BackingStoreException { // Save grammar definitions in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.languageconfiguration.prefs" List definitions = new ArrayList<>(); - userDefinitions.values().forEach(definition -> definitions.add(definition)); + userDefinitions.values().forEach(definitions::add); pluginDefinitions.values().forEach(definition -> { if (!(definition.isBracketAutoClosingEnabled() && definition.isMatchingPairsEnabled() && definition.isOnEnterEnabled())) { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java index 624b2401f..d8bef8a1e 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -27,11 +28,11 @@ public final class CharacterPairSupport { public CharacterPairSupport(List brackets, List autoClosingPairs, List surroundingPairs) { if (autoClosingPairs != null) { - this.autoClosingPairs = autoClosingPairs.stream().filter(el -> el != null) + this.autoClosingPairs = autoClosingPairs.stream().filter(Objects::nonNull) .map(el -> new AutoClosingPairConditional(el.getKey(), el.getValue(), el.getNotIn())) .collect(Collectors.toList()); } else if (brackets != null) { - this.autoClosingPairs = brackets.stream().filter(el -> el != null) + this.autoClosingPairs = brackets.stream().filter(Objects::nonNull) .map(el -> new AutoClosingPairConditional(el.getKey(), el.getValue(), null)) .collect(Collectors.toList()); } else { @@ -39,7 +40,7 @@ public CharacterPairSupport(List brackets, List el != null).collect(Collectors.toList()) + ? surroundingPairs.stream().filter(Objects::nonNull).collect(Collectors.toList()) : this.autoClosingPairs; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java index 799b6175f..eedf7e708 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.supports; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -34,8 +35,8 @@ public class OnEnterSupport { private final List regExpRules; public OnEnterSupport(List brackets, List regExpRules) { - this.brackets = (brackets != null ? brackets : DEFAULT_BRACKETS).stream().filter(el -> el != null) - .map((bracket -> new ProcessedBracketPair(bracket.getKey(), bracket.getValue()))).collect(Collectors.toList()); + this.brackets = (brackets != null ? brackets : DEFAULT_BRACKETS).stream().filter(Objects::nonNull) + .map(ProcessedBracketPair::new).collect(Collectors.toList()); this.regExpRules = regExpRules != null ? regExpRules : Collections.emptyList(); } @@ -81,9 +82,9 @@ private static final class ProcessedBracketPair { private final Pattern openRegExp; private final Pattern closeRegExp; - private ProcessedBracketPair(String open, String close) { - openRegExp = createOpenBracketRegExp(open); - closeRegExp = createCloseBracketRegExp(close); + private ProcessedBracketPair(final CharacterPair charPair) { + openRegExp = createOpenBracketRegExp(charPair.getKey()); + closeRegExp = createCloseBracketRegExp(charPair.getValue()); } private boolean matchOpen(String beforeEnterText) { @@ -105,7 +106,7 @@ private static Pattern createOpenBracketRegExp(String bracket) { } private static Pattern createCloseBracketRegExp(String bracket) { - final StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); + final StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); String c = String.valueOf(str.charAt(str.length() - 1)); if (!B_REGEXP.matcher(c).find()) { str.append("\\b"); //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java index 6c7c80120..4eb1f48c3 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java @@ -12,6 +12,7 @@ package org.eclipse.tm4e.languageconfiguration.internal.widgets; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import org.eclipse.jface.layout.TableColumnLayout; @@ -134,7 +135,7 @@ private List removeNullElements(List list) { if (list == null) { return null; } - return list.stream().filter(el -> el != null).collect(Collectors.toList()); + return list.stream().filter(Objects::nonNull).collect(Collectors.toList()); } private void createCommentsTab(TabFolder folder) { diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java index e5b0b6691..d505c5296 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java @@ -87,7 +87,7 @@ public List execute() { for (ICommand command : commands) { collector.executeCommand((Command) command); } - shell.getDisplay().syncExec(() -> shell.dispose()); + shell.getDisplay().syncExec(shell::dispose); }).start(); Display display = shell.getDisplay(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index d789c75a9..f556d94ad 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -73,8 +73,7 @@ ITheme getDefaultTheme(boolean dark) { @Override public ITheme[] getThemes(boolean dark) { - Collection themes = this.themes.values(); - return themes.stream().filter(theme -> (theme.isDark() == dark)) + return themes.values().stream().filter(theme -> theme.isDark() == dark) .collect(Collectors.toList()).toArray(ITheme[]::new); } From 17643c6ea22d97e864020006507ad0975a5facd9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 19:26:29 +0200 Subject: [PATCH 079/202] Replace Collections.EMPTY_LIST with Collections.emptyList() --- .../internal/widgets/CharacterPairsTableWidget.java | 2 +- .../internal/widgets/OnEnterRuleTableWidget.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java index a25667452..63d3221bd 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java @@ -71,7 +71,7 @@ public Object[] getElements(Object input) { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (newInput == null) { - characterPairList = Collections.EMPTY_LIST; + characterPairList = Collections.emptyList(); } else { characterPairList = (List) newInput; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java index 93020382e..5fda3298d 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java @@ -87,7 +87,7 @@ public Object[] getElements(Object input) { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (newInput == null) { - onEnterRulesList = Collections.EMPTY_LIST; + onEnterRulesList = Collections.emptyList(); } else { onEnterRulesList = (List) newInput; } From 2069f2490fe43d693b60be3476447f6873eca2dc Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 19:29:13 +0200 Subject: [PATCH 080/202] Fix typo --- .../resources/test-cases/first-mate/fixtures/ruby.json | 2 +- .../test/resources/test-cases/suite1/fixtures/Ruby.plist | 2 +- .../test/resources/test-cases/themes/syntaxes/Ruby.plist | 2 +- .../internal/supports/CharacterPairSupport.java | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby.json b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby.json index 17e49e19c..dfc6c8cbb 100644 --- a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby.json +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby.json @@ -219,7 +219,7 @@ "name": "variable.other.constant.ruby" }, { - "begin": "(?x)\n\t\t\t (?=def\\b) # an optimization to help Oniguruma fail fast\n\t\t\t (?<=^|\\s)(def)\\s+ # the def keyword\n\t\t\t ( (?>[a-zA-Z_]\\w*(?>\\.|::))? # a method name prefix\n\t\t\t (?>[a-zA-Z_]\\w*(?>[?!]|=(?!>))? # the method name\n\t\t\t |===?|>[>=]?|<=>|<[<=]?|[%&`/\\|]|\\*\\*?|=?~|[-+]@?|\\[\\]=?) ) # …or an operator method\n\t\t\t \\s*(\\() # the openning parenthesis for arguments\n\t\t\t ", + "begin": "(?x)\n\t\t\t (?=def\\b) # an optimization to help Oniguruma fail fast\n\t\t\t (?<=^|\\s)(def)\\s+ # the def keyword\n\t\t\t ( (?>[a-zA-Z_]\\w*(?>\\.|::))? # a method name prefix\n\t\t\t (?>[a-zA-Z_]\\w*(?>[?!]|=(?!>))? # the method name\n\t\t\t |===?|>[>=]?|<=>|<[<=]?|[%&`/\\|]|\\*\\*?|=?~|[-+]@?|\\[\\]=?) ) # …or an operator method\n\t\t\t \\s*(\\() # the opening parenthesis for arguments\n\t\t\t ", "beginCaptures": { "1": { "name": "keyword.control.def.ruby" diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Ruby.plist b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Ruby.plist index fd18e0930..053a01300 100644 --- a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Ruby.plist +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Ruby.plist @@ -380,7 +380,7 @@ ( (?>[a-zA-Z_]\w*(?>\.|::))? # a method name prefix (?>[a-zA-Z_]\w*(?>[?!]|=(?!>))? # the method name |===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?) ) # …or an operator method - \s*(\() # the openning parenthesis for arguments + \s*(\() # the opening parenthesis for arguments beginCaptures diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Ruby.plist b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Ruby.plist index 04e41fabb..909581a5f 100644 --- a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Ruby.plist +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Ruby.plist @@ -381,7 +381,7 @@ ( (?>[a-zA-Z_]\w*(?>\.|::))? # a method name prefix (?>[a-zA-Z_]\w*(?>[?!]|=(?!>))? # the method name |===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?) ) # …or an operator method - \s*(\() # the openning parenthesis for arguments + \s*(\() # the opening parenthesis for arguments beginCaptures diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java index d8bef8a1e..b119b99fd 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java @@ -50,13 +50,13 @@ public CharacterPair getAutoClosePair(String text, Integer offset, return null; } for (CharacterPair autoClosingPair : autoClosingPairs) { - String openning = autoClosingPair.getKey(); - if (!openning.endsWith(newCharacter)) { + String opening = autoClosingPair.getKey(); + if (!opening.endsWith(newCharacter)) { continue; } - if (openning.length() > 1) { + if (opening.length() > 1) { String offsetPrefix = text.substring(0, offset); - if (!offsetPrefix.endsWith(openning.substring(0, openning.length() - 1))) { + if (!offsetPrefix.endsWith(opening.substring(0, opening.length() - 1))) { continue; } } From 7ed324270eb108f0c68b5c83f7bc93bffe9ae976 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 19:30:54 +0200 Subject: [PATCH 081/202] Fix potential NPE --- .../java/org/eclipse/tm4e/core/internal/matcher/Matcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java index d630f5a65..1bf32ef0a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java @@ -81,10 +81,10 @@ private Predicate parseInnerExpression() { Predicate matcher = parseConjunction(); while (matcher != null) { matchers.add(matcher); - if (token.equals("|") || token.equals(",")) { + if ("|".equals(token) || ",".equals(token)) { do { token = tokenizer.next(); - } while (token.equals("|") || token.equals(",")); // ignore subsequent + } while ("|".equals(token) || ",".equals(token)); // ignore subsequent // commas } else { break; From c6d54e314784a2504e200056a481077ab09bc827 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 19:42:34 +0200 Subject: [PATCH 082/202] Ignore false-positive NPE compiler warning --- .../org/eclipse/tm4e/core/theme/ThemeTrieElement.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java index 293823fc4..334aa43b2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java @@ -58,8 +58,12 @@ private static int cmpBySpecificity(ThemeTrieElementRule a, ThemeTrieElementRule int bParentScopesLen = bParentScopes == null ? 0 : bParentScopes.size(); if (aParentScopesLen == bParentScopesLen) { for (int i = 0; i < aParentScopesLen; i++) { - int aLen = aParentScopes.get(i).length(); - int bLen = bParentScopes.get(i).length(); + @SuppressWarnings("null") + String aScope = aParentScopes.get(i); + @SuppressWarnings("null") + String bScope = bParentScopes.get(i); + int aLen = aScope.length(); + int bLen = bScope.length(); if (aLen != bLen) { return bLen - aLen; } From 34172ff40e9ae502dc03b0ac42e1698269f6c7d2 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 20 Apr 2022 19:46:54 +0200 Subject: [PATCH 083/202] Parameterize generic type Class --- .../src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java index ccfce1ed5..998e497ed 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java @@ -20,7 +20,7 @@ public class ClassHelper { @SuppressWarnings("unchecked") - public static T getFieldValue(Object object, String name, Class clazz) { + public static T getFieldValue(Object object, String name, Class clazz) { Field f = getDeclaredField(clazz, name); if (f != null) { try { @@ -36,7 +36,7 @@ public static T getFieldValue(Object object, String name) { return getFieldValue(object, name, object.getClass()); } - public static Field getDeclaredField(Class clazz, String name) { + public static Field getDeclaredField(Class clazz, String name) { if (clazz == null) { return null; } From 843f8df42f0ab7dd4e50099a1d6999a10d719ace Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 11:24:08 +0000 Subject: [PATCH 084/202] fix(deps): bump maven-javadoc-plugin from 3.3.2 to 3.4.0 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.2 to 3.4.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.2...maven-javadoc-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1da402fda..d8efdf5af 100644 --- a/pom.xml +++ b/pom.xml @@ -214,7 +214,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.2 + 3.4.0 true From 6fa964be2f10278c8a6b6f43d9c99bbc68e25387 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 15:46:32 +0200 Subject: [PATCH 085/202] Fix "Javadoc: Invalid URL reference." --- .../tm4e/core/grammar/GrammarSuiteTest.java | 27 ++++++++++-------- .../tm4e/core/theme/ThemeMatchingTest.java | 28 +++++++++---------- .../tm4e/core/theme/ThemeParsingTest.java | 17 +++++------ .../tm4e/core/theme/ThemeResolvingTest.java | 19 +++++++------ .../eclipse/tm4e/core/grammar/IGrammar.java | 11 ++++---- .../tm4e/core/grammar/IGrammarRepository.java | 9 +++--- .../core/grammar/ITokenizeLineResult.java | 11 ++++---- .../core/grammar/ITokenizeLineResult2.java | 5 ++-- .../tm4e/core/grammar/StackElement.java | 3 +- .../tm4e/core/internal/grammar/Grammar.java | 11 ++++---- .../tm4e/core/internal/matcher/Matcher.java | 3 +- .../core/internal/oniguruma/OnigRegExp.java | 14 +++++----- .../core/internal/oniguruma/OnigString.java | 21 +++++++------- .../tm4e/core/internal/rule/RegExpSource.java | 9 +++--- .../core/internal/rule/RegExpSourceList.java | 3 +- .../tm4e/core/internal/rule/RuleFactory.java | 9 +++--- .../eclipse/tm4e/core/registry/Registry.java | 3 +- .../eclipse/tm4e/core/theme/FontStyle.java | 10 +++---- .../tm4e/core/theme/IRawThemeSetting.java | 11 ++++---- .../core/internal/grammar/GrammarTest.java | 10 +++---- .../internal/LanguageConfiguration.java | 4 ++- 21 files changed, 130 insertions(+), 108 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java index 2f1a32d53..52a2f2a0c 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.grammar; @@ -34,7 +34,8 @@ * VSCode TextMate grammar tests which uses same vscode-textmate tests located * at src\test\resources\test-cases * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts * */ public class GrammarSuiteTest { @@ -42,26 +43,29 @@ public class GrammarSuiteTest { private static final File REPO_ROOT = new File("src/test/resources"); // TODO: fix thoses tests: - // It seems that problem comes from with encoding. OnigString should support UTF-16 like https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc + // It seems that problem comes from with encoding. OnigString should support UTF-16 like + // https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66"); - @TestFactory @DisplayName("Tokenization /first-mate/") + @TestFactory + @DisplayName("Tokenization /first-mate/") Collection firstMate() throws Exception { return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/first-mate/tests.json")); } - @TestFactory @DisplayName("Tokenization /suite1/ tests.json") + @TestFactory + @DisplayName("Tokenization /suite1/ tests.json") Collection testsJSon() throws Exception { return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/tests.json")); } - @TestFactory @DisplayName("Tokenization /suite1/ whileTests.json") + @TestFactory + @DisplayName("Tokenization /suite1/ whileTests.json") Collection whileTests() throws Exception { return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/whileTests.json")); } - - private List createVSCodeTestSuite(File testLocation) throws Exception { + private List createVSCodeTestSuite(File testLocation) throws Exception { Type listType = new TypeToken>() { }.getType(); List tests = new GsonBuilder().create().fromJson(new FileReader(testLocation), listType); @@ -75,7 +79,8 @@ private List createVSCodeTestSuite(File testLocation) throws Excep return dynamicTests; } - @TestFactory @DisplayName("Matcher tests") + @TestFactory + @DisplayName("Matcher tests") Collection dynamicTestsWithCollection() throws JsonIOException, JsonSyntaxException, FileNotFoundException { Type listType = new TypeToken>() { }.getType(); diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java index 0af252213..428a8c622 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; @@ -25,8 +25,9 @@ import org.junit.jupiter.api.Test; /** - * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts * */ class ThemeMatchingTest { @@ -76,7 +77,7 @@ void testGivesHigherPriorityToParentMatches1() throws Exception { int _C = colorMap.getId("#500000"); int _D = colorMap.getId("#300000"); int _E = colorMap.getId("#400000"); - + List actual = theme.match("a.b"); assertArrayEquals(new ThemeTrieElementRule[] { @@ -84,7 +85,7 @@ void testGivesHigherPriorityToParentMatches1() throws Exception { new ThemeTrieElementRule(1, Arrays.asList("c"), FontStyle.NotSet, _D, _NOT_SET), new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET) }, actual.toArray()); } - + @Test void testGivesHigherPriorityToParentMatches2() throws Exception { Theme theme = loadTheme("{" + @@ -107,7 +108,7 @@ void testGivesHigherPriorityToParentMatches2() throws Exception { @Test void testCanMatch() throws Exception { - Theme theme = loadTheme("{" + + Theme theme = loadTheme("{" + "\"settings\": ["+ "{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } },"+ "{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } },"+ @@ -132,7 +133,7 @@ void testCanMatch() throws Exception { int _F = colorMap.getId("#500000"); int _G = colorMap.getId("#100000"); int _H = colorMap.getId("#600000"); - + // matches defaults assertNoMatch(theme, ""); assertNoMatch(theme, "bazz"); @@ -189,8 +190,8 @@ void testCanMatch() throws Exception { new ThemeTrieElementRule[] { new ThemeTrieElementRule(1, Arrays.asList("selector", "source.css"), FontStyle.Bold, _NOT_SET, _C), new ThemeTrieElementRule(1, null, FontStyle.NotSet, _NOT_SET, _C) }); - } - + } + @Test void testMicrosoft_vscode_23460() throws Exception { Theme theme = loadTheme("{" + @@ -228,7 +229,6 @@ void testMicrosoft_vscode_23460() throws Exception { int _C = colorMap.getId("#FF410D"); int _D = colorMap.getId("#ffffff"); - // string.quoted.double.json // meta.structure.dictionary.value.json // meta.structure.dictionary.json @@ -251,7 +251,7 @@ void testMicrosoft_vscode_23460() throws Exception { String color = theme.getColor(StackElementMetadata.getForeground(r)); assertEquals("#FF410D", color); } - + private void assertMatch(Theme theme, String scopeName, ThemeTrieElementRule[] expected) { List actual = theme.match(scopeName); assertArrayEquals(expected, actual.toArray(), "when matching <<" + scopeName + ">>"); @@ -268,7 +268,7 @@ private void assertNoMatch(Theme theme, String scopeName) { new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0 /*_NOT_SET, _NOT_SET*/) }); } - + private Theme loadTheme(String theme) throws Exception { return Theme.createFromRawTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes()))); } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java index 695e8df2c..5b7d8b144 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; @@ -21,15 +21,16 @@ import org.junit.jupiter.api.Test; /** - * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts * */ public class ThemeParsingTest { @Test public void testCanParse() throws Exception { - List actual = parseTheme("{" + + List actual = parseTheme("{" + "\"settings\": [" + "{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } }," + "{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } }," + @@ -61,8 +62,8 @@ public void testCanParse() throws Exception { new ParsedThemeRule("foo", null, 9, FontStyle.None, "#CFA", null), }; assertArrayEquals(expected, actual.toArray()); - } - + } + private List parseTheme(String theme) throws Exception { return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes()))); } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java index a487b2bb4..662612d73 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; @@ -27,8 +27,9 @@ import org.junit.jupiter.api.Test; /** - * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts * */ public class ThemeResolvingTest { @@ -301,7 +302,7 @@ public void testRulesWithParentScopes() { Collections.emptyList(), mapRoot)); assertEquals(actual, expected); } - + @Test public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception { List actual = parseTheme("{" + @@ -357,7 +358,7 @@ public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception { assertArrayEquals(expected.toArray(), actual.toArray()); } - + @Test public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exception { List actual = parseTheme("{" + @@ -394,11 +395,11 @@ public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exc assertArrayEquals(expected.toArray(), actual.toArray()); } - + private void assertStrArrCmp(String testCase, List a, List b, int expected) { assertEquals(expected, CompareUtils.strArrCmp(a, b), testCase); } - + private List parseTheme(String theme) throws Exception { return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes()))); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java index bff5be455..ffa82210e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.grammar; @@ -20,8 +20,9 @@ /** * TextMate grammar API. - * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts * */ public interface IGrammar { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammarRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammarRepository.java index f13f298e6..3314f8245 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammarRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammarRepository.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.grammar; @@ -23,7 +23,8 @@ /** * TextMate grammar repository API. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts * */ public interface IGrammarRepository { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java index ecc16be53..288e7d632 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,15 +11,16 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.grammar; /** * Result of the line tokenization API. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts */ public interface ITokenizeLineResult { @@ -27,7 +28,7 @@ public interface ITokenizeLineResult { /** * Returns the `prevState` to be passed on to the next line tokenization. - * + * * @return the `prevState` to be passed on to the next line tokenization. */ StackElement getRuleStack(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java index 4b57ca3de..d22948895 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java @@ -19,7 +19,8 @@ /** * Result of the line tokenization2 API. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts */ public interface ITokenizeLineResult2 { @@ -32,7 +33,7 @@ public interface ITokenizeLineResult2 { /** * Returns the `prevState` to be passed on to the next line tokenization. - * + * * @return the `prevState` to be passed on to the next line tokenization. */ StackElement getRuleStack(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java index 4b2250b23..b1ed7f9bf 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java @@ -27,7 +27,8 @@ /** * Represents a "pushed" state on the stack (as a linked list element). * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts * */ public class StackElement { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index c31b8a2dd..d0831de2b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,9 +11,9 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - * - Fabio Zadrozny - Not adding '\n' on tokenize if it already finished with '\n' + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java + * - Fabio Zadrozny - Not adding '\n' on tokenize if it already finished with '\n' */ package org.eclipse.tm4e.core.internal.grammar; @@ -49,7 +49,8 @@ /** * TextMate grammar implementation. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts * */ public final class Grammar implements IGrammar, IRuleFactoryHelper { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java index 1bf32ef0a..744a8e49e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java @@ -25,7 +25,8 @@ /** * Matcher utilities. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/matcher.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/matcher.ts * */ public final class Matcher implements Predicate { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java index 871439175..2f153803b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,10 +11,10 @@ * Initial license: MIT * * Contributors: - * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - * - Fabio Zadrozny - Convert uniqueId to Object (for identity compare) - * - Fabio Zadrozny - Fix recursion error on creation of OnigRegExp with unicode chars + * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java + * - Fabio Zadrozny - Convert uniqueId to Object (for identity compare) + * - Fabio Zadrozny - Fix recursion error on creation of OnigRegExp with unicode chars */ package org.eclipse.tm4e.core.internal.oniguruma; @@ -33,8 +33,8 @@ /** * - * @see https://github.com/atom/node-oniguruma/blob/master/src/onig-reg-exp.cc - * + * @see + * github.com/atom/node-oniguruma/blob/master/src/onig-reg-exp.cc * */ final class OnigRegExp { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java index 77d28d89a..d9d65949d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,10 +11,10 @@ * Initial license: MIT * * Contributors: - * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - * - Fabio Zadrozny - Convert uniqueId to Object (for identity compare) - * - Fabio Zadrozny - Utilities to convert between utf-8 and utf-16 + * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java + * - Fabio Zadrozny - Convert uniqueId to Object (for identity compare) + * - Fabio Zadrozny - Utilities to convert between utf-8 and utf-16 */ package org.eclipse.tm4e.core.internal.oniguruma; @@ -26,7 +26,8 @@ /** * Oniguruma string. * - * @see https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc + * @see + * github.com/atom/node-oniguruma/blob/master/src/onig-string.cc * */ public final class OnigString { @@ -43,7 +44,7 @@ public OnigString(String str) { } int convertUtf16OffsetToUtf8(int posInChars) { - if(!computedOffsets) { + if (!computedOffsets) { computeOffsets(); } if (charsPosFromBytePos == null) { @@ -83,7 +84,7 @@ int convertUtf16OffsetToUtf8(int posInChars) { } int convertUtf8OffsetToUtf16(int posInBytes) { - if(!computedOffsets) { + if (!computedOffsets) { computeOffsets(); } if (charsPosFromBytePos == null) { @@ -114,8 +115,8 @@ private void computeOffsets() { i += codeLen; charsLen += 1; } - if(bytesLen != this.utf8_value.length) { - throw new AssertionError(bytesLen + " != "+this.utf8_value.length); + if (bytesLen != this.utf8_value.length) { + throw new AssertionError(bytesLen + " != " + this.utf8_value.length); } } computedOffsets = true; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index a2ff9ae61..0b7cddcbb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; @@ -26,7 +26,8 @@ /** * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts * */ final class RegExpSource { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index 5007d07f9..f8c322db1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -24,7 +24,8 @@ /** * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts * */ final class RegExpSourceList { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index 03b52473f..032924f94 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; @@ -28,7 +28,8 @@ /** * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts * */ public final class RuleFactory { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index 964a0e1ec..f6ce201bb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -36,7 +36,8 @@ /** * The registry that will hold all grammars. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts * */ public class Registry { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java index 0a2c70965..b70bb6fa4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java @@ -1,21 +1,21 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; /** * Font style definitions. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts - * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts */ public class FontStyle { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java index 095813d4a..f833b7698 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java @@ -1,20 +1,21 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; /** * A single theme setting. - * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/main.ts + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts */ public interface IRawThemeSetting { diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java index e25529ba9..1a3e0bbdd 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.grammar; @@ -18,8 +18,8 @@ /** * {@link StackElementMetadata} tests same than vscode-textmate. * - * @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/grammar.test.ts - * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/tests/grammar.test.ts */ public class GrammarTest { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java index 2535188e8..b4efeac2c 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java @@ -33,7 +33,8 @@ /** * VSCode language-configuration.json * - * @see https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages + * @see + * code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages */ public final class LanguageConfiguration implements ILanguageConfiguration { @@ -42,6 +43,7 @@ public final class LanguageConfiguration implements ILanguageConfiguration { * language-configuration.json file reader. * * @param reader + * * @return an instance of {@link LanguageConfiguration} loaded from the VSCode * language-configuration.json file reader. */ From 26dc1c3e1ce66ea1238f8f77a35f917962102989 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 15:48:30 +0200 Subject: [PATCH 086/202] Replace StringBuffer usage with StringBuilder --- .../org/eclipse/tm4e/core/internal/rule/RegExpSource.java | 4 ++-- .../org/eclipse/tm4e/core/internal/utils/RegexSource.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index 0b7cddcbb..4e9633f28 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -128,7 +128,7 @@ String resolveBackReferences(String lineText, IOnigCaptureIndex[] captureIndices List capturedValues = Arrays.stream(captureIndices) .map(capture -> lineText.substring(capture.getStart(), capture.getEnd())).collect(Collectors.toList()); Matcher m = BACK_REFERENCING_END.matcher(this.source); - StringBuffer sb = new StringBuffer(); + final StringBuilder sb = new StringBuilder(); while (m.find()) { String g1 = m.group(); int index = Integer.parseInt(g1.substring(1)); @@ -147,7 +147,7 @@ String resolveBackReferences(String lineText, IOnigCaptureIndex[] captureIndices private String escapeRegExpCharacters(String value) { Matcher m = REGEXP_CHARACTERS.matcher(value); - StringBuffer sb = new StringBuffer(); + final StringBuilder sb = new StringBuilder(); while (m.find()) { m.appendReplacement(sb, "\\\\\\\\" + m.group()); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index dd2bc9587..b37394500 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -41,7 +41,7 @@ public static boolean hasCaptures(String regexSource) { public static String replaceCaptures(String regexSource, String captureSource, IOnigCaptureIndex[] captureIndices) { Matcher m = CAPTURING_REGEX_SOURCE.matcher(regexSource); - StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); while (m.find()) { String match = m.group(); String replacement = getReplacement(match, captureSource, captureIndices); From eecc5ba9953f431d44fb7474f696ae9c69ca7cfc Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 15:50:32 +0200 Subject: [PATCH 087/202] Remove unnecessary null check --- .../java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java index 46aae559c..bcde73d9c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java @@ -313,7 +313,7 @@ public Object put(String key, Object value) { @Override @SuppressWarnings("unlikely-arg-type") public void putAll(Map m) { - if (m != null && m.containsKey(FILE_TYPES)) + if (m.containsKey(FILE_TYPES)) fileTypes = null; super.putAll(m); } From 3e0bad367b4d097906861067ff9d6853db5cf29c Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 15:59:05 +0200 Subject: [PATCH 088/202] Rename types with 'I' prefix which are classes and not interfaces --- .../core/internal/grammar/LineTokenizer.java | 8 ++++---- .../tm4e/core/internal/rule/BeginEndRule.java | 4 ++-- .../core/internal/rule/BeginWhileRule.java | 6 +++--- .../tm4e/core/internal/rule/CaptureRule.java | 2 +- ...sResult.java => CompilePatternsResult.java} | 4 ++-- .../{ICompiledRule.java => CompiledRule.java} | 4 ++-- .../core/internal/rule/IncludeOnlyRule.java | 4 ++-- .../tm4e/core/internal/rule/MatchRule.java | 2 +- .../tm4e/core/internal/rule/RegExpSource.java | 6 +++--- ...Cache.java => RegExpSourceAnchorCache.java} | 4 ++-- .../core/internal/rule/RegExpSourceList.java | 18 +++++++++--------- .../eclipse/tm4e/core/internal/rule/Rule.java | 2 +- .../tm4e/core/internal/rule/RuleFactory.java | 4 ++-- 13 files changed, 34 insertions(+), 34 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/{ICompilePatternsResult.java => CompilePatternsResult.java} (87%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/{ICompiledRule.java => CompiledRule.java} (90%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/{IRegExpSourceAnchorCache.java => RegExpSourceAnchorCache.java} (87%) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 4edc5ea30..a671c5586 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -33,7 +33,7 @@ import org.eclipse.tm4e.core.internal.rule.BeginEndRule; import org.eclipse.tm4e.core.internal.rule.BeginWhileRule; import org.eclipse.tm4e.core.internal.rule.CaptureRule; -import org.eclipse.tm4e.core.internal.rule.ICompiledRule; +import org.eclipse.tm4e.core.internal.rule.CompiledRule; import org.eclipse.tm4e.core.internal.rule.MatchRule; import org.eclipse.tm4e.core.internal.rule.Rule; @@ -264,7 +264,7 @@ private void scanNext() { private IMatchResult matchRule(Grammar grammar, OnigString lineText, boolean isFirstLine, final int linePos, StackElement stack, int anchorPosition) { Rule rule = stack.getRule(grammar); - final ICompiledRule ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos == anchorPosition); + final CompiledRule ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos == anchorPosition); final IOnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); if (r != null) { @@ -337,7 +337,7 @@ private IMatchInjectionsResult matchInjections(List injections, Gramm continue; } - ICompiledRule ruleScanner = grammar.getRule(injection.ruleId).compile(grammar, null, isFirstLine, + CompiledRule ruleScanner = grammar.getRule(injection.ruleId).compile(grammar, null, isFirstLine, linePos == anchorPosition); IOnigNextMatchResult matchResult = ruleScanner.scanner.findNextMatchSync(lineText, linePos); @@ -487,7 +487,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe } for (int i = whileRules.size() - 1; i >= 0; i--) { WhileStack whileRule = whileRules.get(i); - ICompiledRule ruleScanner = whileRule.rule.compileWhile(grammar, whileRule.stack.endRule, isFirstLine, + CompiledRule ruleScanner = whileRule.rule.compileWhile(grammar, whileRule.stack.endRule, isFirstLine, currentanchorPosition == linePos); IOnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); // if (IN_DEBUG_MODE) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index 392359de2..bbdfc306e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -33,7 +33,7 @@ public final class BeginEndRule extends Rule { private RegExpSourceList cachedCompiledPatterns; BeginEndRule(int id, String name, String contentName, String begin, List beginCaptures, - String end, List endCaptures, boolean applyEndPatternLast, ICompilePatternsResult patterns) { + String end, List endCaptures, boolean applyEndPatternLast, CompilePatternsResult patterns) { super(id, name, contentName); this.begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; @@ -62,7 +62,7 @@ void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boole } @Override - public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { RegExpSourceList precompiled = this.precompile(grammar); if (this.end.hasBackReferences()) { if (this.applyEndPatternLast) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index 07477ed4e..1c72967b9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -34,7 +34,7 @@ public final class BeginWhileRule extends Rule { BeginWhileRule(/* $location:ILocation, */ int id, String name, String contentName, String begin, List beginCaptures, String _while, List whileCaptures, - ICompilePatternsResult patterns) { + CompilePatternsResult patterns) { super(/* $location, */id, name, contentName); this.begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; @@ -63,7 +63,7 @@ void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boole } @Override - public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { this.precompile(grammar); return this.cachedCompiledPatterns.compile(grammar, allowA, allowG); } @@ -75,7 +75,7 @@ private void precompile(IRuleRegistry grammar) { } } - public ICompiledRule compileWhile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compileWhile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { this.precompileWhile(); if (this._while.hasBackReferences()) { this.cachedCompiledWhilePatterns.setSource(0, endRegexSource); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java index 4ff8b6ac4..55b208651 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java @@ -31,7 +31,7 @@ void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boole } @Override - public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { throw new UnsupportedOperationException(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java similarity index 87% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java index fa1fd9210..c1750b039 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompilePatternsResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java @@ -18,12 +18,12 @@ import java.util.Collection; -final class ICompilePatternsResult { +final class CompilePatternsResult { final Integer[] patterns; final boolean hasMissingPatterns; - ICompilePatternsResult(Collection patterns, boolean hasMissingPatterns) { + CompilePatternsResult(Collection patterns, boolean hasMissingPatterns) { this.hasMissingPatterns = hasMissingPatterns; this.patterns = patterns.toArray(Integer[]::new); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java similarity index 90% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java index ff829e011..9be77600c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/ICompiledRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java @@ -18,12 +18,12 @@ import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner; -public final class ICompiledRule { +public final class CompiledRule { public final OnigScanner scanner; public final Integer[] rules; - ICompiledRule(OnigScanner scanner, Integer[] rules) { + CompiledRule(OnigScanner scanner, Integer[] rules) { this.scanner = scanner; this.rules = rules; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java index fa71ed9b0..f16a91bd6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java @@ -22,7 +22,7 @@ final class IncludeOnlyRule extends Rule { final Integer[] patterns; private RegExpSourceList cachedCompiledPatterns; - IncludeOnlyRule(int id, String name, String contentName, ICompilePatternsResult patterns) { + IncludeOnlyRule(int id, String name, String contentName, CompilePatternsResult patterns) { super(id, name, contentName); this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; @@ -37,7 +37,7 @@ void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boole } @Override - public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { if (this.cachedCompiledPatterns == null) { this.cachedCompiledPatterns = new RegExpSourceList(); this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java index 59111415f..eb90329c1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java @@ -36,7 +36,7 @@ void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boole } @Override - public ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { if (this.cachedCompiledPatterns == null) { this.cachedCompiledPatterns = new RegExpSourceList(); this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index 4e9633f28..a46fcd59a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -40,7 +40,7 @@ final class RegExpSource { private final int ruleId; private boolean _hasAnchor; private final boolean _hasBackReferences; - private IRegExpSourceAnchorCache anchorCache; + private RegExpSourceAnchorCache anchorCache; private String source; RegExpSource(String regExpSource, int ruleId) { @@ -155,7 +155,7 @@ private String escapeRegExpCharacters(String value) { return sb.toString(); } - private IRegExpSourceAnchorCache _buildAnchorCache() { + private RegExpSourceAnchorCache _buildAnchorCache() { // Collection A0_G0_result=new ArrayList(); // Collection A0_G1_result=new ArrayList(); @@ -202,7 +202,7 @@ private IRegExpSourceAnchorCache _buildAnchorCache() { } } - return new IRegExpSourceAnchorCache(A0_G0_result.toString(), A0_G1_result.toString(), A1_G0_result.toString(), + return new RegExpSourceAnchorCache(A0_G0_result.toString(), A0_G1_result.toString(), A1_G0_result.toString(), A1_G1_result.toString() // StringUtils.join(A0_G0_result, ""), // StringUtils.join(A0_G1_result, ""), diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceAnchorCache.java similarity index 87% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceAnchorCache.java index 940b5d79a..502c4e2ed 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRegExpSourceAnchorCache.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceAnchorCache.java @@ -16,14 +16,14 @@ */ package org.eclipse.tm4e.core.internal.rule; -final class IRegExpSourceAnchorCache { +final class RegExpSourceAnchorCache { final String A0_G0; final String A0_G1; final String A1_G0; final String A1_G1; - IRegExpSourceAnchorCache(String A0_G0, String A0_G1, String A1_G0, String A1_G1) { + RegExpSourceAnchorCache(String A0_G0, String A0_G1, String A1_G0, String A1_G1) { this.A0_G0 = A0_G0; this.A0_G1 = A0_G1; this.A1_G0 = A1_G0; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index f8c322db1..f05741824 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -32,16 +32,16 @@ final class RegExpSourceList { private static final class RegExpSourceListAnchorCache { - private ICompiledRule A0_G0; - private ICompiledRule A0_G1; - private ICompiledRule A1_G0; - private ICompiledRule A1_G1; + private CompiledRule A0_G0; + private CompiledRule A0_G1; + private CompiledRule A1_G0; + private CompiledRule A1_G1; } private final List _items = new ArrayList<>(); private boolean _hasAnchors; - private ICompiledRule _cached; + private CompiledRule _cached; private final RegExpSourceListAnchorCache _anchorCache; RegExpSourceList() { @@ -75,14 +75,14 @@ void setSource(int index, String newSource) { } } - ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) { + CompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) { if (!this._hasAnchors) { if (this._cached == null) { List regexps = new ArrayList<>(); for (RegExpSource regExpSource : _items) { regexps.add(regExpSource.getSource()); } - this._cached = new ICompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); + this._cached = new CompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); } return this._cached; } @@ -117,12 +117,12 @@ ICompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) { return this._anchorCache.A0_G0; } - private ICompiledRule _resolveAnchors(boolean allowA, boolean allowG) { + private CompiledRule _resolveAnchors(boolean allowA, boolean allowG) { List regexps = new ArrayList<>(); for (RegExpSource regExpSource : _items) { regexps.add(regExpSource.resolveAnchors(allowA, allowG)); } - return new ICompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); + return new CompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); } private OnigScanner createOnigScanner(String[] regexps) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java index c4618ce61..8ca7ffb1f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java @@ -53,6 +53,6 @@ public String getContentName(String lineText, IOnigCaptureIndex[] captureIndices abstract void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst); - public abstract ICompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG); + public abstract CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG); } \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index 032924f94..2fcd0c808 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -138,7 +138,7 @@ private static int parseInt(String string, int base) { } } - private static ICompilePatternsResult _compilePatterns(Collection patterns, IRuleFactoryHelper helper, + private static CompilePatternsResult _compilePatterns(Collection patterns, IRuleFactoryHelper helper, IRawRepository repository) { Collection r = new ArrayList<>(); int patternId; @@ -237,7 +237,7 @@ private static ICompilePatternsResult _compilePatterns(Collection patt } } - return new ICompilePatternsResult(r, ((patterns != null ? patterns.size() : 0) != r.size())); + return new CompilePatternsResult(r, ((patterns != null ? patterns.size() : 0) != r.size())); } } From 3a4c65c627b28c0c80717890dddeefc56f6c361f Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 16:06:13 +0200 Subject: [PATCH 089/202] Remove unnecessary internal interfaces --- .../core/internal/grammar/LineTokenizer.java | 24 ++++---- .../core/internal/matcher/IMatchResult.java | 4 +- .../internal/oniguruma/IOnigCaptureIndex.java | 29 ---------- .../oniguruma/IOnigNextMatchResult.java | 25 -------- .../internal/oniguruma/OnigCaptureIndex.java | 56 ++++++++++++++++++ .../oniguruma/OnigNextMatchResult.java | 58 ++----------------- .../core/internal/oniguruma/OnigScanner.java | 4 +- .../tm4e/core/internal/rule/BeginEndRule.java | 4 +- .../core/internal/rule/BeginWhileRule.java | 4 +- .../tm4e/core/internal/rule/RegExpSource.java | 4 +- .../eclipse/tm4e/core/internal/rule/Rule.java | 6 +- .../tm4e/core/internal/utils/RegexSource.java | 8 +-- .../core/internal/oniguruma/TestOngurama.java | 2 +- 13 files changed, 92 insertions(+), 136 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index a671c5586..1aa4d2176 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -27,8 +27,8 @@ import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.matcher.IMatchInjectionsResult; import org.eclipse.tm4e.core.internal.matcher.IMatchResult; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigNextMatchResult; +import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; +import org.eclipse.tm4e.core.internal.oniguruma.OnigNextMatchResult; import org.eclipse.tm4e.core.internal.oniguruma.OnigString; import org.eclipse.tm4e.core.internal.rule.BeginEndRule; import org.eclipse.tm4e.core.internal.rule.BeginWhileRule; @@ -118,7 +118,7 @@ private void scanNext() { return; } - IOnigCaptureIndex[] captureIndices = r.getCaptureIndices(); + OnigCaptureIndex[] captureIndices = r.getCaptureIndices(); int matchedRuleId = r.getMatchedRuleId(); boolean hasAdvanced = (captureIndices != null && captureIndices.length > 0) @@ -265,7 +265,7 @@ private IMatchResult matchRule(Grammar grammar, OnigString lineText, boolean isF StackElement stack, int anchorPosition) { Rule rule = stack.getRule(grammar); final CompiledRule ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos == anchorPosition); - final IOnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); + final OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); if (r != null) { return new IMatchResult() { @@ -276,7 +276,7 @@ public int getMatchedRuleId() { } @Override - public IOnigCaptureIndex[] getCaptureIndices() { + public OnigCaptureIndex[] getCaptureIndices() { return r.getCaptureIndices(); } }; @@ -325,7 +325,7 @@ private IMatchInjectionsResult matchInjections(List injections, Gramm boolean isFirstLine, int linePos, StackElement stack, int anchorPosition) { // The lower the better int bestMatchRating = Integer.MAX_VALUE; - IOnigCaptureIndex[] bestMatchCaptureIndices = null; + OnigCaptureIndex[] bestMatchCaptureIndices = null; int bestMatchRuleId = -1; int bestMatchResultPriority = 0; @@ -339,7 +339,7 @@ private IMatchInjectionsResult matchInjections(List injections, Gramm CompiledRule ruleScanner = grammar.getRule(injection.ruleId).compile(grammar, null, isFirstLine, linePos == anchorPosition); - IOnigNextMatchResult matchResult = ruleScanner.scanner.findNextMatchSync(lineText, linePos); + OnigNextMatchResult matchResult = ruleScanner.scanner.findNextMatchSync(lineText, linePos); if (matchResult == null) { continue; @@ -366,7 +366,7 @@ private IMatchInjectionsResult matchInjections(List injections, Gramm if (bestMatchCaptureIndices != null) { final int matchedRuleId = bestMatchRuleId; - final IOnigCaptureIndex[] matchCaptureIndices = bestMatchCaptureIndices; + final OnigCaptureIndex[] matchCaptureIndices = bestMatchCaptureIndices; final boolean matchResultPriority = bestMatchResultPriority == -1; return new IMatchInjectionsResult() { @@ -376,7 +376,7 @@ public int getMatchedRuleId() { } @Override - public IOnigCaptureIndex[] getCaptureIndices() { + public OnigCaptureIndex[] getCaptureIndices() { return matchCaptureIndices; } @@ -391,7 +391,7 @@ public boolean isPriorityMatch() { } private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirstLine, StackElement stack, - LineTokens lineTokens, List captures, IOnigCaptureIndex[] captureIndices) { + LineTokens lineTokens, List captures, OnigCaptureIndex[] captureIndices) { if (captures.isEmpty()) { return; } @@ -399,7 +399,7 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs int len = Math.min(captures.size(), captureIndices.length); List localStack = new ArrayList<>(); int maxEnd = captureIndices[0].getEnd(); - IOnigCaptureIndex captureIndex; + OnigCaptureIndex captureIndex; for (int i = 0; i < len; i++) { CaptureRule captureRule = captures.get(i); @@ -489,7 +489,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe WhileStack whileRule = whileRules.get(i); CompiledRule ruleScanner = whileRule.rule.compileWhile(grammar, whileRule.stack.endRule, isFirstLine, currentanchorPosition == linePos); - IOnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); + OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); // if (IN_DEBUG_MODE) { // console.log(' scanning for while rule'); // console.log(debugCompiledRuleToString(ruleScanner)); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java index 9d1ada41c..3f8b80da0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java @@ -16,11 +16,11 @@ */ package org.eclipse.tm4e.core.internal.matcher; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; +import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; public interface IMatchResult { - IOnigCaptureIndex[] getCaptureIndices(); + OnigCaptureIndex[] getCaptureIndices(); int getMatchedRuleId(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java deleted file mode 100644 index 5012f5fb1..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigCaptureIndex.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/atom/node-oniguruma - * Initial copyright Copyright (c) 2013 GitHub Inc. - * Initial license: MIT - * - * Contributors: - * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.oniguruma; - -public interface IOnigCaptureIndex { - - int getIndex(); - - int getStart(); - - int getEnd(); - - int getLength(); - -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java deleted file mode 100644 index be56fb86c..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/IOnigNextMatchResult.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/atom/node-oniguruma - * Initial copyright Copyright (c) 2013 GitHub Inc. - * Initial license: MIT - * - * Contributors: - * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ - -package org.eclipse.tm4e.core.internal.oniguruma; - -public interface IOnigNextMatchResult { - - int getIndex(); - - IOnigCaptureIndex[] getCaptureIndices(); -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java new file mode 100644 index 000000000..b8e035b3a --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/atom/node-oniguruma + * Initial copyright Copyright (c) 2013 GitHub Inc. + * Initial license: MIT + * + * Contributors: + * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java + */ +package org.eclipse.tm4e.core.internal.oniguruma; + +public final class OnigCaptureIndex { + + private final int index; + private final int start; + private final int end; + + OnigCaptureIndex(int index, int start, int end) { + this.index = index; + this.start = start >= 0 ? start : 0; + this.end = end >= 0 ? end : 0; + } + + public int getIndex() { + return index; + } + + public int getStart() { + return start; + } + + public int getEnd() { + return end; + } + + public int getLength() { + return end - start; + } + + @Override + public String toString() { + return "{" + + "\"index\": " + index + + ", \"start\": " + start + + ", \"end\": " + end + + ", \"length\": " + getLength() + + "}"; + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java index 9a78bdfac..4df6e1063 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java @@ -16,24 +16,22 @@ */ package org.eclipse.tm4e.core.internal.oniguruma; -final class OnigNextMatchResult implements IOnigNextMatchResult { +public final class OnigNextMatchResult { private final int index; - private final IOnigCaptureIndex[] captureIndices; + private final OnigCaptureIndex[] captureIndices; OnigNextMatchResult(OnigResult result, OnigString source) { this.index = result.getIndex(); this.captureIndices = captureIndicesForMatch(result, source); } - @Override public int getIndex() { return index; } - @Override - public IOnigCaptureIndex[] getCaptureIndices() { + public OnigCaptureIndex[] getCaptureIndices() { return captureIndices; } @@ -45,7 +43,7 @@ public String toString() { result.append(",\n"); result.append(" \"captureIndices\": [\n"); int i = 0; - for (IOnigCaptureIndex captureIndex : getCaptureIndices()) { + for (OnigCaptureIndex captureIndex : getCaptureIndices()) { if (i > 0) { result.append(",\n"); } @@ -59,9 +57,9 @@ public String toString() { return result.toString(); } - private static IOnigCaptureIndex[] captureIndicesForMatch(OnigResult result, OnigString source) { + private static OnigCaptureIndex[] captureIndicesForMatch(OnigResult result, OnigString source) { int resultCount = result.count(); - IOnigCaptureIndex[] captures = new IOnigCaptureIndex[resultCount]; + OnigCaptureIndex[] captures = new OnigCaptureIndex[resultCount]; for (int index = 0; index < resultCount; index++) { int captureStart = source.convertUtf8OffsetToUtf16(result.locationAt(index)); int captureEnd = source.convertUtf8OffsetToUtf16(result.locationAt(index) + result.lengthAt(index)); @@ -69,48 +67,4 @@ private static IOnigCaptureIndex[] captureIndicesForMatch(OnigResult result, Oni } return captures; } - - private static final class OnigCaptureIndex implements IOnigCaptureIndex { - - private final int index; - private final int start; - private final int end; - - private OnigCaptureIndex(int index, int start, int end) { - this.index = index; - this.start = start >= 0 ? start : 0; - this.end = end >= 0 ? end : 0; - } - - @Override - public int getIndex() { - return index; - } - - @Override - public int getStart() { - return start; - } - - @Override - public int getEnd() { - return end; - } - - @Override - public int getLength() { - return end - start; - } - - @Override - public String toString() { - return "{" + - "\"index\": " + index + - ", \"start\": " + start + - ", \"end\": " + end + - ", \"length\": " + getLength() + - "}"; - } - } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java index 0a3de09a5..50af76c91 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java @@ -25,7 +25,7 @@ public OnigScanner(String[] regexps) { this.searcher = new OnigSearcher(regexps); } - public IOnigNextMatchResult findNextMatchSync(OnigString source, int charOffset) { + public OnigNextMatchResult findNextMatchSync(OnigString source, int charOffset) { OnigResult bestResult = searcher.search(source, charOffset); if (bestResult != null) { return new OnigNextMatchResult(bestResult, source); @@ -33,7 +33,7 @@ public IOnigNextMatchResult findNextMatchSync(OnigString source, int charOffset) return null; } - IOnigNextMatchResult findNextMatchSync(String lin, int pos) { + OnigNextMatchResult findNextMatchSync(String lin, int pos) { return findNextMatchSync(new OnigString(lin), pos); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index bbdfc306e..b5ffa7c1f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -18,7 +18,7 @@ import java.util.List; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; +import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; public final class BeginEndRule extends Rule { @@ -45,7 +45,7 @@ public final class BeginEndRule extends Rule { this.hasMissingPatterns = patterns.hasMissingPatterns; } - public String getEndWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) { + public String getEndWithResolvedBackReferences(String lineText, OnigCaptureIndex[] captureIndices) { return this.end.resolveBackReferences(lineText, captureIndices); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index 1c72967b9..d90d8366f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -18,7 +18,7 @@ import java.util.List; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; +import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; public final class BeginWhileRule extends Rule { @@ -45,7 +45,7 @@ public final class BeginWhileRule extends Rule { this.hasMissingPatterns = patterns.hasMissingPatterns; } - public String getWhileWithResolvedBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) { + public String getWhileWithResolvedBackReferences(String lineText, OnigCaptureIndex[] captureIndices) { return this._while.resolveBackReferences(lineText, captureIndices); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index a46fcd59a..c93b72233 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -22,7 +22,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; +import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; /** * @@ -123,7 +123,7 @@ private void _handleAnchors(String regExpSource) { } } - String resolveBackReferences(String lineText, IOnigCaptureIndex[] captureIndices) { + String resolveBackReferences(String lineText, OnigCaptureIndex[] captureIndices) { try { List capturedValues = Arrays.stream(captureIndices) .map(capture -> lineText.substring(capture.getStart(), capture.getEnd())).collect(Collectors.toList()); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java index 8ca7ffb1f..90d838c5f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java @@ -16,7 +16,7 @@ */ package org.eclipse.tm4e.core.internal.rule; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; +import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; import org.eclipse.tm4e.core.internal.utils.RegexSource; public abstract class Rule { @@ -37,14 +37,14 @@ public abstract class Rule { this.contentNameIsCapturing = RegexSource.hasCaptures(this.contentName); } - public String getName(String lineText, IOnigCaptureIndex[] captureIndices) { + public String getName(String lineText, OnigCaptureIndex[] captureIndices) { if (!this.nameIsCapturing) { return this.name; } return RegexSource.replaceCaptures(this.name, lineText, captureIndices); } - public String getContentName(String lineText, IOnigCaptureIndex[] captureIndices) { + public String getContentName(String lineText, OnigCaptureIndex[] captureIndices) { if (!this.contentNameIsCapturing) { return this.contentName; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index b37394500..6c195a81f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -19,7 +19,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.tm4e.core.internal.oniguruma.IOnigCaptureIndex; +import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; public final class RegexSource { @@ -39,7 +39,7 @@ public static boolean hasCaptures(String regexSource) { return CAPTURING_REGEX_SOURCE.matcher(regexSource).find(); } - public static String replaceCaptures(String regexSource, String captureSource, IOnigCaptureIndex[] captureIndices) { + public static String replaceCaptures(String regexSource, String captureSource, OnigCaptureIndex[] captureIndices) { Matcher m = CAPTURING_REGEX_SOURCE.matcher(regexSource); final StringBuilder result = new StringBuilder(); while (m.find()) { @@ -51,7 +51,7 @@ public static String replaceCaptures(String regexSource, String captureSource, I return result.toString(); } - private static String getReplacement(String match, String captureSource, IOnigCaptureIndex[] captureIndices) { + private static String getReplacement(String match, String captureSource, OnigCaptureIndex[] captureIndices) { int index = -1; String command = null; int doublePointIndex = match.indexOf(':'); @@ -61,7 +61,7 @@ private static String getReplacement(String match, String captureSource, IOnigCa } else { index = Integer.parseInt(match.substring(1)); } - IOnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null; + OnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null; if (capture != null) { String result = captureSource.substring(capture.getStart(), capture.getEnd()); // Remove leading dots that would make the selector invalid diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java index 6c3e2d6d9..818972101 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java @@ -16,7 +16,7 @@ public class TestOngurama { public static void main(String[] args) { OnigScanner scanner = new OnigScanner(new String[] { "c", "a(b)?" }); - IOnigNextMatchResult result = scanner.findNextMatchSync("abc", 0); + OnigNextMatchResult result = scanner.findNextMatchSync("abc", 0); System.err.println(result); scanner = new OnigScanner(new String[] { "a([b-d])c" }); From a5862376a8c843109a47ade7ab4e595394b84d26 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 16:26:39 +0200 Subject: [PATCH 090/202] Remove unused parameter --- .../eclipse/tm4e/core/internal/grammar/LineTokenizer.java | 2 +- .../org/eclipse/tm4e/core/internal/rule/BeginEndRule.java | 2 +- .../org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java | 6 +++--- .../eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java | 2 +- .../java/org/eclipse/tm4e/core/internal/rule/MatchRule.java | 2 +- .../eclipse/tm4e/core/internal/rule/RegExpSourceList.java | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 1aa4d2176..c4e5debce 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -487,7 +487,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe } for (int i = whileRules.size() - 1; i >= 0; i--) { WhileStack whileRule = whileRules.get(i); - CompiledRule ruleScanner = whileRule.rule.compileWhile(grammar, whileRule.stack.endRule, isFirstLine, + CompiledRule ruleScanner = whileRule.rule.compileWhile(whileRule.stack.endRule, isFirstLine, currentanchorPosition == linePos); OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); // if (IN_DEBUG_MODE) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index b5ffa7c1f..9a8805b6b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -71,7 +71,7 @@ public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolea precompiled.setSource(0, endRegexSource); } } - return this.cachedCompiledPatterns.compile(grammar, allowA, allowG); + return this.cachedCompiledPatterns.compile(allowA, allowG); } private RegExpSourceList precompile(IRuleRegistry grammar) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index d90d8366f..39fa1087d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -65,7 +65,7 @@ void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boole @Override public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { this.precompile(grammar); - return this.cachedCompiledPatterns.compile(grammar, allowA, allowG); + return this.cachedCompiledPatterns.compile(allowA, allowG); } private void precompile(IRuleRegistry grammar) { @@ -75,12 +75,12 @@ private void precompile(IRuleRegistry grammar) { } } - public CompiledRule compileWhile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compileWhile(String endRegexSource, boolean allowA, boolean allowG) { this.precompileWhile(); if (this._while.hasBackReferences()) { this.cachedCompiledWhilePatterns.setSource(0, endRegexSource); } - return this.cachedCompiledWhilePatterns.compile(grammar, allowA, allowG); + return this.cachedCompiledWhilePatterns.compile(allowA, allowG); } private void precompileWhile() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java index f16a91bd6..8d3647534 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java @@ -42,7 +42,7 @@ public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolea this.cachedCompiledPatterns = new RegExpSourceList(); this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); } - return this.cachedCompiledPatterns.compile(grammar, allowA, allowG); + return this.cachedCompiledPatterns.compile(allowA, allowG); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java index eb90329c1..6b85f22a3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java @@ -41,6 +41,6 @@ public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolea this.cachedCompiledPatterns = new RegExpSourceList(); this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); } - return this.cachedCompiledPatterns.compile(grammar, allowA, allowG); + return this.cachedCompiledPatterns.compile(allowA, allowG); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index f05741824..83e7b792a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -75,7 +75,7 @@ void setSource(int index, String newSource) { } } - CompiledRule compile(IRuleRegistry grammar, boolean allowA, boolean allowG) { + CompiledRule compile(boolean allowA, boolean allowG) { if (!this._hasAnchors) { if (this._cached == null) { List regexps = new ArrayList<>(); From e58bb801f0f19766e61a9e4394a526906c9146f9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 16:30:34 +0200 Subject: [PATCH 091/202] Simplify expression --- .../eclipse/tm4e/core/internal/grammar/LineTokenizer.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index c4e5debce..869a9a067 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -121,9 +121,8 @@ private void scanNext() { OnigCaptureIndex[] captureIndices = r.getCaptureIndices(); int matchedRuleId = r.getMatchedRuleId(); - boolean hasAdvanced = (captureIndices != null && captureIndices.length > 0) - ? (captureIndices[0].getEnd() > linePos) - : false; + final boolean hasAdvanced = captureIndices != null && captureIndices.length > 0 + && captureIndices[0].getEnd() > linePos; if (matchedRuleId == -1) { // We matched the `end` for this rule => pop it From 6bdee0b3a1d376e488b207909319f0987a9ba4ca Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 16:35:07 +0200 Subject: [PATCH 092/202] Remove unnecessary default constructor --- .../eclipse/tm4e/core/internal/css/CSSDocumentHandler.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java index ae145a85f..c5f6cb91b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java @@ -28,13 +28,9 @@ public final class CSSDocumentHandler implements DocumentHandler { - private final List list; + private final List list = new ArrayList<>(); private CSSStyle currentStyle; - public CSSDocumentHandler() { - list = new ArrayList<>(); - } - @Override public void comment(String arg0) throws CSSException { @@ -53,7 +49,6 @@ public void endFontFace() throws CSSException { @Override public void endMedia(SACMediaList arg0) throws CSSException { // TODO Auto-generated method stub - } @Override From e3c45105d68fd206f9fe6be96d1e0a38dae3f1fc Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 16:35:22 +0200 Subject: [PATCH 093/202] Make value field private final --- .../main/java/org/eclipse/tm4e/core/internal/css/Measure.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java index 48cf2ed59..c1c89f1a1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java @@ -8,7 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - package org.eclipse.tm4e.core.internal.css; import org.w3c.css.sac.LexicalUnit; @@ -17,7 +16,7 @@ final class Measure extends CSSValueImpl { - LexicalUnit value; + private final LexicalUnit value; Measure(LexicalUnit value) { this.value = value; From 2ac394df02179b9f4b24ceb9723b239e7d4ef155 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 17:13:47 +0200 Subject: [PATCH 094/202] Remove unnecessary interface --- .../tm4e/core/internal/types/IBaseRaw.java | 21 ------------------- .../core/internal/types/IRawCaptures.java | 2 +- 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java deleted file mode 100644 index d532ea21e..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IBaseRaw.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.types; - -interface IBaseRaw extends Iterable{ - -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java index 20b83de8b..d699257c7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java @@ -16,7 +16,7 @@ */ package org.eclipse.tm4e.core.internal.types; -public interface IRawCaptures extends IBaseRaw { +public interface IRawCaptures extends Iterable { IRawRule getCapture(String captureId); From 399fbe2a7d75e2515336f097243d37017161268d Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 17:16:24 +0200 Subject: [PATCH 095/202] Refactor Raw object cloning --- .../tm4e/core/internal/grammar/Grammar.java | 26 ++++---- .../core/internal/grammar/parser/Raw.java | 21 +++++- .../tm4e/core/internal/rule/RuleFactory.java | 3 +- .../tm4e/core/internal/types/IRawGrammar.java | 2 + .../core/internal/types/IRawRepository.java | 20 +++++- .../tm4e/core/internal/utils/CloneUtils.java | 66 ------------------- 6 files changed, 50 insertions(+), 88 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index d0831de2b..73bd33ae6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -60,7 +60,7 @@ public final class Grammar implements IGrammar, IRuleFactoryHelper { private final Map ruleId2desc = new HashMap<>(); private final Map includedGrammars = new HashMap<>(); private final IGrammarRepository grammarRepository; - private final IRawGrammar grammar; + private final IRawGrammar rawGrammar; private List injections; private final ScopeMetadataProvider scopeMetadataProvider; @@ -68,7 +68,7 @@ public Grammar(IRawGrammar grammar, int initialLanguage, Map em IGrammarRepository grammarRepository, IThemeProvider themeProvider) { this.scopeMetadataProvider = new ScopeMetadataProvider(initialLanguage, themeProvider, embeddedLanguages); this.grammarRepository = grammarRepository; - this.grammar = initGrammar(grammar, null); + this.rawGrammar = initGrammar(grammar, null); } public void onDidChangeTheme() { @@ -83,19 +83,19 @@ List getInjections() { if (this.injections == null) { this.injections = new ArrayList<>(); // add injections from the current grammar - Map rawInjections = this.grammar.getInjections(); + Map rawInjections = this.rawGrammar.getInjections(); if (rawInjections != null) { for (Entry injection : rawInjections.entrySet()) { String expression = injection.getKey(); IRawRule rule = injection.getValue(); - collectInjections(this.injections, expression, rule, this, this.grammar); + collectInjections(this.injections, expression, rule, this, this.rawGrammar); } } // add injection grammars contributed for the current scope if (this.grammarRepository != null) { Collection injectionScopeNames = this.grammarRepository - .injections(this.grammar.getScopeName()); + .injections(this.rawGrammar.getScopeName()); if (injectionScopeNames != null) { injectionScopeNames.forEach(injectionScopeName -> { IRawGrammar injectionGrammar = this.getExternalGrammar(injectionScopeName); @@ -160,7 +160,7 @@ public IRawGrammar getExternalGrammar(String scopeName, IRawRepository repositor } private IRawGrammar initGrammar(IRawGrammar grammar, IRawRule base) { - grammar = clone(grammar); + grammar = grammar.clone(); if (grammar.getRepository() == null) { ((Raw) grammar).setRepository(new Raw()); } @@ -176,10 +176,6 @@ private IRawGrammar initGrammar(IRawGrammar grammar, IRawRule base) { return grammar; } - private IRawGrammar clone(IRawGrammar grammar) { - return (IRawGrammar) ((Raw) grammar).clone(); - } - @Override public ITokenizeLineResult tokenizeLine(String lineText) { return tokenizeLine(lineText, null); @@ -203,8 +199,8 @@ public ITokenizeLineResult2 tokenizeLine2(String lineText, StackElement prevStat @SuppressWarnings("unchecked") private T tokenize(String lineText, StackElement prevState, boolean emitBinaryTokens) { if (this.rootId == -1) { - this.rootId = RuleFactory.getCompiledRuleId(this.grammar.getRepository().getSelf(), this, - this.grammar.getRepository()); + this.rootId = RuleFactory.getCompiledRuleId(this.rawGrammar.getRepository().getSelf(), this, + this.rawGrammar.getRepository()); } boolean isFirstLine; @@ -246,17 +242,17 @@ private T tokenize(String lineText, StackElement prevState, boolean emitBina @Override public String getName() { - return grammar.getName(); + return rawGrammar.getName(); } @Override public String getScopeName() { - return grammar.getScopeName(); + return rawGrammar.getScopeName(); } @Override public Collection getFileTypes() { - return grammar.getFileTypes(); + return rawGrammar.getFileTypes(); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java index bcde73d9c..3fe8c5b68 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java @@ -18,12 +18,12 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.eclipse.tm4e.core.internal.types.IRawCaptures; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; import org.eclipse.tm4e.core.internal.types.IRawRule; -import org.eclipse.tm4e.core.internal.utils.CloneUtils; /** * Raw @@ -299,8 +299,23 @@ public Iterator iterator() { } @Override - public Object clone() { - return CloneUtils.clone(this); + public Raw clone() { + return (Raw) clone(this); + } + + private Object clone(final Object value) { + if (value instanceof Raw) { + final Raw rowToClone = (Raw) value; + final Raw raw = new Raw(); + for (final Entry entry : rowToClone.entrySet()) { + raw.put(entry.getKey(), clone(entry.getValue())); + } + return raw; + } + if (value instanceof List) { + return ((List) value).stream().map(this::clone).collect(Collectors.toList()); + } + return value; } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index 2fcd0c808..d5fb84e88 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -24,7 +24,6 @@ import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; import org.eclipse.tm4e.core.internal.types.IRawRule; -import org.eclipse.tm4e.core.internal.utils.CloneUtils; /** * @@ -54,7 +53,7 @@ public static int getCompiledRuleId(final IRawRule desc, final IRuleFactoryHelpe if (desc.getBegin() == null) { IRawRepository r = repository; if (desc.getRepository() != null) { - r = CloneUtils.mergeObjects(repository, desc.getRepository()); + r = IRawRepository.merge(repository, desc.getRepository()); } return new IncludeOnlyRule(desc.getId(), desc.getName(), desc.getContentName(), RuleFactory._compilePatterns(desc.getPatterns(), helper, r)); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java index 09de8299c..920859f5f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java @@ -21,6 +21,8 @@ public interface IRawGrammar { + IRawGrammar clone(); + IRawRepository getRepository(); String getScopeName(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java index c0e63d170..ec97f9126 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java @@ -16,9 +16,26 @@ */ package org.eclipse.tm4e.core.internal.types; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import org.eclipse.tm4e.core.internal.grammar.parser.Raw; + public interface IRawRepository { - // IRawRule getRule(String name); + static IRawRepository merge(IRawRepository... sources) { + final Raw merged = new Raw(); + for (final IRawRepository source : sources) { + final Set> entries = source.entrySet(); + for (final Entry entry : entries) { + merged.put(entry.getKey(), entry.getValue()); + } + } + return merged; + } + + Set> entrySet(); IRawRule getProp(String name); @@ -29,5 +46,4 @@ public interface IRawRepository { void setSelf(IRawRule raw); void setBase(IRawRule base); - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java deleted file mode 100644 index 87d903881..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CloneUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.utils; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.stream.Collectors; - -import org.eclipse.tm4e.core.internal.grammar.parser.Raw; -import org.eclipse.tm4e.core.internal.types.IRawRepository; - -/** - * Clone utilities. - * - */ -public final class CloneUtils { - - /** - * Helper class, use methods statically - */ - private CloneUtils() { - - } - - public static Object clone(Object value) { - if (value instanceof Raw) { - Raw rowToClone = (Raw) value; - Raw raw = new Raw(); - for (Entry entry : rowToClone.entrySet()) { - raw.put(entry.getKey(), clone(entry.getValue())); - } - return raw; - } else if (value instanceof List) { - return ((List) value).stream().map(CloneUtils::clone).collect(Collectors.toList()); - } else if (value instanceof String) { - return value; - } else if (value instanceof Integer) { - return value; - } else if (value instanceof Boolean) { - return value; - } - return value; - } - - public static IRawRepository mergeObjects(IRawRepository... sources) { - Raw target = new Raw(); - for (IRawRepository source : sources) { - Set> entries = ((Map) source).entrySet(); - for (Entry entry : entries) { - target.put(entry.getKey(), entry.getValue()); - } - } - return target; - } -} From 85e765d8b7f314882c37c67003296a77ad33f92f Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 17:42:43 +0200 Subject: [PATCH 096/202] Make tm4e.ui.utils internal package --- .../HasLanguageConfigurationPropertyTester.java | 4 ++-- .../LanguageConfigurationAutoEditStrategy.java | 4 ++-- .../LanguageConfigurationCharacterPairMatcher.java | 4 ++-- .../languageconfiguration/ToggleLineCommentHandler.java | 4 ++-- .../internal/LanguageConfigurationDefinition.java | 2 +- .../internal/preferences/PreferenceHelper.java | 2 +- .../languageconfiguration/internal/utils/TextUtils.java | 2 +- .../wizards/SelectLanguageConfigurationWizardPage.java | 2 +- org.eclipse.tm4e.ui/META-INF/MANIFEST.MF | 4 ++-- .../tm4e/ui/internal/themes/AbstractThemeManager.java | 2 +- .../org/eclipse/tm4e/ui/internal/themes/ThemeManager.java | 2 +- .../eclipse/tm4e/ui/{ => internal}/utils/ClassHelper.java | 2 +- .../tm4e/ui/{ => internal}/utils/ContentTypeHelper.java | 2 +- .../tm4e/ui/{ => internal}/utils/ContentTypeInfo.java | 2 +- .../tm4e/ui/{ => internal}/utils/PreferenceUtils.java | 2 +- .../eclipse/tm4e/ui/text/TMPresentationReconciler.java | 8 ++++---- .../java/org/eclipse/tm4e/ui/themes/ColorManager.java | 2 +- 17 files changed, 25 insertions(+), 25 deletions(-) rename org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/{ => internal}/utils/ClassHelper.java (96%) rename org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/{ => internal}/utils/ContentTypeHelper.java (99%) rename org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/{ => internal}/utils/ContentTypeInfo.java (94%) rename org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/{ => internal}/utils/PreferenceUtils.java (97%) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java index 5acb00080..259ee0473 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java @@ -17,8 +17,8 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.text.IDocument; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeInfo; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java index 7a2cc468b..bd18fe0df 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java @@ -27,8 +27,8 @@ import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterActionAndIndent; import org.eclipse.tm4e.languageconfiguration.internal.utils.TabSpacesInfo; import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeInfo; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java index c4d5765ac..af2a15538 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java @@ -22,8 +22,8 @@ import org.eclipse.jface.text.source.ICharacterPairMatcherExtension; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager; import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeInfo; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; /** * Support of matching bracket with language configuration. diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java index 823c4c20a..5c1e5569c 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java @@ -34,8 +34,8 @@ import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport; import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeInfo; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java index 55ec3230e..1d779d870 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java @@ -26,7 +26,7 @@ import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterSupport; import org.eclipse.tm4e.registry.TMResource; import org.eclipse.tm4e.registry.XMLConstants; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; /** * Language configuration definition. diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java index 1160b6cf8..cf18be1b6 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java @@ -15,7 +15,7 @@ import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; import com.google.gson.Gson; import com.google.gson.GsonBuilder; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java index e2e4fd38a..702cf4a92 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java @@ -21,7 +21,7 @@ import org.eclipse.jface.text.TabsToSpacesConverter; import org.eclipse.jface.text.TextUtilities; import org.eclipse.jface.text.TextViewer; -import org.eclipse.tm4e.ui.utils.ClassHelper; +import org.eclipse.tm4e.ui.internal.utils.ClassHelper; public final class TextUtils { diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java index a7ae5b7fc..17b433056 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java @@ -52,7 +52,7 @@ import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationPlugin; import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationInfoWidget; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; import org.eclipse.ui.dialogs.ResourceSelectionDialog; final class SelectLanguageConfigurationWizardPage extends WizardPage implements Listener { diff --git a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF index 15fbf14b3..44ad03bfa 100644 --- a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF @@ -24,11 +24,11 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.eclipse.tm4e.ui, org.eclipse.tm4e.ui.internal.model;x-friends:="org.eclipse.tm4e.ui.tests", org.eclipse.tm4e.ui.internal.themes;x-friends:="org.eclipse.tm4e.ui.tests", + org.eclipse.tm4e.ui.internal.utils;x-friends:="org.eclipse.tm4e.ui.tests", org.eclipse.tm4e.ui.model, org.eclipse.tm4e.ui.text, org.eclipse.tm4e.ui.themes, - org.eclipse.tm4e.ui.themes.css, - org.eclipse.tm4e.ui.utils + org.eclipse.tm4e.ui.themes.css Bundle-Activator: org.eclipse.tm4e.ui.TMUIPlugin Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.core.filebuffers diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index f556d94ad..7d84d05d0 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -19,12 +19,12 @@ import java.util.stream.Collectors; import org.eclipse.swt.graphics.RGB; +import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils; import org.eclipse.tm4e.ui.themes.ITheme; import org.eclipse.tm4e.ui.themes.IThemeAssociation; import org.eclipse.tm4e.ui.themes.IThemeManager; import org.eclipse.tm4e.ui.themes.ITokenProvider; import org.eclipse.tm4e.ui.themes.ThemeAssociation; -import org.eclipse.tm4e.ui.utils.PreferenceUtils; /** * TextMate theme manager implementation. diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java index f1091b2ce..8255533f8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java @@ -22,10 +22,10 @@ import org.eclipse.tm4e.ui.TMUIPlugin; import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; import org.eclipse.tm4e.ui.internal.preferences.PreferenceHelper; +import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils; import org.eclipse.tm4e.ui.themes.IThemeAssociation; import org.eclipse.tm4e.ui.themes.Theme; import org.eclipse.tm4e.ui.themes.ThemeAssociation; -import org.eclipse.tm4e.ui.utils.PreferenceUtils; import org.osgi.service.prefs.BackingStoreException; import com.google.gson.Gson; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java similarity index 96% rename from org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java rename to org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java index 998e497ed..c30a4548a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ClassHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.utils; +package org.eclipse.tm4e.ui.internal.utils; import java.lang.reflect.Field; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java similarity index 99% rename from org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java rename to org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java index 5f8229eec..880c6012a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.utils; +package org.eclipse.tm4e.ui.internal.utils; import java.io.IOException; import java.io.InputStream; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeInfo.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java similarity index 94% rename from org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeInfo.java rename to org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java index d3cdcbd63..2d195fb1b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/ContentTypeInfo.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.utils; +package org.eclipse.tm4e.ui.internal.utils; import org.eclipse.core.runtime.content.IContentType; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/PreferenceUtils.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java similarity index 97% rename from org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/PreferenceUtils.java rename to org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java index 925f1f0bb..a855a053a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/utils/PreferenceUtils.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.ui.utils; +package org.eclipse.tm4e.ui.internal.utils; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index e571e8db7..21e8430d5 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -69,14 +69,14 @@ import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; import org.eclipse.tm4e.ui.internal.text.TMPresentationReconcilerTestGenerator; import org.eclipse.tm4e.ui.internal.themes.ThemeManager; +import org.eclipse.tm4e.ui.internal.utils.ClassHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; +import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils; import org.eclipse.tm4e.ui.model.ITMModelManager; import org.eclipse.tm4e.ui.themes.ITheme; import org.eclipse.tm4e.ui.themes.IThemeManager; import org.eclipse.tm4e.ui.themes.ITokenProvider; -import org.eclipse.tm4e.ui.utils.ClassHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeHelper; -import org.eclipse.tm4e.ui.utils.ContentTypeInfo; -import org.eclipse.tm4e.ui.utils.PreferenceUtils; import org.eclipse.ui.IEditorPart; /** diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java index a08cc15f2..992476ccd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java @@ -18,7 +18,7 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; import org.eclipse.tm4e.core.theme.RGB; -import org.eclipse.tm4e.ui.utils.PreferenceUtils; +import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils; import org.eclipse.ui.texteditor.AbstractTextEditor; import com.google.common.base.Splitter; From 3846c1fd5dc6b9fb057aa7976fb85f0d18e4effd Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 21 Apr 2022 17:45:04 +0200 Subject: [PATCH 097/202] Make classes final --- .../org/eclipse/tm4e/core/grammar/GrammarHelper.java | 2 +- .../eclipse/tm4e/ui/internal/utils/ClassHelper.java | 2 +- .../tm4e/ui/internal/utils/ContentTypeHelper.java | 2 +- .../tm4e/ui/internal/utils/ContentTypeInfo.java | 4 ++-- .../tm4e/ui/internal/utils/PreferenceUtils.java | 10 +++++----- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java index 316199566..e13cabdba 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java @@ -23,7 +23,7 @@ import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.theme.IThemeProvider; -public class GrammarHelper { +public final class GrammarHelper { private GrammarHelper() { // methods should be accessed statically diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java index c30a4548a..e3c2b2330 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java @@ -17,7 +17,7 @@ * Class Reflection utilities. * */ -public class ClassHelper { +public final class ClassHelper { @SuppressWarnings("unchecked") public static T getFieldValue(Object object, String name, Class clazz) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java index 880c6012a..4030100d8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java @@ -40,7 +40,7 @@ * {@link IContentType} utilities. * */ -public class ContentTypeHelper { +public final class ContentTypeHelper { /** * Find the content types from the given {@link IDocument} and null otherwise. diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java index 2d195fb1b..d97a0d3c8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java @@ -14,11 +14,11 @@ import org.eclipse.core.runtime.content.IContentType; /** - * + * * @author azerr * */ -public class ContentTypeInfo { +public final class ContentTypeInfo { private final String fileName; private final IContentType[] contentTypes; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java index a855a053a..735cb714a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java @@ -17,7 +17,7 @@ import org.eclipse.tm4e.ui.TMUIPlugin; import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; -public class PreferenceUtils { +public final class PreferenceUtils { private static final String E4_CSS_PREFERENCE_NAME = "org.eclipse.e4.ui.css.swt.theme"; //$NON-NLS-1$ private static final String EDITORS_PREFERENCE_NAME = "org.eclipse.ui.editors"; //$NON-NLS-1$ @@ -27,7 +27,7 @@ private PreferenceUtils() { /** * Get e4 preferences store - * + * * @return preferences store */ public static IEclipsePreferences getE4PreferenceStore() { @@ -36,7 +36,7 @@ public static IEclipsePreferences getE4PreferenceStore() { /** * Get Id of the current eclipse theme - * + * * @return themeIf of the current eclipse theme */ public static String getE4PreferenceCSSThemeId() { @@ -46,7 +46,7 @@ public static String getE4PreferenceCSSThemeId() { /** * Get editors preferences store - * + * * @return preferences store */ public static IEclipsePreferences getEditorsPreferenceStore() { @@ -55,7 +55,7 @@ public static IEclipsePreferences getEditorsPreferenceStore() { /** * Get TM4E preferences store - * + * * @return preferences store */ public static IPreferenceStore getTM4EPreferencesStore() { From 8ed55758c3ec0c9a640c99f80f96b924beb776cd Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Apr 2022 13:55:03 +0200 Subject: [PATCH 098/202] Move IGrammarRepository and remove GrammarHelper --- .../tm4e/core/grammar/GrammarHelper.java | 41 ------------------- .../tm4e/core/internal/grammar/Grammar.java | 5 +-- .../core/internal/grammar/LineTokenizer.java | 3 +- .../grammars}/IGrammarRepository.java | 2 +- .../core/internal/grammars/SyncRegistry.java | 13 +++--- 5 files changed, 9 insertions(+), 55 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{grammar => internal/grammars}/IGrammarRepository.java (95%) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java deleted file mode 100644 index e13cabdba..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/GrammarHelper.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.grammar; - -import java.util.Map; - -import org.eclipse.tm4e.core.internal.grammar.Grammar; -import org.eclipse.tm4e.core.internal.oniguruma.OnigString; -import org.eclipse.tm4e.core.internal.types.IRawGrammar; -import org.eclipse.tm4e.core.theme.IThemeProvider; - -public final class GrammarHelper { - - private GrammarHelper() { - // methods should be accessed statically - } - - public static IGrammar createGrammar(IRawGrammar grammar, int initialLanguage, - Map embeddedLanguages, IGrammarRepository repository, IThemeProvider themeProvider) { - return new Grammar(grammar, initialLanguage, embeddedLanguages, repository, themeProvider); - } - - public static OnigString createOnigString(String str) { - return new OnigString(str); - } - -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 73bd33ae6..d5380a9b3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -26,14 +26,13 @@ import java.util.Map.Entry; import java.util.function.IntFunction; -import org.eclipse.tm4e.core.grammar.GrammarHelper; import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.grammar.IGrammarRepository; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.grammar.parser.Raw; +import org.eclipse.tm4e.core.internal.grammars.IGrammarRepository; import org.eclipse.tm4e.core.internal.matcher.Matcher; import org.eclipse.tm4e.core.internal.matcher.MatcherWithPriority; import org.eclipse.tm4e.core.internal.oniguruma.OnigString; @@ -228,7 +227,7 @@ private T tokenize(String lineText, StackElement prevState, boolean emitBina // Only add \n if the passed lineText didn't have it. lineText += '\n'; } - OnigString onigLineText = GrammarHelper.createOnigString(lineText); + OnigString onigLineText = new OnigString(lineText); int lineLength = lineText.length(); LineTokens lineTokens = new LineTokens(emitBinaryTokens, lineText); StackElement nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 869a9a067..f10afa519 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.List; -import org.eclipse.tm4e.core.grammar.GrammarHelper; import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.matcher.IMatchInjectionsResult; @@ -445,7 +444,7 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs StackElement stackClone = stack.push(captureRule.retokenizeCapturedWithRuleId, captureIndex.getStart(), null, nameScopesList, contentNameScopesList); tokenizeString(grammar, - GrammarHelper.createOnigString(lineText.string.substring(0, captureIndex.getEnd())), + new OnigString(lineText.string.substring(0, captureIndex.getEnd())), (isFirstLine && captureIndex.getStart() == 0), captureIndex.getStart(), stackClone, lineTokens); continue; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammarRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/IGrammarRepository.java similarity index 95% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammarRepository.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/IGrammarRepository.java index 3314f8245..f264de73a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammarRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/IGrammarRepository.java @@ -14,7 +14,7 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.grammar; +package org.eclipse.tm4e.core.internal.grammars; import java.util.Collection; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java index c0aa0e9d0..e82de72a9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.grammars; @@ -24,9 +24,7 @@ import java.util.Map.Entry; import java.util.Set; -import org.eclipse.tm4e.core.grammar.GrammarHelper; import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.grammar.IGrammarRepository; import org.eclipse.tm4e.core.internal.grammar.Grammar; import org.eclipse.tm4e.core.internal.grammar.parser.Raw; import org.eclipse.tm4e.core.internal.types.IRawGrammar; @@ -107,8 +105,7 @@ public IGrammar grammarForScopeName(String scopeName, int initialLanguage, if (rawGrammar == null) { return null; } - this.grammars.put(scopeName, - GrammarHelper.createGrammar(rawGrammar, initialLanguage, embeddedLanguages, this, this)); + this.grammars.put(scopeName, new Grammar(rawGrammar, initialLanguage, embeddedLanguages, this, this)); } return this.grammars.get(scopeName); } @@ -175,7 +172,7 @@ private static void extractIncludedScopesInRepository(Collection result, if (!(repository instanceof Raw)) { return; } - Raw rawRepository = (Raw)repository; + Raw rawRepository = (Raw) repository; for (Entry entry : rawRepository.entrySet()) { IRawRule rule = (IRawRule) entry.getValue(); if (rule.getPatterns() != null) { From aed45d00eb612d4036a7f6b0c05556714e73a3db Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Apr 2022 14:08:06 +0200 Subject: [PATCH 099/202] Remove unnecessary internal method --- .../main/java/org/eclipse/tm4e/core/registry/Registry.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index f6ce201bb..b8f532853 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -70,11 +70,6 @@ public Set getColorMap() { } public IGrammar loadGrammar(String initialScopeName) { - return _loadGrammar(initialScopeName); - } - - private IGrammar _loadGrammar(String initialScopeName) { - List remainingScopeNames = new ArrayList<>(); remainingScopeNames.add(initialScopeName); From 3a1f2d18041095a7ed2fa2b450d506e260a737a9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Apr 2022 14:14:22 +0200 Subject: [PATCH 100/202] Avoid unnecessary cast --- .../org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java index e82de72a9..8fa44d99a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java @@ -36,7 +36,7 @@ public final class SyncRegistry implements IGrammarRepository, IThemeProvider { - private final Map grammars = new HashMap<>(); + private final Map grammars = new HashMap<>(); private final Map rawGrammars = new HashMap<>(); private final Map> injectionGrammars = new HashMap<>(); private Theme theme; @@ -47,7 +47,7 @@ public SyncRegistry(Theme theme) { public void setTheme(Theme theme) { this.theme = theme; - this.grammars.values().forEach(grammar -> ((Grammar) grammar).onDidChangeTheme()); + this.grammars.values().forEach(Grammar::onDidChangeTheme); } public Set getColorMap() { From 76440d8343276c68c3e8b38d43264c816b3ff5fe Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Apr 2022 14:15:40 +0200 Subject: [PATCH 101/202] Fix formatting --- .../org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java index 8fa44d99a..6e09f3f2d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java @@ -111,8 +111,7 @@ public IGrammar grammarForScopeName(String scopeName, int initialLanguage, } private static void collectIncludedScopes(Collection result, IRawGrammar grammar) { - if (grammar - .getPatterns() != null /* && Array.isArray(grammar.patterns) */) { + if (grammar.getPatterns() != null /* && Array.isArray(grammar.patterns) */) { extractIncludedScopesInPatterns(result, grammar.getPatterns()); } From 75ce1e209147e69c9cf428d5c38d1fe06d7188b3 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Apr 2022 14:17:51 +0200 Subject: [PATCH 102/202] Add default case to switch statement --- .../org/eclipse/tm4e/core/internal/css/Measure.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java index c1c89f1a1..69418abfe 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java @@ -93,14 +93,14 @@ public short getPrimitiveType() { case LexicalUnit.SAC_DIMENSION: return CSS_DIMENSION; case LexicalUnit.SAC_OPERATOR_COMMA: - return CSS_CUSTOM; // TODO don't think this is right, see bug - // #278139 + return CSS_CUSTOM; // TODO don't think this is right, see bug #278139 case LexicalUnit.SAC_INHERIT: return CSS_INHERIT; + default: + // TODO Auto-generated method stub + throw new UnsupportedOperationException( + "NOT YET IMPLEMENTED - LexicalUnit type: " + value.getLexicalUnitType()); } - // TODO Auto-generated method stub - throw new UnsupportedOperationException( - "NOT YET IMPLEMENTED - LexicalUnit type: " + value.getLexicalUnitType()); } @Override From 5a3c7ba072c3ee6988425e8b6ca5ba3e67cfde7e Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Apr 2022 14:24:34 +0200 Subject: [PATCH 103/202] Use specific exception types in throws declaration --- .../tm4e/core/internal/parser/json/JSONPListParser.java | 4 +++- .../tm4e/core/internal/parser/xml/XMLPListParser.java | 5 ++++- .../tm4e/core/internal/parser/yaml/YamlPListParser.java | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java index 4b455d1fa..ef7a20031 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java @@ -11,11 +11,13 @@ */ package org.eclipse.tm4e.core.internal.parser.json; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import org.eclipse.tm4e.core.internal.parser.PList; +import org.xml.sax.SAXException; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; @@ -28,7 +30,7 @@ public JSONPListParser(boolean theme) { this.theme = theme; } - public T parse(InputStream contents) throws Exception { + public T parse(InputStream contents) throws IOException, SAXException { PList pList = new PList<>(theme); try (JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8))) { // reader.setLenient(true); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java index a30e6214a..4a22b7e3a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java @@ -12,13 +12,16 @@ package org.eclipse.tm4e.core.internal.parser.xml; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.eclipse.tm4e.core.internal.parser.PList; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import org.xml.sax.XMLReader; public final class XMLPListParser { @@ -29,7 +32,7 @@ public XMLPListParser(boolean theme) { this.theme = theme; } - public T parse(InputStream contents) throws Exception { + public T parse(InputStream contents) throws IOException, ParserConfigurationException, SAXException { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); SAXParser saxParser = spf.newSAXParser(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java index a0fde87f2..8aac22a1d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java @@ -20,6 +20,7 @@ import org.eclipse.tm4e.core.internal.parser.PList; import org.xml.sax.SAXException; import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; /** * Parses TextMate Grammar file in YAML format. @@ -75,7 +76,7 @@ private void addStringToPList(PList pList, String value) throws SAXException pList.endElement(null, "string", null); } - public T parse(InputStream contents) throws Exception { + public T parse(InputStream contents) throws SAXException, YAMLException { PList pList = new PList<>(theme); addMapToPList(pList, new Yaml().loadAs(contents, Map.class)); return pList.getResult(); From bd2abab6ba7308935a4e2794fcc03d48773ff3b5 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 23 Apr 2022 20:34:36 +0200 Subject: [PATCH 104/202] Improve GenericEditor tests --- .../tm4e/ui/TMinGenericEditorTest.java | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java index 13326d6e7..7ee2bcec3 100644 --- a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java +++ b/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java @@ -11,14 +11,12 @@ */ package org.eclipse.tm4e.ui; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.junit.jupiter.api.Assertions.*; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.widgets.Control; @@ -40,22 +38,35 @@ class TMinGenericEditorTest { private File f; private IEditorPart editor; - private Set getTM4EThreads() { - Set threads = Thread.getAllStackTraces().keySet(); - Set res = new HashSet<>(); - for (Thread thread : threads) { - if (thread.getClass().getName().contains("tm4e")) { - res.add(thread); - } - } - return res; + @BeforeEach + public void checkHasGenericEditor() { + editorDescriptor = PlatformUI.getWorkbench().getEditorRegistry() + .findEditor("org.eclipse.ui.genericeditor.GenericEditor"); + assertNotNull(editorDescriptor); } @BeforeEach - public void checkHasGenericEditor() { - editorDescriptor = PlatformUI.getWorkbench().getEditorRegistry().findEditor("org.eclipse.ui.genericeditor.GenericEditor"); - assumeTrue(editorDescriptor!=null); - assertTrue(getTM4EThreads().isEmpty(), "TM4E threads still running"); + public void checkNoTM4EThreadsRunning() throws InterruptedException { + var tm4eThreads = Thread.getAllStackTraces(); + tm4eThreads.entrySet().removeIf(e -> !e.getKey().getClass().getName().startsWith("org.eclipse.tm4e")); + + if (!tm4eThreads.isEmpty()) { + Thread.sleep(5_000); // give threads time to finish + } + + tm4eThreads = Thread.getAllStackTraces(); + tm4eThreads.entrySet().removeIf(e -> !e.getKey().getClass().getName().startsWith("org.eclipse.tm4e")); + + if (!tm4eThreads.isEmpty()) { + // print the stacktrace of one of the hung threads + final var tm4eThread = tm4eThreads.entrySet().iterator().next(); + final var ex = new IllegalStateException("Thread " + tm4eThread.getKey() + " is still busy"); + ex.setStackTrace(tm4eThread.getValue()); + ex.printStackTrace(System.out); + + fail("TM4E threads still running:\n" + tm4eThreads.keySet().stream() + .map(t -> " - " + t + " " + t.getClass().getName()).collect(Collectors.joining("\n"))); + } } @AfterEach @@ -84,7 +95,7 @@ void testTMHighlightInGenericEditor() throws IOException, PartInitException { f.deleteOnExit(); editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), f.toURI(), editorDescriptor.getId(), true); - StyledText text = (StyledText)editor.getAdapter(Control.class); + StyledText text = (StyledText) editor.getAdapter(Control.class); assertTrue(new DisplayHelper() { @Override protected boolean condition() { @@ -102,7 +113,7 @@ void testTMHighlightInGenericEditorEdit() throws IOException, PartInitException f.deleteOnExit(); editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), f.toURI(), editorDescriptor.getId(), true); - StyledText text = (StyledText)editor.getAdapter(Control.class); + StyledText text = (StyledText) editor.getAdapter(Control.class); assertTrue(new DisplayHelper() { @Override protected boolean condition() { @@ -112,7 +123,8 @@ protected boolean condition() { int initialNumberOfRanges = text.getStyleRanges().length; text.setText("let a = '';\nlet b = 10;\nlet c = true;"); assertTrue(new DisplayHelper() { - @Override protected boolean condition() { + @Override + protected boolean condition() { return text.getStyleRanges().length > initialNumberOfRanges + 3; } }.waitForCondition(text.getDisplay(), 300000), "More styles should have been added"); @@ -122,8 +134,6 @@ protected boolean condition() { void testReconcilierStartsAndDisposeThread() throws Exception { testTMHighlightInGenericEditor(); editor.getEditorSite().getPage().closeEditor(editor, false); - Thread.sleep(500); // give time to dispose - assertTrue(getTM4EThreads().isEmpty()); + checkNoTM4EThreadsRunning(); } - } From fb2b86167abb417855eac9cbe1b9261d1cebf098 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 23 Apr 2022 20:52:02 +0200 Subject: [PATCH 105/202] Grant tm4e.languageconfiguration access to tm4e.ui.internal.utils --- org.eclipse.tm4e.ui/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF index 44ad03bfa..58129daa9 100644 --- a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF @@ -24,7 +24,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.eclipse.tm4e.ui, org.eclipse.tm4e.ui.internal.model;x-friends:="org.eclipse.tm4e.ui.tests", org.eclipse.tm4e.ui.internal.themes;x-friends:="org.eclipse.tm4e.ui.tests", - org.eclipse.tm4e.ui.internal.utils;x-friends:="org.eclipse.tm4e.ui.tests", + org.eclipse.tm4e.ui.internal.utils;x-friends:="org.eclipse.tm4e.ui.tests,org.eclipse.tm4e.languageconfiguration", org.eclipse.tm4e.ui.model, org.eclipse.tm4e.ui.text, org.eclipse.tm4e.ui.themes, From 33abe2312bc6352b471e23e7c6d4188ef833d515 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Apr 2022 17:39:55 +0200 Subject: [PATCH 106/202] Make gson dependency non-optional --- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index 119a38e8c..1dad02c1a 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -7,7 +7,7 @@ Bundle-SymbolicName: org.eclipse.tm4e.core Bundle-Version: 0.4.4.qualifier Require-Bundle: org.apache.batik.css;bundle-version="1.9.1";resolution:=optional, org.apache.batik.util;bundle-version="1.9.1";resolution:=optional, - com.google.gson;resolution:=optional, + com.google.gson, com.google.guava;bundle-version="30.1.0", org.jcodings;bundle-version="1.0.57", org.joni;bundle-version="2.1.43", From e35e0c2398892b1d86c1b53ce4dbe28bb49f2020 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 23 Apr 2022 22:01:02 +0200 Subject: [PATCH 107/202] Avoid repeated auto-unboxing of same value --- .../main/java/org/eclipse/tm4e/core/model/TMModel.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index 447f38b0f..a381f9337 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -90,7 +90,7 @@ public void run() { do { try { - Integer toProcess = model.invalidLines.take(); + final int toProcess = model.invalidLines.take().intValue(); if (model.lines.get(toProcess).isInvalid) { try { this.revalidateTokensNow(toProcess, null); @@ -114,9 +114,11 @@ public void run() { */ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { model.buildEventWithCallback(eventBuilder -> { - Integer toLineIndex = toLineIndexOrNull; - if (toLineIndex == null || toLineIndex >= model.lines.getNumberOfLines()) { + final int toLineIndex; + if (toLineIndexOrNull == null || toLineIndexOrNull >= model.lines.getNumberOfLines()) { toLineIndex = model.lines.getNumberOfLines() - 1; + } else { + toLineIndex = toLineIndexOrNull; } long tokenizedChars = 0; From 74bafa91881ec06005d9056ceb779269f9e9916d Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 24 Apr 2022 13:58:09 +0200 Subject: [PATCH 108/202] Improve TMModel thread-safety --- .../org/eclipse/tm4e/core/model/TMModel.java | 89 +++++++++---------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index a381f9337..9d07abf70 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -1,23 +1,24 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.model; import static java.lang.System.Logger.Level.*; import java.lang.System.Logger; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.PriorityBlockingQueue; import java.util.function.Consumer; @@ -38,19 +39,19 @@ public class TMModel implements ITMModel { private IGrammar grammar; /** Listener when TextMate model tokens changed **/ - private final List listeners = new ArrayList<>(); + private final Set listeners = new CopyOnWriteArraySet<>(); Tokenizer tokenizer; /** The background thread. */ - private TokenizerThread fThread; + private volatile TokenizerThread fThread; private final IModelLines lines; private final PriorityBlockingQueue invalidLines = new PriorityBlockingQueue<>(); public TMModel(IModelLines lines) { this.lines = lines; - ((AbstractLineList)lines).setModel(this); + ((AbstractLineList) lines).setModel(this); lines.forEach(ModelLine::resetTokenizationState); invalidateLine(0); } @@ -60,22 +61,19 @@ public TMModel(IModelLines lines) { * runs tokenizing in background on the lines found in {@link TMModel#lines}. * The {@link TMModel#lines} are expected to be accessed through {@link TMModel#getLines()} * and manipulated by the UI part to inform of needs to (re)tokenize area, then the {@link TokenizerThread} - * processes them and emits events through the model. UI elements are supposed to subscribe and react to the events with - * {@link TMModel#addModelTokensChangedListener(IModelTokensChangedListener)}. - * + * processes them and emits events through the model. UI elements are supposed to subscribe and react to the events + * with {@link TMModel#addModelTokensChangedListener(IModelTokensChangedListener)}. */ private static final class TokenizerThread extends Thread { private final TMModel model; private TMState lastState; /** - * Creates a new background thread. The thread runs with minimal - * priority. + * Creates a new background thread. The thread runs with minimal priority. * - * @param name - * the thread's name + * @param name the thread's name */ - public TokenizerThread(String name, TMModel model) { + TokenizerThread(String name, TMModel model) { super(name); this.model = model; setPriority(Thread.MIN_PRIORITY); @@ -84,11 +82,7 @@ public TokenizerThread(String name, TMModel model) { @Override public void run() { - if (isInterrupted()) { - return; - } - - do { + while (!isInterrupted() && model.fThread == this) { try { final int toProcess = model.invalidLines.take().intValue(); if (model.lines.get(toProcess).isInvalid) { @@ -104,7 +98,7 @@ public void run() { } catch (InterruptedException e) { interrupt(); } - } while (!isInterrupted() && model.fThread != null); + } } /** @@ -113,7 +107,7 @@ public void run() { * @param toLineIndexOrNull 0-based */ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { - model.buildEventWithCallback(eventBuilder -> { + model.buildAndEmitEvent(eventBuilder -> { final int toLineIndex; if (toLineIndexOrNull == null || toLineIndexOrNull >= model.lines.getNumberOfLines()) { toLineIndex = model.lines.getNumberOfLines() - 1; @@ -171,12 +165,12 @@ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { * @param startIndex 0-based * @param endLineIndex 0-based * @param emitEvents + * * @return the first line index (0-based) that was NOT processed by this operation */ private int updateTokensInRange(ModelTokensChangedEventBuilder eventBuilder, int startIndex, int endLineIndex) { - int stopLineTokenizationAfter = 1000000000; // 1 billion, if a line is - // so long, you have other - // trouble :). + int stopLineTokenizationAfter = 1_000_000_000; // 1 billion, if a line is so long, you have other trouble :) + // Validate all states up to and including endLineIndex int nextInvalidLineIndex = startIndex; int lineIndex = startIndex; @@ -256,21 +250,21 @@ public void setGrammar(IGrammar grammar) { } @Override - public void addModelTokensChangedListener(IModelTokensChangedListener listener) { - if (this.fThread == null || this.fThread.isInterrupted()) { - this.fThread = new TokenizerThread(getClass().getName(), this); - } - if (!this.fThread.isAlive()) { - this.fThread.start(); + public synchronized void addModelTokensChangedListener(IModelTokensChangedListener listener) { + listeners.add(listener); + + if (fThread == null || fThread.isInterrupted()) { + fThread = new TokenizerThread(getClass().getName(), this); } - if (!listeners.contains(listener)) { - listeners.add(listener); + if (!fThread.isAlive()) { + fThread.start(); } } @Override - public void removeModelTokensChangedListener(IModelTokensChangedListener listener) { + public synchronized void removeModelTokensChangedListener(IModelTokensChangedListener listener) { listeners.remove(listener); + if (listeners.isEmpty()) { // no need to keep tokenizing if no-one cares stop(); @@ -286,22 +280,22 @@ public void dispose() { /** * Interrupt the thread. */ - private void stop() { + private synchronized void stop() { if (fThread == null) { return; } - this.fThread.interrupt(); - this.fThread = null; + fThread.interrupt(); + fThread = null; } - private void buildEventWithCallback(Consumer callback) { - ModelTokensChangedEventBuilder eventBuilder = new ModelTokensChangedEventBuilder(this); + private void buildAndEmitEvent(final Consumer callback) { + final ModelTokensChangedEventBuilder eventBuilder = new ModelTokensChangedEventBuilder(this); callback.accept(eventBuilder); - ModelTokensChangedEvent e = eventBuilder.build(); - if (e != null) { - this.emit(e); + final ModelTokensChangedEvent event = eventBuilder.build(); + if (event != null) { + emit(event); } } @@ -312,10 +306,12 @@ private void emit(ModelTokensChangedEvent e) { } @Override - public void forceTokenization(int lineNumber) { - this.buildEventWithCallback(eventBuilder -> - this.fThread.updateTokensInRange(eventBuilder, lineNumber, lineNumber) - ); + public void forceTokenization(final int lineNumber) { + final var tokenizerThread = this.fThread; + if (tokenizerThread == null) { + return; + } + buildAndEmitEvent(eventBuilder -> tokenizerThread.updateTokensInRange(eventBuilder, lineNumber, lineNumber)); } @Override @@ -335,5 +331,4 @@ void invalidateLine(int lineIndex) { public IModelLines getLines() { return this.lines; } - } From ea9fc2d22c4b769502f3712f0477c048acf4e47e Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 26 Apr 2022 18:42:17 +0200 Subject: [PATCH 109/202] Upgrade Maven from 3.8.2 to 3.8.5 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3f17ad41..34022d8b3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,7 @@ jobs: - name: Set up Maven uses: stCarolas/setup-maven@v4.3 with: - maven-version: 3.8.2 + maven-version: 3.8.5 - name: Build with Maven From a7f5c8283b4ec13e36159f886d9276b7f8c112e1 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Wed, 27 Apr 2022 14:40:21 +0300 Subject: [PATCH 110/202] No need for OSGi to know about buildtime dependency. Handle at pde/tycho level. --- org.eclipse.tm4e.ui/META-INF/MANIFEST.MF | 1 - org.eclipse.tm4e.ui/build.properties | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF index 58129daa9..e1200a303 100644 --- a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF @@ -18,7 +18,6 @@ Require-Bundle: org.eclipse.tm4e.core, org.eclipse.e4.ui.css.swt.theme, org.eclipse.core.expressions, org.eclipse.ui.workbench.texteditor, - org.eclipse.jdt.annotation;bundle-version="2.2.0";resolution:=optional, org.eclipse.ui.trace;resolution:=optional Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.eclipse.tm4e.ui, diff --git a/org.eclipse.tm4e.ui/build.properties b/org.eclipse.tm4e.ui/build.properties index 0b1c73d72..e175a5d15 100644 --- a/org.eclipse.tm4e.ui/build.properties +++ b/org.eclipse.tm4e.ui/build.properties @@ -8,3 +8,5 @@ bin.includes = META-INF/,\ themes/,\ .options,\ about.html +## JDT Null Analysis +additional.bundles = org.eclipse.jdt.annotation From dd303fab43ce5277ac8de4da37d0f23b5647b138 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 27 Apr 2022 13:31:20 +0200 Subject: [PATCH 111/202] Refactor oniguruma package and enable annotation-based null analysis --- .../.settings/org.eclipse.jdt.core.prefs | 4 +- org.eclipse.tm4e.core/build.properties | 6 + .../tm4e/core/internal/grammar/Grammar.java | 2 +- .../core/internal/grammar/LineTokenizer.java | 16 +- .../internal/oniguruma/OnigCaptureIndex.java | 38 +++- .../oniguruma/OnigNextMatchResult.java | 60 ++++-- .../core/internal/oniguruma/OnigRegExp.java | 36 ++-- .../core/internal/oniguruma/OnigResult.java | 15 +- .../core/internal/oniguruma/OnigScanner.java | 25 ++- .../core/internal/oniguruma/OnigSearcher.java | 26 +-- .../core/internal/oniguruma/OnigString.java | 197 ++++++++++++------ .../core/internal/oniguruma/package-info.java | 4 + .../core/internal/rule/RegExpSourceList.java | 7 +- .../internal/oniguruma/OnigScannerTest.java | 43 ++++ .../internal/oniguruma/OnigStringTest.java | 161 ++++++++++---- .../core/internal/oniguruma/TestOngurama.java | 26 --- 16 files changed, 445 insertions(+), 221 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/package-info.java create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScannerTest.java delete mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java diff --git a/org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs index f648802b5..6b99f88fc 100644 --- a/org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.tm4e.core/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullable.secondary= -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 @@ -75,7 +75,7 @@ org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=wa org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=info org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning diff --git a/org.eclipse.tm4e.core/build.properties b/org.eclipse.tm4e.core/build.properties index 065c68847..0a9f3a653 100644 --- a/org.eclipse.tm4e.core/build.properties +++ b/org.eclipse.tm4e.core/build.properties @@ -4,3 +4,9 @@ bin.includes = META-INF/,\ .,\ plugin.properties,\ about.html + +# https://codeiseasy.wordpress.com/2013/03/08/tycho-and-jdt-null-analysis/ +# JDT Null Analysis for Eclipse +additional.bundles = org.eclipse.jdt.annotation +# JDT Null Analysis types for Tycho +jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index d5380a9b3..f48ff69ba 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -227,7 +227,7 @@ private T tokenize(String lineText, StackElement prevState, boolean emitBina // Only add \n if the passed lineText didn't have it. lineText += '\n'; } - OnigString onigLineText = new OnigString(lineText); + OnigString onigLineText = OnigString.of(lineText); int lineLength = lineText.length(); LineTokens lineTokens = new LineTokens(emitBinaryTokens, lineText); StackElement nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index f10afa519..738f09792 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -74,13 +74,11 @@ private WhileCheckResult(StackElement stack, int linePos, int anchorPosition, bo private final LineTokens lineTokens; private int anchorPosition = -1; private boolean stop; - private final int lineLength; private LineTokenizer(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, StackElement stack, LineTokens lineTokens) { this.grammar = grammar; this.lineText = lineText; - this.lineLength = lineText.utf8_value.length; this.isFirstLine = isFirstLine; this.linePos = linePos; this.stack = stack; @@ -112,7 +110,7 @@ private void scanNext() { if (r == null) { LOGGER.log(TRACE, " no more matches."); // No match - lineTokens.produce(stack, lineLength); + lineTokens.produce(stack, lineText.bytesCount); stop = true; return; } @@ -150,7 +148,7 @@ private void scanNext() { // intent was to continue in this state stack = popped; - lineTokens.produce(stack, lineLength); + lineTokens.produce(stack, lineText.bytesCount); stop = true; return; } @@ -193,7 +191,7 @@ private void scanNext() { LOGGER.log(INFO, "[2] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); stack = stack.pop(); - lineTokens.produce(stack, lineLength); + lineTokens.produce(stack, lineText.bytesCount); stop = true; return; } @@ -222,7 +220,7 @@ private void scanNext() { LOGGER.log(INFO, "[3] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); stack = stack.pop(); - lineTokens.produce(stack, lineLength); + lineTokens.produce(stack, lineText.bytesCount); stop = true; return; } @@ -245,7 +243,7 @@ private void scanNext() { LOGGER.log(INFO, "[4] - Grammar is in an endless loop - Grammar is not advancing, nor is it pushing/popping"); stack = stack.safePop(); - lineTokens.produce(stack, lineLength); + lineTokens.produce(stack, lineText.bytesCount); stop = true; return; } @@ -444,7 +442,7 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs StackElement stackClone = stack.push(captureRule.retokenizeCapturedWithRuleId, captureIndex.getStart(), null, nameScopesList, contentNameScopesList); tokenizeString(grammar, - new OnigString(lineText.string.substring(0, captureIndex.getEnd())), + OnigString.of(lineText.string.substring(0, captureIndex.getEnd())), (isFirstLine && captureIndex.getStart() == 0), captureIndex.getStart(), stackClone, lineTokens); continue; } @@ -500,7 +498,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe stack = whileRule.stack.pop(); break; } - if (r.getCaptureIndices() != null && r.getCaptureIndices().length > 0) { + if (r.getCaptureIndices().length > 0) { lineTokens.produce(whileRule.stack, r.getCaptureIndices()[0].getStart()); handleCaptures(grammar, lineText, isFirstLine, whileRule.stack, lineTokens, whileRule.rule.whileCaptures, r.getCaptureIndices()); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java index b8e035b3a..4ffc4c801 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java @@ -16,34 +16,58 @@ */ package org.eclipse.tm4e.core.internal.oniguruma; +import org.eclipse.jdt.annotation.Nullable; + public final class OnigCaptureIndex { private final int index; private final int start; private final int end; - OnigCaptureIndex(int index, int start, int end) { + OnigCaptureIndex(final int index, int start, final int end) { this.index = index; this.start = start >= 0 ? start : 0; this.end = end >= 0 ? end : 0; } - public int getIndex() { - return index; - } - - public int getStart() { - return start; + @Override + public boolean equals(@Nullable final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + final var other = (OnigCaptureIndex) obj; + return end == other.end + && index == other.index + && start == other.start; } public int getEnd() { return end; } + public int getIndex() { + return index; + } + public int getLength() { return end - start; } + public int getStart() { + return start; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + end; + result = prime * result + index; + result = prime * result + start; + return result; + } + @Override public String toString() { return "{" + diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java index 4df6e1063..ed96aa880 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigNextMatchResult.java @@ -16,34 +16,69 @@ */ package org.eclipse.tm4e.core.internal.oniguruma; +import java.util.Arrays; + +import org.eclipse.jdt.annotation.Nullable; + public final class OnigNextMatchResult { private final int index; - private final OnigCaptureIndex[] captureIndices; - OnigNextMatchResult(OnigResult result, OnigString source) { + OnigNextMatchResult(final OnigResult result, final OnigString source) { this.index = result.getIndex(); - this.captureIndices = captureIndicesForMatch(result, source); + this.captureIndices = captureIndicesOfMatch(result, source); } - public int getIndex() { - return index; + private OnigCaptureIndex[] captureIndicesOfMatch(final OnigResult result, final OnigString source) { + final int resultCount = result.count(); + final var captures = new OnigCaptureIndex[resultCount]; + for (int i = 0; i < resultCount; i++) { + final int loc = result.locationAt(i); + final int captureStart = source.getCharIndexOfByte(loc); + final int captureEnd = source.getCharIndexOfByte(loc + result.lengthAt(i)); + captures[i] = new OnigCaptureIndex(i, captureStart, captureEnd); + } + return captures; + } + + @Override + public boolean equals(@Nullable final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + final var other = (OnigNextMatchResult) obj; + return index == other.index + && Arrays.equals(captureIndices, other.captureIndices); } public OnigCaptureIndex[] getCaptureIndices() { return captureIndices; } + public int getIndex() { + return index; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + index; + result = prime * result + Arrays.hashCode(captureIndices); + return result; + } + @Override public String toString() { - final StringBuilder result = new StringBuilder("{\n"); + final var result = new StringBuilder("{\n"); result.append(" \"index\": "); result.append(getIndex()); result.append(",\n"); result.append(" \"captureIndices\": [\n"); int i = 0; - for (OnigCaptureIndex captureIndex : getCaptureIndices()) { + for (final OnigCaptureIndex captureIndex : getCaptureIndices()) { if (i > 0) { result.append(",\n"); } @@ -56,15 +91,4 @@ public String toString() { result.append("}"); return result.toString(); } - - private static OnigCaptureIndex[] captureIndicesForMatch(OnigResult result, OnigString source) { - int resultCount = result.count(); - OnigCaptureIndex[] captures = new OnigCaptureIndex[resultCount]; - for (int index = 0; index < resultCount; index++) { - int captureStart = source.convertUtf8OffsetToUtf16(result.locationAt(index)); - int captureEnd = source.convertUtf8OffsetToUtf16(result.locationAt(index) + result.lengthAt(index)); - captures[index] = new OnigCaptureIndex(index, captureStart, captureEnd); - } - return captures; - } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java index 2f153803b..2997f5b97 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.TMException; import org.jcodings.specific.UTF8Encoding; import org.joni.Matcher; @@ -38,38 +39,47 @@ */ final class OnigRegExp { + @Nullable private OnigString lastSearchString; + private int lastSearchPosition = -1; + + @Nullable private OnigResult lastSearchResult; + private final Regex regex; - OnigRegExp(String source) { - byte[] pattern = source.getBytes(StandardCharsets.UTF_8); + OnigRegExp(final String source) { + final byte[] pattern = source.getBytes(StandardCharsets.UTF_8); try { - this.regex = new Regex(pattern, 0, pattern.length, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, - Syntax.DEFAULT, WarnCallback.DEFAULT); + regex = new Regex(pattern, 0, pattern.length, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, Syntax.DEFAULT, + WarnCallback.DEFAULT); } catch (SyntaxException ex) { throw new TMException("Parsing regex pattern \"" + source + "\" failed with " + ex, ex); } } - OnigResult search(OnigString str, int position) { - if (lastSearchString == str && lastSearchPosition <= position && - (lastSearchResult == null || lastSearchResult.locationAt(0) >= position)) { - return lastSearchResult; + @Nullable + OnigResult search(final OnigString str, final int position) { + final OnigResult theLastSearchResult = lastSearchResult; + if (lastSearchString == str + && lastSearchPosition <= position + && (theLastSearchResult == null || theLastSearchResult.locationAt(0) >= position)) { + return theLastSearchResult; } lastSearchString = str; lastSearchPosition = position; - lastSearchResult = search(str.utf8_value, position, str.utf8_value.length); + lastSearchResult = search(str.bytesUTF8, position, str.bytesCount); return lastSearchResult; } - private OnigResult search(byte[] data, int position, int end) { - Matcher matcher = regex.matcher(data); - int status = matcher.search(position, end, Option.DEFAULT); + @Nullable + private OnigResult search(final byte[] data, final int position, final int end) { + final Matcher matcher = regex.matcher(data); + final int status = matcher.search(position, end, Option.DEFAULT); if (status != Matcher.FAILED) { - Region region = matcher.getEagerRegion(); + final Region region = matcher.getEagerRegion(); return new OnigResult(region, -1); } return null; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java index 4bb1c3b13..70323d2f0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigResult.java @@ -14,7 +14,6 @@ * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ - package org.eclipse.tm4e.core.internal.oniguruma; import org.joni.Region; @@ -24,7 +23,7 @@ final class OnigResult { private int indexInScanner; private final Region region; - OnigResult(Region region, int indexInScanner) { + OnigResult(final Region region, final int indexInScanner) { this.region = region; this.indexInScanner = indexInScanner; } @@ -33,12 +32,12 @@ int getIndex() { return indexInScanner; } - void setIndex(int index) { - this.indexInScanner = index; + void setIndex(final int index) { + indexInScanner = index; } - int locationAt(int index) { - int bytes = region.beg[index]; + int locationAt(final int index) { + final int bytes = region.beg[index]; if (bytes > 0) { return bytes; } @@ -49,8 +48,8 @@ int count() { return region.numRegs; } - int lengthAt(int index) { - int bytes = region.end[index] - region.beg[index]; + int lengthAt(final int index) { + final int bytes = region.end[index] - region.beg[index]; if (bytes > 0) { return bytes; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java index 50af76c91..4209e880e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScanner.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,30 +11,35 @@ * Initial license: MIT * * Contributors: - * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ - package org.eclipse.tm4e.core.internal.oniguruma; +import java.util.Collection; + +import org.eclipse.jdt.annotation.Nullable; + public final class OnigScanner { private final OnigSearcher searcher; - public OnigScanner(String[] regexps) { - this.searcher = new OnigSearcher(regexps); + public OnigScanner(final Collection regexps) { + searcher = new OnigSearcher(regexps); } - public OnigNextMatchResult findNextMatchSync(OnigString source, int charOffset) { - OnigResult bestResult = searcher.search(source, charOffset); + @Nullable + public OnigNextMatchResult findNextMatchSync(final OnigString source, final int charOffset) { + final OnigResult bestResult = searcher.search(source, charOffset); if (bestResult != null) { return new OnigNextMatchResult(bestResult, source); } return null; } - OnigNextMatchResult findNextMatchSync(String lin, int pos) { - return findNextMatchSync(new OnigString(lin), pos); + @Nullable + OnigNextMatchResult findNextMatchSync(final String lin, final int pos) { + return findNextMatchSync(OnigString.of(lin), pos); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java index 7dd66d328..d7309e6d0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigSearcher.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,34 +11,37 @@ * Initial license: MIT * * Contributors: - * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - GitHub Inc.: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.oniguruma; -import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; + final class OnigSearcher { private final List regExps; - OnigSearcher(String[] regexps) { - this.regExps = Arrays.stream(regexps).map(OnigRegExp::new).collect(Collectors.toList()); + OnigSearcher(final Collection regExps) { + this.regExps = regExps.stream().map(OnigRegExp::new).collect(Collectors.toList()); } - OnigResult search(OnigString source, int charOffset) { - int byteOffset = source.convertUtf16OffsetToUtf8(charOffset); + @Nullable + OnigResult search(final OnigString source, final int charOffset) { + final int byteOffset = source.getByteIndexOfChar(charOffset); int bestLocation = 0; OnigResult bestResult = null; int index = 0; - for (OnigRegExp regExp : regExps) { - OnigResult result = regExp.search(source, byteOffset); + for (final OnigRegExp regExp : regExps) { + final OnigResult result = regExp.search(source, byteOffset); if (result != null && result.count() > 0) { - int location = result.locationAt(0); + final int location = result.locationAt(0); if (bestResult == null || location < bestLocation) { bestLocation = location; @@ -54,5 +57,4 @@ OnigResult search(OnigString source, int charOffset) { } return bestResult; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java index d9d65949d..9122036d0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; +import org.eclipse.jdt.annotation.Nullable; import org.jcodings.specific.UTF8Encoding; /** @@ -30,95 +31,153 @@ * github.com/atom/node-oniguruma/blob/master/src/onig-string.cc * */ -public final class OnigString { +public abstract class OnigString { - public final String string; - public final byte[] utf8_value; - - private int[] charsPosFromBytePos; - private boolean computedOffsets; + /** + * Represents a string that contains multi-byte characters + */ + static final class MultiByteString extends OnigString { - public OnigString(String str) { - this.string = str; - this.utf8_value = str.getBytes(StandardCharsets.UTF_8); - } + /** + * For each byte holds the index of the char to which the byte belongs. + * E.g. in case of byteToCharOffsets[100] == 60 && byteToCharOffsets[101] == 60, + * the bytes at indexes 100 and 101 both belong to the same multi-byte character at index 60. + */ + private int @Nullable [] byteToCharOffsets; + private final int lastCharIndex; - int convertUtf16OffsetToUtf8(int posInChars) { - if (!computedOffsets) { - computeOffsets(); + private MultiByteString(final String str, final byte[] bytesUTF8) { + super(str, bytesUTF8); + lastCharIndex = str.length() - 1; } - if (charsPosFromBytePos == null) { - // Same conditions as code below, but taking into account that the - // bytes and chars len are the same. - if (posInChars < 0 || this.utf8_value.length == 0 || posInChars > this.utf8_value.length) { - throw new ArrayIndexOutOfBoundsException(posInChars); + + @Override + int getByteIndexOfChar(final int charIndex) { + if (charIndex == lastCharIndex + 1) { + // One off can happen when finding the end of a regexp (it's the right boundary). + return lastCharIndex + 1; } - return posInChars; - } - int[] charsLenInBytes = charsPosFromBytePos; - if (posInChars < 0 || charsLenInBytes.length == 0) { - throw new ArrayIndexOutOfBoundsException(posInChars); - } - if (posInChars == 0) { - return 0; + if (charIndex < 0 || charIndex > lastCharIndex) { + throwOutOfBoundsException("Char", charIndex, 0, lastCharIndex); + } + if (charIndex == 0) { + return 0; + } + + final int[] byteToCharOffsets = getByteToCharOffsets(); + int byteIndex = Arrays.binarySearch(byteToCharOffsets, charIndex); + while (byteIndex > 0 && byteToCharOffsets[byteIndex - 1] == charIndex) { + byteIndex--; + } + return byteIndex; } - int last = charsLenInBytes[charsLenInBytes.length - 1]; - if (last < posInChars) { - if (last == posInChars - 1) { - return charsLenInBytes.length; + private int[] getByteToCharOffsets() { + int[] offsets = byteToCharOffsets; + if (offsets == null) { + offsets = new int[bytesCount]; + int charIndex = 0; + int byteIndex = 0; + final int maxByteIndex = bytesCount - 1; + while (byteIndex <= maxByteIndex) { + final int charLenInBytes = UTF8Encoding.INSTANCE.length(bytesUTF8, byteIndex, bytesCount); + // same as "Arrays.fill(offsets, byteIndex, byteIndex + charLenInBytes, charIndex)" but faster + for (int l = byteIndex + charLenInBytes; byteIndex < l; byteIndex++) { + offsets[byteIndex] = charIndex; + } + charIndex++; + } + byteToCharOffsets = offsets; } - throw new ArrayIndexOutOfBoundsException(posInChars); + return offsets; } - int index = Arrays.binarySearch(charsLenInBytes, posInChars); - while (index > 0) { - if (charsLenInBytes[index - 1] == posInChars) { - index--; - } else { - break; + @Override + int getCharIndexOfByte(final int byteIndex) { + if (byteIndex == bytesCount) { + // One off can happen when finding the end of a regexp (it's the right boundary). + return lastCharIndex + 1; + } + + if (byteIndex < 0 || byteIndex >= bytesCount) { + throwOutOfBoundsException("Byte", byteIndex, 0, bytesCount - 1); } + if (byteIndex == 0) { + return 0; + } + + return getByteToCharOffsets()[byteIndex]; } - return index; } - int convertUtf8OffsetToUtf16(int posInBytes) { - if (!computedOffsets) { - computeOffsets(); - } - if (charsPosFromBytePos == null) { - return posInBytes; - } - if (posInBytes < 0) { - return posInBytes; + /** + * Represents a string is only composed of single-byte characters + */ + static final class SingleByteString extends OnigString { + + private SingleByteString(final String str, final byte[] bytesUTF8) { + super(str, bytesUTF8); } - if (posInBytes >= charsPosFromBytePos.length) { - //One off can happen when finding the end of a regexp (it's the right boundary). - return charsPosFromBytePos[posInBytes - 1] + 1; + + @Override + int getByteIndexOfChar(final int charIndex) { + if (charIndex == bytesCount) { + // One off can happen when finding the end of a regexp (it's the right boundary). + return charIndex; + } + + if (charIndex < 0 || charIndex >= bytesCount) { + throwOutOfBoundsException("Char", charIndex, 0, bytesCount - 1); + } + return charIndex; } - return charsPosFromBytePos[posInBytes]; - } - private void computeOffsets() { - if (this.utf8_value.length != this.string.length()) { - charsPosFromBytePos = new int[this.utf8_value.length]; - int bytesLen = 0; - int charsLen = 0; - int length = this.utf8_value.length; - for (int i = 0; i < length;) { - int codeLen = UTF8Encoding.INSTANCE.length(this.utf8_value, i, length); - for (int i1 = 0; i1 < codeLen; i1++) { - charsPosFromBytePos[bytesLen + i1] = charsLen; - } - bytesLen += codeLen; - i += codeLen; - charsLen += 1; + @Override + int getCharIndexOfByte(final int byteIndex) { + if (byteIndex == bytesCount) { + // One off can happen when finding the end of a regexp (it's the right boundary). + return byteIndex; } - if (bytesLen != this.utf8_value.length) { - throw new AssertionError(bytesLen + " != " + this.utf8_value.length); + + if (byteIndex < 0 || byteIndex >= bytesCount) { + throwOutOfBoundsException("Byte", byteIndex, 0, bytesCount - 1); } + return byteIndex; } - computedOffsets = true; + } + + public static OnigString of(final String str) { + final byte[] bytesUtf8 = str.getBytes(StandardCharsets.UTF_8); + if (bytesUtf8.length == str.length()) { + return new SingleByteString(str, bytesUtf8); + } + return new MultiByteString(str, bytesUtf8); + } + + public final String string; + + public final int bytesCount; + final byte[] bytesUTF8; + + private OnigString(final String str, final byte[] bytesUTF8) { + string = str; + this.bytesUTF8 = bytesUTF8; + bytesCount = bytesUTF8.length; + } + + protected final String throwOutOfBoundsException(final String indexName, final int index, final int minIndex, + final int maxIndex) { + throw new ArrayIndexOutOfBoundsException( + indexName + " index " + index + " is out of range " + minIndex + ".." + maxIndex + " of " + this); + } + + abstract int getByteIndexOfChar(int charIndex); + + abstract int getCharIndexOfByte(int byteIndex); + + @Override + public String toString() { + return getClass().getSimpleName() + "[string=\"" + string + "\"]"; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/package-info.java new file mode 100644 index 000000000..e57353dd1 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.oniguruma; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index 83e7b792a..1d6c029ad 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -82,7 +82,7 @@ CompiledRule compile(boolean allowA, boolean allowG) { for (RegExpSource regExpSource : _items) { regexps.add(regExpSource.getSource()); } - this._cached = new CompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); + this._cached = new CompiledRule(new OnigScanner(regexps), getRules()); } return this._cached; } @@ -122,12 +122,9 @@ private CompiledRule _resolveAnchors(boolean allowA, boolean allowG) { for (RegExpSource regExpSource : _items) { regexps.add(regExpSource.resolveAnchors(allowA, allowG)); } - return new CompiledRule(createOnigScanner(regexps.toArray(String[]::new)), getRules()); + return new CompiledRule(new OnigScanner(regexps), getRules()); } - private OnigScanner createOnigScanner(String[] regexps) { - return new OnigScanner(regexps); - } private Integer[] getRules() { Collection ruleIds = new ArrayList<>(); diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScannerTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScannerTest.java new file mode 100644 index 000000000..21e411ffc --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigScannerTest.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.core.internal.oniguruma; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class OnigScannerTest { + + @Test + void testOnigScanner() { + OnigScanner scanner = new OnigScanner(Arrays.asList("c", "a(b)?")); + OnigNextMatchResult result = scanner.findNextMatchSync("abc", 0); + assertNotNull(result); + assertEquals(1, result.getIndex()); + assertArrayEquals(new OnigCaptureIndex[] { + new OnigCaptureIndex(0, 0, 2), + new OnigCaptureIndex(1, 1, 2) }, + result.getCaptureIndices()); + + scanner = new OnigScanner(Arrays.asList("a([b-d])c")); + result = scanner.findNextMatchSync("!abcdef", 0); + assertNotNull(result); + assertEquals(0, result.getIndex()); + assertArrayEquals(new OnigCaptureIndex[] { + new OnigCaptureIndex(0, 1, 4), + new OnigCaptureIndex(1, 2, 3) }, + result.getCaptureIndices()); + + } +} diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigStringTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigStringTest.java index 277c7fec3..25495a42a 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigStringTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/OnigStringTest.java @@ -4,52 +4,131 @@ import org.junit.jupiter.api.Test; -public class OnigStringTest { +class OnigStringTest { + + private OnigString verifyBasics(final String string, final Class expectedType) { + final OnigString onigString = OnigString.of(string); + assertInstanceOf(expectedType, onigString); + assertEquals(string, onigString.string); + assertTrue(onigString.toString().contains(string)); + + assertEquals(onigString.bytesCount, onigString.bytesUTF8.length); + + /* + * getByteIndexOfChar tests + */ + assertThrows(ArrayIndexOutOfBoundsException.class, () -> onigString.getByteIndexOfChar(-1)); + assertEquals(0, onigString.getByteIndexOfChar(0)); + if (!string.isEmpty()) + onigString.getByteIndexOfChar(string.length() - 1); // does not throws exception, because in range + onigString.getByteIndexOfChar(string.length()); // does not throws exception, because of internal workaround + assertThrows(ArrayIndexOutOfBoundsException.class, () -> onigString.getByteIndexOfChar(string.length() + 1)); + + /* + * getCharIndexOfByte tests + */ + assertThrows(ArrayIndexOutOfBoundsException.class, () -> onigString.getCharIndexOfByte(-1)); + assertEquals(0, onigString.getCharIndexOfByte(0)); + if (!string.isEmpty()) { + // does not throws exception, because in range + assertEquals(string.length() - 1, onigString.getCharIndexOfByte(onigString.bytesCount - 1)); + } + // does not throws exception, because of internal workaround + assertEquals(string.length(), onigString.getCharIndexOfByte(onigString.bytesCount)); + + assertThrows(ArrayIndexOutOfBoundsException.class, + () -> onigString.getCharIndexOfByte(onigString.bytesCount + 1)); + + return onigString; + } + + @Test + void testEmptyStrings() { + String string = ""; + OnigString onigString = verifyBasics(string, OnigString.SingleByteString.class); + + assertEquals(0, onigString.bytesCount); + } + + @Test + void testSingleBytesStrings() { + String string = "ab"; + OnigString onigString = verifyBasics(string, OnigString.SingleByteString.class); + + assertEquals(2, onigString.bytesCount); + + /* + * getByteIndexOfChar tests + */ + assertEquals(1, onigString.getByteIndexOfChar(1)); + assertEquals(string.length() - 1, onigString.getByteIndexOfChar(string.length() - 1)); + + /* + * getCharIndexOfByte tests + */ + assertEquals(1, onigString.getCharIndexOfByte(1)); // b + assertEquals(2, onigString.getCharIndexOfByte(2)); // does not throws exception, because of internal workaround + assertThrows(ArrayIndexOutOfBoundsException.class, () -> onigString.getCharIndexOfByte(3)); + } @Test - public void testUtf8Utf16Conversions() { - OnigString onigString = new OnigString("áé"); - assertEquals(onigString.utf8_value.length, 4); - assertEquals(onigString.string.length(), 2); - assertEquals(onigString.convertUtf8OffsetToUtf16(0), 0); + void testMultiByteString() { + String string = "áé"; + OnigString onigString = verifyBasics(string, OnigString.MultiByteString.class); + + assertEquals(4, onigString.bytesCount); + + /* + * getByteIndexOfChar tests + */ + assertEquals(2, onigString.getByteIndexOfChar(1)); + + /* + * getCharIndexOfByte tests + */ + assertEquals(0, onigString.getCharIndexOfByte(1)); // á + assertEquals(1, onigString.getCharIndexOfByte(2)); // é + assertEquals(1, onigString.getCharIndexOfByte(3)); // é + assertEquals(2, onigString.getCharIndexOfByte(4)); // this is an internal workaround + assertThrows(ArrayIndexOutOfBoundsException.class, () -> onigString.getCharIndexOfByte(5)); + } @Test - public void testUtf8Utf16Conversions2() { - - String string = "myááçóúôõaab"; - OnigString utf8WithCharLen = new OnigString(string); - - assertEquals(0, utf8WithCharLen.convertUtf16OffsetToUtf8(0)); - assertEquals(1, utf8WithCharLen.convertUtf16OffsetToUtf8(1)); - assertEquals(2, utf8WithCharLen.convertUtf16OffsetToUtf8(2)); - assertEquals(4, utf8WithCharLen.convertUtf16OffsetToUtf8(3)); - assertEquals(6, utf8WithCharLen.convertUtf16OffsetToUtf8(4)); - assertEquals(8, utf8WithCharLen.convertUtf16OffsetToUtf8(5)); - assertEquals(10, utf8WithCharLen.convertUtf16OffsetToUtf8(6)); - assertEquals(12, utf8WithCharLen.convertUtf16OffsetToUtf8(7)); - try { - utf8WithCharLen.convertUtf16OffsetToUtf8(55); - fail("Expected error"); - } catch (ArrayIndexOutOfBoundsException e) { - } - - assertEquals(0, utf8WithCharLen.convertUtf8OffsetToUtf16(0)); - assertEquals(1, utf8WithCharLen.convertUtf8OffsetToUtf16(1)); - assertEquals(2, utf8WithCharLen.convertUtf8OffsetToUtf16(2)); - assertEquals(2, utf8WithCharLen.convertUtf8OffsetToUtf16(3)); - assertEquals(3, utf8WithCharLen.convertUtf8OffsetToUtf16(4)); - assertEquals(3, utf8WithCharLen.convertUtf8OffsetToUtf16(5)); - assertEquals(4, utf8WithCharLen.convertUtf8OffsetToUtf16(6)); - assertEquals(4, utf8WithCharLen.convertUtf8OffsetToUtf16(7)); - assertEquals(5, utf8WithCharLen.convertUtf8OffsetToUtf16(8)); - assertEquals(6, utf8WithCharLen.convertUtf8OffsetToUtf16(10)); - assertEquals(7, utf8WithCharLen.convertUtf8OffsetToUtf16(12)); - try { - utf8WithCharLen.convertUtf8OffsetToUtf16(55); - fail("Expected error"); - } catch (ArrayIndexOutOfBoundsException e) { - } + void testMixedMultiByteString() { + String string = "myááçóúôõaab"; + OnigString onigString = verifyBasics(string, OnigString.MultiByteString.class); + + assertEquals(19, onigString.bytesCount); + + /* + * getByteIndexOfChar tests + */ + assertEquals(1, onigString.getByteIndexOfChar(1)); + assertEquals(2, onigString.getByteIndexOfChar(2)); + assertEquals(4, onigString.getByteIndexOfChar(3)); + assertEquals(6, onigString.getByteIndexOfChar(4)); + assertEquals(8, onigString.getByteIndexOfChar(5)); + assertEquals(10, onigString.getByteIndexOfChar(6)); + assertEquals(12, onigString.getByteIndexOfChar(7)); + + /* + * getCharIndexOfByte tests + */ + assertEquals(1, onigString.getCharIndexOfByte(1)); + assertEquals(2, onigString.getCharIndexOfByte(2)); + assertEquals(2, onigString.getCharIndexOfByte(3)); + assertEquals(3, onigString.getCharIndexOfByte(4)); + assertEquals(3, onigString.getCharIndexOfByte(5)); + assertEquals(4, onigString.getCharIndexOfByte(6)); + assertEquals(4, onigString.getCharIndexOfByte(7)); + assertEquals(5, onigString.getCharIndexOfByte(8)); + assertEquals(6, onigString.getCharIndexOfByte(10)); + assertEquals(7, onigString.getCharIndexOfByte(12)); + assertEquals(10, onigString.getCharIndexOfByte(17)); // a + assertEquals(11, onigString.getCharIndexOfByte(18)); // b + assertEquals(12, onigString.getCharIndexOfByte(19)); // this is an internal workaround + assertThrows(ArrayIndexOutOfBoundsException.class, () -> onigString.getCharIndexOfByte(20)); } } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java deleted file mode 100644 index 818972101..000000000 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/oniguruma/TestOngurama.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.oniguruma; - -public class TestOngurama { - - public static void main(String[] args) { - - OnigScanner scanner = new OnigScanner(new String[] { "c", "a(b)?" }); - OnigNextMatchResult result = scanner.findNextMatchSync("abc", 0); - System.err.println(result); - - scanner = new OnigScanner(new String[] { "a([b-d])c" }); - result = scanner.findNextMatchSync("!abcdef", 0); - System.err.println(result); - } -} From 09fcb8bfd0615bbb57c297139c37adfeb2d9eb40 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 27 Apr 2022 13:31:33 +0200 Subject: [PATCH 112/202] Enable annotation-based null analysis for tm4e.core.internal.utils --- .../core/internal/utils/CompareUtils.java | 20 +++++-------- .../tm4e/core/internal/utils/RegexSource.java | 30 +++++++++++-------- .../core/internal/utils/package-info.java | 4 +++ 3 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java index c661aff3f..b0bbbe9b7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java @@ -2,9 +2,11 @@ import java.util.List; +import org.eclipse.jdt.annotation.Nullable; + public final class CompareUtils { - public static int strcmp(String a, String b) { + public static int strcmp(@Nullable final String a, @Nullable final String b) { if (a == null && b == null) { return 0; } @@ -14,23 +16,16 @@ public static int strcmp(String a, String b) { if (b == null) { return 1; } -// if (a < b) { -// return -1; -// } -// if (a > b) { -// return 1; -// } -// return 0; int result = a.compareTo(b); - if (result < 0 ) { + if (result < 0) { return -1; - } else if (result > 0 ) { + } else if (result > 0) { return 1; - } + } return 0; } - public static int strArrCmp(List a, List b) { + public static int strArrCmp(@Nullable final List a, @Nullable final List b) { if (a == null && b == null) { return 0; } @@ -53,5 +48,4 @@ public static int strArrCmp(List a, List b) { } return len1 - len2; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index 6c195a81f..62217ca1d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,14 +11,15 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.utils; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; public final class RegexSource { @@ -32,36 +33,39 @@ private RegexSource() { private static final Pattern CAPTURING_REGEX_SOURCE = Pattern .compile("\\$(\\d+)|\\$\\{(\\d+):\\/(downcase|upcase)}"); - public static boolean hasCaptures(String regexSource) { + public static boolean hasCaptures(@Nullable final String regexSource) { if (regexSource == null) { return false; } return CAPTURING_REGEX_SOURCE.matcher(regexSource).find(); } - public static String replaceCaptures(String regexSource, String captureSource, OnigCaptureIndex[] captureIndices) { - Matcher m = CAPTURING_REGEX_SOURCE.matcher(regexSource); + public static String replaceCaptures(final String regexSource, final String captureSource, + final OnigCaptureIndex[] captureIndices) { + final Matcher m = CAPTURING_REGEX_SOURCE.matcher(regexSource); final StringBuilder result = new StringBuilder(); while (m.find()) { - String match = m.group(); - String replacement = getReplacement(match, captureSource, captureIndices); + final String match = m.group(); + final String replacement = getReplacement(match, captureSource, captureIndices); m.appendReplacement(result, replacement); } m.appendTail(result); return result.toString(); } - private static String getReplacement(String match, String captureSource, OnigCaptureIndex[] captureIndices) { - int index = -1; - String command = null; - int doublePointIndex = match.indexOf(':'); + private static String getReplacement(final String match, final String captureSource, + final OnigCaptureIndex[] captureIndices) { + final int index; + final String command; + final int doublePointIndex = match.indexOf(':'); if (doublePointIndex != -1) { index = Integer.parseInt(match.substring(2, doublePointIndex)); command = match.substring(doublePointIndex + 2, match.length() - 1); } else { index = Integer.parseInt(match.substring(1)); + command = null; } - OnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null; + final OnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null; if (capture != null) { String result = captureSource.substring(capture.getStart(), capture.getEnd()); // Remove leading dots that would make the selector invalid diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/package-info.java new file mode 100644 index 000000000..110daeb6c --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.utils; + +import org.eclipse.jdt.annotation.NonNullByDefault; From 8344217cbe14308d97c5b718c6e4bf15150c1712 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 27 Apr 2022 13:36:10 +0200 Subject: [PATCH 113/202] Refactor internal matcher package, enable annotation-based null analysis --- .../core/internal/grammar/LineTokenizer.java | 11 +- .../matcher/IMatchInjectionsResult.java | 23 ---- .../core/internal/matcher/IMatchResult.java | 27 ---- .../core/internal/matcher/IMatchesName.java | 25 ++-- .../tm4e/core/internal/matcher/Matcher.java | 130 +++++++++++------- .../internal/matcher/MatcherWithPriority.java | 13 +- .../core/internal/matcher/package-info.java | 4 + 7 files changed, 106 insertions(+), 127 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 738f09792..d24f4a931 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -24,8 +24,6 @@ import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; -import org.eclipse.tm4e.core.internal.matcher.IMatchInjectionsResult; -import org.eclipse.tm4e.core.internal.matcher.IMatchResult; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; import org.eclipse.tm4e.core.internal.oniguruma.OnigNextMatchResult; import org.eclipse.tm4e.core.internal.oniguruma.OnigString; @@ -40,6 +38,15 @@ final class LineTokenizer { private static final Logger LOGGER = System.getLogger(LineTokenizer.class.getName()); + private interface IMatchResult { + OnigCaptureIndex[] getCaptureIndices(); + int getMatchedRuleId(); + } + + private interface IMatchInjectionsResult extends IMatchResult { + boolean isPriorityMatch(); + } + private static final class WhileStack { private final StackElement stack; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java deleted file mode 100644 index 37ecd5cf2..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchInjectionsResult.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.matcher; - -public interface IMatchInjectionsResult extends IMatchResult { - - boolean isPriorityMatch(); - -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java deleted file mode 100644 index 3f8b80da0..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchResult.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.matcher; - -import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; - -public interface IMatchResult { - - OnigCaptureIndex[] getCaptureIndices(); - - int getMatchedRuleId(); - -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java index 006fbc936..6f5c3858e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,30 +11,30 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.matcher; import java.util.Collection; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.jdt.annotation.Nullable; interface IMatchesName { IMatchesName> NAME_MATCHER = new IMatchesName<>() { @Override - public boolean match(Collection identifers, List scopes) { + public boolean match(final Collection identifers, final List scopes) { if (scopes.size() < identifers.size()) { return false; } - AtomicInteger lastIndex = new AtomicInteger(); - // every + final int[] lastIndex = { 0 }; return identifers.stream().allMatch(identifier -> { - for (int i = lastIndex.get(); i < scopes.size(); i++) { + for (int i = lastIndex[0]; i < scopes.size(); i++) { if (scopesAreMatching(scopes.get(i), identifier)) { - lastIndex.incrementAndGet(); + lastIndex[0]++; return true; } } @@ -42,7 +42,7 @@ public boolean match(Collection identifers, List scopes) { }); } - private boolean scopesAreMatching(String thisScopeName, String scopeName) { + private boolean scopesAreMatching(@Nullable final String thisScopeName, final String scopeName) { if (thisScopeName == null) { return false; } @@ -50,12 +50,11 @@ private boolean scopesAreMatching(String thisScopeName, String scopeName) { return true; } int len = scopeName.length(); - return thisScopeName.length() > len && thisScopeName.substring(0, len).equals(scopeName) + return thisScopeName.length() > len + && thisScopeName.substring(0, len).equals(scopeName) && thisScopeName.charAt(len) == '.'; } - }; boolean match(Collection names, T scopes); - } \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java index 744a8e49e..0ed87268b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,46 +11,48 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.matcher; +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.function.Predicate; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.Nullable; + /** * Matcher utilities. * * @see * github.com/Microsoft/vscode-textmate/blob/master/src/matcher.ts - * */ -public final class Matcher implements Predicate { +public final class Matcher { - private static final Pattern IDENTIFIER_REGEXP = Pattern.compile("[\\w\\.:]+"); + private static final Logger LOGGER = System.getLogger(Matcher.class.getName()); - public static Collection>> createMatchers(String expression) { - return createMatchers(expression, IMatchesName.NAME_MATCHER); - } - - private static Collection> createMatchers(String selector, IMatchesName matchesName) { - return new Matcher<>(selector, matchesName).results; + public static List>> createMatchers(final String expression) { + return new Matcher<>(expression, IMatchesName.NAME_MATCHER).results; } private final List> results = new ArrayList<>(); private final Tokenizer tokenizer; private final IMatchesName matchesName; + + @Nullable private String token; - private Matcher(String expression, IMatchesName matchesName) { - this.tokenizer = new Tokenizer(expression); + private Matcher(final String expression, final IMatchesName matchesName) { + tokenizer = new Tokenizer(expression); this.matchesName = matchesName; - this.token = tokenizer.next(); + // defining local token variable for annotation-based null analysis + var token = this.token = tokenizer.next(); while (token != null) { int priority = 0; if (token.length() == 2 && token.charAt(1) == ':') { @@ -62,39 +64,38 @@ private Matcher(String expression, IMatchesName matchesName) { priority = -1; break; default: - // console.log(`Unknown priority ${token} in scope selector`); + LOGGER.log(WARNING, "Unknown priority %s in scope selector %s", token, expression); } - token = tokenizer.next(); - } - Predicate matcher = parseConjunction(); - if (matcher != null) { - results.add(new MatcherWithPriority<>(matcher, priority)); + this.token = tokenizer.next(); } - if (!",".equals(token)) { + final Predicate matcher = parseConjunction(); + results.add(new MatcherWithPriority<>(matcher, priority)); + if (!",".equals(this.token)) { break; } - token = tokenizer.next(); + token = this.token = tokenizer.next(); } } private Predicate parseInnerExpression() { - List> matchers = new ArrayList<>(); + final var matchers = new ArrayList>(); Predicate matcher = parseConjunction(); - while (matcher != null) { + while (true) { matchers.add(matcher); if ("|".equals(token) || ",".equals(token)) { do { token = tokenizer.next(); - } while ("|".equals(token) || ",".equals(token)); // ignore subsequent - // commas + } while ("|".equals(token) || ",".equals(token)); // ignore subsequent commas } else { break; } matcher = parseConjunction(); } + // some (or) return matcherInput -> { - for (Predicate matcher1 : matchers) { + // same as 'matchers.stream().anyMatch(m -> m.test(matcherInput))' but more memory friendly + for (final Predicate matcher1 : matchers) { if (matcher1.test(matcherInput)) { return true; } @@ -104,15 +105,17 @@ private Predicate parseInnerExpression() { } private Predicate parseConjunction() { - List> matchers = new ArrayList<>(); + final var matchers = new ArrayList>(); Predicate matcher = parseOperand(); while (matcher != null) { matchers.add(matcher); matcher = parseOperand(); } + // every (and) return matcherInput -> { - for (Predicate matcher1 : matchers) { + // same as 'matchers.stream().allMatch(m -> m.test(matcherInput))' but more memory friendly + for (final Predicate matcher1 : matchers) { if (!matcher1.test(matcherInput)) { return false; } @@ -121,55 +124,77 @@ private Predicate parseConjunction() { }; } + @Nullable private Predicate parseOperand() { if ("-".equals(token)) { token = tokenizer.next(); - Predicate expressionToNegate = parseOperand(); - return matcherInput -> { - if (expressionToNegate == null) { - return false; - } - return !expressionToNegate.test(matcherInput); - }; + final var expressionToNegate = parseOperand(); + return matcherInput -> expressionToNegate != null && !expressionToNegate.test(matcherInput); } + if ("(".equals(token)) { token = tokenizer.next(); - Predicate expressionInParents = parseInnerExpression(); + final var expressionInParents = parseInnerExpression(); if (")".equals(token)) { token = tokenizer.next(); } return expressionInParents; } - if (isIdentifier(token)) { - Collection identifiers = new ArrayList<>(); + + // defining local token variable for annotation-based null analysis + var token = this.token; + if (token != null && isIdentifier(token)) { + final var identifiers = new ArrayList(); do { identifiers.add(token); - token = tokenizer.next(); - } while (isIdentifier(token)); - return matcherInput -> Matcher.this.matchesName.match(identifiers, matcherInput); + token = this.token = tokenizer.next(); + } while (token != null && isIdentifier(token)); + return matcherInput -> matchesName.match(identifiers, matcherInput); } return null; } + /** + * https://github.com/microsoft/vscode-textmate/blob/master/src/matcher.ts#L89 + */ private boolean isIdentifier(String token) { - return token != null && IDENTIFIER_REGEXP.matcher(token).matches(); - } + if (token.isEmpty()) + return false; - @Override - public boolean test(T matcherInput) { - return false; + /* Aprox. 2-3 times faster than: + * static final Pattern IDENTIFIER_REGEXP = Pattern.compile("[\\w\\.:]+"); + * IDENTIFIER_REGEXP.matcher(token).matches(); + * + * Aprox. 10% faster than: + * token.chars().allMatch(ch -> ... ) + */ + for (int i = 0; i < token.length(); i++) { + final char ch = token.charAt(i); + if (ch == '.' || ch == ':' || ch == '_' + || (ch >= 'a' && ch <= 'z') + || (ch >= 'A' && ch <= 'Z') + || (ch >= '0' && ch <= '9')) + continue; + return false; + } + return true; } private static final class Tokenizer { - private static final Pattern REGEXP = Pattern.compile("([LR]:|[\\w\\.:]+|[\\,\\|\\-\\(\\)])"); + /** + * https://github.com/microsoft/vscode-textmate/blob/master/src/matcher.ts#L94 + */ + private static final Pattern TOKEN_PATTERN = Pattern + .compile("([LR]:|[\\w\\.:][\\w\\.:\\-]*|[\\,\\|\\-\\(\\)])"); private final java.util.regex.Matcher regex; - private Tokenizer(String input) { - this.regex = REGEXP.matcher(input); + private Tokenizer(final String input) { + regex = TOKEN_PATTERN.matcher(input); } + @Nullable private String next() { if (regex.find()) { return regex.group(); @@ -177,5 +202,4 @@ private String next() { return null; } } - } \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java index 0cbea1228..3365b05d6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.matcher; @@ -23,13 +23,8 @@ public final class MatcherWithPriority { public final Predicate matcher; public final int priority; - /** - * @param matcher - * @param priority - */ - MatcherWithPriority(Predicate matcher, int priority) { + MatcherWithPriority(final Predicate matcher, final int priority) { this.matcher = matcher; this.priority = priority; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/package-info.java new file mode 100644 index 000000000..5fd900fb5 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.matcher; + +import org.eclipse.jdt.annotation.NonNullByDefault; From fe015cf389f789cc2b6a2536dc839fd933566c83 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 14:05:21 +0200 Subject: [PATCH 114/202] Refactor internal rule package, enable annotation-based null analysis --- .../tm4e/core/internal/grammar/Grammar.java | 8 +- .../core/internal/grammar/LineTokenizer.java | 35 +- .../tm4e/core/internal/rule/BeginEndRule.java | 84 +++-- .../core/internal/rule/BeginWhileRule.java | 79 +++-- .../tm4e/core/internal/rule/CaptureRule.java | 26 +- .../internal/rule/CompilePatternsResult.java | 13 +- .../tm4e/core/internal/rule/CompiledRule.java | 9 +- .../core/internal/rule/IGrammarRegistry.java | 7 + .../internal/rule/IRuleFactoryHelper.java | 5 + .../core/internal/rule/IRuleRegistry.java | 8 +- .../core/internal/rule/IncludeOnlyRule.java | 50 ++- .../tm4e/core/internal/rule/MatchRule.java | 46 ++- .../tm4e/core/internal/rule/RegExpSource.java | 207 +++++------- .../rule/RegExpSourceAnchorCache.java | 32 -- .../core/internal/rule/RegExpSourceList.java | 135 ++++---- .../eclipse/tm4e/core/internal/rule/Rule.java | 51 +-- .../tm4e/core/internal/rule/RuleFactory.java | 303 +++++++++--------- .../tm4e/core/internal/rule/package-info.java | 8 + .../tm4e/core/internal/types/IRawRule.java | 5 +- .../tm4e/core/internal/utils/RegexSource.java | 13 + 20 files changed, 593 insertions(+), 531 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceAnchorCache.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index f48ff69ba..e67221fd4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -26,6 +26,8 @@ import java.util.Map.Entry; import java.util.function.IntFunction; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; @@ -127,9 +129,9 @@ private void collectInjections(List result, String selector, IRawRule } @Override - public Rule registerRule(IntFunction factory) { + public T registerRule(IntFunction factory) { int id = (++this.lastRuleId); - Rule result = factory.apply(id); + T result = factory.apply(id); this.ruleId2desc.put(id, result); return result; } @@ -144,7 +146,7 @@ private IRawGrammar getExternalGrammar(String scopeName) { } @Override - public IRawGrammar getExternalGrammar(String scopeName, IRawRepository repository) { + public IRawGrammar getExternalGrammar(String scopeName, @Nullable IRawRepository repository) { if (this.includedGrammars.containsKey(scopeName)) { return this.includedGrammars.get(scopeName); } else if (this.grammarRepository != null) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index d24f4a931..9e2800f54 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; @@ -39,7 +40,9 @@ final class LineTokenizer { private static final Logger LOGGER = System.getLogger(LineTokenizer.class.getName()); private interface IMatchResult { - OnigCaptureIndex[] getCaptureIndices(); + @NonNull + OnigCaptureIndex @NonNull [] getCaptureIndices(); + int getMatchedRuleId(); } @@ -125,8 +128,7 @@ private void scanNext() { OnigCaptureIndex[] captureIndices = r.getCaptureIndices(); int matchedRuleId = r.getMatchedRuleId(); - final boolean hasAdvanced = captureIndices != null && captureIndices.length > 0 - && captureIndices[0].getEnd() > linePos; + final boolean hasAdvanced = captureIndices.length > 0 && captureIndices[0].getEnd() > linePos; if (matchedRuleId == -1) { // We matched the `end` for this rule => pop it @@ -159,7 +161,7 @@ private void scanNext() { stop = true; return; } - } else if (captureIndices != null && captureIndices.length > 0) { + } else if (captureIndices.length > 0) { // We matched a rule! Rule rule = grammar.getRule(matchedRuleId); @@ -257,7 +259,7 @@ private void scanNext() { } } - if (captureIndices != null && captureIndices.length > 0 && captureIndices[0].getEnd() > linePos) { + if (captureIndices.length > 0 && captureIndices[0].getEnd() > linePos) { // Advance stream linePos = captureIndices[0].getEnd(); isFirstLine = false; @@ -267,7 +269,7 @@ private void scanNext() { private IMatchResult matchRule(Grammar grammar, OnigString lineText, boolean isFirstLine, final int linePos, StackElement stack, int anchorPosition) { Rule rule = stack.getRule(grammar); - final CompiledRule ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos == anchorPosition); + final CompiledRule ruleScanner = rule.compileAG(grammar, stack.endRule, isFirstLine, linePos == anchorPosition); final OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); if (r != null) { @@ -340,7 +342,7 @@ private IMatchInjectionsResult matchInjections(List injections, Gramm continue; } - CompiledRule ruleScanner = grammar.getRule(injection.ruleId).compile(grammar, null, isFirstLine, + CompiledRule ruleScanner = grammar.getRule(injection.ruleId).compileAG(grammar, null, isFirstLine, linePos == anchorPosition); OnigNextMatchResult matchResult = ruleScanner.scanner.findNextMatchSync(lineText, linePos); @@ -424,7 +426,8 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs } // pop captures while needed - while (!localStack.isEmpty() && localStack.get(localStack.size() - 1).getEndPos() <= captureIndex.getStart()) { + while (!localStack.isEmpty() + && localStack.get(localStack.size() - 1).getEndPos() <= captureIndex.getStart()) { // pop! lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).getScopes(), localStack.get(localStack.size() - 1).getEndPos()); @@ -438,7 +441,8 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs lineTokens.produce(stack, captureIndex.getStart()); } - if (captureRule.retokenizeCapturedWithRuleId != null) { + final var retokenizeCapturedWithRuleId = captureRule.retokenizeCapturedWithRuleId; + if (retokenizeCapturedWithRuleId != null) { // the capture requires additional matching String scopeName = captureRule.getName(lineText.string, captureIndices); ScopeListElement nameScopesList = stack.contentNameScopesList.push(grammar, scopeName); @@ -446,8 +450,8 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); // the capture requires additional matching - StackElement stackClone = stack.push(captureRule.retokenizeCapturedWithRuleId, captureIndex.getStart(), - null, nameScopesList, contentNameScopesList); + StackElement stackClone = stack.push(retokenizeCapturedWithRuleId, captureIndex.getStart(), null, + nameScopesList, contentNameScopesList); tokenizeString(grammar, OnigString.of(lineText.string.substring(0, captureIndex.getEnd())), (isFirstLine && captureIndex.getStart() == 0), captureIndex.getStart(), stackClone, lineTokens); @@ -458,8 +462,9 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs String captureRuleScopeName = captureRule.getName(lineText.string, captureIndices); if (captureRuleScopeName != null) { // push - ScopeListElement base = localStack.isEmpty() ? stack.contentNameScopesList : - localStack.get(localStack.size() - 1).getScopes(); + ScopeListElement base = localStack.isEmpty() + ? stack.contentNameScopesList + : localStack.get(localStack.size() - 1).getScopes(); ScopeListElement captureRuleScopesList = base.push(grammar, captureRuleScopeName); localStack.add(new LocalStackElement(captureRuleScopesList, captureIndex.getEnd())); } @@ -490,7 +495,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe } for (int i = whileRules.size() - 1; i >= 0; i--) { WhileStack whileRule = whileRules.get(i); - CompiledRule ruleScanner = whileRule.rule.compileWhile(whileRule.stack.endRule, isFirstLine, + CompiledRule ruleScanner = whileRule.rule.compileWhileAG(whileRule.stack.endRule, isFirstLine, currentanchorPosition == linePos); OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); // if (IN_DEBUG_MODE) { @@ -499,7 +504,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe // } if (r != null) { - Integer matchedRuleId = ruleScanner.rules[r.getIndex()]; + int matchedRuleId = ruleScanner.rules[r.getIndex()]; if (matchedRuleId != -2) { // we shouldn't end up here stack = whileRule.stack.pop(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index 9a8805b6b..4c775a551 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,34 +11,46 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public final class BeginEndRule extends Rule { private final RegExpSource begin; - public final List beginCaptures; + public final List<@Nullable CaptureRule> beginCaptures; + private final RegExpSource end; + public final List<@Nullable CaptureRule> endCaptures; public final boolean endHasBackReferences; - public final List endCaptures; private final boolean applyEndPatternLast; + final boolean hasMissingPatterns; - final Integer[] patterns; + final int[] patterns; + + @Nullable private RegExpSourceList cachedCompiledPatterns; - BeginEndRule(int id, String name, String contentName, String begin, List beginCaptures, - String end, List endCaptures, boolean applyEndPatternLast, CompilePatternsResult patterns) { + BeginEndRule(int id, @Nullable String name, @Nullable String contentName, String begin, + List<@Nullable CaptureRule> beginCaptures, @Nullable String end, List<@Nullable CaptureRule> endCaptures, + boolean applyEndPatternLast, + CompilePatternsResult patterns) { super(id, name, contentName); this.begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; - this.end = new RegExpSource(end, -1); - this.endHasBackReferences = this.end.hasBackReferences(); + this.end = new RegExpSource(end == null ? "\uFFFF" : end, -1); + this.endHasBackReferences = this.end.hasBackReferences; this.endCaptures = endCaptures; this.applyEndPatternLast = applyEndPatternLast; this.patterns = patterns.patterns; @@ -50,43 +62,51 @@ public String getEndWithResolvedBackReferences(String lineText, OnigCaptureIndex } @Override - void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSourceList out, + final boolean isFirst) { if (isFirst) { - for (Integer pattern : this.patterns) { - Rule rule = grammar.getRule(pattern); + for (final int pattern : this.patterns) { + final Rule rule = grammar.getRule(pattern); rule.collectPatternsRecursive(grammar, out, false); } } else { - out.push(this.begin); + out.add(this.begin); } } @Override - public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { - RegExpSourceList precompiled = this.precompile(grammar); - if (this.end.hasBackReferences()) { - if (this.applyEndPatternLast) { - precompiled.setSource(precompiled.length() - 1, endRegexSource); - } else { - precompiled.setSource(0, endRegexSource); - } - } - return this.cachedCompiledPatterns.compile(allowA, allowG); + public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + return getCachedCompiledPatterns(grammar, endRegexSource).compile(); } - private RegExpSourceList precompile(IRuleRegistry grammar) { - if (this.cachedCompiledPatterns == null) { - this.cachedCompiledPatterns = new RegExpSourceList(); + @Override + public CompiledRule compileAG(final IRuleRegistry grammar, @Nullable final String endRegexSource, + final boolean allowA, final boolean allowG) { + return getCachedCompiledPatterns(grammar, endRegexSource).compileAG(allowA, allowG); + } - this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); + private RegExpSourceList getCachedCompiledPatterns(final IRuleRegistry grammar, + @Nullable final String endRegexSource) { + var cachedCompiledPatterns = this.cachedCompiledPatterns; + if (cachedCompiledPatterns == null) { + cachedCompiledPatterns = new RegExpSourceList(); + collectPatternsRecursive(grammar, cachedCompiledPatterns, true); + + if (this.applyEndPatternLast) { + cachedCompiledPatterns.add(this.endHasBackReferences ? this.end.clone() : this.end); + } else { + cachedCompiledPatterns.remove(this.endHasBackReferences ? this.end.clone() : this.end); + } + this.cachedCompiledPatterns = cachedCompiledPatterns; + } + if (this.endHasBackReferences && endRegexSource != null) { if (this.applyEndPatternLast) { - this.cachedCompiledPatterns.push(this.end.hasBackReferences() ? this.end.clone() : this.end); + cachedCompiledPatterns.setSource(cachedCompiledPatterns.length() - 1, endRegexSource); } else { - this.cachedCompiledPatterns.unshift(this.end.hasBackReferences() ? this.end.clone() : this.end); + cachedCompiledPatterns.setSource(0, endRegexSource); } } - return this.cachedCompiledPatterns; + return cachedCompiledPatterns; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index 39fa1087d..894fef8b4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,36 +11,46 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public final class BeginWhileRule extends Rule { private final RegExpSource begin; - public final List beginCaptures; - public final List whileCaptures; + public final List<@Nullable CaptureRule> beginCaptures; + public final List<@Nullable CaptureRule> whileCaptures; private final RegExpSource _while; public final boolean whileHasBackReferences; final boolean hasMissingPatterns; - final Integer[] patterns; + final int[] patterns; + + @Nullable private RegExpSourceList cachedCompiledPatterns; + + @Nullable private RegExpSourceList cachedCompiledWhilePatterns; BeginWhileRule(/* $location:ILocation, */ int id, String name, String contentName, String begin, - List beginCaptures, String _while, List whileCaptures, + List<@Nullable CaptureRule> beginCaptures, String _while, List<@Nullable CaptureRule> whileCaptures, CompilePatternsResult patterns) { super(/* $location, */id, name, contentName); this.begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; this.whileCaptures = whileCaptures; this._while = new RegExpSource(_while, -2); - this.whileHasBackReferences = this._while.hasBackReferences(); + this.whileHasBackReferences = this._while.hasBackReferences; this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; } @@ -50,7 +60,7 @@ public String getWhileWithResolvedBackReferences(String lineText, OnigCaptureInd } @Override - void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { if (isFirst) { Rule rule; for (Integer pattern : patterns) { @@ -58,36 +68,49 @@ void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boole rule.collectPatternsRecursive(grammar, out, false); } } else { - out.push(this.begin); + out.add(this.begin); } } @Override - public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { - this.precompile(grammar); - return this.cachedCompiledPatterns.compile(allowA, allowG); + public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + return getCachedCompiledPatterns(grammar).compile(); } - private void precompile(IRuleRegistry grammar) { - if (this.cachedCompiledPatterns == null) { - this.cachedCompiledPatterns = new RegExpSourceList(); - this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); - } + @Override + public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, + boolean allowG) { + return getCachedCompiledPatterns(grammar).compileAG(allowA, allowG); } - public CompiledRule compileWhile(String endRegexSource, boolean allowA, boolean allowG) { - this.precompileWhile(); - if (this._while.hasBackReferences()) { - this.cachedCompiledWhilePatterns.setSource(0, endRegexSource); + private RegExpSourceList getCachedCompiledPatterns(final IRuleRegistry grammar) { + var cachedCompiledPatterns = this.cachedCompiledPatterns; + if (cachedCompiledPatterns == null) { + cachedCompiledPatterns = new RegExpSourceList(); + collectPatternsRecursive(grammar, cachedCompiledPatterns, true); + this.cachedCompiledPatterns = cachedCompiledPatterns; } - return this.cachedCompiledWhilePatterns.compile(allowA, allowG); + return cachedCompiledPatterns; } - private void precompileWhile() { - if (this.cachedCompiledWhilePatterns == null) { - this.cachedCompiledWhilePatterns = new RegExpSourceList(); - this.cachedCompiledWhilePatterns.push(this._while.hasBackReferences() ? this._while.clone() : this._while); - } + public CompiledRule compileWhile(@Nullable final String endRegexSource) { + return getCachedCompiledWhilePatterns(endRegexSource).compile(); + } + + public CompiledRule compileWhileAG(@Nullable final String endRegexSource, boolean allowA, boolean allowG) { + return getCachedCompiledWhilePatterns(endRegexSource).compileAG(allowA, allowG); } + private RegExpSourceList getCachedCompiledWhilePatterns(@Nullable final String endRegexSource) { + var cachedCompiledWhilePatterns = this.cachedCompiledWhilePatterns; + if (cachedCompiledWhilePatterns == null) { + cachedCompiledWhilePatterns = new RegExpSourceList(); + cachedCompiledWhilePatterns.add(this.whileHasBackReferences ? this._while.clone() : this._while); + if (whileHasBackReferences) { + cachedCompiledWhilePatterns.setSource(0, endRegexSource != null ? endRegexSource : "\uFFFF"); + } + this.cachedCompiledWhilePatterns = cachedCompiledWhilePatterns; + } + return cachedCompiledWhilePatterns; + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java index 55b208651..b6f9959ed 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,28 +11,42 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; +import org.eclipse.jdt.annotation.Nullable; + +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public final class CaptureRule extends Rule { + @Nullable public final Integer retokenizeCapturedWithRuleId; - CaptureRule(int id, String name, String contentName, Integer retokenizeCapturedWithRuleId) { + CaptureRule(int id, @Nullable String name, @Nullable String contentName, + @Nullable Integer retokenizeCapturedWithRuleId) { super(id, name, contentName); this.retokenizeCapturedWithRuleId = retokenizeCapturedWithRuleId; } @Override - void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { throw new UnsupportedOperationException(); } @Override - public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { throw new UnsupportedOperationException(); } + @Override + public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, + boolean allowG) { + throw new UnsupportedOperationException(); + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java index c1750b039..ccda08333 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java @@ -16,16 +16,19 @@ */ package org.eclipse.tm4e.core.internal.rule; -import java.util.Collection; - +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ final class CompilePatternsResult { - final Integer[] patterns; + final int[] patterns; final boolean hasMissingPatterns; - CompilePatternsResult(Collection patterns, boolean hasMissingPatterns) { + CompilePatternsResult(int[] patterns, boolean hasMissingPatterns) { this.hasMissingPatterns = hasMissingPatterns; - this.patterns = patterns.toArray(Integer[]::new); + this.patterns = patterns; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java index 9be77600c..ff3552b5d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java @@ -18,12 +18,17 @@ import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public final class CompiledRule { public final OnigScanner scanner; - public final Integer[] rules; + public final int[] rules; - CompiledRule(OnigScanner scanner, Integer[] rules) { + CompiledRule(OnigScanner scanner, int[] rules) { this.scanner = scanner; this.rules = rules; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java index 8cedf4fa8..e061935e5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IGrammarRegistry.java @@ -16,10 +16,17 @@ */ package org.eclipse.tm4e.core.internal.rule; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ interface IGrammarRegistry { + @Nullable IRawGrammar getExternalGrammar(String scopeName, IRawRepository repository); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java index 59274790c..f84c4195a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleFactoryHelper.java @@ -16,6 +16,11 @@ */ package org.eclipse.tm4e.core.internal.rule; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public interface IRuleFactoryHelper extends IRuleRegistry, IGrammarRegistry { } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java index 8ec52b2ea..2d7608e47 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java @@ -18,10 +18,14 @@ import java.util.function.IntFunction; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public interface IRuleRegistry { Rule getRule(int patternId); - Rule registerRule(IntFunction factory); - + T registerRule(IntFunction factory); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java index 8d3647534..51c788bf2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,38 +11,60 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; +import org.eclipse.jdt.annotation.Nullable; + +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ final class IncludeOnlyRule extends Rule { final boolean hasMissingPatterns; - final Integer[] patterns; + final int[] patterns; + + @Nullable private RegExpSourceList cachedCompiledPatterns; - IncludeOnlyRule(int id, String name, String contentName, CompilePatternsResult patterns) { + IncludeOnlyRule(final int id, @Nullable final String name, @Nullable final String contentName, + final CompilePatternsResult patterns) { super(id, name, contentName); this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; } @Override - void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { - for (Integer pattern : this.patterns) { - Rule rule = grammar.getRule(pattern); + public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSourceList out, + final boolean isFirst) { + for (final Integer pattern : this.patterns) { + final Rule rule = grammar.getRule(pattern); rule.collectPatternsRecursive(grammar, out, false); } } @Override - public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { - if (this.cachedCompiledPatterns == null) { - this.cachedCompiledPatterns = new RegExpSourceList(); - this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); - } - return this.cachedCompiledPatterns.compile(allowA, allowG); + public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + return getCachedCompiledPatterns(grammar).compile(); } + @Override + public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, + boolean allowG) { + return getCachedCompiledPatterns(grammar).compileAG(allowA, allowG); + } + + private RegExpSourceList getCachedCompiledPatterns(final IRuleRegistry grammar) { + var cachedCompiledPatterns = this.cachedCompiledPatterns; + if (cachedCompiledPatterns == null) { + cachedCompiledPatterns = new RegExpSourceList(); + this.collectPatternsRecursive(grammar, cachedCompiledPatterns, true); + this.cachedCompiledPatterns = cachedCompiledPatterns; + } + return cachedCompiledPatterns; + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java index 6b85f22a3..22a38c789 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,36 +11,58 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; + +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public final class MatchRule extends Rule { private final RegExpSource match; - public final List captures; + public final List<@Nullable CaptureRule> captures; + + @Nullable private RegExpSourceList cachedCompiledPatterns; - MatchRule(int id, String name, String match, List captures) { + MatchRule(final int id, final String name, final String match, final List<@Nullable CaptureRule> captures) { super(id, name, null); this.match = new RegExpSource(match, this.id); this.captures = captures; } @Override - void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { - out.push(this.match); + public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSourceList out, + final boolean isFirst) { + out.add(this.match); } @Override - public CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG) { - if (this.cachedCompiledPatterns == null) { - this.cachedCompiledPatterns = new RegExpSourceList(); - this.collectPatternsRecursive(grammar, this.cachedCompiledPatterns, true); + public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + return getCachedCompiledPatterns(grammar).compile(); + } + + @Override + public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, + boolean allowG) { + return getCachedCompiledPatterns(grammar).compileAG(allowA, allowG); + } + + private RegExpSourceList getCachedCompiledPatterns(final IRuleRegistry grammar) { + var cachedCompiledPatterns = this.cachedCompiledPatterns; + if (cachedCompiledPatterns == null) { + cachedCompiledPatterns = new RegExpSourceList(); + this.collectPatternsRecursive(grammar, cachedCompiledPatterns, true); + this.cachedCompiledPatterns = cachedCompiledPatterns; } - return this.cachedCompiledPatterns.compile(allowA, allowG); + return cachedCompiledPatterns; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index c93b72233..6576e13c4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -17,162 +17,123 @@ package org.eclipse.tm4e.core.internal.rule; import java.util.Arrays; -import java.util.List; -import java.util.regex.Matcher; +import java.util.Objects; import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; +import org.eclipse.tm4e.core.internal.utils.RegexSource; /** - * - * @see + * @see * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts - * */ final class RegExpSource { private static final Pattern HAS_BACK_REFERENCES = Pattern.compile("\\\\(\\d+)"); private static final Pattern BACK_REFERENCING_END = Pattern.compile("\\\\(\\d+)"); - private static final Pattern REGEXP_CHARACTERS = Pattern - .compile("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\,\\[\\]\\(\\)\\#\\s]"); - private final int ruleId; - private boolean _hasAnchor; - private final boolean _hasBackReferences; - private RegExpSourceAnchorCache anchorCache; private String source; + final int ruleId; + final boolean hasBackReferences; - RegExpSource(String regExpSource, int ruleId) { - this(regExpSource, ruleId, true); - } + private String @Nullable [][] anchorCache; - private RegExpSource(String regExpSource, int ruleId, boolean handleAnchors) { - if (handleAnchors) { - this._handleAnchors(regExpSource); - } else { - this.source = regExpSource; - this._hasAnchor = false; - } - - if (this._hasAnchor) { - this.anchorCache = this._buildAnchorCache(); - } - - this.ruleId = ruleId; - this._hasBackReferences = HAS_BACK_REFERENCES.matcher(this.source).find(); - - // console.log('input: ' + regExpSource + ' => ' + this.source + ', ' + - // this.hasAnchor); - } - - @Override - protected RegExpSource clone() { - return new RegExpSource(this.source, this.ruleId, true); - } - - void setSource(String newSource) { - if (this.source.equals(newSource)) { - return; - } - this.source = newSource; - - if (this._hasAnchor) { - this.anchorCache = this._buildAnchorCache(); - } + RegExpSource(final String regExpSource, final int ruleId) { + this(regExpSource, ruleId, true); } - private void _handleAnchors(String regExpSource) { - if (regExpSource != null) { - int len = regExpSource.length(); - char ch; - char nextCh; + RegExpSource(final String regExpSource, final int ruleId, final boolean handleAnchors) { + if (handleAnchors && !regExpSource.isEmpty()) { + final int len = regExpSource.length(); int lastPushedPos = 0; - final StringBuilder output = new StringBuilder(); + final var output = new StringBuilder(); - boolean hasAnchor = false; + boolean hasAnchors = false; for (int pos = 0; pos < len; pos++) { - ch = regExpSource.charAt(pos); + final char ch = regExpSource.charAt(pos); if (ch == '\\') { if (pos + 1 < len) { - nextCh = regExpSource.charAt(pos + 1); + final char nextCh = regExpSource.charAt(pos + 1); if (nextCh == 'z') { output.append(regExpSource.substring(lastPushedPos, pos)); output.append("$(?!\\n)(? capturedValues = Arrays.stream(captureIndices) - .map(capture -> lineText.substring(capture.getStart(), capture.getEnd())).collect(Collectors.toList()); - Matcher m = BACK_REFERENCING_END.matcher(this.source); - final StringBuilder sb = new StringBuilder(); - while (m.find()) { - String g1 = m.group(); - int index = Integer.parseInt(g1.substring(1)); - String replacement = escapeRegExpCharacters(capturedValues.size() > index ? capturedValues.get(index) : ""); - m.appendReplacement(sb, replacement); - } - m.appendTail(sb); - return sb.toString(); - } - catch(Throwable e) { - //e.printStackTrace(); + @Override + protected RegExpSource clone() { + return new RegExpSource(source, this.ruleId); + } + + void setSource(final String newSource) { + if (Objects.equals(source, newSource)) { + return; } + this.source = newSource; - return lineText; + if (hasAnchor()) { + this.anchorCache = buildAnchorCache(); + } } - private String escapeRegExpCharacters(String value) { - Matcher m = REGEXP_CHARACTERS.matcher(value); - final StringBuilder sb = new StringBuilder(); - while (m.find()) { - m.appendReplacement(sb, "\\\\\\\\" + m.group()); + String resolveBackReferences(final String lineText, final OnigCaptureIndex[] captureIndices) { + try { + final var capturedValues = Arrays.stream(captureIndices) + .map(capture -> lineText.substring(capture.getStart(), capture.getEnd())) + .collect(Collectors.toList()); + final var m = BACK_REFERENCING_END.matcher(this.source); + final var sb = new StringBuilder(); + while (m.find()) { + final var g1 = m.group(); + final var index = Integer.parseInt(g1.substring(1)); + final var replacement = RegexSource.escapeRegExpCharacters( + capturedValues.size() > index ? capturedValues.get(index) : ""); + m.appendReplacement(sb, replacement); + } + m.appendTail(sb); + return sb.toString(); + } catch (RuntimeException ex) { + // ex.printStackTrace(); + return lineText; } - m.appendTail(sb); - return sb.toString(); } - private RegExpSourceAnchorCache _buildAnchorCache() { - - // Collection A0_G0_result=new ArrayList(); - // Collection A0_G1_result=new ArrayList(); - // Collection A1_G0_result=new ArrayList(); - // Collection A1_G1_result=new ArrayList(); + private String [][] buildAnchorCache() { + final var A0_G0_result = new StringBuilder(); + final var A0_G1_result = new StringBuilder(); + final var A1_G0_result = new StringBuilder(); + final var A1_G1_result = new StringBuilder(); - StringBuilder A0_G0_result = new StringBuilder(); - StringBuilder A0_G1_result = new StringBuilder(); - StringBuilder A1_G0_result = new StringBuilder(); - StringBuilder A1_G1_result = new StringBuilder(); - int pos; - int len; - char ch; - char nextCh; - - for (pos = 0, len = this.source.length(); pos < len; pos++) { - ch = this.source.charAt(pos); + for (int pos = 0, len = source.length(); pos < len; pos++) { + final char ch = source.charAt(pos); A0_G0_result.append(ch); A0_G1_result.append(ch); A1_G0_result.append(ch); @@ -180,7 +141,7 @@ private RegExpSourceAnchorCache _buildAnchorCache() { if (ch == '\\') { if (pos + 1 < len) { - nextCh = this.source.charAt(pos + 1); + final char nextCh = source.charAt(pos + 1); if (nextCh == 'A') { A0_G0_result.append('\uFFFF'); A0_G1_result.append('\uFFFF'); @@ -202,46 +163,26 @@ private RegExpSourceAnchorCache _buildAnchorCache() { } } - return new RegExpSourceAnchorCache(A0_G0_result.toString(), A0_G1_result.toString(), A1_G0_result.toString(), - A1_G1_result.toString() - // StringUtils.join(A0_G0_result, ""), - // StringUtils.join(A0_G1_result, ""), - // StringUtils.join(A1_G0_result, ""), - // StringUtils.join(A1_G1_result, "") - ); + return new String[][] { + { A0_G0_result.toString(), A0_G1_result.toString() }, + { A1_G0_result.toString(), A1_G1_result.toString() } + }; } - String resolveAnchors(boolean allowA, boolean allowG) { - if (!this._hasAnchor) { + String resolveAnchors(final boolean allowA, final boolean allowG) { + final var anchorCache = this.anchorCache; + if (anchorCache == null) { return this.source; } - if (allowA) { - if (allowG) { - return this.anchorCache.A1_G1; - } - return this.anchorCache.A1_G0; - } - if (allowG) { - return this.anchorCache.A0_G1; - } - return this.anchorCache.A0_G0; + return anchorCache[allowA ? 1 : 0][allowG ? 1 : 0]; } boolean hasAnchor() { - return this._hasAnchor; + return anchorCache != null; } String getSource() { return this.source; } - - Integer getRuleId() { - return this.ruleId; - } - - boolean hasBackReferences() { - return this._hasBackReferences; - } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceAnchorCache.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceAnchorCache.java deleted file mode 100644 index 502c4e2ed..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceAnchorCache.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.rule; - -final class RegExpSourceAnchorCache { - - final String A0_G0; - final String A0_G1; - final String A1_G0; - final String A1_G1; - - RegExpSourceAnchorCache(String A0_G0, String A0_G1, String A1_G0, String A1_G1) { - this.A0_G0 = A0_G0; - this.A0_G1 = A0_G1; - this.A1_G0 = A1_G0; - this.A1_G1 = A1_G1; - } -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index 1d6c029ad..689fcff7c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -17,121 +17,96 @@ package org.eclipse.tm4e.core.internal.rule; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner; /** - * - * @see + * @see * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts - * */ final class RegExpSourceList { - private static final class RegExpSourceListAnchorCache { - - private CompiledRule A0_G0; - private CompiledRule A0_G1; - private CompiledRule A1_G0; - private CompiledRule A1_G1; - - } + private final List items = new ArrayList<>(); + private boolean hasAnchors; - private final List _items = new ArrayList<>(); - private boolean _hasAnchors; - private CompiledRule _cached; - private final RegExpSourceListAnchorCache _anchorCache; + @Nullable + private CompiledRule cached; + private final CompiledRule[][] anchorCache = new CompiledRule[2][2]; - RegExpSourceList() { - this._anchorCache = new RegExpSourceListAnchorCache(); + private void disposeCache() { + cached = null; + anchorCache[0][0] = null; + anchorCache[0][1] = null; + anchorCache[1][0] = null; + anchorCache[1][1] = null; } - void push(RegExpSource item) { - this._items.add(item); - this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor(); + void add(final RegExpSource item) { + items.add(item); + if (!hasAnchors) { + hasAnchors = item.hasAnchor(); + } } - void unshift(RegExpSource item) { - this._items.add(0, item); - this._hasAnchors = this._hasAnchors ? this._hasAnchors : item.hasAnchor(); + void remove(final RegExpSource item) { + items.add(0, item); + if (!hasAnchors) { + hasAnchors = item.hasAnchor(); + } } int length() { - return this._items.size(); + return items.size(); } - void setSource(int index, String newSource) { - RegExpSource r = this._items.get(index); - if (!r.getSource().equals(newSource)) { - // bust the cache - this._cached = null; - this._anchorCache.A0_G0 = null; - this._anchorCache.A0_G1 = null; - this._anchorCache.A1_G0 = null; - this._anchorCache.A1_G1 = null; + void setSource(final int index, final String newSource) { + final RegExpSource r = items.get(index); + if (!Objects.equals(r.getSource(), newSource)) { + disposeCache(); r.setSource(newSource); } } - CompiledRule compile(boolean allowA, boolean allowG) { - if (!this._hasAnchors) { - if (this._cached == null) { - List regexps = new ArrayList<>(); - for (RegExpSource regExpSource : _items) { - regexps.add(regExpSource.getSource()); - } - this._cached = new CompiledRule(new OnigScanner(regexps), getRules()); - } - return this._cached; + CompiledRule compile() { + var cached = this.cached; + if (cached == null) { + final List regexps = items.stream().map(RegExpSource::getSource).collect(Collectors.toList()); + cached = this.cached = new CompiledRule(new OnigScanner(regexps), getRules()); } + return cached; + } - if (this._anchorCache.A0_G0 == null) { - this._anchorCache.A0_G0 = (allowA == false && allowG == false) ? this._resolveAnchors(allowA, allowG) - : null; - } - if (this._anchorCache.A0_G1 == null) { - this._anchorCache.A0_G1 = (allowA == false && allowG == true) ? this._resolveAnchors(allowA, allowG) - : null; - } - if (this._anchorCache.A1_G0 == null) { - this._anchorCache.A1_G0 = (allowA == true && allowG == false) ? this._resolveAnchors(allowA, allowG) - : null; - } - if (this._anchorCache.A1_G1 == null) { - this._anchorCache.A1_G1 = (allowA == true && allowG == true) ? this._resolveAnchors(allowA, allowG) - : null; + CompiledRule compileAG(final boolean allowA, final boolean allowG) { + if (!hasAnchors) { + return compile(); } - if (allowA) { - if (allowG) { - return this._anchorCache.A1_G1; - } - return this._anchorCache.A1_G0; - } + final var indexA = allowA ? 1 : 0; + final var indexG = allowG ? 1 : 0; - if (allowG) { - return this._anchorCache.A0_G1; + var rule = anchorCache[indexA][indexG]; + if (rule == null) { + rule = anchorCache[indexA][indexG] = resolveAnchors(allowA, allowG); } - return this._anchorCache.A0_G0; + return rule; } - private CompiledRule _resolveAnchors(boolean allowA, boolean allowG) { - List regexps = new ArrayList<>(); - for (RegExpSource regExpSource : _items) { - regexps.add(regExpSource.resolveAnchors(allowA, allowG)); - } + private CompiledRule resolveAnchors(final boolean allowA, final boolean allowG) { + final List regexps = items.stream().map(e -> e.resolveAnchors(allowA, allowG)) + .collect(Collectors.toList()); return new CompiledRule(new OnigScanner(regexps), getRules()); } - - private Integer[] getRules() { - Collection ruleIds = new ArrayList<>(); - for (RegExpSource item : this._items) { - ruleIds.add(item.getRuleId()); + private int[] getRules() { + final var ruleIds = new int[items.size()]; + for (int i = 0; i < ruleIds.length; i++) { + ruleIds[i] = items.get(i).ruleId; } - return ruleIds.toArray(Integer[]::new); + return ruleIds; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java index 90d838c5f..ede8f48a2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/Rule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,48 +11,63 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; import org.eclipse.tm4e.core.internal.utils.RegexSource; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts + */ public abstract class Rule { final int id; - private final boolean nameIsCapturing; + @Nullable private final String name; + private final boolean nameIsCapturing; - private final boolean contentNameIsCapturing; + @Nullable private final String contentName; + private final boolean contentNameIsCapturing; - Rule(int id, String name, String contentName) { + Rule(final int id, @Nullable final String name, final @Nullable String contentName) { this.id = id; this.name = name; - this.nameIsCapturing = RegexSource.hasCaptures(this.name); + this.nameIsCapturing = RegexSource.hasCaptures(name); this.contentName = contentName; - this.contentNameIsCapturing = RegexSource.hasCaptures(this.contentName); + this.contentNameIsCapturing = RegexSource.hasCaptures(contentName); } - public String getName(String lineText, OnigCaptureIndex[] captureIndices) { - if (!this.nameIsCapturing) { - return this.name; + @Nullable + public String getName(@Nullable final String lineText, final OnigCaptureIndex @Nullable [] captureIndices) { + final var name = this.name; + if (!nameIsCapturing || name == null || lineText == null || captureIndices == null) { + return name; } - return RegexSource.replaceCaptures(this.name, lineText, captureIndices); + return RegexSource.replaceCaptures(name, lineText, captureIndices); } - public String getContentName(String lineText, OnigCaptureIndex[] captureIndices) { - if (!this.contentNameIsCapturing) { - return this.contentName; + @Nullable + public String getContentName(final String lineText, final OnigCaptureIndex[] captureIndices) { + final var contentName = this.contentName; + if (!contentNameIsCapturing || contentName == null) { + return contentName; } - return RegexSource.replaceCaptures(this.contentName, lineText, captureIndices); + return RegexSource.replaceCaptures(contentName, lineText, captureIndices); } - abstract void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst); + public abstract void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst); + + public abstract CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource); - public abstract CompiledRule compile(IRuleRegistry grammar, String endRegexSource, boolean allowA, boolean allowG); + public abstract CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, + boolean allowG); } \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index d5fb84e88..60ef5441e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -16,227 +16,234 @@ */ package org.eclipse.tm4e.core.internal.rule; +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.internal.grammar.parser.Raw; import org.eclipse.tm4e.core.internal.types.IRawCaptures; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; import org.eclipse.tm4e.core.internal.types.IRawRule; /** - * - * @see + * @see * github.com/Microsoft/vscode-textmate/blob/master/src/rule.ts - * */ public final class RuleFactory { - private static CaptureRule createCaptureRule(IRuleFactoryHelper helper, final String name, final String contentName, - final Integer retokenizeCapturedWithRuleId) { - return (CaptureRule) helper.registerRule(id -> new CaptureRule(id, name, contentName, retokenizeCapturedWithRuleId)); + private static final Logger LOGGER = System.getLogger(RuleFactory.class.getName()); + + private static CaptureRule createCaptureRule(final IRuleFactoryHelper helper, final String name, + final String contentName, @Nullable final Integer retokenizeCapturedWithRuleId) { + return helper.registerRule(id -> new CaptureRule(id, name, contentName, retokenizeCapturedWithRuleId)); } public static int getCompiledRuleId(final IRawRule desc, final IRuleFactoryHelper helper, final IRawRepository repository) { if (desc.getId() == null) { + helper.registerRule(ruleId -> { + desc.setId(ruleId); - helper.registerRule(id -> { - desc.setId(id); - - if (desc.getMatch() != null) { - return new MatchRule(desc.getId(), desc.getName(), desc.getMatch(), - RuleFactory.compileCaptures(desc.getCaptures(), helper, repository)); + final var ruleMatch = desc.getMatch(); + if (ruleMatch != null) { + return new MatchRule(ruleId, desc.getName(), ruleMatch, + compileCaptures(desc.getCaptures(), helper, repository)); } if (desc.getBegin() == null) { - IRawRepository r = repository; - if (desc.getRepository() != null) { - r = IRawRepository.merge(repository, desc.getRepository()); + final var repository1 = desc.getRepository() == null + ? repository + : IRawRepository.merge(repository, desc.getRepository()); + var patterns = desc.getPatterns(); + if (patterns == null && desc.getInclude() != null) { + final var includeRule = new Raw(); + includeRule.setInclude(desc.getInclude()); + patterns = List.of(includeRule); } - return new IncludeOnlyRule(desc.getId(), desc.getName(), desc.getContentName(), - RuleFactory._compilePatterns(desc.getPatterns(), helper, r)); + return new IncludeOnlyRule( + /* desc.$vscodeTextmateLocation, */ + ruleId, + desc.getName(), + desc.getContentName(), + compilePatterns(patterns, helper, repository1)); } - String ruleWhile = desc.getWhile(); + final String ruleWhile = desc.getWhile(); if (ruleWhile != null) { return new BeginWhileRule( /* desc.$vscodeTextmateLocation, */ - desc.getId(), desc.getName(), desc.getContentName(), desc.getBegin(), - RuleFactory.compileCaptures( + ruleId, + desc.getName(), + desc.getContentName(), + desc.getBegin(), compileCaptures( desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(), helper, repository), - ruleWhile, - RuleFactory.compileCaptures( + ruleWhile, compileCaptures( desc.getWhileCaptures() != null ? desc.getWhileCaptures() : desc.getCaptures(), helper, repository), - RuleFactory._compilePatterns(desc.getPatterns(), helper, repository)); + compilePatterns(desc.getPatterns(), helper, repository)); } - return new BeginEndRule(desc.getId(), desc.getName(), desc.getContentName(), desc.getBegin(), - RuleFactory.compileCaptures( + return new BeginEndRule( + /* desc.$vscodeTextmateLocation, */ + ruleId, + desc.getName(), + desc.getContentName(), + desc.getBegin(), compileCaptures( desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(), helper, repository), - desc.getEnd(), - RuleFactory.compileCaptures( + desc.getEnd(), compileCaptures( desc.getEndCaptures() != null ? desc.getEndCaptures() : desc.getCaptures(), helper, repository), desc.isApplyEndPatternLast(), - RuleFactory._compilePatterns(desc.getPatterns(), helper, repository)); + compilePatterns(desc.getPatterns(), helper, repository)); }); } - return desc.getId(); } - private static List compileCaptures(IRawCaptures captures, IRuleFactoryHelper helper, - IRawRepository repository) { - List r = new ArrayList<>(); - int numericCaptureId; - int maximumCaptureId; - int i; - - if (captures != null) { - // Find the maximum capture id - maximumCaptureId = 0; - for (String captureId : captures) { - numericCaptureId = parseInt(captureId, 10); - if (numericCaptureId > maximumCaptureId) { - maximumCaptureId = numericCaptureId; - } - } + private static List<@Nullable CaptureRule> compileCaptures(@Nullable final IRawCaptures captures, + final IRuleFactoryHelper helper, final IRawRepository repository) { + if (captures == null) { + return Collections.emptyList(); + } - // Initialize result - for (i = 0; i <= maximumCaptureId; i++) { - r.add(null); + // Find the maximum capture id + int maximumCaptureId = 0; + for (final String captureId : captures) { + final int numericCaptureId = parseInt(captureId, 10); + if (numericCaptureId > maximumCaptureId) { + maximumCaptureId = numericCaptureId; } + } - // Fill out result - for (String captureId : captures) { - numericCaptureId = parseInt(captureId, 10); - Integer retokenizeCapturedWithRuleId = null; - IRawRule rule = captures.getCapture(captureId); - if (rule.getPatterns() != null) { - retokenizeCapturedWithRuleId = RuleFactory.getCompiledRuleId(captures.getCapture(captureId), helper, - repository); - } - r.set(numericCaptureId, RuleFactory.createCaptureRule(helper, rule.getName(), rule.getContentName(), - retokenizeCapturedWithRuleId)); - } + // Initialize result + final var r = new ArrayList<@Nullable CaptureRule>(); + for (int i = 0; i <= maximumCaptureId; i++) { + r.add(null); } + // Fill out result + for (String captureId : captures) { + final int numericCaptureId = parseInt(captureId, 10); + final IRawRule rule = captures.getCapture(captureId); + final Integer retokenizeCapturedWithRuleId = rule.getPatterns() == null + ? null + : getCompiledRuleId(captures.getCapture(captureId), helper, repository); + r.set(numericCaptureId, createCaptureRule(helper, rule.getName(), rule.getContentName(), + retokenizeCapturedWithRuleId)); + } return r; } - private static int parseInt(String string, int base) { + private static int parseInt(final String string, final int base) { try { return Integer.parseInt(string, base); - } catch (Throwable e) { + } catch (NumberFormatException ex) { return 0; } } - private static CompilePatternsResult _compilePatterns(Collection patterns, IRuleFactoryHelper helper, - IRawRepository repository) { - Collection r = new ArrayList<>(); - int patternId; - IRawGrammar externalGrammar; - Rule rule; - boolean skipRule; - - if (patterns != null) { - for (IRawRule pattern : patterns) { - patternId = -1; - - if (pattern.getInclude() != null) { - if (pattern.getInclude().charAt(0) == '#') { - // Local include found in `repository` - IRawRule localIncludedRule = repository.getProp(pattern.getInclude().substring(1)); - if (localIncludedRule != null) { - patternId = RuleFactory.getCompiledRuleId(localIncludedRule, helper, repository); - } else { - // console.warn('CANNOT find rule for scopeName: ' + - // pattern.include + ', I am: ', - // repository['$base'].name); - } - } else if (pattern.getInclude().equals("$base") || pattern.getInclude().equals("$self")) { - // Special include also found in `repository` - patternId = RuleFactory.getCompiledRuleId(repository.getProp(pattern.getInclude()), helper, - repository); + private static CompilePatternsResult compilePatterns(@Nullable final Collection patterns, + final IRuleFactoryHelper helper, final IRawRepository repository) { + if (patterns == null) { + return new CompilePatternsResult(new int[0], false); + } + + final var r = new ArrayList(); + for (final IRawRule pattern : patterns) { + int patternId = -1; + + final var patternInclude = pattern.getInclude(); + if (patternInclude == null) { + patternId = getCompiledRuleId(pattern, helper, repository); + } else { + if (patternInclude.charAt(0) == '#') { + // Local include found in `repository` + final IRawRule localIncludedRule = repository.getProp(patternInclude.substring(1)); + if (localIncludedRule != null) { + patternId = getCompiledRuleId(localIncludedRule, helper, repository); + } else if (LOGGER.isLoggable(DEBUG)) { + LOGGER.log(DEBUG, "CANNOT find rule for scopeName: %s, I am: %s", + patternInclude, repository.getBase().getName()); + } + } else if (patternInclude.equals(Raw.DOLLAR_BASE) || patternInclude.equals(Raw.DOLLAR_SELF)) { + // Special include also found in `repository` + patternId = getCompiledRuleId(repository.getProp(patternInclude), helper, + repository); + } else { + final String externalGrammarName; + final String externalGrammarInclude; + int sharpIndex = patternInclude.indexOf('#'); + if (sharpIndex >= 0) { + externalGrammarName = patternInclude.substring(0, sharpIndex); + externalGrammarInclude = patternInclude.substring(sharpIndex + 1); } else { - String externalGrammarName = null, externalGrammarInclude = null; - int sharpIndex = pattern.getInclude().indexOf('#'); - if (sharpIndex >= 0) { - externalGrammarName = pattern.getInclude().substring(0, sharpIndex); - externalGrammarInclude = pattern.getInclude().substring(sharpIndex + 1); - } else { - externalGrammarName = pattern.getInclude(); - } - // External include - externalGrammar = helper.getExternalGrammar(externalGrammarName, repository); - - if (externalGrammar != null) { - if (externalGrammarInclude != null) { - IRawRule externalIncludedRule = externalGrammar.getRepository() - .getProp(externalGrammarInclude); - if (externalIncludedRule != null) { - patternId = RuleFactory.getCompiledRuleId(externalIncludedRule, helper, - externalGrammar.getRepository()); - } else { - // console.warn('CANNOT find rule for - // scopeName: ' + pattern.include + ', I am: - // ', repository['$base'].name); - } - } else { - patternId = RuleFactory.getCompiledRuleId(externalGrammar.getRepository().getSelf(), - helper, externalGrammar.getRepository()); + externalGrammarName = patternInclude; + externalGrammarInclude = null; + } + + // External include + final IRawGrammar externalGrammar = helper.getExternalGrammar(externalGrammarName, repository); + if (externalGrammar != null) { + if (externalGrammarInclude != null) { + final IRawRule externalIncludedRule = externalGrammar.getRepository() + .getProp(externalGrammarInclude); + if (externalIncludedRule != null) { + patternId = getCompiledRuleId(externalIncludedRule, helper, + externalGrammar.getRepository()); + } else if (LOGGER.isLoggable(DEBUG)) { + LOGGER.log(DEBUG, "CANNOT find rule for scopeName: %s, I am: %s", + patternInclude, repository.getBase().getName()); } } else { - // console.warn('CANNOT find grammar for scopeName: - // ' + pattern.include + ', I am: ', - // repository['$base'].name); + patternId = getCompiledRuleId(externalGrammar.getRepository().getSelf(), + helper, externalGrammar.getRepository()); } - + } else if (LOGGER.isLoggable(DEBUG)) { + LOGGER.log(DEBUG, "CANNOT find grammar for scopeName: %s, I am: %s", + patternInclude, repository.getBase().getName()); } - } else { - patternId = RuleFactory.getCompiledRuleId(pattern, helper, repository); } + } - if (patternId != -1) { - rule = helper.getRule(patternId); - - skipRule = false; + if (patternId != -1) { + final Rule rule = helper.getRule(patternId); + boolean skipRule = false; - if (rule instanceof IncludeOnlyRule) { - IncludeOnlyRule ior = (IncludeOnlyRule) rule; - if (ior.hasMissingPatterns && ior.patterns.length == 0) { - skipRule = true; - } - } else if (rule instanceof BeginEndRule) { - BeginEndRule br = (BeginEndRule) rule; - if (br.hasMissingPatterns && br.patterns.length == 0) { - skipRule = true; - } - } else if (rule instanceof BeginWhileRule) { - BeginWhileRule br = (BeginWhileRule) rule; - if (br.hasMissingPatterns && br.patterns.length == 0) { - skipRule = true; - } + if (rule instanceof IncludeOnlyRule) { + final var ior = (IncludeOnlyRule) rule; + if (ior.hasMissingPatterns && ior.patterns.length == 0) { + skipRule = true; } - - if (skipRule) { - // console.log('REMOVING RULE ENTIRELY DUE TO EMPTY - // PATTERNS THAT ARE MISSING'); - continue; + } else if (rule instanceof BeginEndRule) { + final var ber = (BeginEndRule) rule; + if (ber.hasMissingPatterns && ber.patterns.length == 0) { + skipRule = true; } + } else if (rule instanceof BeginWhileRule) { + final var bwr = (BeginWhileRule) rule; + if (bwr.hasMissingPatterns && bwr.patterns.length == 0) { + skipRule = true; + } + } - r.add(patternId); + if (skipRule) { + LOGGER.log(DEBUG, "REMOVING RULE ENTIRELY DUE TO EMPTY PATTERNS THAT ARE MISSING"); + continue; } + + r.add(patternId); } } - return new CompilePatternsResult(r, ((patterns != null ? patterns.size() : 0) != r.size())); + return new CompilePatternsResult(r.stream().mapToInt(Integer::intValue).toArray(), patterns.size() != r.size()); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/package-info.java new file mode 100644 index 000000000..95f07f89b --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/package-info.java @@ -0,0 +1,8 @@ +/** + * Types in this package are modeled after github.com/Microsoft/vscode-textmate/blob/main/src/rule.ts + */ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.rule; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java index 1eebea10f..e1e1fcc46 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java @@ -18,6 +18,8 @@ import java.util.Collection; +import org.eclipse.jdt.annotation.Nullable; + public interface IRawRule { Integer getId(); @@ -48,6 +50,7 @@ public interface IRawRule { void setBegin(String begin); + @Nullable IRawCaptures getBeginCaptures(); void setBeginCaptures(IRawCaptures beginCaptures); @@ -57,7 +60,7 @@ public interface IRawRule { void setEnd(String end); String getWhile(); - + IRawCaptures getEndCaptures(); void setEndCaptures(IRawCaptures endCaptures); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index 62217ca1d..4b10cc302 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -33,6 +33,19 @@ private RegexSource() { private static final Pattern CAPTURING_REGEX_SOURCE = Pattern .compile("\\$(\\d+)|\\$\\{(\\d+):\\/(downcase|upcase)}"); + private static final Pattern REGEXP_CHARACTERS = Pattern + .compile("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\,\\[\\]\\(\\)\\#\\s]"); + + public static String escapeRegExpCharacters(final String value) { + final var m = REGEXP_CHARACTERS.matcher(value); + final var sb = new StringBuilder(); + while (m.find()) { + m.appendReplacement(sb, "\\\\\\\\" + m.group()); + } + m.appendTail(sb); + return sb.toString(); + } + public static boolean hasCaptures(@Nullable final String regexSource) { if (regexSource == null) { return false; From e4c70634f7ea334f333ae23fb3c0402f9e34e648 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 14:23:55 +0200 Subject: [PATCH 115/202] Fix endless grammar loop See https://github.com/microsoft/vscode-textmate/issues/145 --- .../org/eclipse/tm4e/core/grammar/StackElement.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java index b1ed7f9bf..d92c4ddad 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java @@ -171,7 +171,14 @@ public StackElement setEndRule(String endRule) { return new StackElement(this.parent, this.ruleId, this.enterPosition, endRule, this.nameScopesList, this.contentNameScopesList); } - public boolean hasSameRuleAs(StackElement other) { - return this.ruleId == other.ruleId; + public boolean hasSameRuleAs(final StackElement other) { + var el = this; + while (el != null && el.enterPosition == other.enterPosition) { + if (el.ruleId == other.ruleId) { + return true; + } + el = el.parent; + } + return false; } } From a43461b3fe3287f14d37919892a2bcd38703e84e Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 14:25:00 +0200 Subject: [PATCH 116/202] Extend grammar test suite --- .../tm4e/core/grammar/GrammarSuiteTest.java | 2 +- .../suite1/fixtures/105.grammarA.json | 20 + .../suite1/fixtures/105.grammarB.json | 14 + .../suite1/fixtures/147.grammar.json | 9 + .../test-cases/suite1/fixtures/66.plist | 21 + .../test-cases/suite1/fixtures/Jade22.json | 964 +++++++++++ .../test-cases/suite1/fixtures/Pug.tmLanguage | 1486 +++++++++++++++++ .../suite1/fixtures/YAML.tmLanguage | 1164 +++++++++++++ .../suite1/fixtures/infinite-loop.json | 79 + .../resources/test-cases/suite1/tests.json | 577 ++++++- 10 files changed, 4334 insertions(+), 2 deletions(-) create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarA.json create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarB.json create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/147.grammar.json create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/66.plist create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade22.json create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Pug.tmLanguage create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/YAML.tmLanguage create mode 100644 org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/infinite-loop.json diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java index 52a2f2a0c..b65376594 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java @@ -45,7 +45,7 @@ public class GrammarSuiteTest { // TODO: fix thoses tests: // It seems that problem comes from with encoding. OnigString should support UTF-16 like // https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc - private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66"); + private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66", "Issue #82", "Issue #119"); @TestFactory @DisplayName("Tokenization /first-mate/") diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarA.json b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarA.json new file mode 100644 index 000000000..8d74b8c63 --- /dev/null +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarA.json @@ -0,0 +1,20 @@ +{ + "scopeName": "source.test", + "patterns": [{ "include": "#test" }, { "include": "#embedded" }], + "repository": { + "test": { + "begin": "testStart", + "end": "testEnd", + "patterns": [{ "include": "#test2" }] + }, + "test2": { + "match": "some test pattern", + "name": "test.name" + }, + "embedded": { + "begin": "embedStart", + "end": "embedEnd", + "patterns": [{ "include": "source.test.embedded" }] + } + } +} diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarB.json b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarB.json new file mode 100644 index 000000000..d08bbf2d1 --- /dev/null +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarB.json @@ -0,0 +1,14 @@ +{ + "scopeName": "source.test.embedded", + "patterns": [{ "include": "#test" }], + "repository": { + "test": { + "begin": "testStart", + "end": "testEnd", + "patterns": [{ "include": "#test2" }] + }, + "test2": { + "include": "source.test#test2" + } + } +} diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/147.grammar.json b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/147.grammar.json new file mode 100644 index 000000000..7f214d731 --- /dev/null +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/147.grammar.json @@ -0,0 +1,9 @@ +{ + "scopeName": "source.test", + "patterns": [ + { + "match": "\\b(?i:function)\\b", + "name": "storage.type.$0 keyword.declaration.$0" + } + ] +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/66.plist b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/66.plist new file mode 100644 index 000000000..0e22924a4 --- /dev/null +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/66.plist @@ -0,0 +1,21 @@ + + + + + scopeName + text.test + + patterns + + + begin^. + namecomment + + + + begin. + nameinvalid + + + + \ No newline at end of file diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade22.json b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade22.json new file mode 100644 index 000000000..0bb3f8882 --- /dev/null +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade22.json @@ -0,0 +1,964 @@ +{ + "fileTypes": [ + "jade" + ], + "name": "Jade", + "patterns": [ + { + "comment": "Doctype declaration.", + "match": "^(!!!|doctype)(\\s*[a-zA-Z0-9-_]+)?", + "name": "meta.tag.sgml.doctype.html" + }, + { + "begin": "^(\\s*)//-", + "comment": "Unbuffered (jade-only) comments.", + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "comment.unbuffered.block.jade" + }, + { + "begin": "^(\\s*)//", + "comment": "Buffered (html) comments.", + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "string.comment.buffered.block.jade", + "patterns": [ + { + "captures": { + "1": { + "name": "invalid.illegal.comment.comment.block.jade" + } + }, + "comment": "Buffered comments inside buffered comments will generate invalid html.", + "match": "^\\s*(//)(?!-)", + "name": "string.comment.buffered.block.jade" + } + ] + }, + { + "begin": "^(\\s*)-$", + "comment": "Unbuffered code block.", + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "source.js", + "patterns": [ + { + "include": "source.js" + } + ] + }, + { + "begin": "^(\\s*)(script)(?=[.#(\\s])((?![^\\n]*type=)|(?=[^\\n]*(text|application)/javascript))", + "beginCaptures": { + "2": { + "name": "entity.name.tag.script.jade" + } + }, + "comment": "Script tag with JavaScript code.", + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "meta.tag.other", + "patterns": [ + { + "begin": "\\G(?=\\()", + "end": "$", + "name": "stuff.tag.script.jade", + "patterns": [ + { + "include": "#tag_attributes" + } + ] + }, + { + "begin": "\\G(?=[.#])", + "end": "$", + "name": "stuff.tag.script.jade", + "patterns": [ + { + "include": "#complete_tag" + } + ] + }, + { + "include": "source.js" + } + ] + }, + { + "begin": "^(\\s*)(style)((\\.$)|(?=[.#(].*\\.$))", + "beginCaptures": { + "2": { + "name": "entity.name.tag.script.jade" + } + }, + "comment": "Style tag with CSS code.", + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "meta.tag.other", + "patterns": [ + { + "begin": "\\G(?=\\()", + "end": "$", + "name": "stuff.tag.style.jade", + "patterns": [ + { + "include": "#tag_attributes" + } + ] + }, + { + "begin": "\\G(?=[.#])", + "end": "$", + "name": "stuff.tag.style.jade", + "patterns": [ + { + "include": "#complete_tag" + } + ] + }, + { + "include": "source.css" + } + ] + }, + { + "begin": "^(\\s*):(sass)(?=\\(|$)", + "beginCaptures": { + "2": { + "name": "constant.language.name.sass.filter.jade" + } + }, + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "source.sass.filter.jade", + "patterns": [ + { + "include": "#tag_attributes" + }, + { + "include": "source.sass" + } + ] + }, + { + "begin": "^(\\s*):(less)(?=\\(|$)", + "beginCaptures": { + "2": { + "name": "constant.language.name.less.filter.jade" + } + }, + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "source.less.filter.jade", + "patterns": [ + { + "include": "#tag_attributes" + }, + { + "include": "source.less" + } + ] + }, + { + "begin": "^(\\s*):(stylus)(?=\\(|$)", + "beginCaptures": { + "2": { + "name": "constant.language.name.stylus.filter.jade" + } + }, + "end": "^(?!(\\1\\s)|\\s*$)", + "patterns": [ + { + "include": "#tag_attributes" + }, + { + "include": "source.stylus" + } + ] + }, + { + "begin": "^(\\s*):(coffee(-?script)?)(?=\\(|$)", + "beginCaptures": { + "2": { + "name": "constant.language.name.coffeescript.filter.jade" + } + }, + "end": "^(?!(\\1\\s)|\\s*$)", + "name": "source.coffeescript.filter.jade", + "patterns": [ + { + "include": "#tag_attributes" + }, + { + "include": "source.coffee" + } + ] + }, + { + "begin": "^(\\s*)((:(?=.))|(:$))", + "beginCaptures": { + "4": { + "name": "invalid.illegal.empty.generic.filter.jade" + } + }, + "comment": "Generic Jade filter.", + "end": "^(?!(\\1\\s)|\\s*$)", + "patterns": [ + { + "begin": "\\G(?<=:)(?=.)", + "end": "$", + "name": "name.generic.filter.jade", + "patterns": [ + { + "match": "\\G\\(", + "name": "invalid.illegal.name.generic.filter.jade" + }, + { + "match": "[\\w-]", + "name": "constant.language.name.generic.filter.jade" + }, + { + "include": "#tag_attributes" + }, + { + "match": "\\W", + "name": "invalid.illegal.name.generic.filter.jade" + } + ] + } + ] + }, + { + "begin": "^(\\s*)(?=[\\w.#].*?\\.$)(?=(?:(?:(?:(?:(?:#[\\w-]+)|(?:\\.[\\w-]+))|(?:(?:[#!]\\{[^}]*\\})|(?:\\w(?:(?:[\\w:-]+[\\w-])|(?:[\\w-]*)))))(?:(?:#[\\w-]+)|(?:\\.[\\w-]+)|(?:\\((?:[^()\\'\\\"]*(?:(?:\\'(?:[^\\']|(?:(?|$", + "patterns": [ + { + "include": "#inline_jade" + }, + { + "include": "#interpolated_value" + }, + { + "include": "#interpolated_error" + } + ] + }, + { + "include": "#inline_jade" + }, + { + "include": "#embedded_html" + }, + { + "include": "#html_entity" + }, + { + "include": "#interpolated_value" + }, + { + "include": "#interpolated_error" + } + ] + }, + { + "include": "#complete_tag" + } + ] + } + ], + "repository": { + "blocks_and_includes": { + "captures": { + "1": { + "name": "storage.type.import.include.jade" + }, + "4": { + "name": "variable.control.import.include.jade" + } + }, + "comment": "Template blocks and includes.", + "match": "(extends|include|yield|append|prepend|block( (append|prepend))?)\\s+(.*)$", + "name": "meta.first-class.jade" + }, + "case_conds": { + "begin": "(default|when)((\\s+|(?=:))|$)", + "captures": { + "1": { + "name": "storage.type.function.jade" + } + }, + "comment": "Jade case conditionals.", + "end": "$", + "name": "meta.control.flow.jade", + "patterns": [ + { + "begin": "\\G(?!:)", + "end": "(?=:\\s+)|$", + "name": "js.embedded.control.flow.jade", + "patterns": [ + { + "include": "#case_when_paren" + }, + { + "include": "source.js" + } + ] + }, + { + "begin": ":\\s+", + "end": "$", + "name": "tag.case.control.flow.jade", + "patterns": [ + { + "include": "#complete_tag" + } + ] + } + ] + }, + "case_when_paren": { + "begin": "\\(", + "end": "\\)", + "name": "js.when.control.flow.jade", + "patterns": [ + { + "include": "#case_when_paren" + }, + { + "match": ":", + "name": "invalid.illegal.name.tag.jade" + }, + { + "include": "source.js" + } + ] + }, + "complete_tag": { + "begin": "(?=[\\w.#])|(:\\s*)", + "end": "(\\.?$)|(?=:.)", + "patterns": [ + { + "include": "#blocks_and_includes" + }, + { + "include": "#unbuffered_code" + }, + { + "include": "#mixin_call" + }, + { + "include": "#flow_control" + }, + { + "match": "(?<=:)\\w.*$", + "name": "invalid.illegal.name.tag.jade" + }, + { + "include": "#tag_name" + }, + { + "include": "#tag_id" + }, + { + "include": "#tag_classes" + }, + { + "include": "#tag_attributes" + }, + { + "include": "#tag_mixin_attributes" + }, + { + "captures": { + "2": { + "name": "invalid.illegal.end.tag.jade" + }, + "4": { + "name": "invalid.illegal.end.tag.jade" + } + }, + "match": "((\\.)\\s+$)|((:)\\s*$)" + }, + { + "include": "#printed_expression" + }, + { + "include": "#tag_text" + } + ] + }, + "embedded_html": { + "begin": "(?=<[^>]*>)", + "end": "$|(?=>)", + "name": "html", + "patterns": [ + { + "include": "text.html.basic" + }, + { + "include": "#interpolated_value" + }, + { + "include": "#interpolated_error" + } + ] + }, + "flow_control": { + "begin": "(for|if|else if|else|each|until|while|unless|case)(\\s+|$)", + "captures": { + "1": { + "name": "storage.type.function.jade" + } + }, + "comment": "Jade control flow.", + "end": "$", + "name": "meta.control.flow.jade", + "patterns": [ + { + "begin": "", + "end": "$", + "name": "js.embedded.control.flow.jade", + "patterns": [ + { + "include": "source.js" + } + ] + } + ] + }, + "html_entity": { + "patterns": [ + { + "match": "(&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;)", + "name": "constant.character.entity.html.text.jade" + }, + { + "match": "[<>&]", + "name": "invalid.illegal.html_entity.text.jade" + } + ] + }, + "inline_jade": { + "begin": "(?:?/])|\\))", + "name": "attribute_value", + "patterns": [ + { + "include": "#string" + }, + { + "include": "#js_parens" + }, + { + "include": "#js_brackets" + }, + { + "include": "#js_braces" + }, + { + "include": "source.js" + } + ] + }, + { + "begin": "(?<=[%&*-+~|<>:?/])\\s+", + "end": "$|(?=,|(?:\\s+[^!%&*-+~|<>:?/])|\\))", + "name": "attribute_value2", + "patterns": [ + { + "include": "#string" + }, + { + "include": "#js_parens" + }, + { + "include": "#js_brackets" + }, + { + "include": "#js_braces" + }, + { + "include": "source.js" + } + ] + } + ] + }, + "tag_classes": { + "captures": { + "1": { + "name": "invalid.illegal.tag.jade" + } + }, + "match": "\\.([^\\w-])?[\\w-]*", + "name": "constant.language.js" + }, + "tag_id": { + "match": "#[\\w-]+", + "name": "constant.id.tag.jade" + }, + "tag_mixin_attributes": { + "begin": "(&attributes\\()", + "captures": { + "1": { + "name": "entity.name.function.jade" + } + }, + "end": "(\\))", + "name": "meta.tag.other", + "patterns": [ + { + "match": "attributes(?=\\))", + "name": "storage.type.keyword.jade" + }, + { + "include": "source.js" + } + ] + }, + "tag_name": { + "begin": "([#!]\\{(?=.*?\\}))|(\\w(([\\w:-]+[\\w-])|([\\w-]*)))", + "end": "(\\G(? + + + + fileTypes + + pug + + name + Pug + patterns + + + comment + Doctype declaration. + match + ^(!!!|doctype)(\s*[a-zA-Z0-9-_]+)? + name + meta.tag.sgml.doctype.html + + + begin + ^(\s*)//- + comment + Unbuffered (pug-only) comments. + end + ^(?!(\1\s)|\s*$) + name + comment.unbuffered.block.pug + + + begin + ^(\s*)// + comment + Buffered (html) comments. + end + ^(?!(\1\s)|\s*$) + name + string.comment.buffered.block.pug + patterns + + + captures + + 1 + + name + invalid.illegal.comment.comment.block.pug + + + comment + Buffered comments inside buffered comments will generate invalid html. + match + ^\s*(//)(?!-) + name + string.comment.buffered.block.pug + + + + + begin + <!-- + end + --\s*> + name + comment.unbuffered.block.pug + patterns + + + match + -- + name + invalid.illegal.comment.comment.block.pug + + + + + begin + ^(\s*)-$ + comment + Unbuffered code block. + end + ^(?!(\1\s)|\s*$) + name + source.js + patterns + + + include + source.js + + + + + begin + ^(\s*)(script)((\.$)|(?=[^\n]*(text|application)/javascript.*\.$)) + beginCaptures + + 2 + + name + entity.name.tag.pug + + + comment + Script tag with JavaScript code. + end + ^(?!(\1\s)|\s*$) + name + meta.tag.other + patterns + + + begin + \G(?=\() + end + $ + patterns + + + include + #tag_attributes + + + + + begin + \G(?=[.#]) + end + $ + patterns + + + include + #complete_tag + + + + + include + source.js + + + + + begin + ^(\s*)(style)((\.$)|(?=[.#(].*\.$)) + beginCaptures + + 2 + + name + entity.name.tag.pug + + + comment + Style tag with CSS code. + end + ^(?!(\1\s)|\s*$) + name + meta.tag.other + patterns + + + begin + \G(?=\() + end + $ + patterns + + + include + #tag_attributes + + + + + begin + \G(?=[.#]) + end + $ + patterns + + + include + #complete_tag + + + + + include + source.css + + + + + begin + ^(\s*):(sass)(?=\(|$) + beginCaptures + + 2 + + name + constant.language.name.sass.filter.pug + + + end + ^(?!(\1\s)|\s*$) + name + source.sass.filter.pug + patterns + + + include + #tag_attributes + + + include + source.sass + + + + + begin + ^(\s*):(less)(?=\(|$) + beginCaptures + + 2 + + name + constant.language.name.less.filter.pug + + + end + ^(?!(\1\s)|\s*$) + name + source.less.filter.pug + patterns + + + include + #tag_attributes + + + include + source.less + + + + + begin + ^(\s*):(stylus)(?=\(|$) + beginCaptures + + 2 + + name + constant.language.name.stylus.filter.pug + + + end + ^(?!(\1\s)|\s*$) + patterns + + + include + #tag_attributes + + + include + source.stylus + + + + + begin + ^(\s*):(coffee(-?script)?)(?=\(|$) + beginCaptures + + 2 + + name + constant.language.name.coffeescript.filter.pug + + + end + ^(?!(\1\s)|\s*$) + name + source.coffeescript.filter.pug + patterns + + + include + #tag_attributes + + + include + source.coffee + + + + + begin + ^(\s*)((:(?=.))|(:$)) + beginCaptures + + 4 + + name + invalid.illegal.empty.generic.filter.pug + + + comment + Generic Pug filter. + end + ^(?!(\1\s)|\s*$) + patterns + + + begin + \G(?<=:)(?=.) + end + $ + name + name.generic.filter.pug + patterns + + + match + \G\( + name + invalid.illegal.name.generic.filter.pug + + + match + [\w-] + name + constant.language.name.generic.filter.pug + + + include + #tag_attributes + + + match + \W + name + invalid.illegal.name.generic.filter.pug + + + + + + + begin + ^(\s*)(?=[\w.#].*?\.$)(?=(?:(?:(?:(?:(?:#[\w-]+)|(?:\.[\w-]+))|(?:(?:[#!]\{[^}]*\})|(?:\w(?:(?:[\w:-]+[\w-])|(?:[\w-]*)))))(?:(?:#[\w-]+)|(?:\.[\w-]+)|(?:\((?:[^()\'\"]*(?:(?:\'(?:[^\']|(?:(?<!\\)\\\'))*\')|(?:\"(?:[^\"]|(?:(?<!\\)\\\"))*\")))*[^()]*\))*)*)(?:(?:(?::\s+)|(?<=\)))(?:(?:(?:(?:#[\w-]+)|(?:\.[\w-]+))|(?:(?:[#!]\{[^}]*\})|(?:\w(?:(?:[\w:-]+[\w-])|(?:[\w-]*)))))(?:(?:#[\w-]+)|(?:\.[\w-]+)|(?:\((?:[^()\'\"]*(?:(?:\'(?:[^\']|(?:(?<!\\)\\\'))*\')|(?:\"(?:[^\"]|(?:(?<!\\)\\\"))*\")))*[^()]*\))*)*))*)\.$)(?:(?:(#[\w-]+)|(\.[\w-]+))|((?:[#!]\{[^}]*\})|(?:\w(?:(?:[\w:-]+[\w-])|(?:[\w-]*))))) + beginCaptures + + 2 + + name + entity.other.attribute-name.id.pug + + 3 + + name + entity.other.attribute-name.class.pug + + 4 + + name + meta.tag.other entity.name.tag.pug + + + comment + Generated from dot_block_tag.py + end + ^(?!(\1\s)|\s*$) + patterns + + + include + #tag_attributes + + + include + #complete_tag + + + begin + ^(?=.) + end + $ + name + text.block.pug + patterns + + + include + #inline_pug + + + include + #embedded_html + + + include + #html_entity + + + include + #interpolated_value + + + include + #interpolated_error + + + + + + + begin + ^\s* + comment + All constructs that generally span a single line starting with any number of white-spaces. + end + $ + patterns + + + include + #inline_pug + + + include + #blocks_and_includes + + + include + #unbuffered_code + + + include + #mixin_definition + + + include + #mixin_call + + + include + #flow_control + + + include + #case_conds + + + begin + \| + comment + Tag pipe text line. + end + $ + name + text.block.pipe.pug + patterns + + + include + #inline_pug + + + include + #embedded_html + + + include + #html_entity + + + include + #interpolated_value + + + include + #interpolated_error + + + + + include + #printed_expression + + + begin + \G(?=(#[^\{\w-])|[^\w.#]) + comment + Line starting with characters incompatible with tag name/id/class is standalone text. + end + $ + patterns + + + begin + </?(?=[!#]) + end + >|$ + patterns + + + include + #inline_pug + + + include + #interpolated_value + + + include + #interpolated_error + + + + + include + #inline_pug + + + include + #embedded_html + + + include + #html_entity + + + include + #interpolated_value + + + include + #interpolated_error + + + + + include + #complete_tag + + + + + repository + + babel_parens + + begin + \( + end + \)|(({\s*)?$) + patterns + + + include + #babel_parens + + + include + source.js + + + + blocks_and_includes + + captures + + 1 + + name + storage.type.import.include.pug + + 4 + + name + variable.control.import.include.pug + + + comment + Template blocks and includes. + match + (extends|include|yield|append|prepend|block( (append|prepend))?)\s+(.*)$ + name + meta.first-class.pug + + case_conds + + begin + (default|when)((\s+|(?=:))|$) + captures + + 1 + + name + storage.type.function.pug + + + comment + Pug case conditionals. + end + $ + name + meta.control.flow.pug + patterns + + + begin + \G(?!:) + end + (?=:\s+)|$ + name + js.embedded.control.flow.pug + patterns + + + include + #case_when_paren + + + include + source.js + + + + + begin + :\s+ + end + $ + name + tag.case.control.flow.pug + patterns + + + include + #complete_tag + + + + + + case_when_paren + + begin + \( + end + \) + name + js.when.control.flow.pug + patterns + + + include + #case_when_paren + + + match + : + name + invalid.illegal.name.tag.pug + + + include + source.js + + + + complete_tag + + begin + (?=[\w.#])|(:\s*) + end + (\.?$)|(?=:.) + patterns + + + include + #blocks_and_includes + + + include + #unbuffered_code + + + include + #mixin_call + + + include + #flow_control + + + match + (?<=:)\w.*$ + name + invalid.illegal.name.tag.pug + + + include + #tag_name + + + include + #tag_id + + + include + #tag_classes + + + include + #tag_attributes + + + include + #tag_mixin_attributes + + + captures + + 2 + + name + invalid.illegal.end.tag.pug + + 4 + + name + invalid.illegal.end.tag.pug + + + match + ((\.)\s+$)|((:)\s*$) + + + include + #printed_expression + + + include + #tag_text + + + + embedded_html + + begin + (?=<[^>]*>) + end + $|(?=>) + name + html + patterns + + + include + text.html.basic + + + include + #interpolated_value + + + include + #interpolated_error + + + + flow_control + + begin + (for|if|else if|else|each|until|while|unless|case)(\s+|$) + captures + + 1 + + name + storage.type.function.pug + + + comment + Pug control flow. + end + $ + name + meta.control.flow.pug + patterns + + + begin + + end + $ + name + js.embedded.control.flow.pug + patterns + + + include + source.js + + + + + + html_entity + + patterns + + + match + (&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;) + name + constant.character.entity.html.text.pug + + + match + [<>&] + name + invalid.illegal.html_entity.text.pug + + + + inline_pug + + begin + (?<!\\)(#\[) + captures + + 1 + + name + entity.name.function.pug + + 2 + + name + entity.name.function.pug + + + end + (\]) + name + inline.pug + patterns + + + include + #inline_pug + + + include + #mixin_call + + + begin + (?<!\])(?=[\w.#])|(:\s*) + end + (?=\]|(:.)|=|\s) + name + tag.inline.pug + patterns + + + include + #tag_name + + + include + #tag_id + + + include + #tag_classes + + + include + #tag_attributes + + + include + #tag_mixin_attributes + + + include + #inline_pug + + + match + \[ + name + invalid.illegal.tag.pug + + + + + include + #unbuffered_code + + + include + #printed_expression + + + match + \[ + name + invalid.illegal.tag.pug + + + include + #inline_pug_text + + + + inline_pug_text + + begin + + end + (?=\]) + patterns + + + begin + \[ + end + \] + patterns + + + include + #inline_pug_text + + + + + include + #inline_pug + + + include + #embedded_html + + + include + #html_entity + + + include + #interpolated_value + + + include + #interpolated_error + + + + interpolated_error + + match + (?<!\\)[#!]\{(?=[^}]*$) + name + invalid.illegal.tag.pug + + interpolated_value + + begin + (?<!\\)[#!]\{(?=.*?\}) + end + \} + name + string.interpolated.pug + patterns + + + match + { + name + invalid.illegal.tag.pug + + + include + source.js + + + + js_braces + + begin + \{ + end + \} + patterns + + + include + #js_braces + + + include + source.js + + + + js_brackets + + begin + \[ + end + \] + patterns + + + include + #js_brackets + + + include + source.js + + + + js_parens + + begin + \( + end + \) + patterns + + + include + #js_parens + + + include + source.js + + + + mixin_call + + begin + ((?:mixin\s+)|\+)([\w-]+) + beginCaptures + + 1 + + name + storage.type.function.pug + + 2 + + name + meta.tag.other entity.name.function.pug + + + end + (?!\()|$ + patterns + + + begin + (?<!\))\( + end + \) + name + args.mixin.pug + patterns + + + include + #js_parens + + + include + #string + + + captures + + 1 + + name + meta.tag.other entity.other.attribute-name.tag.pug + + + match + ([^\s(),=/]+)\s*=\s* + + + include + source.js + + + + + include + #tag_attributes + + + + mixin_definition + + captures + + 1 + + name + storage.type.function.pug + + 2 + + name + meta.tag.other entity.name.function.pug + + 3 + + name + punctuation.definition.parameters.begin.js + + 4 + + name + variable.parameter.function.js + + 5 + + name + punctuation.definition.parameters.begin.js + + + match + (mixin\s+)([\w-]+)(?:(\()\s*((?:[a-zA-Z_]\w*\s*)(?:,\s*[a-zA-Z_]\w*\s*)*)(\)))?$ + + printed_expression + + begin + (!?\=)\s* + captures + + 1 + + name + constant + + + end + (?=\])|$ + name + source.js + patterns + + + include + #js_brackets + + + include + source.js + + + + string + + begin + (['"]) + end + (?<!\\)\1 + name + string.quoted.pug + patterns + + + match + \\((x[0-9a-fA-F]{2})|(u[0-9]{4})|.) + name + constant.character.quoted.pug + + + include + #interpolated_value + + + include + #interpolated_error + + + + tag_attribute_name + + captures + + 1 + + name + entity.other.attribute-name.tag.pug + + + match + ([^\s(),=/!]+)\s* + + tag_attribute_name_paren + + begin + \(\s* + end + \) + name + entity.other.attribute-name.tag.pug + patterns + + + include + #tag_attribute_name_paren + + + include + #tag_attribute_name + + + + tag_attributes + + begin + (\(\s*) + captures + + 1 + + name + constant.name.attribute.tag.pug + + + end + (\)) + name + meta.tag.other + patterns + + + include + #tag_attribute_name_paren + + + include + #tag_attribute_name + + + match + !(?!=) + name + invalid.illegal.tag.pug + + + begin + =\s* + end + $|(?=,|(?:\s+[^!%&*-+~|<>:?/])|\)) + name + attribute_value + patterns + + + include + #string + + + include + #js_parens + + + include + #js_brackets + + + include + #js_braces + + + include + source.js + + + + + begin + (?<=[%&*-+~|<>:?/])\s+ + end + $|(?=,|(?:\s+[^!%&*-+~|<>:?/])|\)) + name + attribute_value2 + patterns + + + include + #string + + + include + #js_parens + + + include + #js_brackets + + + include + #js_braces + + + include + source.js + + + + + + tag_classes + + captures + + 1 + + name + invalid.illegal.tag.pug + + + match + \.([^\w-])?[\w-]* + name + entity.other.attribute-name.class.pug + + tag_id + + match + #[\w-]+ + name + entity.other.attribute-name.id.pug + + tag_mixin_attributes + + begin + (&attributes\() + captures + + 1 + + name + entity.name.function.pug + + + end + (\)) + name + meta.tag.other + patterns + + + match + attributes(?=\)) + name + storage.type.keyword.pug + + + include + source.js + + + + tag_name + + begin + ([#!]\{(?=.*?\}))|(\w(([\w:-]+[\w-])|([\w-]*))) + end + (\G(?<!\5[^\w-]))|\}|$ + name + meta.tag.other entity.name.tag.pug + patterns + + + begin + \G(?<=\{) + end + (?=\}) + name + meta.tag.other entity.name.tag.pug + patterns + + + match + { + name + invalid.illegal.tag.pug + + + include + source.js + + + + + + tag_text + + begin + (?=.) + end + $ + patterns + + + include + #inline_pug + + + include + #embedded_html + + + include + #html_entity + + + include + #interpolated_value + + + include + #interpolated_error + + + + unbuffered_code + + begin + (-|(([a-zA-Z0-9_]+)\s+=)) + beginCaptures + + 3 + + name + variable.parameter.javascript.embedded.pug + + + comment + name = function() {} + end + (?=\])|(({\s*)?$) + name + source.js + patterns + + + include + #js_brackets + + + include + #babel_parens + + + include + source.js + + + + + scopeName + text.pug + uuid + eee6ba25-6ac2-4f7e-9c70-cddf2bd3448b + + \ No newline at end of file diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/YAML.tmLanguage b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/YAML.tmLanguage new file mode 100644 index 000000000..4a1b7b15b --- /dev/null +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/YAML.tmLanguage @@ -0,0 +1,1164 @@ + + + + + fileTypes + + yaml + yml + rviz + reek + clang-format + yaml-tmlanguage + syntax + sublime-syntax + + firstLineMatch + ^%YAML( ?1.\d+)? + keyEquivalent + ^~Y + name + YAML + patterns + + + include + #comment + + + include + #property + + + include + #directive + + + match + ^--- + name + entity.other.document.begin.yaml + + + match + ^\.{3} + name + entity.other.document.end.yaml + + + include + #node + + + repository + + block-collection + + patterns + + + include + #block-sequence + + + include + #block-mapping + + + + block-mapping + + patterns + + + include + #block-pair + + + + block-node + + patterns + + + include + #prototype + + + include + #block-scalar + + + include + #block-collection + + + include + #flow-scalar-plain-out + + + include + #flow-node + + + + block-pair + + patterns + + + begin + \? + beginCaptures + + 1 + + name + punctuation.definition.key-value.begin.yaml + + + end + (?=\?)|^ *(:)|(:) + endCaptures + + 1 + + name + punctuation.separator.key-value.mapping.yaml + + 2 + + name + invalid.illegal.expected-newline.yaml + + + name + meta.block-mapping.yaml + patterns + + + include + #block-node + + + + + begin + (?x) + (?= + (?x: + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] \S + ) + ( + [^\s:] + | : \S + | \s+ (?![#\s]) + )* + \s* + : + (\s|$) + ) + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + + patterns + + + include + #flow-scalar-plain-out-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] \S + + beginCaptures + + 0 + + name + entity.name.tag.yaml + + + contentName + entity.name.tag.yaml + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + + name + string.unquoted.plain.out.yaml + + + + + match + :(?=\s|$) + name + punctuation.separator.key-value.mapping.yaml + + + + block-scalar + + begin + (?:(\|)|(>))([1-9])?([-+])?(.*\n?) + beginCaptures + + 1 + + name + keyword.control.flow.block-scalar.literal.yaml + + 2 + + name + keyword.control.flow.block-scalar.folded.yaml + + 3 + + name + constant.numeric.indentation-indicator.yaml + + 4 + + name + storage.modifier.chomping-indicator.yaml + + 5 + + patterns + + + include + #comment + + + match + .+ + name + invalid.illegal.expected-comment-or-newline.yaml + + + + + end + ^(?=\S)|(?!\G) + patterns + + + begin + ^([ ]+)(?! ) + end + ^(?!\1|\s*$) + name + string.unquoted.block.yaml + + + + block-sequence + + match + (-)(?!\S) + name + punctuation.definition.block.sequence.item.yaml + + comment + + begin + (?:(^[ \t]*)|[ \t]+)(?=#\p{Print}*$) + beginCaptures + + 1 + + name + punctuation.whitespace.comment.leading.yaml + + + end + (?!\G) + patterns + + + begin + # + beginCaptures + + 0 + + name + punctuation.definition.comment.yaml + + + end + \n + name + comment.line.number-sign.yaml + + + + directive + + begin + ^% + beginCaptures + + 0 + + name + punctuation.definition.directive.begin.yaml + + + end + (?=$|[ \t]+($|#)) + name + meta.directive.yaml + patterns + + + captures + + 1 + + name + keyword.other.directive.yaml.yaml + + 2 + + name + constant.numeric.yaml-version.yaml + + + match + \G(YAML)[ \t]+(\d+\.\d+) + + + captures + + 1 + + name + keyword.other.directive.tag.yaml + + 2 + + name + storage.type.tag-handle.yaml + + 3 + + name + support.type.tag-prefix.yaml + + + match + (?x) + \G + (TAG) + (?:[ \t]+ + ((?:!(?:[0-9A-Za-z\-]*!)?)) + (?:[ \t]+ ( + ! (?x: %[0-9A-Fa-f]{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )* + | (?![,!\[\]{}]) (?x: %[0-9A-Fa-f]{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )+ + ) + )? + )? + + + + captures + + 1 + + name + support.other.directive.reserved.yaml + + 2 + + name + string.unquoted.directive-name.yaml + + 3 + + name + string.unquoted.directive-parameter.yaml + + + match + (?x) \G (\w+) (?:[ \t]+ (\w+) (?:[ \t]+ (\w+))? )? + + + match + \S+ + name + invalid.illegal.unrecognized.yaml + + + + flow-alias + + captures + + 1 + + name + keyword.control.flow.alias.yaml + + 2 + + name + punctuation.definition.alias.yaml + + 3 + + name + variable.other.alias.yaml + + 4 + + name + invalid.illegal.character.anchor.yaml + + + match + ((\*))([^\s\[\]/{/},]+)([^\s\]},]\S*)? + + flow-collection + + patterns + + + include + #flow-sequence + + + include + #flow-mapping + + + + flow-mapping + + begin + \{ + beginCaptures + + 0 + + name + punctuation.definition.mapping.begin.yaml + + + end + \} + endCaptures + + 0 + + name + punctuation.definition.mapping.end.yaml + + + name + meta.flow-mapping.yaml + patterns + + + include + #prototype + + + match + , + name + punctuation.separator.mapping.yaml + + + include + #flow-pair + + + + flow-node + + patterns + + + include + #prototype + + + include + #flow-alias + + + include + #flow-collection + + + include + #flow-scalar + + + + flow-pair + + patterns + + + begin + \? + beginCaptures + + 0 + + name + punctuation.definition.key-value.begin.yaml + + + end + (?=[},\]]) + name + meta.flow-pair.explicit.yaml + patterns + + + include + #prototype + + + include + #flow-pair + + + include + #flow-node + + + begin + :(?=\s|$|[\[\]{},]) + beginCaptures + + 0 + + name + punctuation.separator.key-value.mapping.yaml + + + end + (?=[},\]]) + patterns + + + include + #flow-value + + + + + + + begin + (?x) + (?= + (?: + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] [^\s[\[\]{},]] + ) + ( + [^\s:[\[\]{},]] + | : [^\s[\[\]{},]] + | \s+ (?![#\s]) + )* + \s* + : + (\s|$) + ) + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + + name + meta.flow-pair.key.yaml + patterns + + + include + #flow-scalar-plain-in-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] [^\s[\[\]{},]] + + beginCaptures + + 0 + + name + entity.name.tag.yaml + + + contentName + entity.name.tag.yaml + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + + name + string.unquoted.plain.in.yaml + + + + + include + #flow-node + + + begin + :(?=\s|$|[\[\]{},]) + captures + + 0 + + name + punctuation.separator.key-value.mapping.yaml + + + end + (?=[},\]]) + name + meta.flow-pair.yaml + patterns + + + include + #flow-value + + + + + + flow-scalar + + patterns + + + include + #flow-scalar-double-quoted + + + include + #flow-scalar-single-quoted + + + include + #flow-scalar-plain-in + + + + flow-scalar-double-quoted + + begin + " + beginCaptures + + 0 + + name + punctuation.definition.string.begin.yaml + + + end + " + endCaptures + + 0 + + name + punctuation.definition.string.end.yaml + + + name + string.quoted.double.yaml + patterns + + + match + \\([0abtnvfre "/\\N_Lp]|x\d\d|u\d{4}|U\d{8}) + name + constant.character.escape.yaml + + + match + \\\n + name + constant.character.escape.double-quoted.newline.yaml + + + + flow-scalar-plain-in + + patterns + + + include + #flow-scalar-plain-in-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] [^\s[\[\]{},]] + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + + name + string.unquoted.plain.in.yaml + + + + flow-scalar-plain-in-implicit-type + + patterns + + + captures + + 1 + + name + constant.language.null.yaml + + 2 + + name + constant.language.boolean.yaml + + 3 + + name + constant.numeric.integer.yaml + + 4 + + name + constant.numeric.float.yaml + + 5 + + name + constant.other.timestamp.yaml + + 6 + + name + constant.language.value.yaml + + 7 + + name + constant.language.merge.yaml + + + match + (?x) + (?x: + (null|Null|NULL|~) + | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF) + | ( + (?: + [-+]? 0b [0-1_]+ # (base 2) + | [-+]? 0 [0-7_]+ # (base 8) + | [-+]? (?: 0|[1-9][0-9_]*) # (base 10) + | [-+]? 0x [0-9a-fA-F_]+ # (base 16) + | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60) + ) + ) + | ( + (?x: + [-+]? (?: [0-9] [0-9_]*)? \. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10) + | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \. [0-9_]* # (base 60) + | [-+]? \. (?: inf|Inf|INF) # (infinity) + | \. (?: nan|NaN|NAN) # (not a number) + ) + ) + | ( + (?x: + \d{4} - \d{2} - \d{2} # (y-m-d) + | \d{4} # (year) + - \d{1,2} # (month) + - \d{1,2} # (day) + (?: [Tt] | [ \t]+) \d{1,2} # (hour) + : \d{2} # (minute) + : \d{2} # (second) + (?: \.\d*)? # (fraction) + (?: + (?:[ \t]*) Z + | [-+] \d{1,2} (?: :\d{1,2})? + )? # (time zone) + ) + ) + | (=) + | (<<) + ) + (?: + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + | \s* : [\[\]{},] + | \s* [\[\]{},] + ) + ) + + + + + flow-scalar-plain-out + + patterns + + + include + #flow-scalar-plain-out-implicit-type + + + begin + (?x) + [^\s[-?:,\[\]{}#&*!|>'"%@`]] + | [?:-] \S + + end + (?x) + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + + name + string.unquoted.plain.out.yaml + + + + flow-scalar-plain-out-implicit-type + + patterns + + + captures + + 1 + + name + constant.language.null.yaml + + 2 + + name + constant.language.boolean.yaml + + 3 + + name + constant.numeric.integer.yaml + + 4 + + name + constant.numeric.float.yaml + + 5 + + name + constant.other.timestamp.yaml + + 6 + + name + constant.language.value.yaml + + 7 + + name + constant.language.merge.yaml + + + match + (?x) + (?x: + (null|Null|NULL|~) + | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF) + | ( + (?: + [-+]? 0b [0-1_]+ # (base 2) + | [-+]? 0 [0-7_]+ # (base 8) + | [-+]? (?: 0|[1-9][0-9_]*) # (base 10) + | [-+]? 0x [0-9a-fA-F_]+ # (base 16) + | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60) + ) + ) + | ( + (?x: + [-+]? (?: [0-9] [0-9_]*)? \. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10) + | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \. [0-9_]* # (base 60) + | [-+]? \. (?: inf|Inf|INF) # (infinity) + | \. (?: nan|NaN|NAN) # (not a number) + ) + ) + | ( + (?x: + \d{4} - \d{2} - \d{2} # (y-m-d) + | \d{4} # (year) + - \d{1,2} # (month) + - \d{1,2} # (day) + (?: [Tt] | [ \t]+) \d{1,2} # (hour) + : \d{2} # (minute) + : \d{2} # (second) + (?: \.\d*)? # (fraction) + (?: + (?:[ \t]*) Z + | [-+] \d{1,2} (?: :\d{1,2})? + )? # (time zone) + ) + ) + | (=) + | (<<) + ) + (?x: + (?= + \s* $ + | \s+ \# + | \s* : (\s|$) + ) + ) + + + + + flow-scalar-single-quoted + + begin + ' + beginCaptures + + 0 + + name + punctuation.definition.string.begin.yaml + + + end + '(?!') + endCaptures + + 0 + + name + punctuation.definition.string.end.yaml + + + name + string.quoted.single.yaml + patterns + + + match + '' + name + constant.character.escape.single-quoted.yaml + + + + flow-sequence + + begin + \[ + beginCaptures + + 0 + + name + punctuation.definition.sequence.begin.yaml + + + end + \] + endCaptures + + 0 + + name + punctuation.definition.sequence.end.yaml + + + name + meta.flow-sequence.yaml + patterns + + + include + #prototype + + + match + , + name + punctuation.separator.sequence.yaml + + + include + #flow-pair + + + include + #flow-node + + + + flow-value + + patterns + + + begin + \G(?![},\]]) + end + (?=[},\]]) + name + meta.flow-pair.value.yaml + patterns + + + include + #flow-node + + + + + + node + + patterns + + + include + #block-node + + + + property + + begin + (?=!|&) + end + (?!\G) + name + meta.property.yaml + patterns + + + captures + + 1 + + name + keyword.control.property.anchor.yaml + + 2 + + name + punctuation.definition.anchor.yaml + + 3 + + name + entity.name.type.anchor.yaml + + 4 + + name + invalid.illegal.character.anchor.yaml + + + match + \G((&))([^\s\[\]/{/},]+)(\S+)? + + + match + (?x) + \G + (?: + ! < (?: %[0-9A-Fa-f]{2} | [0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]] )+ > + | (?:!(?:[0-9A-Za-z\-]*!)?) (?: %[0-9A-Fa-f]{2} | [0-9A-Za-z\-#;/?:@&=+$_.~*'()] )+ + | ! + ) + (?=\ |\t|$) + + name + storage.type.tag-handle.yaml + + + match + \S+ + name + invalid.illegal.tag-handle.yaml + + + + prototype + + patterns + + + include + #comment + + + include + #property + + + + + scopeName + source.yaml + uuid + 686AD6AE-33F3-4493-9512-9E9FC1D5417F + + diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/infinite-loop.json b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/infinite-loop.json new file mode 100644 index 000000000..a0b5e6b36 --- /dev/null +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/infinite-loop.json @@ -0,0 +1,79 @@ +{ + "name": "infinite-loop-grammar", + "scopeName": "source.infinite-loop", + "patterns": [ + { + "name": "start", + "begin": "\\A", + "end": "$", + "patterns": [ + { + "name": "negative-look-ahead", + "match": "(?!a)" + } + ] + }, + { + "include": "#test" + }, + { + "include": "#not_a_problem" + } + ], + "repository": { + "test": { + "name": "test", + "begin": "(?=test)", + "end": "$", + "patterns": [ + { + "include": "#test_this" + } + ] + }, + "test_this": { + "name": "test_this", + "begin": "(?=test this)", + "end": "$", + "patterns": [ + { + "include": "#test_this_line" + } + ] + }, + "test_this_line": { + "name": "test_this_line", + "begin": "(?=test this line)", + "end": "$", + "patterns": [ + { + "include": "#test" + } + ] + }, + "spaces": + { + "name": "spaces", + "begin": "^(?=\\s)", + "end": "(?=\\S)" + }, + "not_a_problem": + { + "name": "not_a_problem", + "begin": "(?=not)", + "end": "\\z", + "patterns": [ + { + "name": "not", + "match": "\\Gnot" + }, + { + "include": "#not_a_problem" + }, + { + "include": "#spaces" + } + ] + } + } +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/tests.json b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/tests.json index 59652aa00..5e80f11b7 100644 --- a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/tests.json +++ b/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/tests.json @@ -1253,5 +1253,580 @@ ] } ] + }, + { + "grammars": [ + "fixtures/Jade22.json" + ], + "grammarPath": "fixtures/Jade22.json", + "desc": "Issue #22", + "lines": [ + { + "line": ".class One #[span text.] Two text.", + "tokens": [ + { + "scopes": [ + "text.jade", + "constant.language.js" + ], + "value": ".class" + }, + { + "scopes": [ + "text.jade" + ], + "value": " One " + }, + { + "scopes": [ + "text.jade", + "inline.jade", + "entity.name.function.jade" + ], + "value": "#[" + }, + { + "scopes": [ + "text.jade", + "inline.jade", + "tag.inline.jade", + "meta.tag.other", + "entity.name.tag.jade" + ], + "value": "span" + }, + { + "scopes": [ + "text.jade", + "inline.jade" + ], + "value": " text." + }, + { + "scopes": [ + "text.jade", + "inline.jade", + "entity.name.function.jade" + ], + "value": "]" + }, + { + "scopes": [ + "text.jade" + ], + "value": " Two text." + } + ] + } + ] + }, + { + "grammars": [ + "fixtures/Pug.tmLanguage" + ], + "grammarPath": "fixtures/Pug.tmLanguage", + "desc": "Issue #82", + "lines": [ + { + "line": "li: custom-link.has-text-primary(to=\"/\")", + "tokens": [ + { + "scopes": [ + "text.pug", + "meta.tag.other", + "entity.name.tag.pug" + ], + "value": "li" + }, + { + "scopes": [ + "text.pug" + ], + "value": ": " + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "entity.name.tag.pug" + ], + "value": "custom-link" + }, + { + "scopes": [ + "text.pug", + "entity.other.attribute-name.class.pug" + ], + "value": ".has-text-primary" + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "constant.name.attribute.tag.pug" + ], + "value": "(" + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "entity.other.attribute-name.tag.pug" + ], + "value": "to" + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "attribute_value" + ], + "value": "=" + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "attribute_value", + "string.quoted.pug" + ], + "value": "\"" + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "attribute_value", + "string.quoted.pug" + ], + "value": "/" + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "attribute_value", + "string.quoted.pug" + ], + "value": "\"" + }, + { + "scopes": [ + "text.pug", + "meta.tag.other", + "constant.name.attribute.tag.pug" + ], + "value": ")" + } + ] + } + ] + }, + { + "grammars": [ + "fixtures/66.plist" + ], + "grammarPath": "fixtures/66.plist", + "desc": "Issue #66", + "lines": [ + { + "line": "Just some text", + "tokens": [ + { + "value": "J", + "scopes": [ + "text.test", + "comment" + ] + }, + { + "value": "ust some text", + "scopes": [ + "text.test", + "comment" + ] + } + ] + }, + { + "line": "which contains undefined and then", + "tokens": [ + { + "value": "which contains undefined and then", + "scopes": [ + "text.test", + "comment" + ] + } + ] + }, + { + "line": "more text", + "tokens": [ + { + "value": "more text", + "scopes": [ + "text.test", + "comment" + ] + } + ] + } + ] + }, + { + "grammars": [ + "fixtures/105.grammarA.json", + "fixtures/105.grammarB.json" + ], + "grammarPath": "fixtures/105.grammarA.json", + "desc": "Issue #105", + "lines": [ + { + "line": "embedStart", + "tokens": [ + { + "value": "embedStart", + "scopes": [ + "source.test" + ] + } + ] + }, + { + "line": "testStart", + "tokens": [ + { + "value": "testStart", + "scopes": [ + "source.test" + ] + } + ] + }, + { + "line": "some test pattern", + "tokens": [ + { + "value": "some test pattern", + "scopes": [ + "source.test", + "test.name" + ] + } + ] + } + ] + }, + { + "grammars": [ + "fixtures/YAML.tmLanguage" + ], + "grammarPath": "fixtures/YAML.tmLanguage", + "desc": "Issue #119", + "lines": [ + { + "line": "- run:", + "tokens": [ + { + "scopes": [ + "source.yaml", + "punctuation.definition.block.sequence.item.yaml" + ], + "value": "-" + }, + { + "scopes": [ + "source.yaml" + ], + "value": " " + }, + { + "scopes": [ + "source.yaml", + "string.unquoted.plain.out.yaml", + "entity.name.tag.yaml" + ], + "value": "r" + }, + { + "scopes": [ + "source.yaml", + "string.unquoted.plain.out.yaml", + "entity.name.tag.yaml" + ], + "value": "un" + }, + { + "scopes": [ + "source.yaml", + "punctuation.separator.key-value.mapping.yaml" + ], + "value": ":" + } + ] + }, + { + "line": " command: |", + "tokens": [ + { + "scopes": [ + "source.yaml" + ], + "value": " " + }, + { + "scopes": [ + "source.yaml", + "string.unquoted.plain.out.yaml", + "entity.name.tag.yaml" + ], + "value": "c" + }, + { + "scopes": [ + "source.yaml", + "string.unquoted.plain.out.yaml", + "entity.name.tag.yaml" + ], + "value": "ommand" + }, + { + "scopes": [ + "source.yaml", + "punctuation.separator.key-value.mapping.yaml" + ], + "value": ":" + }, + { + "scopes": [ + "source.yaml" + ], + "value": " " + }, + { + "scopes": [ + "source.yaml", + "keyword.control.flow.block-scalar.literal.yaml" + ], + "value": "|" + } + ] + }, + { + "line": " docker run \\", + "tokens": [ + { + "scopes": [ + "source.yaml", + "string.unquoted.block.yaml" + ], + "value": " " + }, + { + "scopes": [ + "source.yaml", + "string.unquoted.block.yaml" + ], + "value": "docker run \\" + } + ] + }, + { + "line": " sh -c \"\\", + "tokens": [ + { + "scopes": [ + "source.yaml", + "string.unquoted.block.yaml" + ], + "value": " sh -c \"\\" + } + ] + }, + { + "line": " command3", + "tokens": [ + { + "scopes": [ + "source.yaml", + "string.unquoted.block.yaml" + ], + "value": " command3" + } + ] + }, + { + "line": " \"", + "tokens": [ + { + "scopes": [ + "source.yaml", + "string.unquoted.block.yaml" + ], + "value": " \"" + } + ] + }, + { + "line": "- run:", + "tokens": [ + { + "scopes": [ + "source.yaml", + "punctuation.definition.block.sequence.item.yaml" + ], + "value": "-" + }, + { + "scopes": [ + "source.yaml" + ], + "value": " " + }, + { + "scopes": [ + "source.yaml", + "string.unquoted.plain.out.yaml", + "entity.name.tag.yaml" + ], + "value": "r" + }, + { + "scopes": [ + "source.yaml", + "string.unquoted.plain.out.yaml", + "entity.name.tag.yaml" + ], + "value": "un" + }, + { + "scopes": [ + "source.yaml", + "punctuation.separator.key-value.mapping.yaml" + ], + "value": ":" + } + ] + } + ] + }, + { + "grammars": [ + "fixtures/infinite-loop.json" + ], + "grammarPath": "fixtures/infinite-loop.json", + "desc": "Issue #145", + "lines": [ + { + "line": "abc", + "tokens": [ + { + "value": "a", + "scopes": [ + "source.infinite-loop", + "start" + ] + }, + { + "value": "bc", + "scopes": [ + "source.infinite-loop" + ] + } + ] + }, + { + "line": "test this line", + "tokens": [ + { + "value": "test this line", + "scopes": [ + "source.infinite-loop", + "test", + "test_this", + "test_this_line" + ] + } + ] + }, + { + "line": "not", + "tokens": [ + { + "value": "not", + "scopes": [ + "source.infinite-loop", + "test", + "test_this", + "test_this_line" + ] + } + ] + }, + { + "line": " not", + "tokens": [ + { + "value": " ", + "scopes": [ + "source.infinite-loop" + ] + }, + { + "value": "not", + "scopes": [ + "source.infinite-loop", + "not_a_problem", + "not" + ] + } + ] + }, + { + "line": " not", + "tokens": [ + { + "value": " ", + "scopes": [ + "source.infinite-loop", + "not_a_problem", + "spaces" + ] + }, + { + "value": "not", + "scopes": [ + "source.infinite-loop", + "not_a_problem", + "not_a_problem", + "not" + ] + } + ] + } + ] + }, + { + "grammars": [ + "fixtures/147.grammar.json" + ], + "grammarPath": "fixtures/147.grammar.json", + "desc": "Issue #147", + "lines": [ + { + "line": "Function", + "tokens": [ + { + "value": "Function", + "scopes": [ + "source.test", + "storage.type.Function", + "keyword.declaration.Function" + ] + } + ] + } + ] } -] \ No newline at end of file +] From 9b84ed86fe544ab6ebeb874e6620e0e23afbcda6 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 16:52:16 +0200 Subject: [PATCH 117/202] Fix parsing issues Solves microsoft/vscode-textmate#82 and microsoft/vscode-textmate#119 --- .../tm4e/core/grammar/GrammarSuiteTest.java | 3 +- .../tm4e/core/grammar/StackElement.java | 117 ++++++++++++++---- .../tm4e/core/internal/grammar/Grammar.java | 8 +- .../core/internal/grammar/LineTokenizer.java | 23 ++-- 4 files changed, 114 insertions(+), 37 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java index b65376594..8f79e4302 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java @@ -36,7 +36,6 @@ * * @see * github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts - * */ public class GrammarSuiteTest { @@ -45,7 +44,7 @@ public class GrammarSuiteTest { // TODO: fix thoses tests: // It seems that problem comes from with encoding. OnigString should support UTF-16 like // https://github.com/atom/node-oniguruma/blob/master/src/onig-string.cc - private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66", "Issue #82", "Issue #119"); + private static final List IGNORE_TESTS = List.of("TEST #24", "TEST #66"); @TestFactory @DisplayName("Tokenization /first-mate/") diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java index d92c4ddad..077c4ec6b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.grammar; @@ -20,6 +20,7 @@ import java.util.List; import java.util.Objects; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.grammar.ScopeListElement; import org.eclipse.tm4e.core.internal.rule.IRuleRegistry; import org.eclipse.tm4e.core.internal.rule.Rule; @@ -33,7 +34,7 @@ */ public class StackElement { - public static final StackElement NULL = new StackElement(null, 0, 0, null, null, null); + public static final StackElement NULL = new StackElement(null, 0, 0, 0, false, null, null, null); /** * The position on the current line where this state was pushed. @@ -42,10 +43,19 @@ public class StackElement { */ private int enterPosition; + /** + * The captured anchor position when this stack element was pushed. + * This is relevant only while tokenizing a line, to restore the anchor position when popping. + * Its value is meaningless across lines. + */ + private int anchorPos; + /** * The previous state on the stack (or null for the root state). */ + @Nullable public final StackElement parent; + /** * The depth of the stack. */ @@ -55,13 +65,21 @@ public class StackElement { * The state (rule) that this element represents. */ public final int ruleId; + + /** + * The state has entered and captured \n. This means that the next line should have an anchorPosition of 0. + */ + public final boolean beginRuleCapturedEOL; + /** * The "pop" (end) condition for this state in case that it was dynamically generated through captured text. */ public final String endRule; + /** * The list of scopes containing the "name" for this state. */ + public final ScopeListElement nameScopesList; /** * The list of scopes containing the "contentName" (besides "name") for this state. @@ -69,11 +87,21 @@ public class StackElement { */ public final ScopeListElement contentNameScopesList; - public StackElement(StackElement parent, int ruleId, int enterPos, String endRule, ScopeListElement nameScopesList, ScopeListElement contentNameScopesList) { + public StackElement( + @Nullable StackElement parent, + int ruleId, + int enterPos, + int anchorPos, + boolean beginRuleCapturedEOL, + @Nullable String endRule, + ScopeListElement nameScopesList, + ScopeListElement contentNameScopesList) { this.parent = parent; this.depth = (this.parent != null ? this.parent.depth + 1 : 1); this.ruleId = ruleId; this.enterPosition = enterPos; + this.anchorPos = anchorPos; + this.beginRuleCapturedEOL = beginRuleCapturedEOL; this.endRule = endRule; this.nameScopesList = nameScopesList; this.contentNameScopesList = contentNameScopesList; @@ -82,44 +110,71 @@ public StackElement(StackElement parent, int ruleId, int enterPos, String endRul /** * A structural equals check. Does not take into account `scopes`. */ - private static boolean structuralEquals(StackElement a, StackElement b) { + private static boolean structuralEquals(@Nullable StackElement a, @Nullable StackElement b) { + do { + if (a == b) { + return true; + } + + if (a == null && b == null) { + // End of list reached for both + return true; + } + + if (a == null || b == null) { + // End of list reached only for one + return false; + } + + if (a.depth != b.depth || a.ruleId != b.ruleId || !Objects.equals(a.endRule, b.endRule)) { + return false; + } + + // Go to previous pair + a = a.parent; + b = b.parent; + } while (true); + } + + @SuppressWarnings("null") + private static boolean equals(@Nullable StackElement a, @Nullable StackElement b) { if (a == b) { return true; } - if (a == null || b == null) { + if (!structuralEquals(a, b)) { return false; } - return a.depth == b.depth && a.ruleId == b.ruleId && Objects.equals(a.endRule, b.endRule) && structuralEquals(a.parent, b.parent); + return a.contentNameScopesList.equals(b.contentNameScopesList); } @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - if (other == null) { + if (other == null || other.getClass() != StackElement.class) { return false; } - if (!(other instanceof StackElement)) { - return false; - } - StackElement stackElement = (StackElement)other; - return structuralEquals(this, stackElement) && this.contentNameScopesList.equals(stackElement.contentNameScopesList); + return equals(this, (StackElement) other); } @Override public int hashCode() { - return Objects.hash(depth, ruleId, endRule, parent, contentNameScopesList); + final int prime = 31; + int result = 1; + result = prime * result + Objects.hash(endRule, parent, contentNameScopesList); + result = prime * result + depth; + result = prime * result + ruleId; + return result; } public void reset() { StackElement el = this; while (el != null) { el.enterPosition = -1; + el.anchorPos = -1; el = el.parent; } } + @Nullable public StackElement pop() { return this.parent; } @@ -131,8 +186,19 @@ public StackElement safePop() { return this; } - public StackElement push(int ruleId, int enterPos, String endRule, ScopeListElement nameScopesList, ScopeListElement contentNameScopesList) { - return new StackElement(this, ruleId, enterPos, endRule, nameScopesList, contentNameScopesList); + public StackElement push(int ruleId, + int enterPos, + int anchorPos, + boolean beginRuleCapturedEOL, + @Nullable String endRule, + ScopeListElement nameScopesList, + ScopeListElement contentNameScopesList) { + return new StackElement(this, ruleId, enterPos, anchorPos, beginRuleCapturedEOL, endRule, nameScopesList, + contentNameScopesList); + } + + public int getAnchorPos() { + return anchorPos; } public int getEnterPos() { @@ -147,7 +213,8 @@ private void appendString(List res) { if (this.parent != null) { this.parent.appendString(res); } - res.add('(' + Integer.toString(this.ruleId) + ')'); //, TODO-${this.nameScopesList}, TODO-${this.contentNameScopesList})`; + res.add('(' + Integer.toString(this.ruleId) + ')'); // , TODO-${this.nameScopesList}, + // TODO-${this.contentNameScopesList})`; } @Override @@ -161,14 +228,18 @@ public StackElement setContentNameScopesList(ScopeListElement contentNameScopesL if (this.contentNameScopesList.equals(contentNameScopesList)) { return this; } - return this.parent.push(this.ruleId, this.enterPosition, this.endRule, this.nameScopesList, contentNameScopesList); + final var parent = this.parent; + assert parent != null; + return parent.push(this.ruleId, this.enterPosition, this.anchorPos, this.beginRuleCapturedEOL, this.endRule, + this.nameScopesList, contentNameScopesList); } public StackElement setEndRule(String endRule) { if (this.endRule != null && this.endRule.equals(endRule)) { return this; } - return new StackElement(this.parent, this.ruleId, this.enterPosition, endRule, this.nameScopesList, this.contentNameScopesList); + return new StackElement(this.parent, this.ruleId, this.enterPosition, this.anchorPos, this.beginRuleCapturedEOL, + endRule, this.nameScopesList, this.contentNameScopesList); } public boolean hasSameRuleAs(final StackElement other) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index e67221fd4..692d26c09 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -50,9 +50,9 @@ /** * TextMate grammar implementation. * - * @see + * @see * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts - * */ public final class Grammar implements IGrammar, IRuleFactoryHelper { @@ -198,7 +198,7 @@ public ITokenizeLineResult2 tokenizeLine2(String lineText, StackElement prevStat } @SuppressWarnings("unchecked") - private T tokenize(String lineText, StackElement prevState, boolean emitBinaryTokens) { + private T tokenize(String lineText, @Nullable StackElement prevState, boolean emitBinaryTokens) { if (this.rootId == -1) { this.rootId = RuleFactory.getCompiledRuleId(this.rawGrammar.getRepository().getSelf(), this, this.rawGrammar.getRepository()); @@ -219,7 +219,7 @@ private T tokenize(String lineText, StackElement prevState, boolean emitBina ScopeListElement scopeList = new ScopeListElement(null, rootScopeName, rootMetadata); - prevState = new StackElement(null, this.rootId, -1, null, scopeList, scopeList); + prevState = new StackElement(null, this.rootId, -1, -1, false, null, scopeList, scopeList); } else { isFirstLine = false; prevState.reset(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 9e2800f54..26ea4a5b7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -35,6 +35,11 @@ import org.eclipse.tm4e.core.internal.rule.MatchRule; import org.eclipse.tm4e.core.internal.rule.Rule; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts + */ final class LineTokenizer { private static final Logger LOGGER = System.getLogger(LineTokenizer.class.getName()); @@ -145,8 +150,9 @@ private void scanNext() { lineTokens.produce(stack, captureIndices[0].getEnd()); // pop - StackElement popped = stack; + final var popped = stack; stack = stack.pop(); + anchorPosition = popped.getAnchorPos(); if (!hasAdvanced && popped.getEnterPos() == linePos) { // Grammar pushed & popped a rule without advancing @@ -171,7 +177,8 @@ private void scanNext() { // push it on the stack rule String scopeName = rule.getName(lineText.string, captureIndices); ScopeListElement nameScopesList = stack.contentNameScopesList.push(grammar, scopeName); - stack = stack.push(matchedRuleId, linePos, null, nameScopesList, nameScopesList); + stack = stack.push(matchedRuleId, linePos, anchorPosition, + captureIndices[0].getEnd() == lineText.bytesCount, null, nameScopesList, nameScopesList); if (rule instanceof BeginEndRule) { BeginEndRule pushedRule = (BeginEndRule) rule; @@ -450,11 +457,11 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); // the capture requires additional matching - StackElement stackClone = stack.push(retokenizeCapturedWithRuleId, captureIndex.getStart(), null, - nameScopesList, contentNameScopesList); - tokenizeString(grammar, - OnigString.of(lineText.string.substring(0, captureIndex.getEnd())), - (isFirstLine && captureIndex.getStart() == 0), captureIndex.getStart(), stackClone, lineTokens); + StackElement stackClone = stack.push(retokenizeCapturedWithRuleId, captureIndex.getStart(), -1, false, + null, nameScopesList, contentNameScopesList); + final var onigSubStr = OnigString.of(lineText.string.substring(0, captureIndex.getEnd())); + tokenizeString(grammar, onigSubStr, (isFirstLine && captureIndex.getStart() == 0), + captureIndex.getStart(), stackClone, lineTokens); continue; } @@ -485,7 +492,7 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs */ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, StackElement stack, LineTokens lineTokens) { - int currentanchorPosition = -1; + int currentanchorPosition = stack.beginRuleCapturedEOL ? 0 : -1; List whileRules = new ArrayList<>(); for (StackElement node = stack; node != null; node = node.pop()) { Rule nodeRule = node.getRule(grammar); From 1715ef719579e8e4160918c6154643cb58f12bd6 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 19:04:05 +0200 Subject: [PATCH 118/202] Add strikethrough font-style See https://github.com/microsoft/vscode-textmate/pull/159 --- .../tm4e/core/theme/ThemeParsingTest.java | 36 +++++++++---------- .../core/internal/grammar/MetadataConsts.java | 12 +++---- .../internal/grammar/StandardTokenType.java | 2 +- .../eclipse/tm4e/core/theme/FontStyle.java | 6 ++-- .../org/eclipse/tm4e/core/theme/Theme.java | 3 ++ .../core/internal/grammar/GrammarTest.java | 9 +++++ 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java index 5b7d8b144..1fd72baad 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java @@ -30,23 +30,21 @@ public class ThemeParsingTest { @Test public void testCanParse() throws Exception { - List actual = parseTheme("{" + - "\"settings\": [" + - "{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } }," + - "{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } }," + - "{ \"scope\": [\"bar\", \"baz\"], \"settings\": { \"background\": \"#010000\" } }," + - "{ \"scope\": \"source.css selector bar\", \"settings\": { \"fontStyle\": \"bold\" } }," + - "{ \"scope\": \"constant\", \"settings\": { \"fontStyle\": \"italic\", \"foreground\": \"#ff0000\" } }," + - "{ \"scope\": \"constant.numeric\", \"settings\": { \"foreground\": \"#00ff00\" } }," + - "{ \"scope\": \"constant.numeric.hex\", \"settings\": { \"fontStyle\": \"bold\" } }," + - "{ \"scope\": \"constant.numeric.oct\", \"settings\": { \"fontStyle\": \"bold italic underline\" } }," + - "{ \"scope\": \"constant.numeric.dec\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#0000ff\" } }," + - "{ \"scope\": \"foo\", \"settings\": { \"fontStyle\": \"\", \"foreground\": \"#CFA\" } }" + - "]" + - "}"); + final var actual = parseTheme(("{'settings': [" + + "{ 'settings': { 'foreground': '#F8F8F2', 'background': '#272822' } }," + + "{ 'scope': 'source, something', 'settings': { 'background': '#100000' } }," + + "{ 'scope': ['bar', 'baz'], 'settings': { 'background': '#010000' } }," + + "{ 'scope': 'source.css selector bar', 'settings': { 'fontStyle': 'bold' } }," + + "{ 'scope': 'constant', 'settings': { 'fontStyle': 'italic', 'foreground': '#ff0000' } }," + + "{ 'scope': 'constant.numeric', 'settings': { 'foreground': '#00ff00' } }," + + "{ 'scope': 'constant.numeric.hex', 'settings': { 'fontStyle': 'bold' } }," + + "{ 'scope': 'constant.numeric.oct', 'settings': { 'fontStyle': 'bold italic underline' } }," + + "{ 'scope': 'constant.numeric.bin', 'settings': { 'fontStyle': 'bold strikethrough' } }," + + "{ 'scope': 'constant.numeric.dec', 'settings': { 'fontStyle': '', 'foreground': '#0000ff' } }," + + "{ 'scope': 'foo', 'settings': { 'fontStyle': '', 'foreground': '#CFA' } }" + + "]}").replace('\'', '"')); - - ParsedThemeRule[] expected = new ParsedThemeRule[] { + final var expected = new ParsedThemeRule[] { new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#F8F8F2", "#272822"), new ParsedThemeRule("source", null, 1, FontStyle.NotSet, null, "#100000"), new ParsedThemeRule("something", null, 1, FontStyle.NotSet, null, "#100000"), @@ -58,8 +56,10 @@ public void testCanParse() throws Exception { new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null), new ParsedThemeRule("constant.numeric.oct", null, 7, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null), - new ParsedThemeRule("constant.numeric.dec", null, 8, FontStyle.None, "#0000ff", null), - new ParsedThemeRule("foo", null, 9, FontStyle.None, "#CFA", null), }; + new ParsedThemeRule("constant.numeric.bin", null, 8, FontStyle.Bold | FontStyle.Strikethrough, null, + null), + new ParsedThemeRule("constant.numeric.dec", null, 9, FontStyle.None, "#0000ff", null), + new ParsedThemeRule("foo", null, 10, FontStyle.None, "#CFA", null), }; assertArrayEquals(expected, actual.toArray()); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java index 6c624002b..a261959d3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java @@ -23,11 +23,11 @@ * 1098 7654 3210 9876 5432 1098 7654 3210 * - ------------------------------------------- * xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - * bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL + * bbbb bbbb bfff ffff ffFF FFTT LLLL LLLL * - ------------------------------------------- * - L = LanguageId (8 bits) - * - T = StandardTokenType (3 bits) - * - F = FontStyle (3 bits) + * - T = StandardTokenType (2 bits) + * - F = FontStyle (4 bits) * - f = foreground color (9 bits) * - b = background color (9 bits) */ @@ -40,14 +40,14 @@ private MetadataConsts() { } static final int LANGUAGEID_MASK = 0b00000000000000000000000011111111; - static final int TOKEN_TYPE_MASK = 0b00000000000000000000011100000000; - static final int FONT_STYLE_MASK = 0b00000000000000000011100000000000; + static final int TOKEN_TYPE_MASK = 0b00000000000000000000001100000000; + static final int FONT_STYLE_MASK = 0b00000000000000000011110000000000; static final int FOREGROUND_MASK = 0b00000000011111111100000000000000; static final int BACKGROUND_MASK = 0b11111111100000000000000000000000; static final int LANGUAGEID_OFFSET = 0; static final int TOKEN_TYPE_OFFSET = 8; - static final int FONT_STYLE_OFFSET = 11; + static final int FONT_STYLE_OFFSET = 10; static final int FOREGROUND_OFFSET = 14; static final int BACKGROUND_OFFSET = 23; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java index 47f8669e8..8ee0f3222 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java @@ -26,6 +26,6 @@ private StandardTokenType() { static final int Other = 0; static final int Comment = 1; static final int String = 2; - static final int RegEx = 4; + static final int RegEx = 3; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java index b70bb6fa4..cf2001f5a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java @@ -14,8 +14,9 @@ /** * Font style definitions. * - * @see - * github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts + * @see + * github.com/microsoft/vscode-textmate/blob/master/src/theme.ts */ public class FontStyle { @@ -26,5 +27,6 @@ public class FontStyle { public static final int Italic = 1; public static final int Bold = 2; public static final int Underline = 4; + public static final int Strikethrough = 8; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index dbe9bfd6e..6c9813623 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -101,6 +101,9 @@ public static List parseTheme(IRawTheme source) { case "underline": fontStyle = fontStyle | FontStyle.Underline; break; + case "strikethrough": + fontStyle = fontStyle | FontStyle.Strikethrough; + break; } } } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java index 1a3e0bbdd..10fb9f049 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java @@ -60,6 +60,15 @@ public void testCanOverwriteFontStyle() { assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102); } + @Test + public void testCanOverwriteFontStyleWithStrikethrough() { + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102); + + value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.None, 0, 0); + assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102); + } + @Test public void testCanOverwriteForeground() { int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, From 2d0edcb2d0f4bbe0c9bda0e655f57fc5df38a341 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 20:06:56 +0200 Subject: [PATCH 119/202] implement StackElementMetadata#toBinaryStr --- .../core/internal/grammar/StackElementMetadata.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index e71a46bcc..2f92d187c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -27,13 +27,10 @@ public final class StackElementMetadata { private StackElementMetadata() { } - static String toBinaryStr(int metadata) { - /* - * let r = metadata.toString(2); while (r.length < 32) { r = '0' + r; } - * return r; - */ - // TODO!!! - return null; + static String toBinaryStr(final int metadata) { + return new StringBuilder(Integer.toBinaryString(metadata)) + .insert(0, "0".repeat(Integer.numberOfLeadingZeros(metadata))) + .toString(); } static int getLanguageId(int metadata) { From 18f662e3acaa4f0ef59fbfebdb716ffd88baea0d Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 20:30:38 +0200 Subject: [PATCH 120/202] add @Nullable annotations to grammar classes --- .../eclipse/tm4e/core/grammar/IGrammar.java | 20 ++++++++++--------- .../tm4e/core/grammar/StackElement.java | 1 + .../tm4e/core/internal/grammar/Grammar.java | 11 ++++++---- .../core/internal/grammar/LineTokenizer.java | 3 ++- .../core/internal/grammar/LineTokens.java | 7 +++++-- .../internal/grammar/ScopeListElement.java | 15 +++++++------- .../grammar/ScopeMetadataProvider.java | 3 ++- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java index ffa82210e..691fca3b4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java @@ -18,6 +18,8 @@ import java.util.Collection; +import org.eclipse.jdt.annotation.Nullable; + /** * TextMate grammar API. * @@ -29,28 +31,28 @@ public interface IGrammar { /** * Returns the name of the grammar. - * + * * @return the name of the grammar. */ String getName(); /** * Returns the scope name of the grammar. - * + * * @return the scope name of the grammar. */ String getScopeName(); /** * Returns the supported file types and null otherwise. - * + * * @return the supported file types and null otherwise. */ Collection getFileTypes(); /** * Tokenize `lineText`. - * + * * @param lineText * the line text to tokenize. * @return the result of the tokenization. @@ -59,14 +61,14 @@ public interface IGrammar { /** * Tokenize `lineText` using previous line state `prevState`. - * + * * @param lineText * the line text to tokenize. * @param prevState * previous line state. * @return the result of the tokenization. */ - ITokenizeLineResult tokenizeLine(String lineText, StackElement prevState); + ITokenizeLineResult tokenizeLine(String lineText, @Nullable StackElement prevState); /** * Tokenize `lineText` using previous line state `prevState`. @@ -79,7 +81,7 @@ public interface IGrammar { * e.g. for getting the languageId: `(metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET` */ ITokenizeLineResult2 tokenizeLine2(String lineText); - + /** * Tokenize `lineText` using previous line state `prevState`. * The result contains the tokens in binary format, resolved with the following information: @@ -90,6 +92,6 @@ public interface IGrammar { * - background color * e.g. for getting the languageId: `(metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET` */ - ITokenizeLineResult2 tokenizeLine2(String lineText, StackElement prevState); - + ITokenizeLineResult2 tokenizeLine2(String lineText, @Nullable StackElement prevState); + } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java index 077c4ec6b..e01d195da 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java @@ -74,6 +74,7 @@ public class StackElement { /** * The "pop" (end) condition for this state in case that it was dynamically generated through captured text. */ + @Nullable public final String endRule; /** diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 692d26c09..ab5f6c005 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -65,8 +65,11 @@ public final class Grammar implements IGrammar, IRuleFactoryHelper { private List injections; private final ScopeMetadataProvider scopeMetadataProvider; - public Grammar(IRawGrammar grammar, int initialLanguage, Map embeddedLanguages, - IGrammarRepository grammarRepository, IThemeProvider themeProvider) { + public Grammar(IRawGrammar grammar, + int initialLanguage, + @Nullable Map embeddedLanguages, + IGrammarRepository grammarRepository, + IThemeProvider themeProvider) { this.scopeMetadataProvider = new ScopeMetadataProvider(initialLanguage, themeProvider, embeddedLanguages); this.grammarRepository = grammarRepository; this.rawGrammar = initGrammar(grammar, null); @@ -183,7 +186,7 @@ public ITokenizeLineResult tokenizeLine(String lineText) { } @Override - public ITokenizeLineResult tokenizeLine(String lineText, StackElement prevState) { + public ITokenizeLineResult tokenizeLine(String lineText, @Nullable StackElement prevState) { return tokenize(lineText, prevState, false); } @@ -193,7 +196,7 @@ public ITokenizeLineResult2 tokenizeLine2(String lineText) { } @Override - public ITokenizeLineResult2 tokenizeLine2(String lineText, StackElement prevState) { + public ITokenizeLineResult2 tokenizeLine2(String lineText, @Nullable StackElement prevState) { return tokenize(lineText, prevState, true); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 26ea4a5b7..96dbf8aa2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -23,6 +23,7 @@ import java.util.List; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; @@ -403,7 +404,7 @@ public boolean isPriorityMatch() { } private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirstLine, StackElement stack, - LineTokens lineTokens, List captures, OnigCaptureIndex[] captureIndices) { + LineTokens lineTokens, List<@Nullable CaptureRule> captures, OnigCaptureIndex[] captureIndices) { if (captures.isEmpty()) { return; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index c6c61c867..0f60ba997 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -20,8 +20,10 @@ import java.lang.System.Logger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IToken; import org.eclipse.tm4e.core.grammar.StackElement; @@ -29,6 +31,7 @@ final class LineTokens { private static final Logger LOGGER = System.getLogger(LineTokens.class.getName()); + @Nullable private final String lineText; /** @@ -49,11 +52,11 @@ final class LineTokens { this.emitBinaryTokens = emitBinaryTokens; this.lineText = LOGGER.isLoggable(TRACE) ? lineText : null; // store line only if it's logged if (this.emitBinaryTokens) { - this.tokens = null; + this.tokens = Collections.emptyList(); this.binaryTokens = new ArrayList<>(); } else { this.tokens = new ArrayList<>(); - this.binaryTokens = null; + this.binaryTokens = Collections.emptyList(); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index a18b05ea1..2e04be105 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Objects; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.FontStyle; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; @@ -25,17 +26,18 @@ public final class ScopeListElement { private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' '); + @Nullable private final ScopeListElement parent; private final String scope; final int metadata; - public ScopeListElement(ScopeListElement parent, String scope, int metadata) { + public ScopeListElement(@Nullable ScopeListElement parent, String scope, int metadata) { this.parent = parent; this.scope = scope; this.metadata = metadata; } - private static boolean equals(ScopeListElement a, ScopeListElement b) { + private static boolean equals(@Nullable ScopeListElement a, @Nullable ScopeListElement b) { if (a == b) { return true; } @@ -46,7 +48,7 @@ private static boolean equals(ScopeListElement a, ScopeListElement b) { } @Override - public boolean equals(Object other) { + public boolean equals(@Nullable Object other) { if (other == this) { return true; } @@ -64,12 +66,11 @@ public int hashCode() { return Objects.hash(scope, metadata, parent); } - private static boolean matchesScope(String scope, String selector, String selectorWithDot) { return (selector.equals(scope) || scope.startsWith(selectorWithDot)); } - private static boolean matches(ScopeListElement target, List parentScopes) { + private static boolean matches(@Nullable ScopeListElement target, List parentScopes) { if (parentScopes == null) { return true; } @@ -94,7 +95,7 @@ private static boolean matches(ScopeListElement target, List parentScope return false; } - public static int mergeMetadata(int metadata, ScopeListElement scopesList, ScopeMetadata source) { + public static int mergeMetadata(int metadata, @Nullable ScopeListElement scopesList, ScopeMetadata source) { if (source == null) { return metadata; } @@ -128,7 +129,7 @@ private static ScopeListElement push(ScopeListElement target, Grammar grammar, I return target; } - ScopeListElement push(Grammar grammar, String scope) { + ScopeListElement push(Grammar grammar, @Nullable String scope) { if (scope == null) { return this; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java index 3cb3b9aa8..19688c67c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java @@ -21,6 +21,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.TMException; import org.eclipse.tm4e.core.theme.IThemeProvider; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; @@ -42,7 +43,7 @@ final class ScopeMetadataProvider { private Pattern embeddedLanguagesRegex; ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider, - Map embeddedLanguages) { + @Nullable Map embeddedLanguages) { this.initialLanguage = initialLanguage; this.themeProvider = themeProvider; this.onDidChangeTheme(); From f4a9aaf50dae23d8b3f4c8a3e9084568deb786d7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 21:44:36 +0200 Subject: [PATCH 121/202] Remove unnecessary internal getter --- .../core/internal/grammar/LineTokenizer.java | 72 +++++++++---------- .../internal/grammar/LocalStackElement.java | 13 +--- .../internal/oniguruma/OnigCaptureIndex.java | 18 +---- .../tm4e/core/internal/rule/RegExpSource.java | 2 +- .../tm4e/core/internal/utils/RegexSource.java | 2 +- 5 files changed, 43 insertions(+), 64 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 96dbf8aa2..385831f30 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -134,7 +134,7 @@ private void scanNext() { OnigCaptureIndex[] captureIndices = r.getCaptureIndices(); int matchedRuleId = r.getMatchedRuleId(); - final boolean hasAdvanced = captureIndices.length > 0 && captureIndices[0].getEnd() > linePos; + final boolean hasAdvanced = captureIndices.length > 0 && captureIndices[0].end > linePos; if (matchedRuleId == -1) { // We matched the `end` for this rule => pop it @@ -145,10 +145,10 @@ private void scanNext() { * " - " + poppedRule.debugEndRegExp); } */ - lineTokens.produce(stack, captureIndices[0].getStart()); + lineTokens.produce(stack, captureIndices[0].start); stack = stack.setContentNameScopesList(stack.nameScopesList); handleCaptures(grammar, lineText, isFirstLine, stack, lineTokens, poppedRule.endCaptures, captureIndices); - lineTokens.produce(stack, captureIndices[0].getEnd()); + lineTokens.produce(stack, captureIndices[0].end); // pop final var popped = stack; @@ -172,14 +172,14 @@ private void scanNext() { // We matched a rule! Rule rule = grammar.getRule(matchedRuleId); - lineTokens.produce(stack, captureIndices[0].getStart()); + lineTokens.produce(stack, captureIndices[0].start); StackElement beforePush = stack; // push it on the stack rule String scopeName = rule.getName(lineText.string, captureIndices); ScopeListElement nameScopesList = stack.contentNameScopesList.push(grammar, scopeName); stack = stack.push(matchedRuleId, linePos, anchorPosition, - captureIndices[0].getEnd() == lineText.bytesCount, null, nameScopesList, nameScopesList); + captureIndices[0].end == lineText.bytesCount, null, nameScopesList, nameScopesList); if (rule instanceof BeginEndRule) { BeginEndRule pushedRule = (BeginEndRule) rule; @@ -191,8 +191,8 @@ private void scanNext() { handleCaptures(grammar, lineText, isFirstLine, stack, lineTokens, pushedRule.beginCaptures, captureIndices); - lineTokens.produce(stack, captureIndices[0].getEnd()); - anchorPosition = captureIndices[0].getEnd(); + lineTokens.produce(stack, captureIndices[0].end); + anchorPosition = captureIndices[0].end; String contentName = pushedRule.getContentName(lineText.string, captureIndices); ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); @@ -220,8 +220,8 @@ private void scanNext() { handleCaptures(grammar, lineText, isFirstLine, stack, lineTokens, pushedRule.beginCaptures, captureIndices); - lineTokens.produce(stack, captureIndices[0].getEnd()); - anchorPosition = captureIndices[0].getEnd(); + lineTokens.produce(stack, captureIndices[0].end); + anchorPosition = captureIndices[0].end; String contentName = pushedRule.getContentName(lineText.string, captureIndices); ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); @@ -250,7 +250,7 @@ private void scanNext() { handleCaptures(grammar, lineText, isFirstLine, stack, lineTokens, matchingRule.captures, captureIndices); - lineTokens.produce(stack, captureIndices[0].getEnd()); + lineTokens.produce(stack, captureIndices[0].end); // pop rule immediately since it is a MatchRule stack = stack.pop(); @@ -267,9 +267,9 @@ private void scanNext() { } } - if (captureIndices.length > 0 && captureIndices[0].getEnd() > linePos) { + if (captureIndices.length > 0 && captureIndices[0].end > linePos) { // Advance stream - linePos = captureIndices[0].getEnd(); + linePos = captureIndices[0].end; isFirstLine = false; } } @@ -322,8 +322,8 @@ private IMatchResult matchRuleOrInjections(Grammar grammar, OnigString lineText, } // Decide if `matchResult` or `injectionResult` should win - int matchResultScore = matchResult.getCaptureIndices()[0].getStart(); - int injectionResultScore = injectionResult.getCaptureIndices()[0].getStart(); + int matchResultScore = matchResult.getCaptureIndices()[0].start; + int injectionResultScore = injectionResult.getCaptureIndices()[0].start; if (injectionResultScore < matchResultScore || (injectionResult.isPriorityMatch() && injectionResultScore == matchResultScore)) { @@ -358,7 +358,7 @@ private IMatchInjectionsResult matchInjections(List injections, Gramm continue; } - int matchRating = matchResult.getCaptureIndices()[0].getStart(); + int matchRating = matchResult.getCaptureIndices()[0].start; if (matchRating > bestMatchRating) { // Injections are sorted by priority, so the previous injection had a better or @@ -411,7 +411,7 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs int len = Math.min(captures.size(), captureIndices.length); List localStack = new ArrayList<>(); - int maxEnd = captureIndices[0].getEnd(); + int maxEnd = captureIndices[0].end; OnigCaptureIndex captureIndex; for (int i = 0; i < len; i++) { @@ -428,25 +428,25 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs continue; } - if (captureIndex.getStart() > maxEnd) { + if (captureIndex.start > maxEnd) { // Capture going beyond consumed string break; } // pop captures while needed while (!localStack.isEmpty() - && localStack.get(localStack.size() - 1).getEndPos() <= captureIndex.getStart()) { + && localStack.get(localStack.size() - 1).endPos <= captureIndex.start) { // pop! - lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).getScopes(), - localStack.get(localStack.size() - 1).getEndPos()); + lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).scopes, + localStack.get(localStack.size() - 1).endPos); localStack.remove(localStack.size() - 1); } if (!localStack.isEmpty()) { - lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).getScopes(), - captureIndex.getStart()); + lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).scopes, + captureIndex.start); } else { - lineTokens.produce(stack, captureIndex.getStart()); + lineTokens.produce(stack, captureIndex.start); } final var retokenizeCapturedWithRuleId = captureRule.retokenizeCapturedWithRuleId; @@ -458,11 +458,11 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); // the capture requires additional matching - StackElement stackClone = stack.push(retokenizeCapturedWithRuleId, captureIndex.getStart(), -1, false, + StackElement stackClone = stack.push(retokenizeCapturedWithRuleId, captureIndex.start, -1, false, null, nameScopesList, contentNameScopesList); - final var onigSubStr = OnigString.of(lineText.string.substring(0, captureIndex.getEnd())); - tokenizeString(grammar, onigSubStr, (isFirstLine && captureIndex.getStart() == 0), - captureIndex.getStart(), stackClone, lineTokens); + final var onigSubStr = OnigString.of(lineText.string.substring(0, captureIndex.end)); + tokenizeString(grammar, onigSubStr, (isFirstLine && captureIndex.start == 0), + captureIndex.start, stackClone, lineTokens); continue; } @@ -472,16 +472,16 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs // push ScopeListElement base = localStack.isEmpty() ? stack.contentNameScopesList - : localStack.get(localStack.size() - 1).getScopes(); + : localStack.get(localStack.size() - 1).scopes; ScopeListElement captureRuleScopesList = base.push(grammar, captureRuleScopeName); - localStack.add(new LocalStackElement(captureRuleScopesList, captureIndex.getEnd())); + localStack.add(new LocalStackElement(captureRuleScopesList, captureIndex.end)); } } while (!localStack.isEmpty()) { // pop! - lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).getScopes(), - localStack.get(localStack.size() - 1).getEndPos()); + lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).scopes, + localStack.get(localStack.size() - 1).endPos); localStack.remove(localStack.size() - 1); } } @@ -519,13 +519,13 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe break; } if (r.getCaptureIndices().length > 0) { - lineTokens.produce(whileRule.stack, r.getCaptureIndices()[0].getStart()); + lineTokens.produce(whileRule.stack, r.getCaptureIndices()[0].start); handleCaptures(grammar, lineText, isFirstLine, whileRule.stack, lineTokens, whileRule.rule.whileCaptures, r.getCaptureIndices()); - lineTokens.produce(whileRule.stack, r.getCaptureIndices()[0].getEnd()); - currentanchorPosition = r.getCaptureIndices()[0].getEnd(); - if (r.getCaptureIndices()[0].getEnd() > linePos) { - linePos = r.getCaptureIndices()[0].getEnd(); + lineTokens.produce(whileRule.stack, r.getCaptureIndices()[0].end); + currentanchorPosition = r.getCaptureIndices()[0].end; + if (r.getCaptureIndices()[0].end > linePos) { + linePos = r.getCaptureIndices()[0].end; isFirstLine = false; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java index 62a1493fc..ccfa8fbec 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java @@ -18,20 +18,11 @@ final class LocalStackElement { - private final ScopeListElement scopes; - private final int endPos; + final ScopeListElement scopes; + final int endPos; LocalStackElement(ScopeListElement scopes, int endPos) { this.scopes = scopes; this.endPos = endPos; } - - ScopeListElement getScopes() { - return scopes; - } - - int getEndPos() { - return endPos; - } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java index 4ffc4c801..57c9b3a67 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java @@ -20,9 +20,9 @@ public final class OnigCaptureIndex { - private final int index; - private final int start; - private final int end; + public final int index; + public final int start; + public final int end; OnigCaptureIndex(final int index, int start, final int end) { this.index = index; @@ -42,22 +42,10 @@ public boolean equals(@Nullable final Object obj) { && start == other.start; } - public int getEnd() { - return end; - } - - public int getIndex() { - return index; - } - public int getLength() { return end - start; } - public int getStart() { - return start; - } - @Override public int hashCode() { final int prime = 31; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index 6576e13c4..417b12ab2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -107,7 +107,7 @@ void setSource(final String newSource) { String resolveBackReferences(final String lineText, final OnigCaptureIndex[] captureIndices) { try { final var capturedValues = Arrays.stream(captureIndices) - .map(capture -> lineText.substring(capture.getStart(), capture.getEnd())) + .map(capture -> lineText.substring(capture.start, capture.end)) .collect(Collectors.toList()); final var m = BACK_REFERENCING_END.matcher(this.source); final var sb = new StringBuilder(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index 4b10cc302..4be5dfb67 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -80,7 +80,7 @@ private static String getReplacement(final String match, final String captureSou } final OnigCaptureIndex capture = captureIndices.length > index ? captureIndices[index] : null; if (capture != null) { - String result = captureSource.substring(capture.getStart(), capture.getEnd()); + String result = captureSource.substring(capture.start, capture.end); // Remove leading dots that would make the selector invalid while (!result.isEmpty() && result.charAt(0) == '.') { result = result.substring(1); From e5c978d2306b64df604951fefcf8745050417410 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 28 Apr 2022 21:54:14 +0200 Subject: [PATCH 122/202] Apply upstream changes to ScopeListElement --- .../internal/grammar/ScopeListElement.java | 81 +++++++++++++------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index 2e04be105..0eb59b728 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -22,6 +22,12 @@ import com.google.common.base.Splitter; +/** + * @see + * https://github.com/Microsoft/vscode-textmate/blob/main/src/grammar.ts + * + */ public final class ScopeListElement { private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' '); @@ -31,54 +37,74 @@ public final class ScopeListElement { private final String scope; final int metadata; - public ScopeListElement(@Nullable ScopeListElement parent, String scope, int metadata) { + public ScopeListElement(@Nullable final ScopeListElement parent, final String scope, final int metadata) { this.parent = parent; this.scope = scope; this.metadata = metadata; } - private static boolean equals(@Nullable ScopeListElement a, @Nullable ScopeListElement b) { + private static boolean structuralEquals(@Nullable ScopeListElement a, @Nullable ScopeListElement b) { + do { + if (a == b) { + return true; + } + + if (a == null && b == null) { + // End of list reached for both + return true; + } + + if (a == null || b == null) { + // End of list reached only for one + return false; + } + + if (a.scope != b.scope || a.metadata != b.metadata) { + return false; + } + + // Go to previous pair + a = a.parent; + b = b.parent; + } while (true); + } + + private static boolean equals(@Nullable final ScopeListElement a, @Nullable final ScopeListElement b) { if (a == b) { return true; } if (a == null || b == null) { return false; } - return Objects.equals(a.scope, b.scope) && a.metadata == b.metadata && equals(a.parent, b.parent); + return structuralEquals(a, b); } @Override - public boolean equals(@Nullable Object other) { - if (other == this) { - return true; - } - if (other == null) { - return false; - } - if (!(other instanceof ScopeListElement)) { + public boolean equals(@Nullable final Object other) { + if (other == null || other.getClass() != ScopeListElement.class) { return false; } - return ScopeListElement.equals(this, (ScopeListElement)other); + return equals(this, (ScopeListElement) other); } @Override public int hashCode() { - return Objects.hash(scope, metadata, parent); + return Objects.hash(parent, scope, metadata); } - private static boolean matchesScope(String scope, String selector, String selectorWithDot) { + private static boolean matchesScope(final String scope, final String selector, final String selectorWithDot) { return (selector.equals(scope) || scope.startsWith(selectorWithDot)); } - private static boolean matches(@Nullable ScopeListElement target, List parentScopes) { + private static boolean matches(@Nullable ScopeListElement target, final List parentScopes) { if (parentScopes == null) { return true; } - int len = parentScopes.size(); + final int len = parentScopes.size(); int index = 0; String selector = parentScopes.get(index); - String selectorWithDot = selector + "."; + String selectorWithDot = selector + '.'; while (target != null) { if (matchesScope(target.scope, selector, selectorWithDot)) { @@ -95,7 +121,8 @@ private static boolean matches(@Nullable ScopeListElement target, List p return false; } - public static int mergeMetadata(int metadata, @Nullable ScopeListElement scopesList, ScopeMetadata source) { + public static int mergeMetadata(final int metadata, @Nullable final ScopeListElement scopesList, + final ScopeMetadata source) { if (source == null) { return metadata; } @@ -106,7 +133,7 @@ public static int mergeMetadata(int metadata, @Nullable ScopeListElement scopesL if (source.themeData != null) { // Find the first themeData that matches - for (ThemeTrieElementRule themeData : source.themeData) { + for (final ThemeTrieElementRule themeData : source.themeData) { if (matches(scopesList, themeData.parentScopes)) { fontStyle = themeData.fontStyle; foreground = themeData.foreground; @@ -120,24 +147,26 @@ public static int mergeMetadata(int metadata, @Nullable ScopeListElement scopesL background); } - private static ScopeListElement push(ScopeListElement target, Grammar grammar, Iterable scopes) { - for (String scope : scopes) { - ScopeMetadata rawMetadata = grammar.getMetadataForScope(scope); - int metadata = ScopeListElement.mergeMetadata(target.metadata, target, rawMetadata); + private static ScopeListElement push(ScopeListElement target, final Grammar grammar, + final Iterable scopes) { + for (final String scope : scopes) { + final var rawMetadata = grammar.getMetadataForScope(scope); + final int metadata = ScopeListElement.mergeMetadata(target.metadata, target, rawMetadata); target = new ScopeListElement(target, scope, metadata); } return target; } - ScopeListElement push(Grammar grammar, @Nullable String scope) { + ScopeListElement push(final Grammar grammar, @Nullable final String scope) { if (scope == null) { return this; } + return ScopeListElement.push(this, grammar, BY_SPACE_SPLITTER.split(scope)); } - private static List generateScopes(ScopeListElement scopesList) { - List result = new ArrayList<>(); + private static List generateScopes(@Nullable ScopeListElement scopesList) { + final var result = new ArrayList(); while (scopesList != null) { result.add(scopesList.scope); scopesList = scopesList.parent; From bc330df5d288be5c7a2d820e5936916be908616f Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 29 Apr 2022 11:15:04 +0200 Subject: [PATCH 123/202] Refactor internal parser package, enable annotation-based null analysis --- .../tm4e/core/internal/grammar/Grammar.java | 1 - .../internal/grammar/{parser => }/Raw.java | 5 +- .../internal/grammar/parser/PListGrammar.java | 29 ------- .../grammar/reader/GrammarReader.java | 47 +++-------- .../grammar/reader/IGrammarParser.java | 31 ------- .../grammar/reader/SyncGrammarReader.java | 36 -------- .../core/internal/grammars/SyncRegistry.java | 2 +- .../tm4e/core/internal/parser/MapFactory.java | 23 +++++ .../tm4e/core/internal/parser/PListArray.java | 37 ++++++++ .../tm4e/core/internal/parser/PListDict.java | 37 ++++++++ .../core/internal/parser/PListObject.java | 49 +++-------- .../core/internal/parser/PListParser.java | 19 +++++ ...st.java => PListParserContentHandler.java} | 84 +++++++++++-------- ...NPListParser.java => PListParserJSON.java} | 32 ++++--- .../core/internal/parser/PListParserXML.java | 44 ++++++++++ ...lPListParser.java => PListParserYAML.java} | 27 +++--- .../core/internal/parser/package-info.java | 4 + .../internal/parser/xml/XMLPListParser.java | 46 ---------- .../tm4e/core/internal/rule/RuleFactory.java | 2 +- .../tm4e/core/internal/theme/PListTheme.java | 29 ------- .../tm4e/core/internal/theme/ThemeRaw.java | 3 +- .../internal/theme/reader/ThemeReader.java | 9 +- .../core/internal/types/IRawRepository.java | 5 +- .../grammar/parser/PListParserTest.java | 58 +++++++++++++ .../parser/json/JSONPListParserTest.java | 37 -------- .../parser/xml/XMLPlistParserTest.java | 36 -------- .../parser/yaml/YamlPlistParserTest.java | 37 -------- 27 files changed, 338 insertions(+), 431 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/{parser => }/Raw.java (97%) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/IGrammarParser.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParser.java rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/{PList.java => PListParserContentHandler.java} (51%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/{json/JSONPListParser.java => PListParserJSON.java} (68%) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/{yaml/YamlPListParser.java => PListParserYAML.java} (68%) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/package-info.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java delete mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java delete mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java delete mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index ab5f6c005..62e2a6740 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -33,7 +33,6 @@ import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; -import org.eclipse.tm4e.core.internal.grammar.parser.Raw; import org.eclipse.tm4e.core.internal.grammars.IGrammarRepository; import org.eclipse.tm4e.core.internal.matcher.Matcher; import org.eclipse.tm4e.core.internal.matcher.MatcherWithPriority; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java similarity index 97% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java index 3fe8c5b68..7701f963f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java @@ -10,7 +10,7 @@ * Angelo Zerr - initial API and implementation * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes */ -package org.eclipse.tm4e.core.internal.grammar.parser; +package org.eclipse.tm4e.core.internal.grammar; import java.util.ArrayList; import java.util.Collection; @@ -20,6 +20,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.types.IRawCaptures; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; @@ -29,7 +30,7 @@ * Raw * */ -public final class Raw extends HashMap implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { +public final class Raw extends HashMap<@Nullable String, Object> implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { public static final String FIRST_LINE_MATCH = "firstLineMatch"; public static final String FILE_TYPES = "fileTypes"; public static final String SCOPE_NAME = "scopeName"; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java deleted file mode 100644 index f8d6220f4..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/parser/PListGrammar.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.grammar.parser; - -import java.util.Map; - -import org.eclipse.tm4e.core.internal.parser.PListObject; - -public final class PListGrammar extends PListObject { - - public PListGrammar(PListObject parent, boolean valueAsArray) { - super(parent, valueAsArray); - } - - @Override - protected Map createRaw() { - return new Raw(); - } - -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java index 3f83c1cd7..39b46340f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java @@ -18,14 +18,15 @@ import java.io.InputStream; -import org.eclipse.tm4e.core.internal.parser.json.JSONPListParser; -import org.eclipse.tm4e.core.internal.parser.xml.XMLPListParser; -import org.eclipse.tm4e.core.internal.parser.yaml.YamlPListParser; +import org.eclipse.tm4e.core.internal.grammar.Raw; +import org.eclipse.tm4e.core.internal.parser.PListParser; +import org.eclipse.tm4e.core.internal.parser.PListParserJSON; +import org.eclipse.tm4e.core.internal.parser.PListParserXML; +import org.eclipse.tm4e.core.internal.parser.PListParserYAML; import org.eclipse.tm4e.core.internal.types.IRawGrammar; /** * TextMate Grammar reader utilities. - * */ public final class GrammarReader { @@ -33,45 +34,17 @@ public final class GrammarReader { * methods should be accessed statically */ private GrammarReader() { - } - public static final IGrammarParser XML_PARSER = new IGrammarParser() { - - private final XMLPListParser parser = new XMLPListParser<>(false); - - @Override - public IRawGrammar parse(InputStream contents) throws Exception { - return parser.parse(contents); - } - }; - - public static final IGrammarParser JSON_PARSER = new IGrammarParser() { - - private final JSONPListParser parser = new JSONPListParser<>(false); - - @Override - public IRawGrammar parse(InputStream contents) throws Exception { - return parser.parse(contents); - } - }; - - public static final IGrammarParser YAML_PARSER = new IGrammarParser() { - - private final YamlPListParser parser = new YamlPListParser<>(false); - - @Override - public IRawGrammar parse(InputStream contents) throws Exception { - return parser.parse(contents); - } - }; + private static final PListParser XML_PARSER = new PListParserXML<>(Raw::new); + private static final PListParser JSON_PARSER = new PListParserJSON<>(Raw::new); + private static final PListParser YAML_PARSER = new PListParserYAML<>(Raw::new); public static IRawGrammar readGrammarSync(String filePath, InputStream in) throws Exception { - SyncGrammarReader reader = new SyncGrammarReader(in, getGrammarParser(filePath)); - return reader.load(); + return getGrammarParser(filePath).parse(in); } - private static IGrammarParser getGrammarParser(String filePath) { + private static PListParser getGrammarParser(String filePath) { String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); switch (extension) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/IGrammarParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/IGrammarParser.java deleted file mode 100644 index 1cf264b29..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/IGrammarParser.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.grammar.reader; - -import java.io.InputStream; - -import org.eclipse.tm4e.core.internal.types.IRawGrammar; - -/** - * TextMate Grammar parser. - * - */ -@FunctionalInterface -public interface IGrammarParser { - - IRawGrammar parse(InputStream contents) throws Exception; -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java deleted file mode 100644 index d36dec4b3..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/SyncGrammarReader.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.grammar.reader; - -import java.io.InputStream; - -import org.eclipse.tm4e.core.internal.types.IRawGrammar; - -final class SyncGrammarReader { - - private final InputStream in; - private final IGrammarParser parser; - - SyncGrammarReader(InputStream in, IGrammarParser parser) { - this.in = in; - this.parser = parser; - } - - IRawGrammar load() throws Exception { - return this.parser.parse(in); - } -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java index 6e09f3f2d..461b0ffe9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java @@ -26,7 +26,7 @@ import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.internal.grammar.Grammar; -import org.eclipse.tm4e.core.internal.grammar.parser.Raw; +import org.eclipse.tm4e.core.internal.grammar.Raw; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; import org.eclipse.tm4e.core.internal.types.IRawRule; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java new file mode 100644 index 000000000..7356ad68b --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.parser; + +import java.util.Map; + +import org.eclipse.jdt.annotation.Nullable; + +@FunctionalInterface +public interface MapFactory { + + Map<@Nullable String, Object> createMap(); +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java new file mode 100644 index 000000000..fb72ccf93 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.parser; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.annotation.Nullable; + +final class PListArray extends PListObject { + + private final List values = new ArrayList<>(); + + PListArray(@Nullable final PListObject parent) { + super(parent); + } + + @Override + void addValue(final Object value) { + values.add(value); + } + + @Override + Object getValue() { + return values; + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java new file mode 100644 index 000000000..ebd49f705 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.parser; + +import java.util.Map; + +import org.eclipse.jdt.annotation.Nullable; + +final class PListDict extends PListObject { + + private final Map<@Nullable String, Object> values; + + PListDict(@Nullable final PListObject parent, final MapFactory mapFactory) { + super(parent); + values = mapFactory.createMap(); + } + + @Override + void addValue(final Object value) { + values.put(getLastKey(), value); + } + + @Override + Object getValue() { + return values; + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java index 7c520ab1e..3013056fc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java @@ -1,65 +1,40 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.parser; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; -public abstract class PListObject { +abstract class PListObject { + @Nullable final PListObject parent; - private final List arrayValues; - private final Map mapValues; + @Nullable private String lastKey; - protected PListObject(PListObject parent, boolean valueAsArray) { + PListObject(@Nullable final PListObject parent) { this.parent = parent; - if (valueAsArray) { - this.arrayValues = new ArrayList<>(); - this.mapValues = null; - } else { - this.arrayValues = null; - this.mapValues = createRaw(); - } } + @Nullable String getLastKey() { return lastKey; } - void setLastKey(String lastKey) { + void setLastKey(@Nullable final String lastKey) { this.lastKey = lastKey; } - void addValue(Object value) { - if (isValueAsArray()) { - arrayValues.add(value); - } else { - mapValues.put(getLastKey(), value); - } - } - - boolean isValueAsArray() { - return arrayValues != null; - } - - Object getValue() { - if (isValueAsArray()) { - return arrayValues; - } - return mapValues; - } + abstract void addValue(Object value); - protected abstract Map createRaw(); + abstract Object getValue(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParser.java new file mode 100644 index 000000000..a8cb26e9b --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParser.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.parser; + +import java.io.InputStream; + +public interface PListParser { + T parse(InputStream contents) throws Exception; +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java similarity index 51% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java index fc7af4ca7..b1a712360 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java @@ -11,35 +11,45 @@ */ package org.eclipse.tm4e.core.internal.parser; +import java.time.ZonedDateTime; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.List; -import org.eclipse.tm4e.core.internal.grammar.parser.PListGrammar; -import org.eclipse.tm4e.core.internal.theme.PListTheme; +import org.eclipse.jdt.annotation.Nullable; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; -public final class PList extends DefaultHandler { +final class PListParserContentHandler extends DefaultHandler { + + private final MapFactory mapFactory; - private final boolean theme; private final List errors = new ArrayList<>(); + + @Nullable private PListObject currObject; + + @Nullable private T result; - private StringBuilder text; - public PList(boolean theme) { - this.theme = theme; + private final StringBuilder text = new StringBuilder(); + + PListParserContentHandler(final MapFactory mapFactory) { + this.mapFactory = mapFactory; } @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + public void startElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName, + @Nullable final Attributes attributes) throws SAXException { + assert localName != null; + switch (localName) { case "dict": - this.currObject = create(currObject, false); + currObject = new PListDict(currObject, mapFactory); break; case "array": - this.currObject = create(currObject, true); + currObject = new PListArray(currObject); break; case "key": if (currObject != null) { @@ -48,31 +58,28 @@ public void startElement(String uri, String localName, String qName, Attributes break; } - this.text = new StringBuilder(); + text.setLength(0); super.startElement(uri, localName, qName, attributes); } - private PListObject create(PListObject parent, boolean valueAsArray) { - if (theme) { - return new PListTheme(parent, valueAsArray); - } - return new PListGrammar(parent, valueAsArray); - } - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { + public void endElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName) + throws SAXException { + assert localName != null; + endElement(localName); super.endElement(uri, localName, qName); } - public void endElement(String tagName) { + private void endElement(final String tagName) { Object value = null; - String text = this.text.toString(); + final String text = this.text.toString(); + var currObject = this.currObject; switch (tagName) { case "key": - if (currObject == null || currObject.isValueAsArray()) { - errors.add("key can only be used inside an open dict element"); + if (!(currObject instanceof PListDict)) { + errors.add(" tag can only be used inside an open element"); return; } currObject.setLastKey(text); @@ -80,32 +87,38 @@ public void endElement(String tagName) { case "dict": case "array": if (currObject == null) { - errors.add(tagName + " closing tag found, without opening tag"); + errors.add("Closing tag found, without opening tag"); return; } value = currObject.getValue(); - currObject = currObject.parent; + currObject = this.currObject = currObject.parent; break; case "string": case "data": value = text; break; case "date": - // TODO : parse date + // e.g. 2007-10-25T12:36:35Z + try { + value = ZonedDateTime.parse(text); + } catch (final DateTimeParseException ex) { + errors.add("Failed to parse date '" + text + "'. " + ex); + return; + } break; case "integer": try { value = Integer.parseInt(text); - } catch (NumberFormatException e) { - errors.add(text + " is not a integer"); + } catch (final NumberFormatException ex) { + errors.add("Failed to parse integer '" + text + "'. " + ex); return; } break; case "real": try { value = Float.parseFloat(text); - } catch (NumberFormatException e) { - errors.add(text + " is not a float"); + } catch (final NumberFormatException ex) { + errors.add("Failed to parse real as float '" + text + "'. " + ex); return; } break; @@ -122,26 +135,29 @@ public void endElement(String tagName) { return; } + assert value != null; + if (currObject == null) { result = (T) value; - } else if (currObject.isValueAsArray()) { - currObject.addValue(value); - } else { + } else if (currObject instanceof PListDict) { if (currObject.getLastKey() != null) { currObject.addValue(value); } else { errors.add("Dictionary key missing for value " + value); } + } else { // PListArray + currObject.addValue(value); } } @Override - public void characters(char[] ch, int start, int length) throws SAXException { + public void characters(final char @Nullable [] ch, final int start, final int length) throws SAXException { this.text.append(String.valueOf(ch, start, length)); super.characters(ch, start, length); } public T getResult() { + assert result != null; return result; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java similarity index 68% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java index ef7a20031..1b39ce9c1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/json/JSONPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java @@ -1,42 +1,41 @@ /** - * Copyright (c) 2015-2018 Angelo ZERR. + * Copyright (c) 2015-2018 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.parser.json; +package org.eclipse.tm4e.core.internal.parser; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import org.eclipse.tm4e.core.internal.parser.PList; import org.xml.sax.SAXException; import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -public final class JSONPListParser { +public final class PListParserJSON implements PListParser { - private final boolean theme; + private final MapFactory mapFactory; - public JSONPListParser(boolean theme) { - this.theme = theme; + public PListParserJSON(final MapFactory mapFactory) { + this.mapFactory = mapFactory; } - public T parse(InputStream contents) throws IOException, SAXException { - PList pList = new PList<>(theme); - try (JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8))) { + @Override + public T parse(final InputStream contents) throws IOException, SAXException { + final var pList = new PListParserContentHandler(mapFactory); + try (final var reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8))) { // reader.setLenient(true); boolean parsing = true; while (parsing) { - JsonToken nextToken = reader.peek(); + final var nextToken = reader.peek(); switch (nextToken) { case BEGIN_ARRAY: pList.startElement(null, "array", null, null); @@ -55,7 +54,7 @@ public T parse(InputStream contents) throws IOException, SAXException { reader.endObject(); break; case NAME: - String lastName = reader.nextName(); + final var lastName = reader.nextName(); pList.startElement(null, "key", null, null); pList.characters(lastName.toCharArray(), 0, lastName.length()); pList.endElement(null, "key", null); @@ -70,7 +69,7 @@ public T parse(InputStream contents) throws IOException, SAXException { reader.nextLong(); break; case STRING: - String value = reader.nextString(); + final var value = reader.nextString(); pList.startElement(null, "string", null, null); pList.characters(value.toCharArray(), 0, value.length()); pList.endElement(null, "string", null); @@ -85,5 +84,4 @@ public T parse(InputStream contents) throws IOException, SAXException { } return pList.getResult(); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java new file mode 100644 index 000000000..4a62fda61 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.core.internal.parser; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +public final class PListParserXML implements PListParser { + + private final MapFactory mapFactory; + + public PListParserXML(final MapFactory mapFactory) { + this.mapFactory = mapFactory; + } + + @Override + public T parse(final InputStream contents) throws IOException, ParserConfigurationException, SAXException { + final var spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + final var xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setEntityResolver((publicId, systemId) -> new InputSource( + new ByteArrayInputStream("".getBytes()))); + final var result = new PListParserContentHandler(mapFactory); + xmlReader.setContentHandler(result); + xmlReader.parse(new InputSource(contents)); + return result.getResult(); + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java similarity index 68% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java index 8aac22a1d..7aa455a19 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/yaml/YamlPListParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java @@ -10,14 +10,13 @@ * Contributors: * Sebastian Thomschke - initial implementation */ -package org.eclipse.tm4e.core.internal.parser.yaml; +package org.eclipse.tm4e.core.internal.parser; import java.io.InputStream; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.eclipse.tm4e.core.internal.parser.PList; import org.xml.sax.SAXException; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.error.YAMLException; @@ -25,19 +24,19 @@ /** * Parses TextMate Grammar file in YAML format. */ -public final class YamlPListParser { +public final class PListParserYAML implements PListParser { - private final boolean theme; + private final MapFactory mapFactory; - public YamlPListParser(boolean theme) { - this.theme = theme; + public PListParserYAML(final MapFactory mapFactory) { + this.mapFactory = mapFactory; } @SuppressWarnings("unchecked") - private void addListToPList(PList pList, List list) throws SAXException { + private void addListToPList(final PListParserContentHandler pList, final List list) throws SAXException { pList.startElement(null, "array", null, null); - for (Object item : list) { + for (final Object item : list) { if (item instanceof List) { addListToPList(pList, (List) item); } else if (item instanceof Map) { @@ -51,10 +50,11 @@ private void addListToPList(PList pList, List list) throws SAXExcepti } @SuppressWarnings("unchecked") - private void addMapToPList(PList pList, Map map) throws SAXException { + private void addMapToPList(final PListParserContentHandler pList, final Map map) + throws SAXException { pList.startElement(null, "dict", null, null); - for (Entry entry : map.entrySet()) { + for (final Entry entry : map.entrySet()) { pList.startElement(null, "key", null, null); pList.characters(entry.getKey().toCharArray(), 0, entry.getKey().length()); pList.endElement(null, "key", null); @@ -70,14 +70,15 @@ private void addMapToPList(PList pList, Map map) throws SAXEx pList.endElement(null, "dict", null); } - private void addStringToPList(PList pList, String value) throws SAXException { + private void addStringToPList(final PListParserContentHandler pList, final String value) throws SAXException { pList.startElement(null, "string", null, null); pList.characters(value.toCharArray(), 0, value.length()); pList.endElement(null, "string", null); } - public T parse(InputStream contents) throws SAXException, YAMLException { - PList pList = new PList<>(theme); + @Override + public T parse(final InputStream contents) throws SAXException, YAMLException { + final var pList = new PListParserContentHandler(mapFactory); addMapToPList(pList, new Yaml().loadAs(contents, Map.class)); return pList.getResult(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/package-info.java new file mode 100644 index 000000000..ee4fdc13b --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.parser; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java deleted file mode 100644 index 4a22b7e3a..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/xml/XMLPListParser.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.parser.xml; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.tm4e.core.internal.parser.PList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -public final class XMLPListParser { - - private final boolean theme; - - public XMLPListParser(boolean theme) { - this.theme = theme; - } - - public T parse(InputStream contents) throws IOException, ParserConfigurationException, SAXException { - SAXParserFactory spf = SAXParserFactory.newInstance(); - spf.setNamespaceAware(true); - SAXParser saxParser = spf.newSAXParser(); - XMLReader xmlReader = saxParser.getXMLReader(); - xmlReader.setEntityResolver((arg0, arg1) -> new InputSource(new ByteArrayInputStream("".getBytes()))); - PList result = new PList<>(theme); - xmlReader.setContentHandler(result); - xmlReader.parse(new InputSource(contents)); - return result.getResult(); - } -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index 60ef5441e..0be03b85e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -25,7 +25,7 @@ import java.util.List; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.internal.grammar.parser.Raw; +import org.eclipse.tm4e.core.internal.grammar.Raw; import org.eclipse.tm4e.core.internal.types.IRawCaptures; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java deleted file mode 100644 index 04cb2ff56..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/PListTheme.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.theme; - -import java.util.Map; - -import org.eclipse.tm4e.core.internal.parser.PListObject; - -public final class PListTheme extends PListObject { - - public PListTheme(PListObject parent, boolean valueAsArray) { - super(parent, valueAsArray); - } - - @Override - protected Map createRaw() { - return new ThemeRaw(); - } - -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index 027081e88..42e669190 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -14,11 +14,12 @@ import java.util.Collection; import java.util.HashMap; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IRawTheme; import org.eclipse.tm4e.core.theme.IRawThemeSetting; import org.eclipse.tm4e.core.theme.IThemeSetting; -final class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting { +public final class ThemeRaw extends HashMap<@Nullable String, Object> implements IRawTheme, IRawThemeSetting, IThemeSetting { private static final long serialVersionUID = -3622927264735492387L; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java index 604b0ac05..cf352e067 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java @@ -18,8 +18,9 @@ import java.io.InputStream; -import org.eclipse.tm4e.core.internal.parser.json.JSONPListParser; -import org.eclipse.tm4e.core.internal.parser.xml.XMLPListParser; +import org.eclipse.tm4e.core.internal.parser.PListParserJSON; +import org.eclipse.tm4e.core.internal.parser.PListParserXML; +import org.eclipse.tm4e.core.internal.theme.ThemeRaw; import org.eclipse.tm4e.core.theme.IRawTheme; /** @@ -36,7 +37,7 @@ private ThemeReader() { private static final IThemeParser XML_PARSER = new IThemeParser() { - private final XMLPListParser parser = new XMLPListParser<>(true); + private final PListParserXML parser = new PListParserXML<>(ThemeRaw::new); @Override public IRawTheme parse(InputStream contents) throws Exception { @@ -46,7 +47,7 @@ public IRawTheme parse(InputStream contents) throws Exception { public static final IThemeParser JSON_PARSER = new IThemeParser() { - private final JSONPListParser parser = new JSONPListParser<>(true); + private final PListParserJSON parser = new PListParserJSON<>(ThemeRaw::new); @Override public IRawTheme parse(InputStream contents) throws Exception { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java index ec97f9126..112d4b7f0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java @@ -20,7 +20,8 @@ import java.util.Set; import java.util.Map.Entry; -import org.eclipse.tm4e.core.internal.grammar.parser.Raw; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.internal.grammar.Raw; public interface IRawRepository { @@ -35,7 +36,7 @@ static IRawRepository merge(IRawRepository... sources) { return merged; } - Set> entrySet(); + Set> entrySet(); IRawRule getProp(String name); diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java new file mode 100644 index 000000000..6b8a7ad20 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.core.internal.grammar.parser; + +import static org.junit.jupiter.api.Assertions.*; + +import org.eclipse.tm4e.core.Data; +import org.eclipse.tm4e.core.internal.grammar.Raw; +import org.eclipse.tm4e.core.internal.parser.PListParserJSON; +import org.eclipse.tm4e.core.internal.parser.PListParserXML; +import org.eclipse.tm4e.core.internal.parser.PListParserYAML; +import org.eclipse.tm4e.core.internal.types.IRawGrammar; +import org.junit.jupiter.api.Test; + +public class PListParserTest { + + @Test + void testParseJSONPList() throws Exception { + final var parser = new PListParserJSON(Raw::new); + try (final var is = Data.class.getResourceAsStream("csharp.json")) { + final var grammar = parser.parse(is); + assertNotNull(grammar); + assertFalse(grammar.getFileTypes().isEmpty()); + System.out.println(grammar); + } + } + + @Test + void testParseYAMLPlist() throws Exception { + final var parser = new PListParserYAML(Raw::new); + try (final var is = Data.class.getResourceAsStream("JavaScript.tmLanguage.yaml")) { + final var grammar = parser.parse(is); + assertNotNull(grammar); + assertFalse(grammar.getFileTypes().isEmpty()); + System.out.println(grammar); + } + } + + @Test + void testParseXMLPlist() throws Exception { + final var parser = new PListParserXML(Raw::new); + try (final var is = Data.class.getResourceAsStream("JavaScript.tmLanguage")) { + final var grammar = parser.parse(is); + assertNotNull(grammar); + assertFalse(grammar.getFileTypes().isEmpty()); + System.out.println(grammar); + } + } +} diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java deleted file mode 100644 index 70fa76ef9..000000000 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/json/JSONPListParserTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.grammar.parser.json; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.InputStream; - -import org.eclipse.tm4e.core.Data; -import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; -import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser; -import org.eclipse.tm4e.core.internal.types.IRawGrammar; - -import org.junit.jupiter.api.Test; - -public class JSONPListParserTest { - - @Test - public void testParseJSONPList() throws Exception { - IGrammarParser parser = GrammarReader.JSON_PARSER; - try (InputStream is = Data.class.getResourceAsStream("csharp.json")) { - IRawGrammar grammar = parser.parse(is); - assertNotNull(grammar); - assertFalse(grammar.getFileTypes().isEmpty()); - System.err.println(grammar); - } - } -} diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java deleted file mode 100644 index bcd165812..000000000 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/xml/XMLPlistParserTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.grammar.parser.xml; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.InputStream; - -import org.eclipse.tm4e.core.Data; -import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; -import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser; -import org.eclipse.tm4e.core.internal.types.IRawGrammar; -import org.junit.jupiter.api.Test; - -public class XMLPlistParserTest { - - @Test - public void testParseXMLPlist() throws Exception { - IGrammarParser parser = GrammarReader.XML_PARSER; - try (InputStream is = Data.class.getResourceAsStream("JavaScript.tmLanguage")) { - IRawGrammar grammar = parser.parse(is); - assertNotNull(grammar); - assertFalse(grammar.getFileTypes().isEmpty()); - System.err.println(grammar); - } - } -} diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java deleted file mode 100644 index c833ba296..000000000 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/yaml/YamlPlistParserTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2022 Sebastian Thomschke and others. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Sebastian Thomschke - initial implementation - */ -package org.eclipse.tm4e.core.internal.grammar.parser.yaml; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.InputStream; - -import org.eclipse.tm4e.core.Data; -import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; -import org.eclipse.tm4e.core.internal.grammar.reader.IGrammarParser; -import org.eclipse.tm4e.core.internal.types.IRawGrammar; -import org.junit.jupiter.api.Test; - -public class YamlPlistParserTest { - - @Test - public void testParsePlistYaml() throws Exception { - IGrammarParser parser = GrammarReader.YAML_PARSER; - try (InputStream is = Data.class.getResourceAsStream("JavaScript.tmLanguage.yaml")) { - IRawGrammar grammar = parser.parse(is); - assertNotNull(grammar); - assertFalse(grammar.getFileTypes().isEmpty()); - System.err.println(grammar); - } - } -} From 5e29c1b38efedba05779c118e2de89c45a87290f Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 29 Apr 2022 11:47:38 +0200 Subject: [PATCH 124/202] Move package internal.css to internal.theme.css --- .../{ => theme}/css/AbstractAttributeCondition.java | 2 +- .../{ => theme}/css/AbstractCombinatorCondition.java | 2 +- .../internal/{ => theme}/css/AbstractElementSelector.java | 2 +- .../core/internal/{ => theme}/css/CSSAndCondition.java | 2 +- .../internal/{ => theme}/css/CSSAttributeCondition.java | 2 +- .../core/internal/{ => theme}/css/CSSClassCondition.java | 2 +- .../internal/{ => theme}/css/CSSConditionFactory.java | 2 +- .../internal/{ => theme}/css/CSSConditionalSelector.java | 2 +- .../core/internal/{ => theme}/css/CSSDocumentHandler.java | 2 +- .../core/internal/{ => theme}/css/CSSElementSelector.java | 2 +- .../core/internal/{ => theme}/css/CSSSelectorFactory.java | 2 +- .../tm4e/core/internal/{ => theme}/css/CSSValueImpl.java | 2 +- .../core/internal/{ => theme}/css/ExtendedCondition.java | 2 +- .../core/internal/{ => theme}/css/ExtendedSelector.java | 2 +- .../tm4e/core/internal/{ => theme}/css/Measure.java | 2 +- .../tm4e/core/internal/{ => theme}/css/RGBColorImpl.java | 2 +- .../internal/{ => theme}/css/SACParserFactoryImpl.java | 2 +- .../java/org/eclipse/tm4e/core/theme/css/CSSParser.java | 8 ++++---- .../org/eclipse/tm4e/core/theme/css/SACParserFactory.java | 2 +- 19 files changed, 22 insertions(+), 22 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/AbstractAttributeCondition.java (94%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/AbstractCombinatorCondition.java (95%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/AbstractElementSelector.java (94%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSAndCondition.java (95%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSAttributeCondition.java (96%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSClassCondition.java (94%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSConditionFactory.java (98%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSConditionalSelector.java (97%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSDocumentHandler.java (98%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSElementSelector.java (94%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSSelectorFactory.java (98%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/CSSValueImpl.java (98%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/ExtendedCondition.java (91%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/ExtendedSelector.java (92%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/Measure.java (98%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/RGBColorImpl.java (97%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{ => theme}/css/SACParserFactoryImpl.java (98%) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractAttributeCondition.java similarity index 94% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractAttributeCondition.java index 387336b2c..779fdbee2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractAttributeCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractAttributeCondition.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.AttributeCondition; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractCombinatorCondition.java similarity index 95% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractCombinatorCondition.java index ff0c3a0e1..32727d52f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractCombinatorCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractCombinatorCondition.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.CombinatorCondition; import org.w3c.css.sac.Condition; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java similarity index 94% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java index 7aa0b081c..ad1ab9b2d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/AbstractElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.ElementSelector; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAndCondition.java similarity index 95% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAndCondition.java index 278f569bd..36bd7a7a3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAndCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAndCondition.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.Condition; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java similarity index 96% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java index 068a47f1c..4263e4257 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSAttributeCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; class CSSAttributeCondition extends AbstractAttributeCondition { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java similarity index 94% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java index 672cee5f7..10d62e152 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSClassCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; final class CSSClassCondition extends CSSAttributeCondition { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java index ed63ea1ea..2540e0155 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.AttributeCondition; import org.w3c.css.sac.CSSException; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionalSelector.java similarity index 97% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionalSelector.java index d18700e04..8d6bf46ca 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSConditionalSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionalSelector.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.Condition; import org.w3c.css.sac.ConditionalSelector; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java index c5f6cb91b..78e9ee998 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import java.util.ArrayList; import java.util.List; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java similarity index 94% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java index f100a5caf..09a8827be 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; final class CSSElementSelector extends AbstractElementSelector { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java index 6899936c0..528c403ab 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSSelectorFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java @@ -10,7 +10,7 @@ * Angelo Zerr - initial API and implementation * Jochen Ulrich - exception messages */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.CharacterDataSelector; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java index c044ba4ce..92a920dd4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/CSSValueImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java @@ -9,7 +9,7 @@ * Angelo Zerr - initial API and implementation * IBM Corporation - ongoing development *******************************************************************************/ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSPrimitiveValue; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/ExtendedCondition.java similarity index 91% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/ExtendedCondition.java index 3d2a574dd..a20c5a171 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/ExtendedCondition.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; interface ExtendedCondition { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/ExtendedSelector.java similarity index 92% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedSelector.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/ExtendedSelector.java index aa4087c3d..541047cdd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/ExtendedSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/ExtendedSelector.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.Selector; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java index 69418abfe..920361d13 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/Measure.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.LexicalUnit; import org.w3c.dom.DOMException; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/RGBColorImpl.java similarity index 97% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/RGBColorImpl.java index 3a557b4f8..d0c6d8760 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/RGBColorImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/RGBColorImpl.java @@ -9,7 +9,7 @@ * Angelo Zerr - initial API and implementation * IBM Corporation - ongoing development *******************************************************************************/ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.w3c.css.sac.LexicalUnit; import org.w3c.dom.DOMException; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java index 66f2eb23c..d9ab54729 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/css/SACParserFactoryImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java @@ -8,7 +8,7 @@ * Contributors: * Angelo Zerr - initial API and implementation *******************************************************************************/ -package org.eclipse.tm4e.core.internal.css; +package org.eclipse.tm4e.core.internal.theme.css; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java index c7829250d..1a503aadb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java @@ -16,10 +16,10 @@ import java.io.StringReader; import java.util.List; -import org.eclipse.tm4e.core.internal.css.CSSConditionFactory; -import org.eclipse.tm4e.core.internal.css.CSSDocumentHandler; -import org.eclipse.tm4e.core.internal.css.CSSSelectorFactory; -import org.eclipse.tm4e.core.internal.css.ExtendedSelector; +import org.eclipse.tm4e.core.internal.theme.css.CSSConditionFactory; +import org.eclipse.tm4e.core.internal.theme.css.CSSDocumentHandler; +import org.eclipse.tm4e.core.internal.theme.css.CSSSelectorFactory; +import org.eclipse.tm4e.core.internal.theme.css.ExtendedSelector; import org.eclipse.tm4e.core.theme.IStyle; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java index 26b780ed0..0b0fefb96 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java @@ -14,7 +14,7 @@ import java.lang.System.Logger; -import org.eclipse.tm4e.core.internal.css.SACParserFactoryImpl; +import org.eclipse.tm4e.core.internal.theme.css.SACParserFactoryImpl; import org.w3c.css.sac.Parser; import org.w3c.css.sac.helpers.ParserFactory; From 29ece0db73ff725c290496f95d46f761f21529e2 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 29 Apr 2022 12:00:45 +0200 Subject: [PATCH 125/202] Move package internal.grammars to internal.registry --- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 2 -- .../java/org/eclipse/tm4e/core/internal/grammar/Grammar.java | 2 +- .../internal/{grammars => registry}/IGrammarRepository.java | 2 +- .../tm4e/core/internal/{grammars => registry}/SyncRegistry.java | 2 +- .../src/main/java/org/eclipse/tm4e/core/registry/Registry.java | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{grammars => registry}/IGrammarRepository.java (95%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/{grammars => registry}/SyncRegistry.java (99%) diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index 1dad02c1a..11a6480e5 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -19,10 +19,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.eclipse.tm4e.core, org.eclipse.tm4e.core.grammar, org.eclipse.tm4e.core.internal.grammar;x-friends:="org.eclipse.tm4e.core.tests", - org.eclipse.tm4e.core.internal.grammars;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.internal.matcher;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.internal.theme.reader;x-friends:="org.eclipse.tm4e.core.tests", - org.eclipse.tm4e.core.internal.types;x-internal:=true, org.eclipse.tm4e.core.internal.utils;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.model, org.eclipse.tm4e.core.registry, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 62e2a6740..986aa2dbb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -33,10 +33,10 @@ import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; -import org.eclipse.tm4e.core.internal.grammars.IGrammarRepository; import org.eclipse.tm4e.core.internal.matcher.Matcher; import org.eclipse.tm4e.core.internal.matcher.MatcherWithPriority; import org.eclipse.tm4e.core.internal.oniguruma.OnigString; +import org.eclipse.tm4e.core.internal.registry.IGrammarRepository; import org.eclipse.tm4e.core.internal.rule.IRuleFactoryHelper; import org.eclipse.tm4e.core.internal.rule.Rule; import org.eclipse.tm4e.core.internal.rule.RuleFactory; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/IGrammarRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/IGrammarRepository.java similarity index 95% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/IGrammarRepository.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/IGrammarRepository.java index f264de73a..246a81c1a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/IGrammarRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/IGrammarRepository.java @@ -14,7 +14,7 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.internal.grammars; +package org.eclipse.tm4e.core.internal.registry; import java.util.Collection; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java similarity index 99% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java index 461b0ffe9..fb7a82524 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammars/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java @@ -14,7 +14,7 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.internal.grammars; +package org.eclipse.tm4e.core.internal.registry; import java.util.ArrayList; import java.util.Collection; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index b8f532853..4051c9b9a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -28,7 +28,7 @@ import org.eclipse.tm4e.core.TMException; import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; -import org.eclipse.tm4e.core.internal.grammars.SyncRegistry; +import org.eclipse.tm4e.core.internal.registry.SyncRegistry; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.theme.IRawTheme; import org.eclipse.tm4e.core.theme.Theme; From 1db85cfd7ec73ac1c80ae15a494be4fd0243b82c Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 29 Apr 2022 17:54:26 +0200 Subject: [PATCH 126/202] Move Injection class to internal package --- .../java/org/eclipse/tm4e/core/internal/grammar/Grammar.java | 1 - .../eclipse/tm4e/core/{ => internal}/grammar/Injection.java | 4 ++-- .../org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/grammar/Injection.java (94%) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 986aa2dbb..c82e3f2a9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -31,7 +31,6 @@ import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; -import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.matcher.Matcher; import org.eclipse.tm4e.core.internal.matcher.MatcherWithPriority; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/Injection.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java similarity index 94% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/Injection.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java index 2064078a5..f0c47a3d7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/Injection.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java @@ -14,14 +14,14 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.grammar; +package org.eclipse.tm4e.core.internal.grammar; import java.util.List; import java.util.function.Predicate; import org.eclipse.tm4e.core.internal.types.IRawGrammar; -public class Injection { +class Injection { private final Predicate> matcher; public final int priority; // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R' diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 385831f30..e63434112 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -24,7 +24,6 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.grammar.Injection; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; import org.eclipse.tm4e.core.internal.oniguruma.OnigNextMatchResult; From a1d11d0abf786f0611266763f3fdfbf19e8456f2 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 30 Apr 2022 13:58:19 +0200 Subject: [PATCH 127/202] Improve regex parsing --- .../tm4e/core/internal/rule/RegExpSource.java | 53 +++++++++--------- .../tm4e/core/internal/utils/RegexSource.java | 56 ++++++++++++++++--- 2 files changed, 75 insertions(+), 34 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index 417b12ab2..122a5ab62 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -16,10 +16,10 @@ */ package org.eclipse.tm4e.core.internal.rule; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Objects; +import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; @@ -104,35 +104,36 @@ void setSource(final String newSource) { } } + @SuppressWarnings("null") String resolveBackReferences(final String lineText, final OnigCaptureIndex[] captureIndices) { - try { - final var capturedValues = Arrays.stream(captureIndices) - .map(capture -> lineText.substring(capture.start, capture.end)) - .collect(Collectors.toList()); - final var m = BACK_REFERENCING_END.matcher(this.source); - final var sb = new StringBuilder(); - while (m.find()) { - final var g1 = m.group(); - final var index = Integer.parseInt(g1.substring(1)); - final var replacement = RegexSource.escapeRegExpCharacters( - capturedValues.size() > index ? capturedValues.get(index) : ""); - m.appendReplacement(sb, replacement); - } - m.appendTail(sb); - return sb.toString(); - } catch (RuntimeException ex) { - // ex.printStackTrace(); - return lineText; + final var capturedValues = new ArrayList(captureIndices.length); + for (final var capture : captureIndices) { + capturedValues.add(lineText.substring(capture.start, capture.end)); } + return BACK_REFERENCING_END.matcher(this.source).replaceAll(match -> { + try { + final int index = Integer.parseInt(match.group(1)); + if (index < captureIndices.length) { + final var replacement = RegexSource.escapeRegExpCharacters(capturedValues.get(index)); + return Matcher.quoteReplacement(replacement); // see https://stackoverflow.com/a/70785772/5116073 + } + } catch (NumberFormatException ex) { + // ignore + } + return ""; + }); } - private String [][] buildAnchorCache() { - final var A0_G0_result = new StringBuilder(); - final var A0_G1_result = new StringBuilder(); - final var A1_G0_result = new StringBuilder(); - final var A1_G1_result = new StringBuilder(); + private String[][] buildAnchorCache() { + final var source = this.source; + final var sourceLen = source.length(); + + final var A0_G0_result = new StringBuilder(sourceLen); + final var A0_G1_result = new StringBuilder(sourceLen); + final var A1_G0_result = new StringBuilder(sourceLen); + final var A1_G1_result = new StringBuilder(sourceLen); - for (int pos = 0, len = source.length(); pos < len; pos++) { + for (int pos = 0, len = sourceLen; pos < len; pos++) { final char ch = source.charAt(pos); A0_G0_result.append(ch); A0_G1_result.append(ch); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java index 4be5dfb67..b85a2ef03 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/RegexSource.java @@ -33,16 +33,56 @@ private RegexSource() { private static final Pattern CAPTURING_REGEX_SOURCE = Pattern .compile("\\$(\\d+)|\\$\\{(\\d+):\\/(downcase|upcase)}"); - private static final Pattern REGEXP_CHARACTERS = Pattern - .compile("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\,\\[\\]\\(\\)\\#\\s]"); - + /** + * Escapes/prefixes RegEx meta characters with a backslash in the given string. + * + * It is a non-regex based faster alternative to the TypeScript + * implementation: + * + *
+	 * function escapeRegExpCharacters(value: string): string {
+	 *   return value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&');
+	 * }
+	 * 
+ * + * @return a string with the RegEx meta characters escaped + */ public static String escapeRegExpCharacters(final String value) { - final var m = REGEXP_CHARACTERS.matcher(value); - final var sb = new StringBuilder(); - while (m.find()) { - m.appendReplacement(sb, "\\\\\\\\" + m.group()); + final int valueLen = value.length(); + final var sb = new StringBuilder(valueLen); + for (int i = 0; i < valueLen; i++) { + final char ch = value.charAt(i); + switch (ch) { + case '-': + case '\\': + case '{': + case '}': + case '*': + case '+': + case '?': + case '|': + case '^': + case '$': + case '.': + case ',': + case '[': + case ']': + case '(': + case ')': + case '#': + /* escaping white space chars is actually not necessary: + case ' ': + case '\t': + case '\n': + case '\f': + case '\r': + case 0x0B: // vertical tab \v + */ + sb.append('\\'); + } + sb.append(ch); } - m.appendTail(sb); return sb.toString(); } From 40283116950b12c2b3143f8bfb87d56b0bd5db41 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 30 Apr 2022 19:05:03 +0200 Subject: [PATCH 128/202] Refactor internal grammar package, enable annotation-based null analysis --- .../eclipse/tm4e/core/grammar/IGrammar.java | 1 + .../tm4e/core/grammar/StackElement.java | 104 ++++--- .../tm4e/core/grammar/package-info.java | 4 + .../tm4e/core/internal/grammar/Grammar.java | 232 +++++++++------- .../tm4e/core/internal/grammar/Injection.java | 10 +- .../core/internal/grammar/LineTokenizer.java | 165 ++++++------ .../core/internal/grammar/LineTokens.java | 46 ++-- .../internal/grammar/LocalStackElement.java | 2 +- .../tm4e/core/internal/grammar/Raw.java | 216 +++++++++------ .../grammar/ScopeDependencyProcessor.java | 255 ++++++++++++++++++ .../internal/grammar/ScopeListElement.java | 37 +-- .../core/internal/grammar/ScopeMetadata.java | 7 +- .../grammar/ScopeMetadataProvider.java | 118 ++++---- .../grammar/StackElementMetadata.java | 26 +- .../internal/grammar/StandardTokenType.java | 4 +- .../tm4e/core/internal/grammar/Token.java | 4 +- .../internal/grammar/TokenizeLineResult.java | 5 +- .../internal/grammar/TokenizeLineResult2.java | 4 +- .../core/internal/grammar/package-info.java | 4 + .../grammar/reader/GrammarReader.java | 6 +- .../internal/grammar/reader/package-info.java | 4 + .../tm4e/core/internal/parser/MapFactory.java | 2 +- .../tm4e/core/internal/parser/PListDict.java | 2 +- .../parser/PListParserContentHandler.java | 6 +- .../core/internal/parser/PListParserYAML.java | 7 +- .../internal/registry/IGrammarRepository.java | 3 + .../core/internal/registry/SyncRegistry.java | 86 +++--- .../core/internal/registry/package-info.java | 4 + .../core/internal/rule/BeginWhileRule.java | 2 +- .../core/internal/rule/IRuleRegistry.java | 3 + .../tm4e/core/internal/rule/MatchRule.java | 2 +- .../tm4e/core/internal/rule/RuleFactory.java | 47 ++-- .../core/internal/types/IRawCaptures.java | 1 - .../tm4e/core/internal/types/IRawGrammar.java | 15 ++ .../core/internal/types/IRawRepository.java | 21 +- .../tm4e/core/internal/types/IRawRule.java | 43 +-- .../core/internal/types/package-info.java | 4 + .../core/internal/utils/NullSafetyHelper.java | 46 ++++ .../tm4e/core/registry/IRegistryOptions.java | 29 +- .../eclipse/tm4e/core/registry/Registry.java | 9 +- .../tm4e/core/theme/IThemeProvider.java | 5 +- .../core/grammar/GrammarInjectionTest.java | 13 +- 42 files changed, 1050 insertions(+), 554 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/package-info.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/package-info.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/package-info.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/package-info.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/package-info.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java index 691fca3b4..2e799f090 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java @@ -34,6 +34,7 @@ public interface IGrammar { * * @return the name of the grammar. */ + @Nullable String getName(); /** diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java index e01d195da..45c81971e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java @@ -16,6 +16,8 @@ */ package org.eclipse.tm4e.core.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -34,7 +36,8 @@ */ public class StackElement { - public static final StackElement NULL = new StackElement(null, 0, 0, 0, false, null, null, null); + public static final StackElement NULL = new StackElement(null, 0, 0, 0, false, null, + new ScopeListElement(null, "", 0), new ScopeListElement(null, "", 0)); /** * The position on the current line where this state was pushed. @@ -82,6 +85,7 @@ public class StackElement { */ public final ScopeListElement nameScopesList; + /** * The list of scopes containing the "contentName" (besides "name") for this state. * This list **must** contain as an element `scopeName`. @@ -89,18 +93,18 @@ public class StackElement { public final ScopeListElement contentNameScopesList; public StackElement( - @Nullable StackElement parent, - int ruleId, - int enterPos, - int anchorPos, - boolean beginRuleCapturedEOL, - @Nullable String endRule, - ScopeListElement nameScopesList, - ScopeListElement contentNameScopesList) { + @Nullable final StackElement parent, + final int ruleId, + final int enterPos, + final int anchorPos, + final boolean beginRuleCapturedEOL, + @Nullable final String endRule, + final ScopeListElement nameScopesList, + final ScopeListElement contentNameScopesList) { this.parent = parent; - this.depth = (this.parent != null ? this.parent.depth + 1 : 1); + depth = this.parent != null ? this.parent.depth + 1 : 1; this.ruleId = ruleId; - this.enterPosition = enterPos; + enterPosition = enterPos; this.anchorPos = anchorPos; this.beginRuleCapturedEOL = beginRuleCapturedEOL; this.endRule = endRule; @@ -138,7 +142,7 @@ private static boolean structuralEquals(@Nullable StackElement a, @Nullable Stac } @SuppressWarnings("null") - private static boolean equals(@Nullable StackElement a, @Nullable StackElement b) { + private static boolean equals(@Nullable final StackElement a, @Nullable final StackElement b) { if (a == b) { return true; } @@ -149,7 +153,7 @@ private static boolean equals(@Nullable StackElement a, @Nullable StackElement b } @Override - public boolean equals(Object other) { + public boolean equals(@Nullable final Object other) { if (other == null || other.getClass() != StackElement.class) { return false; } @@ -177,24 +181,29 @@ public void reset() { @Nullable public StackElement pop() { - return this.parent; + return parent; } public StackElement safePop() { - if (this.parent != null) { - return this.parent; - } + if (parent != null) + return parent; return this; } - public StackElement push(int ruleId, - int enterPos, - int anchorPos, - boolean beginRuleCapturedEOL, - @Nullable String endRule, - ScopeListElement nameScopesList, - ScopeListElement contentNameScopesList) { - return new StackElement(this, ruleId, enterPos, anchorPos, beginRuleCapturedEOL, endRule, nameScopesList, + public StackElement push(final int ruleId, + final int enterPos, + final int anchorPos, + final boolean beginRuleCapturedEOL, + @Nullable final String endRule, + final ScopeListElement nameScopesList, + final ScopeListElement contentNameScopesList) { + return new StackElement(this, + ruleId, + enterPos, + anchorPos, + beginRuleCapturedEOL, + endRule, + nameScopesList, contentNameScopesList); } @@ -203,44 +212,53 @@ public int getAnchorPos() { } public int getEnterPos() { - return this.enterPosition; + return enterPosition; } - public Rule getRule(IRuleRegistry grammar) { - return grammar.getRule(this.ruleId); + public Rule getRule(final IRuleRegistry grammar) { + return grammar.getRule(ruleId); } - private void appendString(List res) { - if (this.parent != null) { - this.parent.appendString(res); + private void appendString(final List res) { + if (parent != null) { + parent.appendString(res); } - res.add('(' + Integer.toString(this.ruleId) + ')'); // , TODO-${this.nameScopesList}, - // TODO-${this.contentNameScopesList})`; + // , TODO-${this.nameScopesList}, TODO-${this.contentNameScopesList})`; + res.add("(" + ruleId + ")"); } @Override public String toString() { - List r = new ArrayList<>(); - this.appendString(r); + final var r = new ArrayList(); + appendString(r); return '[' + String.join(", ", r) + ']'; } - public StackElement setContentNameScopesList(ScopeListElement contentNameScopesList) { + public StackElement setContentNameScopesList(final ScopeListElement contentNameScopesList) { if (this.contentNameScopesList.equals(contentNameScopesList)) { return this; } - final var parent = this.parent; - assert parent != null; - return parent.push(this.ruleId, this.enterPosition, this.anchorPos, this.beginRuleCapturedEOL, this.endRule, - this.nameScopesList, contentNameScopesList); + return castNonNull(this.parent).push(this.ruleId, + this.enterPosition, + this.anchorPos, + this.beginRuleCapturedEOL, + this.endRule, + this.nameScopesList, + contentNameScopesList); } - public StackElement setEndRule(String endRule) { + public StackElement setEndRule(final String endRule) { if (this.endRule != null && this.endRule.equals(endRule)) { return this; } - return new StackElement(this.parent, this.ruleId, this.enterPosition, this.anchorPos, this.beginRuleCapturedEOL, - endRule, this.nameScopesList, this.contentNameScopesList); + return new StackElement(this.parent, + this.ruleId, + this.enterPosition, + this.anchorPos, + this.beginRuleCapturedEOL, + endRule, + this.nameScopesList, + this.contentNameScopesList); } public boolean hasSameRuleAs(final StackElement other) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/package-info.java new file mode 100644 index 000000000..bfa17ddd6 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.grammar; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index c82e3f2a9..da9ca8b85 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -17,13 +17,15 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; +import java.util.Objects; import java.util.function.IntFunction; import org.eclipse.jdt.annotation.NonNull; @@ -33,7 +35,6 @@ import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.matcher.Matcher; -import org.eclipse.tm4e.core.internal.matcher.MatcherWithPriority; import org.eclipse.tm4e.core.internal.oniguruma.OnigString; import org.eclipse.tm4e.core.internal.registry.IGrammarRepository; import org.eclipse.tm4e.core.internal.rule.IRuleFactoryHelper; @@ -43,7 +44,6 @@ import org.eclipse.tm4e.core.internal.types.IRawRepository; import org.eclipse.tm4e.core.internal.types.IRawRule; import org.eclipse.tm4e.core.theme.IThemeProvider; -import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; /** * TextMate grammar implementation. @@ -54,171 +54,210 @@ */ public final class Grammar implements IGrammar, IRuleFactoryHelper { + private final String scopeName; + private int rootId = -1; private int lastRuleId = 0; - private final Map ruleId2desc = new HashMap<>(); + private final Map ruleId2desc = new HashMap<>(); private final Map includedGrammars = new HashMap<>(); private final IGrammarRepository grammarRepository; - private final IRawGrammar rawGrammar; + private final IRawGrammar grammar; + + @Nullable private List injections; private final ScopeMetadataProvider scopeMetadataProvider; - public Grammar(IRawGrammar grammar, - int initialLanguage, - @Nullable Map embeddedLanguages, - IGrammarRepository grammarRepository, - IThemeProvider themeProvider) { + public Grammar( + final String scopeName, + final IRawGrammar grammar, + final int initialLanguage, + @Nullable final Map embeddedLanguages, + final IGrammarRepository grammarRepository, + final IThemeProvider themeProvider) { + this.scopeName = scopeName; this.scopeMetadataProvider = new ScopeMetadataProvider(initialLanguage, themeProvider, embeddedLanguages); this.grammarRepository = grammarRepository; - this.rawGrammar = initGrammar(grammar, null); + this.grammar = initGrammar(grammar, null); } public void onDidChangeTheme() { this.scopeMetadataProvider.onDidChangeTheme(); } - ScopeMetadata getMetadataForScope(String scope) { + ScopeMetadata getMetadataForScope(final String scope) { return this.scopeMetadataProvider.getMetadataForScope(scope); } - List getInjections() { - if (this.injections == null) { - this.injections = new ArrayList<>(); + private void collectInjections(final List result, final String selector, final IRawRule rule, + final IRuleFactoryHelper ruleFactoryHelper, final IRawGrammar grammar) { + final var matchers = Matcher.createMatchers(selector); + final int ruleId = RuleFactory.getCompiledRuleId(rule, ruleFactoryHelper, this.grammar.getRepositorySafe()); + + for (final var matcher : matchers) { + result.add(new Injection(matcher.matcher, ruleId, grammar, matcher.priority)); + } + } + + private List collectInjections() { + final var grammarRepository = new IGrammarRepository() { + @Override + public @Nullable IRawGrammar lookup(final String scopeName) { + if (Objects.equals(scopeName, Grammar.this.scopeName)) { + return Grammar.this.grammar; + } + return getExternalGrammar(scopeName, null); + } + + @Override + public @Nullable Collection injections(final String targetScope) { + return Grammar.this.grammarRepository.injections(targetScope); + } + }; + + final var dependencyProcessor = new ScopeDependencyProcessor(grammarRepository, this.scopeName); + // TODO: uncomment below to visit all scopes + // while (dependencyProcessor.queue.length > 0) { + // dependencyProcessor.processQueue(); + // } + + final var result = new ArrayList(); + + dependencyProcessor.seenFullScopeRequests.forEach((scopeName) -> { + final var grammar = grammarRepository.lookup(scopeName); + if (grammar == null) { + return; + } + // add injections from the current grammar - Map rawInjections = this.rawGrammar.getInjections(); + final var rawInjections = grammar.getInjections(); if (rawInjections != null) { - for (Entry injection : rawInjections.entrySet()) { - String expression = injection.getKey(); - IRawRule rule = injection.getValue(); - collectInjections(this.injections, expression, rule, this, this.rawGrammar); + for (final var e : rawInjections.entrySet()) { + collectInjections(result, e.getKey(), e.getValue(), this, grammar); } } // add injection grammars contributed for the current scope - if (this.grammarRepository != null) { - Collection injectionScopeNames = this.grammarRepository - .injections(this.rawGrammar.getScopeName()); - if (injectionScopeNames != null) { - injectionScopeNames.forEach(injectionScopeName -> { - IRawGrammar injectionGrammar = this.getExternalGrammar(injectionScopeName); - if (injectionGrammar != null) { - String selector = injectionGrammar.getInjectionSelector(); - if (selector != null) { - collectInjections(this.injections, selector, (IRawRule) injectionGrammar, this, - injectionGrammar); - } + final var injectionScopeNames = this.grammarRepository.injections(scopeName); + if (injectionScopeNames != null) { + injectionScopeNames.forEach(injectionScopeName -> { + final var injectionGrammar = Grammar.this.getExternalGrammar(injectionScopeName, null); + if (injectionGrammar != null) { + final var selector = injectionGrammar.getInjectionSelector(); + if (selector != null) { + collectInjections(result, selector, (IRawRule) injectionGrammar, this, + injectionGrammar); } - }); - } + } + }); } - Collections.sort(this.injections, (i1, i2) -> i1.priority - i2.priority); // sort by priority - } - if (this.injections.isEmpty()) { - return this.injections; - } - return this.injections; - } + }); - private void collectInjections(List result, String selector, IRawRule rule, - IRuleFactoryHelper ruleFactoryHelper, IRawGrammar grammar) { - Collection>> matchers = Matcher.createMatchers(selector); - int ruleId = RuleFactory.getCompiledRuleId(rule, ruleFactoryHelper, grammar.getRepository()); + Collections.sort(result, (i1, i2) -> i1.priority - i2.priority); // sort by priority - for (MatcherWithPriority> matcher : matchers) { - result.add(new Injection(matcher.matcher, ruleId, grammar, matcher.priority)); + return result; + } + + List getInjections() { + var injections = this.injections; + if (injections == null) { + injections = this.injections = this.collectInjections(); } + return injections; } @Override - public T registerRule(IntFunction factory) { - int id = (++this.lastRuleId); - T result = factory.apply(id); + public T registerRule(final IntFunction factory) { + final int id = ++this.lastRuleId; + final @Nullable T result = factory.apply(id); this.ruleId2desc.put(id, result); return result; } @Override - public Rule getRule(int patternId) { - return this.ruleId2desc.get(patternId); - } - - private IRawGrammar getExternalGrammar(String scopeName) { - return getExternalGrammar(scopeName, null); + public Rule getRule(final int patternId) { + final var rule = this.ruleId2desc.get(patternId); + if (rule == null) { + throw new IndexOutOfBoundsException( + "No rule with index " + patternId + " found. Possible values: 0.." + this.ruleId2desc.size()); + } + return rule; } @Override - public IRawGrammar getExternalGrammar(String scopeName, @Nullable IRawRepository repository) { + @Nullable + public IRawGrammar getExternalGrammar(final String scopeName, @Nullable final IRawRepository repository) { if (this.includedGrammars.containsKey(scopeName)) { return this.includedGrammars.get(scopeName); - } else if (this.grammarRepository != null) { - IRawGrammar rawIncludedGrammar = this.grammarRepository.lookup(scopeName); - if (rawIncludedGrammar != null) { - this.includedGrammars.put(scopeName, - initGrammar(rawIncludedGrammar, repository != null ? repository.getBase() : null)); - return this.includedGrammars.get(scopeName); - } + } + + final IRawGrammar rawIncludedGrammar = this.grammarRepository.lookup(scopeName); + if (rawIncludedGrammar != null) { + this.includedGrammars.put(scopeName, + initGrammar(rawIncludedGrammar, repository != null ? repository.getBase() : null)); + return this.includedGrammars.get(scopeName); } return null; } - private IRawGrammar initGrammar(IRawGrammar grammar, IRawRule base) { + private IRawGrammar initGrammar(IRawGrammar grammar, @Nullable final IRawRule base) { grammar = grammar.clone(); - if (grammar.getRepository() == null) { - ((Raw) grammar).setRepository(new Raw()); + var repo = grammar.getRepository(); + if (repo == null) { + repo = new Raw(); + ((IRawRule) grammar).setRepository(repo); } - Raw self = new Raw(); + final var self = new Raw(); self.setPatterns(grammar.getPatterns()); self.setName(grammar.getScopeName()); - grammar.getRepository().setSelf(self); - if (base != null) { - grammar.getRepository().setBase(base); - } else { - grammar.getRepository().setBase(grammar.getRepository().getSelf()); - } + repo.setSelf(self); + repo.setBase(base != null ? base : self); return grammar; } @Override - public ITokenizeLineResult tokenizeLine(String lineText) { + public ITokenizeLineResult tokenizeLine(final String lineText) { return tokenizeLine(lineText, null); } @Override - public ITokenizeLineResult tokenizeLine(String lineText, @Nullable StackElement prevState) { + public ITokenizeLineResult tokenizeLine(final String lineText, @Nullable final StackElement prevState) { return tokenize(lineText, prevState, false); } @Override - public ITokenizeLineResult2 tokenizeLine2(String lineText) { + public ITokenizeLineResult2 tokenizeLine2(final String lineText) { return tokenizeLine2(lineText, null); } @Override - public ITokenizeLineResult2 tokenizeLine2(String lineText, @Nullable StackElement prevState) { + public ITokenizeLineResult2 tokenizeLine2(final String lineText, @Nullable final StackElement prevState) { return tokenize(lineText, prevState, true); } @SuppressWarnings("unchecked") - private T tokenize(String lineText, @Nullable StackElement prevState, boolean emitBinaryTokens) { + private T tokenize(String lineText, @Nullable StackElement prevState, final boolean emitBinaryTokens) { if (this.rootId == -1) { - this.rootId = RuleFactory.getCompiledRuleId(this.rawGrammar.getRepository().getSelf(), this, - this.rawGrammar.getRepository()); + this.rootId = RuleFactory.getCompiledRuleId(this.grammar.getRepositorySafe().getSelf(), this, + this.grammar.getRepositorySafe()); } boolean isFirstLine; if (prevState == null || prevState.equals(StackElement.NULL)) { isFirstLine = true; - ScopeMetadata rawDefaultMetadata = this.scopeMetadataProvider.getDefaultMetadata(); - ThemeTrieElementRule defaultTheme = rawDefaultMetadata.themeData.get(0); - int defaultMetadata = StackElementMetadata.set(0, rawDefaultMetadata.languageId, + final var rawDefaultMetadata = this.scopeMetadataProvider.getDefaultMetadata(); + final var themeData = rawDefaultMetadata.themeData; + final var defaultTheme = themeData == null ? null : themeData.get(0); + final int defaultMetadata = StackElementMetadata.set(0, rawDefaultMetadata.languageId, rawDefaultMetadata.tokenType, defaultTheme.fontStyle, defaultTheme.foreground, defaultTheme.background); - String rootScopeName = this.getRule(this.rootId).getName(null, null); - ScopeMetadata rawRootMetadata = this.scopeMetadataProvider.getMetadataForScope(rootScopeName); - int rootMetadata = ScopeListElement.mergeMetadata(defaultMetadata, null, rawRootMetadata); + final var rootRule = castNonNull(this.getRule(this.rootId)); + final var rootScopeName = rootRule.getName(null, null); + final var rawRootMetadata = this.scopeMetadataProvider.getMetadataForScope(rootScopeName); + final int rootMetadata = ScopeListElement.mergeMetadata(defaultMetadata, null, rawRootMetadata); - ScopeListElement scopeList = new ScopeListElement(null, rootScopeName, rootMetadata); + final ScopeListElement scopeList = new ScopeListElement(null, + rootScopeName == null ? "unknown" : rootScopeName, rootMetadata); prevState = new StackElement(null, this.rootId, -1, -1, false, null, scopeList, scopeList); } else { @@ -230,11 +269,10 @@ private T tokenize(String lineText, @Nullable StackElement prevState, boolea // Only add \n if the passed lineText didn't have it. lineText += '\n'; } - OnigString onigLineText = OnigString.of(lineText); - int lineLength = lineText.length(); - LineTokens lineTokens = new LineTokens(emitBinaryTokens, lineText); - StackElement nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, - lineTokens); + final var onigLineText = OnigString.of(lineText); + final int lineLength = lineText.length(); + final var lineTokens = new LineTokens(emitBinaryTokens, lineText); + final var nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, lineTokens); if (emitBinaryTokens) { return (T) new TokenizeLineResult2(lineTokens.getBinaryResult(nextState, lineLength), nextState); @@ -243,18 +281,18 @@ private T tokenize(String lineText, @Nullable StackElement prevState, boolea } @Override + @Nullable public String getName() { - return rawGrammar.getName(); + return grammar.getName(); } @Override public String getScopeName() { - return rawGrammar.getScopeName(); + return scopeName; } @Override public Collection getFileTypes() { - return rawGrammar.getFileTypes(); + return grammar.getFileTypes(); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java index f0c47a3d7..01db316f2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.grammar; @@ -28,14 +28,14 @@ class Injection { public final int ruleId; public final IRawGrammar grammar; - public Injection(Predicate> matcher, int ruleId, IRawGrammar grammar, int priority) { + public Injection(final Predicate> matcher, final int ruleId, final IRawGrammar grammar, final int priority) { this.matcher = matcher; this.ruleId = ruleId; this.grammar = grammar; this.priority = priority; } - public boolean match(List states) { + public boolean match(final List states) { return matcher.test(states); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index e63434112..ea155321a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -16,13 +16,14 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import static java.lang.System.Logger.Level.*; import java.lang.System.Logger; import java.util.ArrayList; import java.util.List; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; @@ -45,8 +46,7 @@ final class LineTokenizer { private static final Logger LOGGER = System.getLogger(LineTokenizer.class.getName()); private interface IMatchResult { - @NonNull - OnigCaptureIndex @NonNull [] getCaptureIndices(); + OnigCaptureIndex[] getCaptureIndices(); int getMatchedRuleId(); } @@ -60,7 +60,7 @@ private static final class WhileStack { private final StackElement stack; private final BeginWhileRule rule; - private WhileStack(StackElement stack, BeginWhileRule rule) { + private WhileStack(final StackElement stack, final BeginWhileRule rule) { this.stack = stack; this.rule = rule; } @@ -73,7 +73,8 @@ private static final class WhileCheckResult { private final int anchorPosition; private final boolean isFirstLine; - private WhileCheckResult(StackElement stack, int linePos, int anchorPosition, boolean isFirstLine) { + private WhileCheckResult(final StackElement stack, final int linePos, final int anchorPosition, + final boolean isFirstLine) { this.stack = stack; this.linePos = linePos; this.anchorPosition = anchorPosition; @@ -90,8 +91,9 @@ private WhileCheckResult(StackElement stack, int linePos, int anchorPosition, bo private int anchorPosition = -1; private boolean stop; - private LineTokenizer(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, StackElement stack, - LineTokens lineTokens) { + private LineTokenizer(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, + final int linePos, final StackElement stack, + final LineTokens lineTokens) { this.grammar = grammar; this.lineText = lineText; this.isFirstLine = isFirstLine; @@ -103,7 +105,7 @@ private LineTokenizer(Grammar grammar, OnigString lineText, boolean isFirstLine, private StackElement scan() { stop = false; - WhileCheckResult whileCheckResult = checkWhileConditions(grammar, lineText, isFirstLine, linePos, stack, + final WhileCheckResult whileCheckResult = checkWhileConditions(grammar, lineText, isFirstLine, linePos, stack, lineTokens); stack = whileCheckResult.stack; linePos = whileCheckResult.linePos; @@ -120,7 +122,7 @@ private StackElement scan() { private void scanNext() { LOGGER.log(TRACE, () -> "@@scanNext: |" + lineText.string.replace("\n", "\\n").substring(linePos) + '|'); - IMatchResult r = matchRuleOrInjections(grammar, lineText, isFirstLine, linePos, stack, anchorPosition); + final IMatchResult r = matchRuleOrInjections(grammar, lineText, isFirstLine, linePos, stack, anchorPosition); if (r == null) { LOGGER.log(TRACE, " no more matches."); @@ -130,14 +132,14 @@ private void scanNext() { return; } - OnigCaptureIndex[] captureIndices = r.getCaptureIndices(); - int matchedRuleId = r.getMatchedRuleId(); + final OnigCaptureIndex[] captureIndices = r.getCaptureIndices(); + final int matchedRuleId = r.getMatchedRuleId(); final boolean hasAdvanced = captureIndices.length > 0 && captureIndices[0].end > linePos; if (matchedRuleId == -1) { // We matched the `end` for this rule => pop it - BeginEndRule poppedRule = (BeginEndRule) stack.getRule(grammar); + final BeginEndRule poppedRule = (BeginEndRule) stack.getRule(grammar); /* * if (logger.isEnabled()) { logger.log(" popping " + poppedRule.debugName + @@ -151,7 +153,7 @@ private void scanNext() { // pop final var popped = stack; - stack = stack.pop(); + stack = castNonNull(stack.pop()); anchorPosition = popped.getAnchorPos(); if (!hasAdvanced && popped.getEnterPos() == linePos) { @@ -169,19 +171,19 @@ private void scanNext() { } } else if (captureIndices.length > 0) { // We matched a rule! - Rule rule = grammar.getRule(matchedRuleId); + final Rule rule = grammar.getRule(matchedRuleId); lineTokens.produce(stack, captureIndices[0].start); - StackElement beforePush = stack; + final StackElement beforePush = stack; // push it on the stack rule - String scopeName = rule.getName(lineText.string, captureIndices); - ScopeListElement nameScopesList = stack.contentNameScopesList.push(grammar, scopeName); + final String scopeName = rule.getName(lineText.string, captureIndices); + final ScopeListElement nameScopesList = stack.contentNameScopesList.push(grammar, scopeName); stack = stack.push(matchedRuleId, linePos, anchorPosition, captureIndices[0].end == lineText.bytesCount, null, nameScopesList, nameScopesList); if (rule instanceof BeginEndRule) { - BeginEndRule pushedRule = (BeginEndRule) rule; + final BeginEndRule pushedRule = (BeginEndRule) rule; // if (IN_DEBUG_MODE) { // console.log(' pushing ' + pushedRule.debugName + ' - ' + @@ -193,8 +195,8 @@ private void scanNext() { lineTokens.produce(stack, captureIndices[0].end); anchorPosition = captureIndices[0].end; - String contentName = pushedRule.getContentName(lineText.string, captureIndices); - ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); + final String contentName = pushedRule.getContentName(lineText.string, captureIndices); + final ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); stack = stack.setContentNameScopesList(contentNameScopesList); if (pushedRule.endHasBackReferences) { @@ -206,13 +208,13 @@ private void scanNext() { // Grammar pushed the same rule without advancing LOGGER.log(INFO, "[2] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); - stack = stack.pop(); + stack = castNonNull(stack.pop()); lineTokens.produce(stack, lineText.bytesCount); stop = true; return; } } else if (rule instanceof BeginWhileRule) { - BeginWhileRule pushedRule = (BeginWhileRule) rule; + final BeginWhileRule pushedRule = (BeginWhileRule) rule; // if (IN_DEBUG_MODE) { // console.log(' pushing ' + pushedRule.debugName); // } @@ -222,8 +224,8 @@ private void scanNext() { lineTokens.produce(stack, captureIndices[0].end); anchorPosition = captureIndices[0].end; - String contentName = pushedRule.getContentName(lineText.string, captureIndices); - ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); + final String contentName = pushedRule.getContentName(lineText.string, captureIndices); + final ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); stack = stack.setContentNameScopesList(contentNameScopesList); if (pushedRule.whileHasBackReferences) { @@ -235,13 +237,13 @@ private void scanNext() { // Grammar pushed the same rule without advancing LOGGER.log(INFO, "[3] - Grammar is in an endless loop - Grammar pushed the same rule without advancing"); - stack = stack.pop(); + stack = castNonNull(stack.pop()); lineTokens.produce(stack, lineText.bytesCount); stop = true; return; } } else { - MatchRule matchingRule = (MatchRule) rule; + final MatchRule matchingRule = (MatchRule) rule; // if (IN_DEBUG_MODE) { // console.log(' matched ' + matchingRule.debugName + ' - ' + // matchingRule.debugMatchRegExp); @@ -252,7 +254,7 @@ private void scanNext() { lineTokens.produce(stack, captureIndices[0].end); // pop rule immediately since it is a MatchRule - stack = stack.pop(); + stack = castNonNull(stack.pop()); if (!hasAdvanced) { // Grammar is not advancing, nor is it pushing/popping @@ -273,9 +275,11 @@ private void scanNext() { } } - private IMatchResult matchRule(Grammar grammar, OnigString lineText, boolean isFirstLine, final int linePos, - StackElement stack, int anchorPosition) { - Rule rule = stack.getRule(grammar); + @Nullable + private IMatchResult matchRule(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, + final int linePos, + final StackElement stack, final int anchorPosition) { + final Rule rule = stack.getRule(grammar); final CompiledRule ruleScanner = rule.compileAG(grammar, stack.endRule, isFirstLine, linePos == anchorPosition); final OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); @@ -296,19 +300,22 @@ public OnigCaptureIndex[] getCaptureIndices() { return null; } - private IMatchResult matchRuleOrInjections(Grammar grammar, OnigString lineText, boolean isFirstLine, - final int linePos, StackElement stack, int anchorPosition) { + @Nullable + private IMatchResult matchRuleOrInjections(final Grammar grammar, final OnigString lineText, + final boolean isFirstLine, + final int linePos, final StackElement stack, final int anchorPosition) { // Look for normal grammar rule - IMatchResult matchResult = matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPosition); + final IMatchResult matchResult = matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPosition); // Look for injected rules - List injections = grammar.getInjections(); + final List injections = grammar.getInjections(); if (injections.isEmpty()) { // No injections whatsoever => early return return matchResult; } - IMatchInjectionsResult injectionResult = matchInjections(injections, grammar, lineText, isFirstLine, linePos, + final IMatchInjectionsResult injectionResult = matchInjections(injections, grammar, lineText, isFirstLine, + linePos, stack, anchorPosition); if (injectionResult == null) { // No injections matched => early return @@ -321,8 +328,8 @@ private IMatchResult matchRuleOrInjections(Grammar grammar, OnigString lineText, } // Decide if `matchResult` or `injectionResult` should win - int matchResultScore = matchResult.getCaptureIndices()[0].start; - int injectionResultScore = injectionResult.getCaptureIndices()[0].start; + final int matchResultScore = matchResult.getCaptureIndices()[0].start; + final int injectionResultScore = injectionResult.getCaptureIndices()[0].start; if (injectionResultScore < matchResultScore || (injectionResult.isPriorityMatch() && injectionResultScore == matchResultScore)) { @@ -333,31 +340,33 @@ private IMatchResult matchRuleOrInjections(Grammar grammar, OnigString lineText, return matchResult; } - private IMatchInjectionsResult matchInjections(List injections, Grammar grammar, OnigString lineText, - boolean isFirstLine, int linePos, StackElement stack, int anchorPosition) { + @Nullable + private IMatchInjectionsResult matchInjections(final List injections, final Grammar grammar, + final OnigString lineText, + final boolean isFirstLine, final int linePos, final StackElement stack, final int anchorPosition) { // The lower the better int bestMatchRating = Integer.MAX_VALUE; OnigCaptureIndex[] bestMatchCaptureIndices = null; int bestMatchRuleId = -1; int bestMatchResultPriority = 0; - List scopes = stack.contentNameScopesList.generateScopes(); + final List scopes = stack.contentNameScopesList.generateScopes(); - for (Injection injection : injections) { + for (final Injection injection : injections) { if (!injection.match(scopes)) { // injection selector doesn't match stack continue; } - CompiledRule ruleScanner = grammar.getRule(injection.ruleId).compileAG(grammar, null, isFirstLine, + final CompiledRule ruleScanner = grammar.getRule(injection.ruleId).compileAG(grammar, null, isFirstLine, linePos == anchorPosition); - OnigNextMatchResult matchResult = ruleScanner.scanner.findNextMatchSync(lineText, linePos); + final OnigNextMatchResult matchResult = ruleScanner.scanner.findNextMatchSync(lineText, linePos); if (matchResult == null) { continue; } - int matchRating = matchResult.getCaptureIndices()[0].start; + final int matchRating = matchResult.getCaptureIndices()[0].start; if (matchRating > bestMatchRating) { // Injections are sorted by priority, so the previous injection had a better or @@ -402,19 +411,21 @@ public boolean isPriorityMatch() { return null; } - private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirstLine, StackElement stack, - LineTokens lineTokens, List<@Nullable CaptureRule> captures, OnigCaptureIndex[] captureIndices) { + private void handleCaptures(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, + final StackElement stack, + final LineTokens lineTokens, final List<@Nullable CaptureRule> captures, + final OnigCaptureIndex[] captureIndices) { if (captures.isEmpty()) { return; } - int len = Math.min(captures.size(), captureIndices.length); - List localStack = new ArrayList<>(); - int maxEnd = captureIndices[0].end; + final int len = Math.min(captures.size(), captureIndices.length); + final List localStack = new ArrayList<>(); + final int maxEnd = captureIndices[0].end; OnigCaptureIndex captureIndex; for (int i = 0; i < len; i++) { - CaptureRule captureRule = captures.get(i); + final CaptureRule captureRule = captures.get(i); if (captureRule == null) { // Not interested continue; @@ -433,17 +444,14 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs } // pop captures while needed - while (!localStack.isEmpty() - && localStack.get(localStack.size() - 1).endPos <= captureIndex.start) { + while (!localStack.isEmpty() && getLastElement(localStack).endPos <= captureIndex.start) { // pop! - lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).scopes, - localStack.get(localStack.size() - 1).endPos); + lineTokens.produceFromScopes(getLastElement(localStack).scopes, getLastElement(localStack).endPos); localStack.remove(localStack.size() - 1); } if (!localStack.isEmpty()) { - lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).scopes, - captureIndex.start); + lineTokens.produceFromScopes(getLastElement(localStack).scopes, captureIndex.start); } else { lineTokens.produce(stack, captureIndex.start); } @@ -451,13 +459,13 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs final var retokenizeCapturedWithRuleId = captureRule.retokenizeCapturedWithRuleId; if (retokenizeCapturedWithRuleId != null) { // the capture requires additional matching - String scopeName = captureRule.getName(lineText.string, captureIndices); - ScopeListElement nameScopesList = stack.contentNameScopesList.push(grammar, scopeName); - String contentName = captureRule.getContentName(lineText.string, captureIndices); - ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); + final String scopeName = captureRule.getName(lineText.string, captureIndices); + final ScopeListElement nameScopesList = stack.contentNameScopesList.push(grammar, scopeName); + final String contentName = captureRule.getContentName(lineText.string, captureIndices); + final ScopeListElement contentNameScopesList = nameScopesList.push(grammar, contentName); // the capture requires additional matching - StackElement stackClone = stack.push(retokenizeCapturedWithRuleId, captureIndex.start, -1, false, + final StackElement stackClone = stack.push(retokenizeCapturedWithRuleId, captureIndex.start, -1, false, null, nameScopesList, contentNameScopesList); final var onigSubStr = OnigString.of(lineText.string.substring(0, captureIndex.end)); tokenizeString(grammar, onigSubStr, (isFirstLine && captureIndex.start == 0), @@ -466,21 +474,20 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs } // push - String captureRuleScopeName = captureRule.getName(lineText.string, captureIndices); + final String captureRuleScopeName = captureRule.getName(lineText.string, captureIndices); if (captureRuleScopeName != null) { // push - ScopeListElement base = localStack.isEmpty() + final ScopeListElement base = localStack.isEmpty() ? stack.contentNameScopesList - : localStack.get(localStack.size() - 1).scopes; - ScopeListElement captureRuleScopesList = base.push(grammar, captureRuleScopeName); + : getLastElement(localStack).scopes; + final ScopeListElement captureRuleScopesList = base.push(grammar, captureRuleScopeName); localStack.add(new LocalStackElement(captureRuleScopesList, captureIndex.end)); } } while (!localStack.isEmpty()) { // pop! - lineTokens.produceFromScopes(localStack.get(localStack.size() - 1).scopes, - localStack.get(localStack.size() - 1).endPos); + lineTokens.produceFromScopes(getLastElement(localStack).scopes, getLastElement(localStack).endPos); localStack.remove(localStack.size() - 1); } } @@ -490,31 +497,31 @@ private void handleCaptures(Grammar grammar, OnigString lineText, boolean isFirs * order. If any fails, cut off the entire stack above the failed while * condition. While conditions may also advance the linePosition. */ - private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineText, boolean isFirstLine, - int linePos, StackElement stack, LineTokens lineTokens) { + private WhileCheckResult checkWhileConditions(final Grammar grammar, final OnigString lineText, boolean isFirstLine, + int linePos, StackElement stack, final LineTokens lineTokens) { int currentanchorPosition = stack.beginRuleCapturedEOL ? 0 : -1; - List whileRules = new ArrayList<>(); + final List whileRules = new ArrayList<>(); for (StackElement node = stack; node != null; node = node.pop()) { - Rule nodeRule = node.getRule(grammar); + final Rule nodeRule = node.getRule(grammar); if (nodeRule instanceof BeginWhileRule) { whileRules.add(new WhileStack(node, (BeginWhileRule) nodeRule)); } } for (int i = whileRules.size() - 1; i >= 0; i--) { - WhileStack whileRule = whileRules.get(i); - CompiledRule ruleScanner = whileRule.rule.compileWhileAG(whileRule.stack.endRule, isFirstLine, + final var whileRule = castNonNull(whileRules.get(i)); + final var ruleScanner = whileRule.rule.compileWhileAG(whileRule.stack.endRule, isFirstLine, currentanchorPosition == linePos); - OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); + final var r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); // if (IN_DEBUG_MODE) { // console.log(' scanning for while rule'); // console.log(debugCompiledRuleToString(ruleScanner)); // } if (r != null) { - int matchedRuleId = ruleScanner.rules[r.getIndex()]; + final int matchedRuleId = ruleScanner.rules[r.getIndex()]; if (matchedRuleId != -2) { // we shouldn't end up here - stack = whileRule.stack.pop(); + stack = castNonNull(whileRule.stack.pop()); break; } if (r.getCaptureIndices().length > 0) { @@ -529,7 +536,7 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe } } } else { - stack = whileRule.stack.pop(); + stack = castNonNull(whileRule.stack.pop()); break; } } @@ -537,8 +544,8 @@ private WhileCheckResult checkWhileConditions(Grammar grammar, OnigString lineTe return new WhileCheckResult(stack, linePos, currentanchorPosition, isFirstLine); } - static StackElement tokenizeString(Grammar grammar, OnigString lineText, boolean isFirstLine, int linePos, - StackElement stack, LineTokens lineTokens) { + static StackElement tokenizeString(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, + final int linePos, final StackElement stack, final LineTokens lineTokens) { return new LineTokenizer(grammar, lineText, isFirstLine, linePos, stack, lineTokens).scan(); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 0f60ba997..fe8365768 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -16,6 +16,8 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import static java.lang.System.Logger.Level.*; import java.lang.System.Logger; @@ -48,7 +50,7 @@ final class LineTokens { private int lastTokenEndIndex = 0; - LineTokens(boolean emitBinaryTokens, String lineText) { + LineTokens(final boolean emitBinaryTokens, final String lineText) { this.emitBinaryTokens = emitBinaryTokens; this.lineText = LOGGER.isLoggable(TRACE) ? lineText : null; // store line only if it's logged if (this.emitBinaryTokens) { @@ -60,18 +62,18 @@ final class LineTokens { } } - void produce(StackElement stack, int endIndex) { + void produce(final StackElement stack, final int endIndex) { this.produceFromScopes(stack.contentNameScopesList, endIndex); } - void produceFromScopes(ScopeListElement scopesList, int endIndex) { + void produceFromScopes(final ScopeListElement scopesList, final int endIndex) { if (this.lastTokenEndIndex >= endIndex) { return; } if (this.emitBinaryTokens) { - int metadata = scopesList.metadata; - if (!this.binaryTokens.isEmpty() && this.binaryTokens.get(this.binaryTokens.size() - 1) == metadata) { + final int metadata = scopesList.metadata; + if (!this.binaryTokens.isEmpty() && getLastElement(this.binaryTokens) == metadata) { // no need to push a token with the same metadata this.lastTokenEndIndex = endIndex; return; @@ -84,14 +86,15 @@ void produceFromScopes(ScopeListElement scopesList, int endIndex) { return; } - List scopes = scopesList.generateScopes(); + final List scopes = scopesList.generateScopes(); if (this.lineText != null && LOGGER.isLoggable(TRACE)) { - LOGGER.log(TRACE, - " token: |" + this.lineText + LOGGER.log(TRACE, " token: |" + + castNonNull(this.lineText) .substring(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex) - .replace("\n", "\\n") + '|'); - for (String scope : scopes) { + .replace("\n", "\\n") + + '|'); + for (final String scope : scopes) { LOGGER.log(TRACE, " * " + scope); } } @@ -100,8 +103,8 @@ void produceFromScopes(ScopeListElement scopesList, int endIndex) { this.lastTokenEndIndex = endIndex; } - IToken[] getResult(StackElement stack, int lineLength) { - if (!this.tokens.isEmpty() && this.tokens.get(this.tokens.size() - 1).getStartIndex() == lineLength - 1) { + IToken[] getResult(final StackElement stack, final int lineLength) { + if (!this.tokens.isEmpty() && getLastElement(this.tokens).getStartIndex() == lineLength - 1) { // pop produced token for newline this.tokens.remove(this.tokens.size() - 1); } @@ -109,30 +112,25 @@ IToken[] getResult(StackElement stack, int lineLength) { if (this.tokens.isEmpty()) { this.lastTokenEndIndex = -1; this.produce(stack, lineLength); - this.tokens.get(this.tokens.size() - 1).setStartIndex(0); + getLastElement(this.tokens).setStartIndex(0); } return this.tokens.toArray(IToken[]::new); } - int[] getBinaryResult(StackElement stack, int lineLength) { - if (!this.binaryTokens.isEmpty() && this.binaryTokens.get(this.binaryTokens.size() - 2) == lineLength - 1) { + int[] getBinaryResult(final StackElement stack, final int lineLength) { + if (!this.binaryTokens.isEmpty() && this.binaryTokens.get(binaryTokens.size() - 2) == lineLength - 1) { // pop produced token for newline - this.binaryTokens.remove(this.binaryTokens.size() - 1); - this.binaryTokens.remove(this.binaryTokens.size() - 1); + this.binaryTokens.remove(binaryTokens.size() - 1); + this.binaryTokens.remove(binaryTokens.size() - 1); } if (this.binaryTokens.isEmpty()) { this.lastTokenEndIndex = -1; this.produce(stack, lineLength); - this.binaryTokens.set(this.binaryTokens.size() - 2, 0); - } - - int[] result = new int[this.binaryTokens.size()]; - for (int i = 0, len = this.binaryTokens.size(); i < len; i++) { - result[i] = this.binaryTokens.get(i); + this.binaryTokens.set(binaryTokens.size() - 2, 0); } - return result; + return binaryTokens.stream().mapToInt(Integer::intValue).toArray(); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java index ccfa8fbec..7f67b97f0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LocalStackElement.java @@ -21,7 +21,7 @@ final class LocalStackElement { final ScopeListElement scopes; final int endPos; - LocalStackElement(ScopeListElement scopes, int endPos) { + LocalStackElement(final ScopeListElement scopes, final int endPos) { this.scopes = scopes; this.endPos = endPos; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java index 7701f963f..35dccb209 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java @@ -12,6 +12,8 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -20,6 +22,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.types.IRawCaptures; import org.eclipse.tm4e.core.internal.types.IRawGrammar; @@ -28,112 +31,132 @@ /** * Raw - * */ -public final class Raw extends HashMap<@Nullable String, Object> implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { - public static final String FIRST_LINE_MATCH = "firstLineMatch"; - public static final String FILE_TYPES = "fileTypes"; - public static final String SCOPE_NAME = "scopeName"; - public static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast"; - public static final String REPOSITORY = "repository"; - public static final String INJECTION_SELECTOR = "injectionSelector"; - public static final String INJECTIONS = "injections"; - public static final String PATTERNS = "patterns"; - public static final String WHILE_CAPTURES = "whileCaptures"; - public static final String END_CAPTURES = "endCaptures"; - public static final String INCLUDE = "include"; - public static final String WHILE = "while"; - public static final String END = "end"; - public static final String BEGIN = "begin"; - public static final String CAPTURES = "captures"; - public static final String MATCH = "match"; - public static final String BEGIN_CAPTURES = "beginCaptures"; - public static final String CONTENT_NAME = "contentName"; - public static final String NAME = "name"; - public static final String ID = "id"; +public final class Raw extends HashMap<@Nullable String, @Nullable Object> + implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { + public static final String DOLLAR_SELF = "$self"; public static final String DOLLAR_BASE = "$base"; - public static final long serialVersionUID = -2306714541728887963L; - public transient List fileTypes; + private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast"; + private static final String BEGIN = "begin"; + private static final String BEGIN_CAPTURES = "beginCaptures"; + private static final String CAPTURES = "captures"; + private static final String CONTENT_NAME = "contentName"; + private static final String END = "end"; + private static final String END_CAPTURES = "endCaptures"; + private static final String FILE_TYPES = "fileTypes"; + private static final String FIRST_LINE_MATCH = "firstLineMatch"; + private static final String ID = "id"; + private static final String INCLUDE = "include"; + private static final String INJECTIONS = "injections"; + private static final String INJECTION_SELECTOR = "injectionSelector"; + private static final String MATCH = "match"; + private static final String NAME = "name"; + private static final String PATTERNS = "patterns"; + private static final String REPOSITORY = "repository"; + private static final String SCOPE_NAME = "scopeName"; + private static final String WHILE = "while"; + private static final String WHILE_CAPTURES = "whileCaptures"; + + private static final long serialVersionUID = 1L; + + @Nullable + private transient List fileTypes; + + private Object getSafe(@Nullable final Object key) { + @SuppressWarnings("unlikely-arg-type") + final + var obj = get(key); + if (obj == null) { + throw new IllegalArgumentException("Key '" + key + "' does not exit found"); + } + return obj; + } @Override - public IRawRule getProp(String name) { - return (IRawRule) super.get(name); + @Nullable + public IRawRule getProp(final String name) { + return (IRawRule) get(name); } @Override public IRawRule getBase() { - return (IRawRule) super.get(DOLLAR_BASE); + return (IRawRule) getSafe(DOLLAR_BASE); } @Override - public void setBase(IRawRule base) { + public void setBase(final IRawRule base) { super.put(DOLLAR_BASE, base); } @Override public IRawRule getSelf() { - return (IRawRule) super.get(DOLLAR_SELF); + return (IRawRule) getSafe(DOLLAR_SELF); } @Override - public void setSelf(IRawRule self) { + public void setSelf(final IRawRule self) { super.put(DOLLAR_SELF, self); } + @Nullable @Override public Integer getId() { - return (Integer) super.get(ID); + return (Integer) get(ID); } @Override - public void setId(Integer id) { + public void setId(@Nullable final Integer id) { super.put(ID, id); } + @Nullable @Override public String getName() { - return (String) super.get(NAME); + return (String) get(NAME); } @Override - public void setName(String name) { + public void setName(@Nullable final String name) { super.put(NAME, name); } + @Nullable @Override public String getContentName() { - return (String) super.get(CONTENT_NAME); + return (String) get(CONTENT_NAME); } @Override - public void setContentName(String name) { + public void setContentName(@Nullable final String name) { super.put(CONTENT_NAME, name); } + @Nullable @Override public String getMatch() { - return (String) super.get(MATCH); + return (String) get(MATCH); } @Override - public void setMatch(String match) { + public void setMatch(@Nullable final String match) { super.put(MATCH, match); } + @Nullable @Override public IRawCaptures getCaptures() { updateCaptures(CAPTURES); - return (IRawCaptures) super.get(CAPTURES); + return (IRawCaptures) get(CAPTURES); } - public void updateCaptures(String name) { - Object captures = super.get(name); + public void updateCaptures(final String name) { + final Object captures = get(name); if (captures instanceof List) { - Raw rawCaptures = new Raw(); + final Raw rawCaptures = new Raw(); int i = 0; - for (Object capture : (List) captures) { + for (final Object capture : (List) captures) { i++; rawCaptures.put(i + "", capture); } @@ -142,106 +165,124 @@ public void updateCaptures(String name) { } @Override - public void setCaptures(IRawCaptures captures) { + public void setCaptures(@Nullable final IRawCaptures captures) { super.put(CAPTURES, captures); } + @Nullable @Override public String getBegin() { - return (String) super.get(BEGIN); + return (String) get(BEGIN); } @Override - public void setBegin(String begin) { + public void setBegin(@Nullable final String begin) { super.put(BEGIN, begin); } + @Nullable @Override public String getWhile() { - return (String) super.get(WHILE); + return (String) get(WHILE); } + @Nullable @Override public String getInclude() { - return (String) super.get(INCLUDE); + return (String) get(INCLUDE); } @Override - public void setInclude(String include) { + public void setInclude(@Nullable final String include) { super.put(INCLUDE, include); } + @Nullable @Override public IRawCaptures getBeginCaptures() { updateCaptures(BEGIN_CAPTURES); - return (IRawCaptures) super.get(BEGIN_CAPTURES); + return (IRawCaptures) get(BEGIN_CAPTURES); } @Override - public void setBeginCaptures(IRawCaptures beginCaptures) { + public void setBeginCaptures(@Nullable final IRawCaptures beginCaptures) { super.put(BEGIN_CAPTURES, beginCaptures); } + @Nullable @Override public String getEnd() { - return (String) super.get(END); + return (String) get(END); } @Override - public void setEnd(String end) { + public void setEnd(@Nullable final String end) { super.put(END, end); } + @Nullable @Override public IRawCaptures getEndCaptures() { updateCaptures(END_CAPTURES); - return (IRawCaptures) super.get(END_CAPTURES); + return (IRawCaptures) get(END_CAPTURES); } @Override - public void setEndCaptures(IRawCaptures endCaptures) { + public void setEndCaptures(@Nullable final IRawCaptures endCaptures) { super.put(END_CAPTURES, endCaptures); } + @Nullable @Override public IRawCaptures getWhileCaptures() { updateCaptures(WHILE_CAPTURES); - return (IRawCaptures) super.get(WHILE_CAPTURES); + return (IRawCaptures) get(WHILE_CAPTURES); } + @Nullable @Override + @SuppressWarnings("unchecked") public Collection getPatterns() { - return (Collection) super.get(PATTERNS); + return (Collection) get(PATTERNS); } @Override - public void setPatterns(Collection patterns) { + public void setPatterns(final @Nullable Collection patterns) { super.put(PATTERNS, patterns); } + @Nullable @Override + @SuppressWarnings("unchecked") public Map getInjections() { - return (Map) super.get(INJECTIONS); + return (Map) get(INJECTIONS); } + @Nullable @Override public String getInjectionSelector() { - return (String) super.get(INJECTION_SELECTOR); + return (String) get(INJECTION_SELECTOR); } + @Nullable @Override public IRawRepository getRepository() { - return (IRawRepository) super.get(REPOSITORY); + return (IRawRepository) get(REPOSITORY); } @Override - public void setRepository(IRawRepository repository) { + public IRawRepository getRepositorySafe() { + return (IRawRepository) getSafe(REPOSITORY); + } + + @Override + public void setRepository(@Nullable final IRawRepository repository) { super.put(REPOSITORY, repository); } @Override public boolean isApplyEndPatternLast() { - Object applyEndPatternLast = super.get(APPLY_END_PATTERN_LAST); + final Object applyEndPatternLast = get(APPLY_END_PATTERN_LAST); if (applyEndPatternLast == null) { return false; } @@ -255,60 +296,65 @@ public boolean isApplyEndPatternLast() { } @Override - public void setApplyEndPatternLast(boolean applyEndPatternLast) { + public void setApplyEndPatternLast(final boolean applyEndPatternLast) { super.put(APPLY_END_PATTERN_LAST, applyEndPatternLast); } @Override public String getScopeName() { - return (String) super.get(SCOPE_NAME); + return (String) getSafe(SCOPE_NAME); } @Override public Collection getFileTypes() { - if (fileTypes == null) { - List list = new ArrayList<>(); - Collection unparsedFileTypes = (Collection) super.get(FILE_TYPES); + List result = fileTypes; + if (result == null) { + result = new ArrayList<>(); + final Collection<@NonNull ?> unparsedFileTypes = (Collection<@NonNull ?>) get(FILE_TYPES); if (unparsedFileTypes != null) { - for (Object o : unparsedFileTypes) { + for (final Object o : unparsedFileTypes) { String str = o.toString(); // #202 if (str.startsWith(".")) { str = str.substring(1); } - list.add(str); + result.add(str); } } - fileTypes = list; + fileTypes = result; } - return fileTypes; + return result; } @Override + @Nullable public String getFirstLineMatch() { - return (String) super.get(FIRST_LINE_MATCH); + return (String) get(FIRST_LINE_MATCH); } @Override - public IRawRule getCapture(String captureId) { - return getProp(captureId); + public IRawRule getCapture(final String captureId) { + return (IRawRule) getSafe(captureId); } @Override public Iterator iterator() { - return super.keySet().iterator(); + final Iterator it = castNonNull(super.keySet().iterator()); + return castNonNull(it); } @Override public Raw clone() { - return (Raw) clone(this); + final var clone = (Raw) clone(this); + return castNonNull(clone); } - private Object clone(final Object value) { + @Nullable + private Object clone(@Nullable final Object value) { if (value instanceof Raw) { - final Raw rowToClone = (Raw) value; - final Raw raw = new Raw(); - for (final Entry entry : rowToClone.entrySet()) { + final Raw rowToClone = (Raw) value; + final Raw raw = new Raw(); + for (final var entry : rowToClone.entrySet()) { raw.put(entry.getKey(), clone(entry.getValue())); } return raw; @@ -319,17 +365,19 @@ private Object clone(final Object value) { return value; } + @Nullable @Override - public Object put(String key, Object value) { + public Object put(@Nullable final String key, @Nullable final Object value) { if (FILE_TYPES.equals(key)) fileTypes = null; + return super.put(key, value); } @Override @SuppressWarnings("unlikely-arg-type") - public void putAll(Map m) { - if (m.containsKey(FILE_TYPES)) + public void putAll(@Nullable final Map m) { + if (m != null && m.containsKey(FILE_TYPES)) fileTypes = null; super.putAll(m); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java new file mode 100644 index 000000000..c24efd606 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java @@ -0,0 +1,255 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/Microsoft/vscode-textmate/ + * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. + * Initial license: MIT + * + * Contributors: + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Sebastian Thomschke - translation and adaptation to Java + */ +package org.eclipse.tm4e.core.internal.grammar; + +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.TMException; +import org.eclipse.tm4e.core.internal.registry.IGrammarRepository; +import org.eclipse.tm4e.core.internal.types.IRawGrammar; +import org.eclipse.tm4e.core.internal.types.IRawRepository; +import org.eclipse.tm4e.core.internal.types.IRawRule; + +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts + */ +class ScopeDependencyProcessor { + + private static abstract class ScopeDependency { + final String scopeName; + + ScopeDependency(final String scopeName) { + this.scopeName = scopeName; + } + } + + private static final class FullScopeDependency extends ScopeDependency { + FullScopeDependency(final String scopeName) { + super(scopeName); + } + } + + private static final class PartialScopeDependency extends ScopeDependency { + final String include; + + PartialScopeDependency(final String scopeName, final String include) { + super(scopeName); + this.include = include; + } + + String toKey() { + return this.scopeName + '#' + this.include; + } + } + + private static class ScopeDependencyCollector { + + final List full = new ArrayList<>(); + final List partial = new ArrayList<>(); + + final Set visitedRule = new HashSet<>(); + private final Set seenFull = new HashSet<>(); + private final Set seenPartial = new HashSet<>(); + + void add(final ScopeDependency dep) { + if (dep instanceof FullScopeDependency) { + final var fdep = (FullScopeDependency) dep; + if (!this.seenFull.contains(fdep.scopeName)) { + this.seenFull.add(fdep.scopeName); + this.full.add(fdep); + } + } else { + final var pdep = (PartialScopeDependency) dep; + if (!this.seenPartial.contains(pdep.toKey())) { + this.seenPartial.add(pdep.toKey()); + this.partial.add(pdep); + } + } + } + } + + final Set seenFullScopeRequests = new HashSet<>(); + final Set seenPartialScopeRequests = new HashSet<>(); + List queue = new ArrayList<>(); + + public final IGrammarRepository repo; + public final String initialScopeName; + + ScopeDependencyProcessor(final IGrammarRepository repo, final String initialScopeName) { + this.repo = repo; + this.initialScopeName = initialScopeName; + this.seenFullScopeRequests.add(initialScopeName); + this.queue.add(new FullScopeDependency(initialScopeName)); + } + + public void processQueue() { + final var q = queue; + queue = new ArrayList<>(); + + final var deps = new ScopeDependencyCollector(); + for (final var dep : q) { + collectDependenciesForDep(this.repo, this.initialScopeName, deps, dep); + } + + for (final var dep : deps.full) { + if (this.seenFullScopeRequests.contains(dep.scopeName)) { + // already processed + continue; + } + this.seenFullScopeRequests.add(dep.scopeName); + this.queue.add(dep); + } + + for (final var dep : deps.partial) { + if (this.seenFullScopeRequests.contains(dep.scopeName)) { + // already processed in full + continue; + } + if (this.seenPartialScopeRequests.contains(dep.toKey())) { + // already processed + continue; + } + this.seenPartialScopeRequests.add(dep.toKey()); + this.queue.add(dep); + } + } + + void collectDependenciesForDep( + final IGrammarRepository repo, + final String initialScopeName, + final ScopeDependencyCollector result, + final ScopeDependency dep) { + final var grammar = repo.lookup(dep.scopeName); + if (grammar == null) { + if (dep.scopeName.equals(initialScopeName)) { + throw new TMException("No grammar provided for <" + initialScopeName + ">"); + } + return; + } + + final var initialGrammar = repo.lookup(initialScopeName); + if (dep instanceof FullScopeDependency) { + collectDependencies(result, castNonNull(initialGrammar), grammar); + } else { + final var pdep = (PartialScopeDependency) dep; + collectSpecificDependencies(result, castNonNull(initialGrammar), grammar, pdep.include, null); + } + + final var injections = repo.injections(dep.scopeName); + if (injections != null) { + for (final var injection : injections) { + result.add(new FullScopeDependency(injection)); + } + } + } + + /** + * Collect a specific dependency from the grammar's repository + */ + void collectSpecificDependencies(final ScopeDependencyCollector result, final IRawGrammar baseGrammar, + final IRawGrammar selfGrammar, + final String include, @Nullable IRawRepository repository) { + if (repository == null) { + repository = selfGrammar.getRepository(); + } + if (repository != null) { + final var rule = repository.getProp(include); + if (rule != null) { + extractIncludedScopesInPatterns(result, baseGrammar, selfGrammar, List.of(rule), repository); + } + } + } + + /** + * Collects the list of all external included scopes in `grammar`. + */ + void collectDependencies(final ScopeDependencyCollector result, final IRawGrammar baseGrammar, + final IRawGrammar selfGrammar) { + final var patterns = selfGrammar.getPatterns(); + if (patterns != null) { + extractIncludedScopesInPatterns(result, baseGrammar, selfGrammar, patterns, selfGrammar.getRepository()); + } + final var injections = selfGrammar.getInjections(); + if (injections != null) { + extractIncludedScopesInPatterns(result, baseGrammar, selfGrammar, injections.values(), + selfGrammar.getRepository()); + } + } + + /** + * Fill in `result` all external included scopes in `patterns` + */ + void extractIncludedScopesInPatterns( + final ScopeDependencyCollector result, + final IRawGrammar baseGrammar, + final IRawGrammar selfGrammar, + final Collection patterns, + @Nullable final IRawRepository repository) { + for (final var pattern : patterns) { + if (result.visitedRule.contains(pattern)) { + continue; + } + result.visitedRule.add(pattern); + + final var patternRepository = pattern.getRepository() == null + ? repository + : IRawRepository.merge(repository, pattern.getRepository()); + final var patternPatterns = pattern.getPatterns(); + if (patternPatterns != null) { + extractIncludedScopesInPatterns(result, baseGrammar, selfGrammar, patternPatterns, patternRepository); + } + + final var include = pattern.getInclude(); + if (include == null) { + continue; + } + + if (include.equals(Raw.DOLLAR_BASE) || include.equals(baseGrammar.getScopeName())) { + collectDependencies(result, baseGrammar, baseGrammar); + } else if (include.equals(Raw.DOLLAR_SELF) || include.equals(selfGrammar.getScopeName())) { + collectDependencies(result, baseGrammar, selfGrammar); + } else if (include.charAt(0) == '#') { + collectSpecificDependencies(result, baseGrammar, selfGrammar, include.substring(1), patternRepository); + } else { + final var sharpIndex = include.indexOf('#'); + if (sharpIndex >= 0) { + final var scopeName = include.substring(0, sharpIndex); + final var includedName = include.substring(sharpIndex + 1); + if (scopeName.equals(baseGrammar.getScopeName())) { + collectSpecificDependencies(result, baseGrammar, baseGrammar, includedName, patternRepository); + } else if (scopeName.equals(selfGrammar.getScopeName())) { + collectSpecificDependencies(result, baseGrammar, selfGrammar, includedName, patternRepository); + } else { + result.add(new PartialScopeDependency(scopeName, include.substring(sharpIndex + 1))); + } + } else { + result.add(new FullScopeDependency(include)); + } + } + } + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index 0eb59b728..7a9936d4b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -96,33 +96,38 @@ private static boolean matchesScope(final String scope, final String selector, f return (selector.equals(scope) || scope.startsWith(selectorWithDot)); } - private static boolean matches(@Nullable ScopeListElement target, final List parentScopes) { - if (parentScopes == null) { + /** + * implementation differs from upstream in that it is prevents potential NPEs/IndexOutOfBoundExceptions + */ + private static boolean matches(@Nullable ScopeListElement target, @Nullable final List parentScopes) { + if (parentScopes == null || parentScopes.isEmpty()) { return true; } - final int len = parentScopes.size(); - int index = 0; - String selector = parentScopes.get(index); - String selectorWithDot = selector + '.'; + if (target == null) { + return false; + } - while (target != null) { - if (matchesScope(target.scope, selector, selectorWithDot)) { - index++; - if (index == len) { - return true; + parent_scopes_loop: for (final String selector : parentScopes) { + final String selectorWithDot = selector + '.'; + + while (target != null) { + if (matchesScope(target.scope, selector, selectorWithDot)) { + // match for current parent scope found, continue with checking next parent scope + continue parent_scopes_loop; } - selector = parentScopes.get(index); - selectorWithDot = selector + '.'; + target = target.parent; } - target = target.parent; + // no match for current parent scope found, early exit + return false; } - return false; + // matches for all parent scopes found + return true; } public static int mergeMetadata(final int metadata, @Nullable final ScopeListElement scopesList, - final ScopeMetadata source) { + @Nullable final ScopeMetadata source) { if (source == null) { return metadata; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java index 308a46a44..3cec3927b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java @@ -13,16 +13,19 @@ import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; public final class ScopeMetadata { - private final String scopeName; + final String scopeName; final int languageId; final int tokenType; + + @Nullable final List themeData; - public ScopeMetadata(String scopeName, int languageId, int tokenType, List themeData) { + public ScopeMetadata(final String scopeName, final int languageId, final int tokenType, @Nullable final List themeData) { this.scopeName = scopeName; this.languageId = languageId; this.tokenType = tokenType; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java index 19688c67c..0afe7fcfd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java @@ -11,75 +11,72 @@ */ package org.eclipse.tm4e.core.internal.grammar; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.TMException; +import org.eclipse.tm4e.core.internal.utils.RegexSource; import org.eclipse.tm4e.core.theme.IThemeProvider; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts + */ final class ScopeMetadataProvider { - private static final ScopeMetadata _NULL_SCOPE_METADATA = new ScopeMetadata("", 0, StandardTokenType.Other, null); + private static final ScopeMetadata NULL_SCOPE_METADATA = new ScopeMetadata("", 0, StandardTokenType.Other, null); private static final Pattern STANDARD_TOKEN_TYPE_REGEXP = Pattern.compile("\\b(comment|string|regex)\\b"); private static final String COMMENT_TOKEN_TYPE = "comment"; private static final String STRING_TOKEN_TYPE = "string"; private static final String REGEX_TOKEN_TYPE = "regex"; + private static final String META_EMBEDDED_TOKEN_TYPE = "meta.embedded"; private final int initialLanguage; private final IThemeProvider themeProvider; - private final Map cache = new HashMap<>(); + private final Map cache = new HashMap<>(); + private ScopeMetadata defaultMetaData; + private final Map embeddedLanguages = new HashMap<>(); + + @Nullable private Pattern embeddedLanguagesRegex; - ScopeMetadataProvider(int initialLanguage, IThemeProvider themeProvider, - @Nullable Map embeddedLanguages) { + ScopeMetadataProvider(final int initialLanguage, final IThemeProvider themeProvider, + @Nullable final Map embeddedLanguages) { this.initialLanguage = initialLanguage; this.themeProvider = themeProvider; - this.onDidChangeTheme(); + this.defaultMetaData = new ScopeMetadata( + "", + this.initialLanguage, + StandardTokenType.Other, + List.of(this.themeProvider.getDefaults())); // embeddedLanguages handling if (embeddedLanguages != null) { - // If embeddedLanguages are configured, fill in - // `this._embeddedLanguages` - Set> languages = embeddedLanguages.entrySet(); - for (Entry language : languages) { - String scope = language.getKey(); - int languageId = language.getValue(); - /* - * if (typeof language !== 'number' || language === 0) { - * console.warn('Invalid embedded language found at scope ' + - * scope + ': <<' + language + '>>'); // never hurts to be too - * careful continue; } - */ - this.embeddedLanguages.put(scope, languageId); - } + // If embeddedLanguages are configured, fill in `this.embeddedLanguages` + this.embeddedLanguages.putAll(embeddedLanguages); } // create the regex - Set escapedScopes = this.embeddedLanguages.keySet().stream() - .map(ScopeMetadataProvider::escapeRegExpCharacters) - .collect(Collectors.toSet()); + final var escapedScopes = this.embeddedLanguages.keySet().stream() + .map(RegexSource::escapeRegExpCharacters) + .collect(Collectors.toList()); if (escapedScopes.isEmpty()) { // no scopes registered this.embeddedLanguagesRegex = null; } else { - // TODO!!! - this.embeddedLanguagesRegex = null; - // escapedScopes.sort(); - // escapedScopes.reverse(); - // this._embeddedLanguagesRegex = new - // RegExp(`^((${escapedScopes.join(')|(')}))($|\\.)`, ''); + this.embeddedLanguagesRegex = Pattern.compile("^((" + + escapedScopes.stream().sorted(Collections.reverseOrder()).collect(Collectors.joining(")|(")) + + "))($|\\.)"); } } @@ -89,26 +86,18 @@ void onDidChangeTheme() { "", this.initialLanguage, StandardTokenType.Other, - Arrays.asList(this.themeProvider.getDefaults())); + List.of(this.themeProvider.getDefaults())); } ScopeMetadata getDefaultMetadata() { return this.defaultMetaData; } - /** - * Escapes regular expression characters in a given string - */ - private static String escapeRegExpCharacters(String value) { - // TODO!!! - return value; // value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&'); - } - - ScopeMetadata getMetadataForScope(String scopeName) { + ScopeMetadata getMetadataForScope(@Nullable final String scopeName) { if (scopeName == null) { - return ScopeMetadataProvider._NULL_SCOPE_METADATA; + return ScopeMetadataProvider.NULL_SCOPE_METADATA; } - ScopeMetadata value = this.cache.get(scopeName); + var value = this.cache.get(scopeName); if (value != null) { return value; } @@ -117,51 +106,44 @@ ScopeMetadata getMetadataForScope(String scopeName) { return value; } - private ScopeMetadata doGetMetadataForScope(String scopeName) { - int languageId = this.scopeToLanguage(scopeName); - int standardTokenType = ScopeMetadataProvider.toStandardTokenType(scopeName); - List themeData = this.themeProvider.themeMatch(scopeName); + private ScopeMetadata doGetMetadataForScope(final String scopeName) { + final int languageId = this.scopeToLanguage(scopeName); + final int standardTokenType = ScopeMetadataProvider.toStandardTokenType(scopeName); + final List themeData = this.themeProvider.themeMatch(scopeName); return new ScopeMetadata(scopeName, languageId, standardTokenType, themeData); } /** - * Given a produced TM scope, return the language that token describes or - * null if unknown. e.g. source.html => html, source.css.embedded.html => - * css, punctuation.definition.tag.html => null + * Given a produced TM scope, return the language that token describes or null if unknown. + * e.g. source.html => html, source.css.embedded.html => css, punctuation.definition.tag.html => null */ - private int scopeToLanguage(String scope) { + private int scopeToLanguage(@Nullable final String scope) { if (scope == null) { return 0; } - if (this.embeddedLanguagesRegex == null) { + + final var embeddedLanguagesRegex = this.embeddedLanguagesRegex; + if (embeddedLanguagesRegex == null) { // no scopes registered return 0; } - // TODO!!!! - - /*let m = scope.match(this._embeddedLanguagesRegex); - if (!m) { + final var m = embeddedLanguagesRegex.matcher(scope); + if (!m.find()) { // no scopes matched return 0; } - let language = this._embeddedLanguages[m[1]] || 0; - if (!language) { - return 0; - } - - return language;*/ - return 0; + return embeddedLanguages.getOrDefault(m.group(1), 0); } - private static int toStandardTokenType(String tokenType) { - Matcher m = STANDARD_TOKEN_TYPE_REGEXP.matcher(tokenType); // tokenType.match(ScopeMetadataProvider.STANDARD_TOKEN_TYPE_REGEXP); + private static int toStandardTokenType(final String tokenType) { + final var m = STANDARD_TOKEN_TYPE_REGEXP.matcher(tokenType); if (!m.find()) { return StandardTokenType.Other; } - String group = m.group(); + final String group = m.group(1); switch (group) { case COMMENT_TOKEN_TYPE: return StandardTokenType.Comment; @@ -169,6 +151,8 @@ private static int toStandardTokenType(String tokenType) { return StandardTokenType.String; case REGEX_TOKEN_TYPE: return StandardTokenType.RegEx; + case META_EMBEDDED_TOKEN_TYPE: + return StandardTokenType.Other; default: throw new TMException("Unexpected match for standard token type: " + group); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index 2f92d187c..5e48609d9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.grammar; @@ -15,9 +15,7 @@ import org.eclipse.tm4e.core.theme.FontStyle; /** - * * Metadata for {@link StackElement}. - * */ public final class StackElementMetadata { @@ -33,34 +31,36 @@ static String toBinaryStr(final int metadata) { .toString(); } - static int getLanguageId(int metadata) { + static int getLanguageId(final int metadata) { return (metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET; } - static int getTokenType(int metadata) { + static int getTokenType(final int metadata) { return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET; } - static int getFontStyle(int metadata) { + static int getFontStyle(final int metadata) { return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET; } - public static int getForeground(int metadata) { + public static int getForeground(final int metadata) { return (metadata & MetadataConsts.FOREGROUND_MASK) >>> MetadataConsts.FOREGROUND_OFFSET; } - static int getBackground(int metadata) { + static int getBackground(final int metadata) { return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET; } - static int set(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { + static int set(final int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { languageId = languageId == 0 ? StackElementMetadata.getLanguageId(metadata) : languageId; tokenType = tokenType == StandardTokenType.Other ? StackElementMetadata.getTokenType(metadata) : tokenType; fontStyle = fontStyle == FontStyle.NotSet ? StackElementMetadata.getFontStyle(metadata) : fontStyle; foreground = foreground == 0 ? StackElementMetadata.getForeground(metadata) : foreground; background = background == 0 ? StackElementMetadata.getBackground(metadata) : background; - return ((languageId << MetadataConsts.LANGUAGEID_OFFSET) | (tokenType << MetadataConsts.TOKEN_TYPE_OFFSET) - | (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) | (foreground << MetadataConsts.FOREGROUND_OFFSET) + return ((languageId << MetadataConsts.LANGUAGEID_OFFSET) + | (tokenType << MetadataConsts.TOKEN_TYPE_OFFSET) + | (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) + | (foreground << MetadataConsts.FOREGROUND_OFFSET) | (background << MetadataConsts.BACKGROUND_OFFSET)) >>> 0; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java index 8ee0f3222..b106bbac5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java @@ -13,9 +13,8 @@ /** * Standard TextMate token type. - * */ -final class StandardTokenType { +class StandardTokenType { /** * Content should be accessed statically @@ -27,5 +26,4 @@ private StandardTokenType() { static final int Comment = 1; static final int String = 2; static final int RegEx = 3; - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java index 163f6fc5e..59a310ca6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Token.java @@ -28,7 +28,7 @@ final class Token implements IToken { private final List scopes; - Token(int startIndex, int endIndex, List scopes) { + Token(final int startIndex, final int endIndex, final List scopes) { this.startIndex = startIndex; this.endIndex = endIndex; this.scopes = scopes; @@ -40,7 +40,7 @@ public int getStartIndex() { } @Override - public void setStartIndex(int startIndex) { + public void setStartIndex(final int startIndex) { this.startIndex = startIndex; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java index 050b30775..eab6bd926 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java @@ -21,16 +21,14 @@ import org.eclipse.tm4e.core.grammar.StackElement; /** - * * Result of the line tokenization implementation. - * */ final class TokenizeLineResult implements ITokenizeLineResult { private final IToken[] tokens; private final StackElement ruleStack; - TokenizeLineResult(IToken[] tokens, StackElement ruleStack) { + TokenizeLineResult(final IToken[] tokens, final StackElement ruleStack) { this.tokens = tokens; this.ruleStack = ruleStack; } @@ -44,5 +42,4 @@ public IToken[] getTokens() { public StackElement getRuleStack() { return ruleStack; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java index 2d5a2186e..26f67ff4a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java @@ -20,16 +20,14 @@ import org.eclipse.tm4e.core.grammar.StackElement; /** - * * Result of the line tokenization2 implementation. - * */ final class TokenizeLineResult2 implements ITokenizeLineResult2 { private final int[] tokens; private final StackElement ruleStack; - TokenizeLineResult2(int[] tokens, StackElement ruleStack) { + TokenizeLineResult2(final int[] tokens, final StackElement ruleStack) { this.tokens = tokens; this.ruleStack = ruleStack; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/package-info.java new file mode 100644 index 000000000..1e721f14a --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.grammar; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java index 39b46340f..ea6b1b6af 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java @@ -36,15 +36,15 @@ public final class GrammarReader { private GrammarReader() { } - private static final PListParser XML_PARSER = new PListParserXML<>(Raw::new); private static final PListParser JSON_PARSER = new PListParserJSON<>(Raw::new); + private static final PListParser XML_PARSER = new PListParserXML<>(Raw::new); private static final PListParser YAML_PARSER = new PListParserYAML<>(Raw::new); - public static IRawGrammar readGrammarSync(String filePath, InputStream in) throws Exception { + public static IRawGrammar readGrammarSync(final String filePath, final InputStream in) throws Exception { return getGrammarParser(filePath).parse(in); } - private static PListParser getGrammarParser(String filePath) { + private static PListParser getGrammarParser(final String filePath) { String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); switch (extension) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/package-info.java new file mode 100644 index 000000000..838a708c2 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.grammar.reader; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java index 7356ad68b..9ed6d6fbe 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java @@ -19,5 +19,5 @@ @FunctionalInterface public interface MapFactory { - Map<@Nullable String, Object> createMap(); + Map<@Nullable String, @Nullable Object> createMap(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java index ebd49f705..b54d89aa2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java @@ -18,7 +18,7 @@ final class PListDict extends PListObject { - private final Map<@Nullable String, Object> values; + private final Map<@Nullable String, @Nullable Object> values; PListDict(@Nullable final PListObject parent, final MapFactory mapFactory) { super(parent); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java index b1a712360..fd0dd54c8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java @@ -43,7 +43,6 @@ final class PListParserContentHandler extends DefaultHandler { public void startElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName, @Nullable final Attributes attributes) throws SAXException { assert localName != null; - switch (localName) { case "dict": currObject = new PListDict(currObject, mapFactory); @@ -66,7 +65,6 @@ public void startElement(@Nullable final String uri, @Nullable final String loca public void endElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName) throws SAXException { assert localName != null; - endElement(localName); super.endElement(uri, localName, qName); } @@ -138,7 +136,9 @@ private void endElement(final String tagName) { assert value != null; if (currObject == null) { - result = (T) value; + @SuppressWarnings("unchecked") + final var t = (T) value; + result = t; } else if (currObject instanceof PListDict) { if (currObject.getLastKey() != null) { currObject.addValue(value); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java index 7aa455a19..25b14604d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java @@ -12,6 +12,7 @@ */ package org.eclipse.tm4e.core.internal.parser; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.castNonNull; import java.io.InputStream; import java.util.List; import java.util.Map; @@ -54,16 +55,16 @@ private void addMapToPList(final PListParserContentHandler pList, final Map entry : map.entrySet()) { + for (final Entry< String, Object> entry : map.entrySet()) { pList.startElement(null, "key", null, null); - pList.characters(entry.getKey().toCharArray(), 0, entry.getKey().length()); + pList.characters(castNonNull(entry.getKey()).toCharArray(), 0, castNonNull(entry.getKey()).length()); pList.endElement(null, "key", null); if (entry.getValue() instanceof List) { addListToPList(pList, (List) entry.getValue()); } else if (entry.getValue() instanceof Map) { addMapToPList(pList, (Map) entry.getValue()); } else { - addStringToPList(pList, entry.getValue().toString()); + addStringToPList(pList, castNonNull(entry.getValue()).toString()); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/IGrammarRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/IGrammarRepository.java index 246a81c1a..e185e12ac 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/IGrammarRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/IGrammarRepository.java @@ -18,6 +18,7 @@ import java.util.Collection; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.types.IRawGrammar; /** @@ -32,10 +33,12 @@ public interface IGrammarRepository { /** * Lookup a raw grammar. */ + @Nullable IRawGrammar lookup(String scopeName); /** * Returns the injections for the given grammar */ + @Nullable Collection injections(String targetScope); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java index fb7a82524..d620448e6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java @@ -16,14 +16,16 @@ */ package org.eclipse.tm4e.core.internal.registry; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.internal.grammar.Grammar; import org.eclipse.tm4e.core.internal.grammar.Raw; @@ -34,18 +36,23 @@ import org.eclipse.tm4e.core.theme.Theme; import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/registry.ts + */ public final class SyncRegistry implements IGrammarRepository, IThemeProvider { private final Map grammars = new HashMap<>(); - private final Map rawGrammars = new HashMap<>(); - private final Map> injectionGrammars = new HashMap<>(); + private final Map<@Nullable String, IRawGrammar> rawGrammars = new HashMap<>(); + private final Map<@Nullable String, Collection> injectionGrammars = new HashMap<>(); private Theme theme; - public SyncRegistry(Theme theme) { + public SyncRegistry(final Theme theme) { this.theme = theme; } - public void setTheme(Theme theme) { + public void setTheme(final Theme theme) { this.theme = theme; this.grammars.values().forEach(Grammar::onDidChangeTheme); } @@ -56,10 +63,13 @@ public Set getColorMap() { /** * Add `grammar` to registry and return a list of referenced scope names + * + * TODO implementation differs from upstream */ - public Collection addGrammar(IRawGrammar grammar, Collection injectionScopeNames) { + public Collection addGrammar(final IRawGrammar grammar, + @Nullable final Collection injectionScopeNames) { this.rawGrammars.put(grammar.getScopeName(), grammar); - Collection includedScopes = new ArrayList<>(); + final Collection includedScopes = new ArrayList<>(); collectIncludedScopes(includedScopes, grammar); if (injectionScopeNames != null) { @@ -70,12 +80,14 @@ public Collection addGrammar(IRawGrammar grammar, Collection inj } @Override - public IRawGrammar lookup(String scopeName) { + @Nullable + public IRawGrammar lookup(final String scopeName) { return this.rawGrammars.get(scopeName); } @Override - public Collection injections(String targetScope) { + @Nullable + public Collection injections(final String targetScope) { return this.injectionGrammars.get(targetScope); } @@ -91,31 +103,34 @@ public ThemeTrieElementRule getDefaults() { * Match a scope in the theme. */ @Override - public List themeMatch(String scopeName) { + public List themeMatch(final String scopeName) { return this.theme.match(scopeName); } /** * Lookup a grammar. */ - public IGrammar grammarForScopeName(String scopeName, int initialLanguage, - Map embeddedLanguages) { + @Nullable + public IGrammar grammarForScopeName(final String scopeName, final int initialLanguage, + @Nullable final Map embeddedLanguages) { if (!this.grammars.containsKey(scopeName)) { - IRawGrammar rawGrammar = lookup(scopeName); + final var rawGrammar = lookup(scopeName); if (rawGrammar == null) { return null; } - this.grammars.put(scopeName, new Grammar(rawGrammar, initialLanguage, embeddedLanguages, this, this)); + this.grammars.put(scopeName, + new Grammar(scopeName, rawGrammar, initialLanguage, embeddedLanguages, this, this)); } return this.grammars.get(scopeName); } - private static void collectIncludedScopes(Collection result, IRawGrammar grammar) { - if (grammar.getPatterns() != null /* && Array.isArray(grammar.patterns) */) { - extractIncludedScopesInPatterns(result, grammar.getPatterns()); + private static void collectIncludedScopes(final Collection result, final IRawGrammar grammar) { + final var grammarPattners = grammar.getPatterns(); + if (grammarPattners != null) { + extractIncludedScopesInPatterns(result, grammarPattners); } - IRawRepository repository = grammar.getRepository(); + final IRawRepository repository = grammar.getRepository(); if (repository != null) { extractIncludedScopesInRepository(result, repository); } @@ -127,19 +142,20 @@ private static void collectIncludedScopes(Collection result, IRawGrammar /** * Fill in `result` all external included scopes in `patterns` */ - private static void extractIncludedScopesInPatterns(Collection result, Collection patterns) { - for (IRawRule pattern : patterns) { - Collection p = pattern.getPatterns(); + private static void extractIncludedScopesInPatterns(final Collection result, + final Collection patterns) { + for (final IRawRule pattern : patterns) { + final Collection p = pattern.getPatterns(); if (p != null) { extractIncludedScopesInPatterns(result, p); } - String include = pattern.getInclude(); + final String include = pattern.getInclude(); if (include == null) { continue; } - if (include.equals("$base") || include.equals("$self")) { + if (include.equals(Raw.DOLLAR_BASE) || include.equals(Raw.DOLLAR_SELF)) { // Special includes that can be resolved locally in this grammar continue; } @@ -149,7 +165,7 @@ private static void extractIncludedScopesInPatterns(Collection result, C continue; } - int sharpIndex = include.indexOf('#'); + final int sharpIndex = include.indexOf('#'); if (sharpIndex >= 0) { addIncludedScope(include.substring(0, sharpIndex), result); } else { @@ -158,7 +174,7 @@ private static void extractIncludedScopesInPatterns(Collection result, C } } - private static void addIncludedScope(String scopeName, Collection includedScopes) { + private static void addIncludedScope(final String scopeName, final Collection includedScopes) { if (!includedScopes.contains(scopeName)) { includedScopes.add(scopeName); } @@ -167,20 +183,22 @@ private static void addIncludedScope(String scopeName, Collection includ /** * Fill in `result` all external included scopes in `repository` */ - private static void extractIncludedScopesInRepository(Collection result, IRawRepository repository) { + private static void extractIncludedScopesInRepository(final Collection result, + final IRawRepository repository) { if (!(repository instanceof Raw)) { return; } - Raw rawRepository = (Raw) repository; - for (Entry entry : rawRepository.entrySet()) { - IRawRule rule = (IRawRule) entry.getValue(); - if (rule.getPatterns() != null) { - extractIncludedScopesInPatterns(result, rule.getPatterns()); + final Raw rawRepository = (Raw) repository; + for (final var entry : rawRepository.values()) { + final IRawRule rule = (IRawRule) castNonNull(entry); + final var patterns = rule.getPatterns(); + if (patterns != null) { + extractIncludedScopesInPatterns(result, patterns); } - if (rule.getRepository() != null) { - extractIncludedScopesInRepository(result, rule.getRepository()); + final var repo = rule.getRepository(); + if (repo != null) { + extractIncludedScopesInRepository(result, repo); } } } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/package-info.java new file mode 100644 index 000000000..11cd82628 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.registry; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index 894fef8b4..141255d61 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -42,7 +42,7 @@ public final class BeginWhileRule extends Rule { @Nullable private RegExpSourceList cachedCompiledWhilePatterns; - BeginWhileRule(/* $location:ILocation, */ int id, String name, String contentName, String begin, + BeginWhileRule(int id, @Nullable String name, @Nullable String contentName, String begin, List<@Nullable CaptureRule> beginCaptures, String _while, List<@Nullable CaptureRule> whileCaptures, CompilePatternsResult patterns) { super(/* $location, */id, name, contentName); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java index 2d7608e47..c89bed843 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IRuleRegistry.java @@ -25,6 +25,9 @@ */ public interface IRuleRegistry { + /** + * @throws IndexOutOfBoundsException if no rule with the given id was found. + */ Rule getRule(int patternId); T registerRule(IntFunction factory); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java index 22a38c789..e585638c3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java @@ -33,7 +33,7 @@ public final class MatchRule extends Rule { @Nullable private RegExpSourceList cachedCompiledPatterns; - MatchRule(final int id, final String name, final String match, final List<@Nullable CaptureRule> captures) { + MatchRule(final int id, @Nullable final String name, final String match, final List<@Nullable CaptureRule> captures) { super(id, name, null); this.match = new RegExpSource(match, this.id); this.captures = captures; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index 0be03b85e..e9b910c2c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -16,6 +16,8 @@ */ package org.eclipse.tm4e.core.internal.rule; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import static java.lang.System.Logger.Level.*; import java.lang.System.Logger; @@ -40,8 +42,8 @@ public final class RuleFactory { private static final Logger LOGGER = System.getLogger(RuleFactory.class.getName()); - private static CaptureRule createCaptureRule(final IRuleFactoryHelper helper, final String name, - final String contentName, @Nullable final Integer retokenizeCapturedWithRuleId) { + private static CaptureRule createCaptureRule(final IRuleFactoryHelper helper, @Nullable final String name, + @Nullable final String contentName, @Nullable final Integer retokenizeCapturedWithRuleId) { return helper.registerRule(id -> new CaptureRule(id, name, contentName, retokenizeCapturedWithRuleId)); } @@ -57,7 +59,8 @@ public static int getCompiledRuleId(final IRawRule desc, final IRuleFactoryHelpe compileCaptures(desc.getCaptures(), helper, repository)); } - if (desc.getBegin() == null) { + final var begin = desc.getBegin(); + if (begin == null) { final var repository1 = desc.getRepository() == null ? repository : IRawRepository.merge(repository, desc.getRepository()); @@ -82,7 +85,7 @@ public static int getCompiledRuleId(final IRawRule desc, final IRuleFactoryHelpe ruleId, desc.getName(), desc.getContentName(), - desc.getBegin(), compileCaptures( + begin, compileCaptures( desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(), helper, repository), ruleWhile, compileCaptures( @@ -96,7 +99,7 @@ ruleWhile, compileCaptures( ruleId, desc.getName(), desc.getContentName(), - desc.getBegin(), compileCaptures( + begin, compileCaptures( desc.getBeginCaptures() != null ? desc.getBeginCaptures() : desc.getCaptures(), helper, repository), desc.getEnd(), compileCaptures( @@ -106,7 +109,7 @@ ruleWhile, compileCaptures( compilePatterns(desc.getPatterns(), helper, repository)); }); } - return desc.getId(); + return castNonNull(desc.getId()); } private static List<@Nullable CaptureRule> compileCaptures(@Nullable final IRawCaptures captures, @@ -160,7 +163,6 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< final var r = new ArrayList(); for (final IRawRule pattern : patterns) { int patternId = -1; - final var patternInclude = pattern.getInclude(); if (patternInclude == null) { patternId = getCompiledRuleId(pattern, helper, repository); @@ -174,10 +176,10 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< LOGGER.log(DEBUG, "CANNOT find rule for scopeName: %s, I am: %s", patternInclude, repository.getBase().getName()); } - } else if (patternInclude.equals(Raw.DOLLAR_BASE) || patternInclude.equals(Raw.DOLLAR_SELF)) { - // Special include also found in `repository` - patternId = getCompiledRuleId(repository.getProp(patternInclude), helper, - repository); + } else if (patternInclude.equals(Raw.DOLLAR_BASE)) { // Special include also found in `repository` + patternId = getCompiledRuleId(repository.getBase(), helper, repository); + } else if (patternInclude.equals(Raw.DOLLAR_SELF)) { // Special include also found in `repository` + patternId = getCompiledRuleId(repository.getSelf(), helper, repository); } else { final String externalGrammarName; final String externalGrammarInclude; @@ -193,19 +195,17 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< // External include final IRawGrammar externalGrammar = helper.getExternalGrammar(externalGrammarName, repository); if (externalGrammar != null) { + final var externalGrammarRepo = externalGrammar.getRepositorySafe(); if (externalGrammarInclude != null) { - final IRawRule externalIncludedRule = externalGrammar.getRepository() - .getProp(externalGrammarInclude); + final IRawRule externalIncludedRule = externalGrammarRepo.getProp(externalGrammarInclude); if (externalIncludedRule != null) { - patternId = getCompiledRuleId(externalIncludedRule, helper, - externalGrammar.getRepository()); + patternId = getCompiledRuleId(externalIncludedRule, helper, externalGrammarRepo); } else if (LOGGER.isLoggable(DEBUG)) { LOGGER.log(DEBUG, "CANNOT find rule for scopeName: %s, I am: %s", patternInclude, repository.getBase().getName()); } } else { - patternId = getCompiledRuleId(externalGrammar.getRepository().getSelf(), - helper, externalGrammar.getRepository()); + patternId = getCompiledRuleId(externalGrammarRepo.getSelf(), helper, externalGrammarRepo); } } else if (LOGGER.isLoggable(DEBUG)) { LOGGER.log(DEBUG, "CANNOT find grammar for scopeName: %s, I am: %s", @@ -215,7 +215,18 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< } if (patternId != -1) { - final Rule rule = helper.getRule(patternId); + Rule rule; + try { + rule = helper.getRule(patternId); + } catch (IndexOutOfBoundsException ex) { + rule = null; + if (patternInclude != null) { + // TODO currently happens if an include rule references another not yet parsed rule + } else { + // should never happen + ex.printStackTrace(); + } + } boolean skipRule = false; if (rule instanceof IncludeOnlyRule) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java index d699257c7..8b14408d0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java @@ -19,5 +19,4 @@ public interface IRawCaptures extends Iterable { IRawRule getCapture(String captureId); - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java index 920859f5f..f64f11eb1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java @@ -19,25 +19,40 @@ import java.util.Collection; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; + +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/rawGrammar.ts + */ public interface IRawGrammar { IRawGrammar clone(); + @Nullable IRawRepository getRepository(); + IRawRepository getRepositorySafe(); + String getScopeName(); + @Nullable Collection getPatterns(); + @Nullable Map getInjections(); + @Nullable String getInjectionSelector(); // injections?:{ [expression:string]: IRawRule }; Collection getFileTypes(); + @Nullable String getName(); + @Nullable String getFirstLineMatch(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java index 112d4b7f0..356745acc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,33 +11,36 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.types; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.grammar.Raw; public interface IRawRepository { - static IRawRepository merge(IRawRepository... sources) { - final Raw merged = new Raw(); + static IRawRepository merge(@Nullable IRawRepository... sources) { + final Raw merged = new Raw(); for (final IRawRepository source : sources) { - final Set> entries = source.entrySet(); - for (final Entry entry : entries) { + if (source == null) + continue; + final Set> entries = source.entrySet(); + for (final Entry<@Nullable String, @Nullable Object> entry : entries) { merged.put(entry.getKey(), entry.getValue()); } } return merged; } - Set> entrySet(); + Set> entrySet(); + @Nullable IRawRule getProp(String name); IRawRule getBase(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java index e1e1fcc46..920da32e8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.types; @@ -22,58 +22,71 @@ public interface IRawRule { + @Nullable Integer getId(); - void setId(Integer id); + void setId(@Nullable Integer id); + @Nullable String getInclude(); - void setInclude(String include); + void setInclude(@Nullable String include); + @Nullable String getName(); - void setName(String name); + void setName(@Nullable String name); + @Nullable String getContentName(); - void setContentName(String name); + void setContentName(@Nullable String name); + @Nullable String getMatch(); - void setMatch(String match); + void setMatch(@Nullable String match); + @Nullable IRawCaptures getCaptures(); - void setCaptures(IRawCaptures captures); + void setCaptures(@Nullable IRawCaptures captures); + @Nullable String getBegin(); - void setBegin(String begin); + void setBegin(@Nullable String begin); @Nullable IRawCaptures getBeginCaptures(); - void setBeginCaptures(IRawCaptures beginCaptures); + void setBeginCaptures(@Nullable IRawCaptures beginCaptures); + @Nullable String getEnd(); - void setEnd(String end); + void setEnd(@Nullable String end); + @Nullable String getWhile(); + @Nullable IRawCaptures getEndCaptures(); - void setEndCaptures(IRawCaptures endCaptures); + void setEndCaptures(@Nullable IRawCaptures endCaptures); + @Nullable IRawCaptures getWhileCaptures(); + @Nullable Collection getPatterns(); - void setPatterns(Collection patterns); + void setPatterns(@Nullable Collection patterns); + @Nullable IRawRepository getRepository(); - void setRepository(IRawRepository repository); + void setRepository(@Nullable IRawRepository repository); boolean isApplyEndPatternLast(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/package-info.java new file mode 100644 index 000000000..16526224a --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.types; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java new file mode 100644 index 000000000..83878d01f --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.utils; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; + +public final class NullSafetyHelper { + + public static Iterator<@NonNull T> castNonNull(@Nullable Iterator value) { + assert value != null; + return value; + } + + @NonNull + public static T castNonNull(@Nullable T value) { + assert value != null; + return value; + } + + /** + * @param list a non-empty list with non-nullable elements + */ + @NonNull + public static T getLastElement(List list) { + final var value = list.get(list.size() - 1); + assert value != null; + return value; + } + + private NullSafetyHelper() { + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java index 61b4180ef..21d31151b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.registry; @@ -20,8 +20,16 @@ import java.io.InputStream; import java.util.Collection; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IRawTheme; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts + * + */ public interface IRegistryOptions { IRegistryOptions DEFAULT_LOCATOR = new IRegistryOptions() { @@ -30,7 +38,7 @@ public interface IRegistryOptions { public String getFilePath(String scopeName) { return null; } - + @Override public InputStream getInputStream(String scopeName) { return null; @@ -40,17 +48,18 @@ public InputStream getInputStream(String scopeName) { public Collection getInjections(String scopeName) { return null; } - + }; - + default IRawTheme getTheme() { return null; } - + String getFilePath(String scopeName); InputStream getInputStream(String scopeName) throws IOException; - - Collection getInjections(String scopeName); - + + @Nullable + Collection<@NonNull String> getInjections(String scopeName); + } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index 4051c9b9a..8bf2ac480 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -36,7 +36,8 @@ /** * The registry that will hold all grammars. * - * @see + * @see * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts * */ @@ -87,8 +88,7 @@ public IGrammar loadGrammar(String initialScopeName) { if (filePath == null) { if (scopeName.equals(initialScopeName)) { throw new TMException("Unknown location for grammar <" + initialScopeName + ">"); - // callback(new Error('Unknown location for grammar <' + - // initialScopeName + '>'), null); + // callback(new Error('Unknown location for grammar <' + initialScopeName + '>'), null); // return; } continue; @@ -107,8 +107,7 @@ public IGrammar loadGrammar(String initialScopeName) { } } catch (Throwable e) { if (scopeName.equals(initialScopeName)) { - // callback(new Error('Unknown location for grammar <' + - // initialScopeName + '>'), null); + // callback(new Error('Unknown location for grammar <' + initialScopeName + '>'), null); // return; throw new TMException("Unknown location for grammar <" + initialScopeName + ">", e); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java index b26c341d3..08692964a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java @@ -13,9 +13,12 @@ import java.util.List; +import org.eclipse.jdt.annotation.NonNull; + public interface IThemeProvider { - List themeMatch(String scopeName); + @NonNull + List themeMatch(@NonNull String scopeName); ThemeTrieElementRule getDefaults(); diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java index e8a379627..9a342a5e2 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java @@ -13,9 +13,10 @@ import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.Collection; +import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.Data; import org.eclipse.tm4e.core.registry.IRegistryOptions; import org.eclipse.tm4e.core.registry.Registry; @@ -46,17 +47,19 @@ public void angular2TokenizeLine() throws Exception { Registry registry = new Registry(new IRegistryOptions() { @Override - public InputStream getInputStream(String scopeName) throws IOException { + public InputStream getInputStream(@Nullable String scopeName) throws IOException { return Data.class.getResourceAsStream(getFilePath(scopeName)); } + @Nullable @Override - public Collection getInjections(String scopeName) { - return Arrays.asList("template.ng", "styles.ng"); + public Collection getInjections(@Nullable String scopeName) { + return List.of("template.ng", "styles.ng"); } + @Nullable @Override - public String getFilePath(String scopeName) { + public String getFilePath(@Nullable String scopeName) { if (scopeName != null) { switch (scopeName) { case "source.js": From 686ceb633dd42b3cc57cb5bf29d7071e705c5118 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 30 Apr 2022 19:58:46 +0200 Subject: [PATCH 129/202] Refactor registry package, enable annotation-based null analysis --- .../tm4e/core/registry/IRegistryOptions.java | 14 ++-- .../eclipse/tm4e/core/registry/Registry.java | 68 ++++++++++--------- .../tm4e/core/registry/package-info.java | 4 ++ .../org/eclipse/tm4e/core/TestGrammar.java | 12 ++-- .../core/grammar/GrammarInjectionTest.java | 5 +- .../tm4e/core/grammar/GrammarTest.java | 6 +- .../tm4e/core/grammar/GrammarTest2.java | 4 +- .../eclipse/tm4e/core/grammar/MarkDown.java | 16 +++-- 8 files changed, 76 insertions(+), 53 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java index 21d31151b..857ecf0e4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java @@ -28,38 +28,42 @@ * @see * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts - * */ public interface IRegistryOptions { IRegistryOptions DEFAULT_LOCATOR = new IRegistryOptions() { + @Nullable @Override - public String getFilePath(String scopeName) { + public String getFilePath(final String scopeName) { return null; } + @Nullable @Override - public InputStream getInputStream(String scopeName) { + public InputStream getInputStream(final String scopeName) { return null; } + @Nullable @Override - public Collection getInjections(String scopeName) { + public Collection getInjections(final String scopeName) { return null; } }; + @Nullable default IRawTheme getTheme() { return null; } + @Nullable String getFilePath(String scopeName); + @Nullable InputStream getInputStream(String scopeName) throws IOException; @Nullable Collection<@NonNull String> getInjections(String scopeName); - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index 8bf2ac480..d3824a485 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -20,22 +20,23 @@ import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.TMException; import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; import org.eclipse.tm4e.core.internal.registry.SyncRegistry; -import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.theme.IRawTheme; import org.eclipse.tm4e.core.theme.Theme; /** * The registry that will hold all grammars. * + * TODO outdated compared to upstream as of: https://github.com/microsoft/vscode-textmate/commit/b166b75fa72d2dd3efce0d68c98c2bd10adc1ef1 + * * @see * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts @@ -50,16 +51,15 @@ public Registry() { this(IRegistryOptions.DEFAULT_LOCATOR); } - public Registry(IRegistryOptions locator) { + public Registry(final IRegistryOptions locator) { this.locator = locator; this.syncRegistry = new SyncRegistry(Theme.createFromRawTheme(locator.getTheme())); } /** - * Change the theme. Once called, no previous `ruleStack` should be used - * anymore. + * Change the theme. Once called, no previous `ruleStack` should be used anymore. */ - public void setTheme(IRawTheme theme) { + public void setTheme(final IRawTheme theme) { this.syncRegistry.setTheme(Theme.createFromRawTheme(theme)); } @@ -70,45 +70,45 @@ public Set getColorMap() { return this.syncRegistry.getColorMap(); } - public IGrammar loadGrammar(String initialScopeName) { - List remainingScopeNames = new ArrayList<>(); + @Nullable + public IGrammar loadGrammar(final String initialScopeName) { + final List remainingScopeNames = new ArrayList<>(); remainingScopeNames.add(initialScopeName); - List seenScopeNames = new ArrayList<>(); + final List seenScopeNames = new ArrayList<>(); seenScopeNames.add(initialScopeName); while (!remainingScopeNames.isEmpty()) { - String scopeName = remainingScopeNames.remove(0); // shift(); + final String scopeName = remainingScopeNames.remove(0); if (this.syncRegistry.lookup(scopeName) != null) { continue; } - String filePath = this.locator.getFilePath(scopeName); + final String filePath = this.locator.getFilePath(scopeName); if (filePath == null) { if (scopeName.equals(initialScopeName)) { throw new TMException("Unknown location for grammar <" + initialScopeName + ">"); - // callback(new Error('Unknown location for grammar <' + initialScopeName + '>'), null); - // return; } continue; } try (InputStream in = this.locator.getInputStream(scopeName)) { - IRawGrammar grammar = GrammarReader.readGrammarSync(filePath, in); - Collection injections = this.locator.getInjections(scopeName); + if (in == null) { + throw new TMException("Unknown location for grammar <" + initialScopeName + ">"); + } + final var grammar = GrammarReader.readGrammarSync(filePath, in); + final var injections = this.locator.getInjections(scopeName); - Collection deps = this.syncRegistry.addGrammar(grammar, injections); - for (String dep : deps) { + final var deps = this.syncRegistry.addGrammar(grammar, injections); + for (final String dep : deps) { if (!seenScopeNames.contains(dep)) { seenScopeNames.add(dep); remainingScopeNames.add(dep); } } - } catch (Throwable e) { + } catch (final Exception e) { if (scopeName.equals(initialScopeName)) { - // callback(new Error('Unknown location for grammar <' + initialScopeName + '>'), null); - // return; throw new TMException("Unknown location for grammar <" + initialScopeName + ">", e); } } @@ -116,38 +116,42 @@ public IGrammar loadGrammar(String initialScopeName) { return this.grammarForScopeName(initialScopeName); } - public IGrammar loadGrammarFromPathSync(File file) throws Exception { + @Nullable + public IGrammar loadGrammarFromPathSync(final File file) throws Exception { try (InputStream is = new FileInputStream(file)) { return loadGrammarFromPathSync(file.getPath(), is); } } - public IGrammar loadGrammarFromPathSync(String path, InputStream in) throws Exception { + @Nullable + public IGrammar loadGrammarFromPathSync(final String path, final InputStream in) throws Exception { return loadGrammarFromPathSync(path, in, 0, null); } /** * Load the grammar at `path` synchronously. - * - * @throws Exception */ - public IGrammar loadGrammarFromPathSync(String path, InputStream in, int initialLanguage, - Map embeddedLanguages) throws Exception { - IRawGrammar rawGrammar = GrammarReader.readGrammarSync(path, in); - Collection injections = this.locator.getInjections(rawGrammar.getScopeName()); + @Nullable + public IGrammar loadGrammarFromPathSync(final String path, final InputStream in, final int initialLanguage, + @Nullable final Map embeddedLanguages) throws Exception { + final var rawGrammar = GrammarReader.readGrammarSync(path, in); + final var injections = this.locator.getInjections(rawGrammar.getScopeName()); this.syncRegistry.addGrammar(rawGrammar, injections); return this.grammarForScopeName(rawGrammar.getScopeName(), initialLanguage, embeddedLanguages); } - public IGrammar grammarForScopeName(String scopeName) { + @Nullable + public IGrammar grammarForScopeName(final String scopeName) { return grammarForScopeName(scopeName, 0, null); } /** - * Get the grammar for `scopeName`. The grammar must first be created via - * `loadGrammar` or `loadGrammarFromPathSync`. + * Get the grammar for `scopeName`. + * The grammar must first be created via `loadGrammar` or `loadGrammarFromPathSync`. */ - public IGrammar grammarForScopeName(String scopeName, int initialLanguage, Map embeddedLanguages) { + @Nullable + public IGrammar grammarForScopeName(final String scopeName, final int initialLanguage, + @Nullable final Map embeddedLanguages) { return this.syncRegistry.grammarForScopeName(scopeName, initialLanguage, embeddedLanguages); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/package-info.java new file mode 100644 index 000000000..1b343fe1f --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.registry; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java index f0b78972f..d2c4b2d12 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/TestGrammar.java @@ -1,16 +1,18 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; import org.eclipse.tm4e.core.registry.Registry; @@ -20,8 +22,8 @@ public class TestGrammar { public static void main(String[] args) throws Exception { Registry registry = new Registry(); - IGrammar grammar = registry.loadGrammarFromPathSync("Angular2TypeScript.tmLanguage", - TestGrammar.class.getResourceAsStream("Angular2TypeScript.tmLanguage")); + IGrammar grammar = castNonNull(registry.loadGrammarFromPathSync("Angular2TypeScript.tmLanguage", + TestGrammar.class.getResourceAsStream("Angular2TypeScript.tmLanguage"))); ITokenizeLineResult result = grammar.tokenizeLine("/** **/"); for (int i = 0; i < result.getTokens().length; i++) { diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java index 9a342a5e2..c502ccef6 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarInjectionTest.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.core.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.io.IOException; import java.io.InputStream; import java.util.Collection; @@ -46,6 +48,7 @@ public class GrammarInjectionTest { public void angular2TokenizeLine() throws Exception { Registry registry = new Registry(new IRegistryOptions() { + @Nullable @Override public InputStream getInputStream(@Nullable String scopeName) throws IOException { return Data.class.getResourceAsStream(getFilePath(scopeName)); @@ -78,7 +81,7 @@ public String getFilePath(@Nullable String scopeName) { } }); IGrammar grammar = registry.loadGrammar("source.ts"); - ITokenizeLineResult lineTokens = grammar.tokenizeLine("@Component({template:``})"); + final var lineTokens = castNonNull(grammar).tokenizeLine("@Component({template:``})"); for (int i = 0; i < lineTokens.getTokens().length; i++) { IToken token = lineTokens.getTokens()[i]; String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes " diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java index 44ca2ffec..7da49b48c 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.core.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import org.eclipse.tm4e.core.Data; import org.eclipse.tm4e.core.registry.Registry; import org.junit.jupiter.api.Assertions; @@ -62,7 +64,7 @@ public void tokenizeLine() throws Exception { Registry registry = new Registry(); String path = "JavaScript.tmLanguage"; IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path)); - ITokenizeLineResult lineTokens = grammar.tokenizeLine("function add(a,b) { return a+b; }"); + ITokenizeLineResult lineTokens = castNonNull(grammar).tokenizeLine("function add(a,b) { return a+b; }"); for (int i = 0; i < lineTokens.getTokens().length; i++) { IToken token = lineTokens.getTokens()[i]; String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes " @@ -82,7 +84,7 @@ public void tokenizeLines() throws Exception { int j = 0; String[] lines = { "function add(a,b)", "{ return a+b; }" }; for (int l = 0; l < lines.length; l++) { - ITokenizeLineResult lineTokens = grammar.tokenizeLine(lines[l], ruleStack); + ITokenizeLineResult lineTokens = castNonNull(grammar).tokenizeLine(lines[l], ruleStack); ruleStack = lineTokens.getRuleStack(); for (i = 0; i < lineTokens.getTokens().length; i++) { IToken token = lineTokens.getTokens()[i]; diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java index c527140ec..dce646d42 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.core.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; @@ -30,7 +32,7 @@ class GrammarTest2 { void tokenizeLines() throws Exception { Registry registry = new Registry(); String path = "JavaScript.tmLanguage"; - IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path)); + IGrammar grammar = castNonNull(registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path))); StackElement ruleStack = null; int i = 0; diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java index 8e0b59d32..d31a4c0a2 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.core.grammar; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; @@ -24,8 +26,8 @@ public class MarkDown { public static void main(String[] args) throws Exception { Registry registry = new Registry(); String path = "Markdown.tmLanguage"; - IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path)); - + IGrammar grammar = castNonNull(registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path))); + List lines = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("test.md.txt")))) { String line = null; @@ -36,13 +38,13 @@ public static void main(String[] args) throws Exception { e.printStackTrace(); } - + long start = System.currentTimeMillis(); - + StackElement ruleStack = null; int i = 0; for (String line : lines) { - ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack); + ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack); ruleStack = lineTokens.getRuleStack(); for (i = 0; i < lineTokens.getTokens().length; i++) { // IToken token = lineTokens.getTokens()[i]; @@ -51,10 +53,10 @@ public static void main(String[] args) throws Exception { //System.err.println(s); // Assert.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s); } - } + } System.err.println(System.currentTimeMillis() - start); } - + static String convertStreamToString(java.io.InputStream is) { try (java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A")) { return s.hasNext() ? s.next() : ""; From 556af05621b59dc068bcccca481e8a194bd04a5d Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 30 Apr 2022 20:16:28 +0200 Subject: [PATCH 130/202] add MoreCollections utility class --- .../core/internal/grammar/LineTokenizer.java | 5 +- .../core/internal/grammar/LineTokens.java | 7 +-- .../core/internal/utils/MoreCollections.java | 49 +++++++++++++++++++ .../core/internal/utils/NullSafetyHelper.java | 11 ----- .../org/eclipse/tm4e/core/theme/Theme.java | 3 +- 5 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index ea155321a..55bc70542 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -16,6 +16,7 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; import static java.lang.System.Logger.Level.*; @@ -447,7 +448,7 @@ private void handleCaptures(final Grammar grammar, final OnigString lineText, fi while (!localStack.isEmpty() && getLastElement(localStack).endPos <= captureIndex.start) { // pop! lineTokens.produceFromScopes(getLastElement(localStack).scopes, getLastElement(localStack).endPos); - localStack.remove(localStack.size() - 1); + removeLastElement(localStack); } if (!localStack.isEmpty()) { @@ -488,7 +489,7 @@ private void handleCaptures(final Grammar grammar, final OnigString lineText, fi while (!localStack.isEmpty()) { // pop! lineTokens.produceFromScopes(getLastElement(localStack).scopes, getLastElement(localStack).endPos); - localStack.remove(localStack.size() - 1); + removeLastElement(localStack); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index fe8365768..e28d8dced 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -16,6 +16,7 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; import static java.lang.System.Logger.Level.*; @@ -106,7 +107,7 @@ void produceFromScopes(final ScopeListElement scopesList, final int endIndex) { IToken[] getResult(final StackElement stack, final int lineLength) { if (!this.tokens.isEmpty() && getLastElement(this.tokens).getStartIndex() == lineLength - 1) { // pop produced token for newline - this.tokens.remove(this.tokens.size() - 1); + removeLastElement(this.tokens); } if (this.tokens.isEmpty()) { @@ -121,8 +122,8 @@ IToken[] getResult(final StackElement stack, final int lineLength) { int[] getBinaryResult(final StackElement stack, final int lineLength) { if (!this.binaryTokens.isEmpty() && this.binaryTokens.get(binaryTokens.size() - 2) == lineLength - 1) { // pop produced token for newline - this.binaryTokens.remove(binaryTokens.size() - 1); - this.binaryTokens.remove(binaryTokens.size() - 1); + removeLastElement(this.binaryTokens); + removeLastElement(this.binaryTokens); } if (this.binaryTokens.isEmpty()) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java new file mode 100644 index 000000000..2a5033f54 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.utils; + +import java.util.List; + +import org.eclipse.jdt.annotation.Nullable; + +public final class MoreCollections { + + @Nullable + public static T findLastElement(@Nullable List list) { + if (list == null || list.isEmpty()) + return null; + return getLastElement(list); + } + + /** + * @param list a non-empty list with non-nullable elements + */ + public static T getLastElement(List list) { + return list.get(list.size() - 1); + } + + /** + * Removes the last element in this list. + * + * @return the element previously at the specified position + * + * @throws UnsupportedOperationException if the {@code remove} operation is not supported by this list + * @throws IndexOutOfBoundsException if the list is empty + */ + public static T removeLastElement(List list) { + return list.remove(list.size() - 1); + } + + private MoreCollections() { + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java index 83878d01f..931e0fbd1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java @@ -13,7 +13,6 @@ package org.eclipse.tm4e.core.internal.utils; import java.util.Iterator; -import java.util.List; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -31,16 +30,6 @@ public static T castNonNull(@Nullable T value) { return value; } - /** - * @param list a non-empty list with non-nullable elements - */ - @NonNull - public static T getLastElement(List list) { - final var value = list.get(list.size() - 1); - assert value != null; - return value; - } - private NullSafetyHelper() { } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index 6c9813623..b29510588 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.core.theme; +import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -124,7 +125,7 @@ public static List parseTheme(IRawTheme source) { List segments = BY_SPACE_SPLITTER.splitToList(_scope); - String scope = segments.get(segments.size() - 1); + String scope = getLastElement(segments); List parentScopes = null; if (segments.size() > 1) { parentScopes = segments.subList(0, segments.size() - 1); From 2b5a5b4792fc57c22d3ce0cf13ab6230200eefa7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 30 Apr 2022 21:25:24 +0200 Subject: [PATCH 131/202] Refactor model package, enable annotation-based null analysis --- .../tm4e/core/model/AbstractLineList.java | 37 +++-- .../eclipse/tm4e/core/model/DecodeMap.java | 20 +-- .../eclipse/tm4e/core/model/IModelLines.java | 12 +- .../model/IModelTokensChangedListener.java | 2 +- .../org/eclipse/tm4e/core/model/ITMModel.java | 33 +++-- .../eclipse/tm4e/core/model/LineTokens.java | 16 ++- .../eclipse/tm4e/core/model/ModelLine.java | 14 +- .../core/model/ModelTokensChangedEvent.java | 12 +- .../model/ModelTokensChangedEventBuilder.java | 12 +- .../org/eclipse/tm4e/core/model/Range.java | 3 +- .../org/eclipse/tm4e/core/model/TMModel.java | 133 ++++++++++-------- .../org/eclipse/tm4e/core/model/TMState.java | 28 ++-- .../org/eclipse/tm4e/core/model/TMToken.java | 2 +- .../tm4e/core/model/TMTokenDecodeData.java | 2 +- .../eclipse/tm4e/core/model/Tokenizer.java | 76 +++++----- .../eclipse/tm4e/core/model/package-info.java | 4 + 16 files changed, 219 insertions(+), 187 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java index 73e9f8dfd..e6bac6846 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.model; @@ -19,15 +19,16 @@ import java.util.List; import java.util.function.Consumer; +import org.eclipse.jdt.annotation.Nullable; + /** - * Abstract class for Model lines used by the TextMate model. Implementation - * class must : + * Abstract class for Model lines used by the TextMate model. * + * Implementation class must: *
    *
  • synchronizes lines with the lines of the editor content when it changed.
  • *
  • call {@link AbstractLineList#invalidateLine(int)} with the first changed line.
  • *
- * */ public abstract class AbstractLineList implements IModelLines { @@ -35,49 +36,47 @@ public abstract class AbstractLineList implements IModelLines { private final List list = Collections.synchronizedList(new ArrayList<>()); + @Nullable private TMModel model; - protected AbstractLineList() { - } - - void setModel(TMModel model) { + void setModel(@Nullable final TMModel model) { this.model = model; } @Override - public void addLine(int line) { + public void addLine(final int line) { try { this.list.add(line, new ModelLine()); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } @Override - public void removeLine(int line) { + public void removeLine(final int line) { this.list.remove(line); } @Override - public void updateLine(int line) { + public void updateLine(final int line) { try { - // this.list.get(line).text = this.lineToTextResolver.apply(line); - } catch (Exception ex) { + // TODO this.list.get(line).text = this.lineToTextResolver.apply(line); + } catch (final Exception ex) { LOGGER.log(ERROR, ex.getMessage(), ex); } } @Override - public ModelLine get(int index) { + public ModelLine get(final int index) { return this.list.get(index); } @Override - public void forEach(Consumer consumer) { + public void forEach(final Consumer consumer) { this.list.forEach(consumer); } - protected void invalidateLine(int lineIndex) { + protected void invalidateLine(final int lineIndex) { if (model != null) { model.invalidateLine(lineIndex); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java index bfe31aac0..cd865df62 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java @@ -19,30 +19,32 @@ import java.util.LinkedHashMap; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; + import com.google.common.base.Splitter; -class DecodeMap { +final class DecodeMap { private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); - int lastAssignedId = 0; - final Map scopeToTokenIds = new LinkedHashMap<>(); - final Map tokenToTokenId = new LinkedHashMap<>(); - final Map tokenIdToToken = new LinkedHashMap<>(); + private int lastAssignedId = 0; + private final Map scopeToTokenIds = new LinkedHashMap<>(); + private final Map tokenToTokenId = new LinkedHashMap<>(); + private final Map tokenIdToToken = new LinkedHashMap<>(); TMTokenDecodeData prevToken = new TMTokenDecodeData(EMPTY_STRING_ARRAY, new LinkedHashMap<>()); - public int[] getTokenIds(String scope) { + public int[] getTokenIds(final String scope) { int[] tokens = this.scopeToTokenIds.get(scope); if (tokens != null) { return tokens; } - String[] tmpTokens = BY_DOT_SPLITTER.splitToStream(scope).toArray(String[]::new); + final String[] tmpTokens = BY_DOT_SPLITTER.splitToStream(scope).toArray(String[]::new); tokens = new int[tmpTokens.length]; for (int i = 0; i < tmpTokens.length; i++) { - String token = tmpTokens[i]; + final String token = tmpTokens[i]; Integer tokenId = this.tokenToTokenId.get(token); if (tokenId == null) { tokenId = (++this.lastAssignedId); @@ -56,7 +58,7 @@ public int[] getTokenIds(String scope) { return tokens; } - public String getToken(Map tokenMap) { + public String getToken(final Map tokenMap) { final StringBuilder result = new StringBuilder(); boolean isFirst = true; for (int i = 1; i <= this.lastAssignedId; i++) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java index caccc0e8a..a7de6be30 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java @@ -14,9 +14,7 @@ import java.util.function.Consumer; /** - * Mode lines API which must be initalize with a document and changed of - * document. - * + * Mode lines API which must be initalize with a document and changed of document. */ public interface IModelLines { @@ -48,9 +46,8 @@ public interface IModelLines { int getSize(); /** - * * @param lineIndex (0-based) - * @return + * @throws IndexOutOfBoundsException */ ModelLine get(int lineIndex); @@ -59,16 +56,11 @@ public interface IModelLines { int getNumberOfLines(); /** - * * @param line (0-based) - * @return - * @throws Exception */ String getLineText(int lineIndex) throws Exception; int getLineLength(int lineIndex) throws Exception; void dispose(); - - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java index 3743b0c52..5d265cec5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelTokensChangedListener.java @@ -14,6 +14,6 @@ @FunctionalInterface public interface IModelTokensChangedListener { - void modelTokensChanged(ModelTokensChangedEvent e); + void modelTokensChanged(ModelTokensChangedEvent event); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java index dbb7945ce..1304464d5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITMModel.java @@ -1,18 +1,19 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.model; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; /** @@ -22,40 +23,38 @@ public interface ITMModel { /** - * Returns the TextMate grammar to use to parse for each lines of the - * document the TextMate tokens. + * Returns the TextMate grammar to use to parse for each lines of the document the TextMate tokens. * - * @return the TextMate grammar to use to parse for each lines of the - * document the TextMate tokens. + * @return the TextMate grammar to use to parse for each lines of the document the TextMate tokens. */ + @Nullable IGrammar getGrammar(); /** - * Set the TextMate grammar to use to parse for each lines of the document - * the TextMate tokens. - * - * @param grammar + * Set the TextMate grammar to use to parse for each lines of the document the TextMate tokens. */ void setGrammar(IGrammar grammar); /** * Add model tokens changed listener. - * - * @param listener - * to add + * + * @param listener to add */ void addModelTokensChangedListener(IModelTokensChangedListener listener); /** * Remove model tokens changed listener. - * - * @param listener - * to remove + * + * @param listener to remove */ void removeModelTokensChangedListener(IModelTokensChangedListener listener); void dispose(); + /** + * @throws IndexOutOfBoundsException + */ + @Nullable List getLineTokens(int line); void forceTokenization(int lineNumber); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java index 50cc95a9d..55ce01896 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,33 +11,39 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.model; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; + public class LineTokens { final List tokens; int actualStopOffset; + + @Nullable TMState endState; - public LineTokens(List tokens, int actualStopOffset, TMState endState) { + public LineTokens(final List tokens, final int actualStopOffset, @Nullable final TMState endState) { this.tokens = tokens; this.actualStopOffset = actualStopOffset; this.endState = endState; } + @Nullable public TMState getEndState() { return endState; } - public void setEndState(TMState endState) { + public void setEndState(@Nullable final TMState endState) { this.endState = endState; } + @Nullable public List getTokens() { return tokens; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java index b38a8fde2..02e3852f7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java @@ -13,10 +13,16 @@ import java.util.List; +import org.eclipse.jdt.annotation.Nullable; + public class ModelLine { boolean isInvalid; - TMState state; + + @Nullable + private TMState state; + + @Nullable List tokens; public void resetTokenizationState() { @@ -24,18 +30,20 @@ public void resetTokenizationState() { this.tokens = null; } + @Nullable public TMState getState() { return state; } - public void setState(TMState state) { + public void setState(@Nullable final TMState state) { this.state = state; } - public void setTokens(List tokens) { + public void setTokens(@Nullable final List tokens) { this.tokens = tokens; } + @Nullable public List getTokens() { return tokens; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java index c2ff2ac15..2b60c792c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEvent.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.model; @@ -21,20 +21,18 @@ /** * Model tokens changed event. - * */ public class ModelTokensChangedEvent { public final List ranges; public final ITMModel model; - public ModelTokensChangedEvent(Range range, ITMModel model) { + public ModelTokensChangedEvent(final Range range, final ITMModel model) { this(Arrays.asList(range), model); } - public ModelTokensChangedEvent(List ranges, ITMModel model) { + public ModelTokensChangedEvent(final List ranges, final ITMModel model) { this.ranges = ranges; this.model = model; } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java index d5ac5d872..cb40e9fdd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java @@ -16,20 +16,23 @@ */ package org.eclipse.tm4e.core.model; +import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import java.util.ArrayList; import java.util.List; -class ModelTokensChangedEventBuilder { +import org.eclipse.jdt.annotation.Nullable; + +final class ModelTokensChangedEventBuilder { private final ITMModel model; private final List ranges = new ArrayList<>(); - public ModelTokensChangedEventBuilder(ITMModel model) { + public ModelTokensChangedEventBuilder(final ITMModel model) { this.model = model; } - public void registerChangedTokens(int lineNumber) { - Range previousRange = ranges.isEmpty() ? null : ranges.get(ranges.size() - 1); + public void registerChangedTokens(final int lineNumber) { + final Range previousRange = findLastElement(ranges); if (previousRange != null && previousRange.toLineNumber == lineNumber - 1) { // extend previous range @@ -40,6 +43,7 @@ public void registerChangedTokens(int lineNumber) { } } + @Nullable public ModelTokensChangedEvent build() { if (this.ranges.isEmpty()) { return null; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java index 53448f6ab..d0961c465 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Range.java @@ -23,9 +23,8 @@ public class Range { /** * Constructs a range made of a single line - * @param lineNumber */ - public Range(int lineNumber) { + public Range(final int lineNumber) { this.fromLineNumber = lineNumber; this.toLineNumber = lineNumber; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index 9d07abf70..21d9357d0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -12,9 +12,10 @@ package org.eclipse.tm4e.core.model; import static java.lang.System.Logger.Level.*; +import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; import java.lang.System.Logger; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; @@ -22,34 +23,34 @@ import java.util.concurrent.PriorityBlockingQueue; import java.util.function.Consumer; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; /** * TextMate model class. - * */ public class TMModel implements ITMModel { private static final Logger LOGGER = System.getLogger(TMModel.class.getName()); - /** - * The TextMate grammar to use to parse for each lines of the document the - * TextMate tokens. - **/ + /** The TextMate grammar to use to parse for each lines of the document the TextMate tokens. **/ + @Nullable private IGrammar grammar; /** Listener when TextMate model tokens changed **/ private final Set listeners = new CopyOnWriteArraySet<>(); - Tokenizer tokenizer; + @Nullable + private Tokenizer tokenizer; /** The background thread. */ + @Nullable private volatile TokenizerThread fThread; private final IModelLines lines; private final PriorityBlockingQueue invalidLines = new PriorityBlockingQueue<>(); - public TMModel(IModelLines lines) { + public TMModel(final IModelLines lines) { this.lines = lines; ((AbstractLineList) lines).setModel(this); lines.forEach(ModelLine::resetTokenizationState); @@ -57,15 +58,20 @@ public TMModel(IModelLines lines) { } /** - * The {@link TokenizerThread} takes as input an {@link TMModel} and continuously - * runs tokenizing in background on the lines found in {@link TMModel#lines}. - * The {@link TMModel#lines} are expected to be accessed through {@link TMModel#getLines()} - * and manipulated by the UI part to inform of needs to (re)tokenize area, then the {@link TokenizerThread} - * processes them and emits events through the model. UI elements are supposed to subscribe and react to the events - * with {@link TMModel#addModelTokensChangedListener(IModelTokensChangedListener)}. + * The {@link TokenizerThread} takes as input an {@link TMModel} and continuously runs tokenizing in background on + * the lines found in {@link TMModel#lines}. + * + * The {@link TMModel#lines} are expected to be accessed through {@link TMModel#getLines()} and manipulated by the + * UI part to inform of needs to (re)tokenize area, then the {@link TokenizerThread} processes them and emits events + * through the model. + * + * UI elements are supposed to subscribe and react to the events with + * {@link TMModel#addModelTokensChangedListener(IModelTokensChangedListener)}. */ private static final class TokenizerThread extends Thread { private final TMModel model; + + @Nullable private TMState lastState; /** @@ -73,7 +79,7 @@ private static final class TokenizerThread extends Thread { * * @param name the thread's name */ - TokenizerThread(String name, TMModel model) { + TokenizerThread(final String name, final TMModel model) { super(name); this.model = model; setPriority(Thread.MIN_PRIORITY); @@ -87,26 +93,25 @@ public void run() { final int toProcess = model.invalidLines.take().intValue(); if (model.lines.get(toProcess).isInvalid) { try { - this.revalidateTokensNow(toProcess, null); - } catch (Exception ex) { + revalidateTokensNow(toProcess, null); + } catch (final Exception ex) { LOGGER.log(ERROR, ex.getMessage()); if (toProcess < model.lines.getNumberOfLines()) { model.invalidateLine(toProcess); } } } - } catch (InterruptedException e) { + } catch (final InterruptedException e) { interrupt(); } } } /** - * * @param startLine 0-based * @param toLineIndexOrNull 0-based */ - private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { + private void revalidateTokensNow(final int startLine, @Nullable final Integer toLineIndexOrNull) { model.buildAndEmitEvent(eventBuilder -> { final int toLineIndex; if (toLineIndexOrNull == null || toLineIndexOrNull >= model.lines.getNumberOfLines()) { @@ -120,7 +125,7 @@ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { final long MAX_ALLOWED_TIME = 20; long currentEstimatedTimeToTokenize = 0; long elapsedTime; - long startTime = System.currentTimeMillis(); + final long startTime = System.currentTimeMillis(); // Tokenize at most 1000 lines. Estimate the tokenization speed per // character and stop when: // - MAX_ALLOWED_TIME is reached @@ -138,13 +143,14 @@ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { // Compute how many characters will be tokenized for this line try { currentCharsToTokenize = model.lines.getLineLength(lineIndex); - } catch (Exception ex) { + } catch (final Exception ex) { LOGGER.log(ERROR, ex.getMessage()); } if (tokenizedChars > 0) { // If we have enough history, estimate how long tokenizing this line would take - currentEstimatedTimeToTokenize = (long) ((double)elapsedTime / tokenizedChars) * currentCharsToTokenize; + currentEstimatedTimeToTokenize = (long) ((double) elapsedTime / tokenizedChars) + * currentCharsToTokenize; if (elapsedTime + currentEstimatedTimeToTokenize > MAX_ALLOWED_TIME) { // Tokenizing this line will go above MAX_ALLOWED_TIME model.invalidateLine(lineIndex); @@ -152,7 +158,7 @@ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { } } - lineIndex = this.updateTokensInRange(eventBuilder, lineIndex, lineIndex) + 1; + lineIndex = updateTokensInRange(eventBuilder, lineIndex, lineIndex) + 1; tokenizedChars += currentCharsToTokenize; } }); @@ -160,36 +166,35 @@ private void revalidateTokensNow(int startLine, Integer toLineIndexOrNull) { } /** - * - * @param eventBuilder * @param startIndex 0-based * @param endLineIndex 0-based - * @param emitEvents * * @return the first line index (0-based) that was NOT processed by this operation */ - private int updateTokensInRange(ModelTokensChangedEventBuilder eventBuilder, int startIndex, int endLineIndex) { - int stopLineTokenizationAfter = 1_000_000_000; // 1 billion, if a line is so long, you have other trouble :) + private int updateTokensInRange(final ModelTokensChangedEventBuilder eventBuilder, final int startIndex, + final int endLineIndex) { + final int stopLineTokenizationAfter = 1_000_000_000; // 1 billion, if a line is so long, you have other + // trouble :) // Validate all states up to and including endLineIndex int nextInvalidLineIndex = startIndex; int lineIndex = startIndex; while (lineIndex <= endLineIndex && lineIndex < model.lines.getNumberOfLines()) { - int endStateIndex = lineIndex + 1; + final int endStateIndex = lineIndex + 1; LineTokens r = null; String text = null; - ModelLine modeLine = model.lines.get(lineIndex); + final ModelLine modeLine = model.lines.get(lineIndex); try { text = model.lines.getLineText(lineIndex); // Tokenize only the first X characters - r = model.tokenizer.tokenize(text, modeLine.getState(), 0, stopLineTokenizationAfter); - } catch (Exception ex) { + r = castNonNull(model.tokenizer).tokenize(text, modeLine.getState(), 0, stopLineTokenizationAfter); + } catch (final Exception ex) { LOGGER.log(ERROR, ex.getMessage()); } - if (r != null && r.tokens != null && !r.tokens.isEmpty()) { + if (r != null && !r.tokens.isEmpty()) { // Cannot have a stop offset before the last token - r.actualStopOffset = Math.max(r.actualStopOffset, r.tokens.get(r.tokens.size() - 1).startIndex + 1); + r.actualStopOffset = Math.max(r.actualStopOffset, getLastElement(r.tokens).startIndex + 1); } if (r != null && r.actualStopOffset < text.length()) { @@ -200,22 +205,25 @@ private int updateTokensInRange(ModelTokensChangedEventBuilder eventBuilder, int } if (r == null) { - r = new LineTokens(Collections.singletonList(new TMToken(0, "")), text.length(), modeLine.getState()); + r = new LineTokens(List.of(new TMToken(0, "")), text.length(), modeLine.getState()); } modeLine.setTokens(r.tokens); eventBuilder.registerChangedTokens(lineIndex + 1); modeLine.isInvalid = false; if (endStateIndex < model.lines.getNumberOfLines()) { - ModelLine endStateLine = model.lines.get(endStateIndex); - if (endStateLine.getState() != null && r.endState.equals(endStateLine.getState())) { + final ModelLine endStateLine = castNonNull(model.lines.get(endStateIndex)); + if (endStateLine.getState() != null && Objects.equals(endStateLine.getState(), r.endState)) { // The end state of this line remains the same nextInvalidLineIndex = lineIndex + 1; while (nextInvalidLineIndex < model.lines.getNumberOfLines()) { - boolean isLastLine = nextInvalidLineIndex + 1 >= model.lines.getNumberOfLines(); - if (model.lines.get(nextInvalidLineIndex).isInvalid - || (!isLastLine && model.lines.get(nextInvalidLineIndex + 1).getState() == null) - || (isLastLine && this.lastState == null)) { + if (model.lines.get(nextInvalidLineIndex).isInvalid) { + break; + } + final var isLastLine = nextInvalidLineIndex + 1 >= model.lines.getNumberOfLines(); + if (isLastLine + ? lastState == null + : model.lines.get(nextInvalidLineIndex + 1).getState() == null) { break; } nextInvalidLineIndex++; @@ -226,35 +234,36 @@ private int updateTokensInRange(ModelTokensChangedEventBuilder eventBuilder, int lineIndex++; } } else { - this.lastState = r.endState; + lastState = r.endState; lineIndex++; } } return nextInvalidLineIndex; } - } + @Nullable @Override public IGrammar getGrammar() { return grammar; } @Override - public void setGrammar(IGrammar grammar) { + public void setGrammar(final IGrammar grammar) { if (!Objects.equals(grammar, this.grammar)) { this.grammar = grammar; - this.tokenizer = new Tokenizer(grammar); + final var tokenizer = this.tokenizer = new Tokenizer(grammar); lines.get(0).setState(tokenizer.getInitialState()); } } @Override - public synchronized void addModelTokensChangedListener(IModelTokensChangedListener listener) { + public synchronized void addModelTokensChangedListener(final IModelTokensChangedListener listener) { listeners.add(listener); + var fThread = this.fThread; if (fThread == null || fThread.isInterrupted()) { - fThread = new TokenizerThread(getClass().getName(), this); + fThread = this.fThread = new TokenizerThread(getClass().getName(), this); } if (!fThread.isAlive()) { fThread.start(); @@ -262,7 +271,7 @@ public synchronized void addModelTokensChangedListener(IModelTokensChangedListen } @Override - public synchronized void removeModelTokensChangedListener(IModelTokensChangedListener listener) { + public synchronized void removeModelTokensChangedListener(final IModelTokensChangedListener listener) { listeners.remove(listener); if (listeners.isEmpty()) { @@ -281,11 +290,12 @@ public void dispose() { * Interrupt the thread. */ private synchronized void stop() { + var fThread = this.fThread; if (fThread == null) { return; } fThread.interrupt(); - fThread = null; + this.fThread = null; } private void buildAndEmitEvent(final Consumer callback) { @@ -299,8 +309,8 @@ private void buildAndEmitEvent(final Consumer ca } } - private void emit(ModelTokensChangedEvent e) { - for (IModelTokensChangedListener listener : listeners) { + private void emit(final ModelTokensChangedEvent e) { + for (final IModelTokensChangedListener listener : listeners) { listener.modelTokensChanged(e); } } @@ -315,20 +325,27 @@ public void forceTokenization(final int lineNumber) { } @Override - public List getLineTokens(int lineNumber) { + @Nullable + public List getLineTokens(final int lineNumber) { return lines.get(lineNumber).tokens; } - public boolean isLineInvalid(int lineNumber) { + /** + * @throws IndexOutOfBoundsException + */ + public boolean isLineInvalid(final int lineNumber) { return lines.get(lineNumber).isInvalid; } - void invalidateLine(int lineIndex) { - this.lines.get(lineIndex).isInvalid = true; - this.invalidLines.add(lineIndex); + /** + * @throws IndexOutOfBoundsException + */ + void invalidateLine(final int lineIndex) { + lines.get(lineIndex).isInvalid = true; + invalidLines.add(lineIndex); } public IModelLines getLines() { - return this.lines; + return lines; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java index 3d957ce6d..594e6cb4a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,52 +11,58 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.model; import java.util.Objects; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.StackElement; public class TMState { + @Nullable private final TMState parentEmbedderState; + + @Nullable private StackElement ruleStack; - public TMState(TMState parentEmbedderState, StackElement ruleStatck) { + public TMState(@Nullable final TMState parentEmbedderState, @Nullable final StackElement ruleStatck) { this.parentEmbedderState = parentEmbedderState; this.ruleStack = ruleStatck; } - public void setRuleStack(StackElement ruleStack) { + public void setRuleStack(final StackElement ruleStack) { this.ruleStack = ruleStack; } + @Nullable public StackElement getRuleStack() { return ruleStack; } @Override public TMState clone() { - TMState parentEmbedderStateClone = this.parentEmbedderState != null ? this.parentEmbedderState.clone() : null; + final TMState parentEmbedderStateClone = this.parentEmbedderState != null + ? this.parentEmbedderState.clone() + : null; return new TMState(parentEmbedderStateClone, this.ruleStack); } @Override - public boolean equals(Object other) { + public boolean equals(@Nullable final Object other) { if (!(other instanceof TMState)) { return false; } - TMState otherState = (TMState) other; - return Objects.equals(this.parentEmbedderState, otherState.parentEmbedderState) && - Objects.equals(this.ruleStack, otherState.ruleStack); + final TMState otherState = (TMState) other; + return Objects.equals(this.parentEmbedderState, otherState.parentEmbedderState) + && Objects.equals(this.ruleStack, otherState.ruleStack); } @Override public int hashCode() { return Objects.hash(this.parentEmbedderState, this.ruleStack); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java index d93796e29..38e554063 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMToken.java @@ -21,7 +21,7 @@ public class TMToken { public final int startIndex; public final String type; - public TMToken(int startIndex, String type) { + public TMToken(final int startIndex, final String type) { this.startIndex = startIndex; this.type = type; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java index f6879d290..bbebd480a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java @@ -23,7 +23,7 @@ public class TMTokenDecodeData { public final String[] scopes; public final Map> scopeTokensMaps; - TMTokenDecodeData(String[] scopes, Map> scopeTokensMaps) { + TMTokenDecodeData(final String[] scopes, final Map> scopeTokensMaps) { this.scopes = scopes; this.scopeTokensMaps = scopeTokensMaps; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java index 1392785a9..fdb9eb2a9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,26 +11,24 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.model; import java.util.ArrayList; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.grammar.IToken; -import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; public class Tokenizer implements ITokenizationSupport { private final IGrammar grammar; private final DecodeMap decodeMap = new DecodeMap(); - public Tokenizer(IGrammar grammar) { + public Tokenizer(final IGrammar grammar) { this.grammar = grammar; } @@ -40,40 +38,40 @@ public TMState getInitialState() { } @Override - public LineTokens tokenize(String line, TMState state) { + public LineTokens tokenize(final String line, final TMState state) { return tokenize(line, state, null, null); } @Override - public LineTokens tokenize(String line, TMState state, Integer offsetDelta, Integer stopAtOffset) { - if (offsetDelta == null) { - offsetDelta = 0; - } - // Do not attempt to tokenize if a line has over 20k - // or if the rule stack contains more than 100 rules (indicator of - // broken grammar that forgets to pop rules) - // if (line.length >= 20000 || depth(state.ruleStack) > 100) { - // return new RawLineTokens( - // [new Token(offsetDelta, '')], - // [new ModeTransition(offsetDelta, this._modeId)], - // offsetDelta, - // state - // ); - // } - TMState freshState = state != null ? state.clone() : getInitialState(); - ITokenizeLineResult textMateResult = grammar.tokenizeLine(line, freshState.getRuleStack()); + public LineTokens tokenize(final String line, @Nullable final TMState state, @Nullable Integer offsetDeltaOrNull, + @Nullable final Integer stopAtOffset) { + /* + Do not attempt to tokenize if a line has over 20k or + if the rule stack contains more than 100 rules (indicator of broken grammar that forgets to pop rules) + + if (line.length >= 20000 || depth(state.ruleStack) > 100) { + return new RawLineTokens( + [new Token(offsetDelta, '')], + [new ModeTransition(offsetDelta, this._modeId)], + offsetDelta, + state + ); + } + */ + final int offsetDelta = offsetDeltaOrNull == null ? 0 : offsetDeltaOrNull; + final var freshState = state != null ? state.clone() : getInitialState(); + final var textMateResult = grammar.tokenizeLine(line, freshState.getRuleStack()); freshState.setRuleStack(textMateResult.getRuleStack()); // Create the result early and fill in the tokens later - List tokens = new ArrayList<>(); + final var tokens = new ArrayList(); String lastTokenType = null; for (int tokenIndex = 0, len = textMateResult.getTokens().length; tokenIndex < len; tokenIndex++) { - IToken token = textMateResult.getTokens()[tokenIndex]; - int tokenStartIndex = token.getStartIndex(); - String tokenType = decodeTextMateToken(this.decodeMap, token.getScopes().toArray(String[]::new)); + final var token = textMateResult.getTokens()[tokenIndex]; + final int tokenStartIndex = token.getStartIndex(); + final var tokenType = decodeTextMateToken(this.decodeMap, token.getScopes().toArray(String[]::new)); - // do not push a new token if the type is exactly the same (also - // helps with ligatures) + // do not push a new token if the type is exactly the same (also helps with ligatures) if (!tokenType.equals(lastTokenType)) { tokens.add(new TMToken(tokenStartIndex + offsetDelta, tokenType)); lastTokenType = tokenType; @@ -83,16 +81,16 @@ public LineTokens tokenize(String line, TMState state, Integer offsetDelta, Inte } - private String decodeTextMateToken(DecodeMap decodeMap, String[] scopes) { - String[] prevTokenScopes = decodeMap.prevToken.scopes; - int prevTokenScopesLength = prevTokenScopes.length; - Map> prevTokenScopeTokensMaps = decodeMap.prevToken.scopeTokensMaps; + private String decodeTextMateToken(final DecodeMap decodeMap, final String[] scopes) { + final String[] prevTokenScopes = decodeMap.prevToken.scopes; + final int prevTokenScopesLength = prevTokenScopes.length; + final var prevTokenScopeTokensMaps = decodeMap.prevToken.scopeTokensMaps; - Map> scopeTokensMaps = new LinkedHashMap<>(); + final var scopeTokensMaps = new LinkedHashMap>(); Map prevScopeTokensMaps = new LinkedHashMap<>(); boolean sameAsPrev = true; for (int level = 1/* deliberately skip scope 0 */; level < scopes.length; level++) { - String scope = scopes[level]; + final String scope = scopes[level]; if (sameAsPrev) { if (level < prevTokenScopesLength && prevTokenScopes[level].equals(scope)) { @@ -103,9 +101,9 @@ private String decodeTextMateToken(DecodeMap decodeMap, String[] scopes) { sameAsPrev = false; } - int[] tokens = decodeMap.getTokenIds(scope); + final int[] tokens = decodeMap.getTokenIds(scope); prevScopeTokensMaps = new LinkedHashMap<>(prevScopeTokensMaps); - for (int token : tokens) { + for (final int token : tokens) { prevScopeTokensMaps.put(token, true); } scopeTokensMaps.put(level, prevScopeTokensMaps); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/package-info.java new file mode 100644 index 000000000..c72badf4a --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.model; + +import org.eclipse.jdt.annotation.NonNullByDefault; From da488dae7eca0c212be73153dde0dde5e65d9828 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 30 Apr 2022 21:28:47 +0200 Subject: [PATCH 132/202] Prevent accessing potentially null 'text' variable --- .../main/java/org/eclipse/tm4e/core/model/TMModel.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index 21d9357d0..e7ee86427 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -189,24 +189,22 @@ private int updateTokensInRange(final ModelTokensChangedEventBuilder eventBuilde // Tokenize only the first X characters r = castNonNull(model.tokenizer).tokenize(text, modeLine.getState(), 0, stopLineTokenizationAfter); } catch (final Exception ex) { - LOGGER.log(ERROR, ex.getMessage()); + LOGGER.log(ERROR, ex.toString()); + return nextInvalidLineIndex; } - if (r != null && !r.tokens.isEmpty()) { + if (!r.tokens.isEmpty()) { // Cannot have a stop offset before the last token r.actualStopOffset = Math.max(r.actualStopOffset, getLastElement(r.tokens).startIndex + 1); } - if (r != null && r.actualStopOffset < text.length()) { + if (r.actualStopOffset < text.length()) { // Treat the rest of the line (if above limit) as one default token r.tokens.add(new TMToken(r.actualStopOffset, "")); // Use as end state the starting state r.endState = modeLine.getState(); } - if (r == null) { - r = new LineTokens(List.of(new TMToken(0, "")), text.length(), modeLine.getState()); - } modeLine.setTokens(r.tokens); eventBuilder.registerChangedTokens(lineIndex + 1); modeLine.isInvalid = false; From 8e443f25b1b6980af4de2f4707ebf004947708fe Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 12:06:29 +0200 Subject: [PATCH 133/202] Remove unused setters --- .../tm4e/core/internal/grammar/Raw.java | 38 +------------------ .../tm4e/core/internal/types/IRawRule.java | 14 ------- 2 files changed, 1 insertion(+), 51 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java index 35dccb209..eef58271e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java @@ -66,8 +66,7 @@ public final class Raw extends HashMap<@Nullable String, @Nullable Object> private Object getSafe(@Nullable final Object key) { @SuppressWarnings("unlikely-arg-type") - final - var obj = get(key); + final var obj = get(key); if (obj == null) { throw new IllegalArgumentException("Key '" + key + "' does not exit found"); } @@ -128,22 +127,12 @@ public String getContentName() { return (String) get(CONTENT_NAME); } - @Override - public void setContentName(@Nullable final String name) { - super.put(CONTENT_NAME, name); - } - @Nullable @Override public String getMatch() { return (String) get(MATCH); } - @Override - public void setMatch(@Nullable final String match) { - super.put(MATCH, match); - } - @Nullable @Override public IRawCaptures getCaptures() { @@ -164,22 +153,12 @@ public void updateCaptures(final String name) { } } - @Override - public void setCaptures(@Nullable final IRawCaptures captures) { - super.put(CAPTURES, captures); - } - @Nullable @Override public String getBegin() { return (String) get(BEGIN); } - @Override - public void setBegin(@Nullable final String begin) { - super.put(BEGIN, begin); - } - @Nullable @Override public String getWhile() { @@ -215,11 +194,6 @@ public String getEnd() { return (String) get(END); } - @Override - public void setEnd(@Nullable final String end) { - super.put(END, end); - } - @Nullable @Override public IRawCaptures getEndCaptures() { @@ -227,11 +201,6 @@ public IRawCaptures getEndCaptures() { return (IRawCaptures) get(END_CAPTURES); } - @Override - public void setEndCaptures(@Nullable final IRawCaptures endCaptures) { - super.put(END_CAPTURES, endCaptures); - } - @Nullable @Override public IRawCaptures getWhileCaptures() { @@ -295,11 +264,6 @@ public boolean isApplyEndPatternLast() { return false; } - @Override - public void setApplyEndPatternLast(final boolean applyEndPatternLast) { - super.put(APPLY_END_PATTERN_LAST, applyEndPatternLast); - } - @Override public String getScopeName() { return (String) getSafe(SCOPE_NAME); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java index 920da32e8..9b0899560 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java @@ -40,23 +40,15 @@ public interface IRawRule { @Nullable String getContentName(); - void setContentName(@Nullable String name); - @Nullable String getMatch(); - void setMatch(@Nullable String match); - @Nullable IRawCaptures getCaptures(); - void setCaptures(@Nullable IRawCaptures captures); - @Nullable String getBegin(); - void setBegin(@Nullable String begin); - @Nullable IRawCaptures getBeginCaptures(); @@ -65,16 +57,12 @@ public interface IRawRule { @Nullable String getEnd(); - void setEnd(@Nullable String end); - @Nullable String getWhile(); @Nullable IRawCaptures getEndCaptures(); - void setEndCaptures(@Nullable IRawCaptures endCaptures); - @Nullable IRawCaptures getWhileCaptures(); @@ -89,6 +77,4 @@ public interface IRawRule { void setRepository(@Nullable IRawRepository repository); boolean isApplyEndPatternLast(); - - void setApplyEndPatternLast(boolean applyEndPatternLast); } From 1b974bd8cbcd624b62fe0f9bc5e1eafaa9c18145 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 12:07:06 +0200 Subject: [PATCH 134/202] Remove commented out code --- .../java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java index f64f11eb1..7d65d1d70 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java @@ -46,8 +46,6 @@ public interface IRawGrammar { @Nullable String getInjectionSelector(); - // injections?:{ [expression:string]: IRawRule }; - Collection getFileTypes(); @Nullable From d33296ab6871c8744a5ca6a1c103809241d78243 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 12:15:43 +0200 Subject: [PATCH 135/202] Use less Nullable annotations in model --- .../tm4e/core/internal/grammar/Raw.java | 18 +++++++++--------- .../tm4e/core/internal/parser/MapFactory.java | 2 +- .../tm4e/core/internal/parser/PListDict.java | 6 ++++-- .../tm4e/core/internal/theme/ThemeRaw.java | 2 +- .../core/internal/types/IRawRepository.java | 6 +++--- .../tm4e/core/internal/types/IRawRule.java | 4 ++-- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java index eef58271e..6042fa7e0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java @@ -20,9 +20,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.types.IRawCaptures; import org.eclipse.tm4e.core.internal.types.IRawGrammar; @@ -32,11 +32,11 @@ /** * Raw */ -public final class Raw extends HashMap<@Nullable String, @Nullable Object> +public final class Raw extends HashMap implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { - public static final String DOLLAR_SELF = "$self"; public static final String DOLLAR_BASE = "$base"; + public static final String DOLLAR_SELF = "$self"; private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast"; private static final String BEGIN = "begin"; @@ -106,7 +106,7 @@ public Integer getId() { } @Override - public void setId(@Nullable final Integer id) { + public void setId(final Integer id) { super.put(ID, id); } @@ -117,7 +117,7 @@ public String getName() { } @Override - public void setName(@Nullable final String name) { + public void setName(final String name) { super.put(NAME, name); } @@ -274,10 +274,10 @@ public Collection getFileTypes() { List result = fileTypes; if (result == null) { result = new ArrayList<>(); - final Collection<@NonNull ?> unparsedFileTypes = (Collection<@NonNull ?>) get(FILE_TYPES); + final Collection unparsedFileTypes = (Collection) get(FILE_TYPES); if (unparsedFileTypes != null) { for (final Object o : unparsedFileTypes) { - String str = o.toString(); + String str = Objects.toString(o); // #202 if (str.startsWith(".")) { str = str.substring(1); @@ -331,7 +331,7 @@ private Object clone(@Nullable final Object value) { @Nullable @Override - public Object put(@Nullable final String key, @Nullable final Object value) { + public Object put(final String key, @Nullable final Object value) { if (FILE_TYPES.equals(key)) fileTypes = null; @@ -340,7 +340,7 @@ public Object put(@Nullable final String key, @Nullable final Object value) { @Override @SuppressWarnings("unlikely-arg-type") - public void putAll(@Nullable final Map m) { + public void putAll(@Nullable final Map m) { if (m != null && m.containsKey(FILE_TYPES)) fileTypes = null; super.putAll(m); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java index 9ed6d6fbe..f0f8dece7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java @@ -19,5 +19,5 @@ @FunctionalInterface public interface MapFactory { - Map<@Nullable String, @Nullable Object> createMap(); + Map createMap(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java index b54d89aa2..59179e2c5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java @@ -12,13 +12,15 @@ */ package org.eclipse.tm4e.core.internal.parser; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.Map; import org.eclipse.jdt.annotation.Nullable; final class PListDict extends PListObject { - private final Map<@Nullable String, @Nullable Object> values; + private final Map values; PListDict(@Nullable final PListObject parent, final MapFactory mapFactory) { super(parent); @@ -27,7 +29,7 @@ final class PListDict extends PListObject { @Override void addValue(final Object value) { - values.put(getLastKey(), value); + values.put(castNonNull(getLastKey()), value); } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index 42e669190..ad04b416d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -19,7 +19,7 @@ import org.eclipse.tm4e.core.theme.IRawThemeSetting; import org.eclipse.tm4e.core.theme.IThemeSetting; -public final class ThemeRaw extends HashMap<@Nullable String, Object> implements IRawTheme, IRawThemeSetting, IThemeSetting { +public final class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting { private static final long serialVersionUID = -3622927264735492387L; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java index 356745acc..9861be3cb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java @@ -30,15 +30,15 @@ static IRawRepository merge(@Nullable IRawRepository... sources) { for (final IRawRepository source : sources) { if (source == null) continue; - final Set> entries = source.entrySet(); - for (final Entry<@Nullable String, @Nullable Object> entry : entries) { + final Set> entries = source.entrySet(); + for (final Entry entry : entries) { merged.put(entry.getKey(), entry.getValue()); } } return merged; } - Set> entrySet(); + Set> entrySet(); @Nullable IRawRule getProp(String name); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java index 9b0899560..23009ed23 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java @@ -25,7 +25,7 @@ public interface IRawRule { @Nullable Integer getId(); - void setId(@Nullable Integer id); + void setId(Integer id); @Nullable String getInclude(); @@ -35,7 +35,7 @@ public interface IRawRule { @Nullable String getName(); - void setName(@Nullable String name); + void setName(String name); @Nullable String getContentName(); From 6dcbf1cc5168dc779f56232b1ba4a10470c91f63 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 12:17:51 +0200 Subject: [PATCH 136/202] Move lastKey property from PListObject to PListDict --- .../tm4e/core/internal/parser/PListDict.java | 14 +++++++++++++- .../tm4e/core/internal/parser/PListObject.java | 12 ------------ .../internal/parser/PListParserContentHandler.java | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java index 59179e2c5..425bb272e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java @@ -22,6 +22,9 @@ final class PListDict extends PListObject { private final Map values; + @Nullable + private String lastKey; + PListDict(@Nullable final PListObject parent, final MapFactory mapFactory) { super(parent); values = mapFactory.createMap(); @@ -29,11 +32,20 @@ final class PListDict extends PListObject { @Override void addValue(final Object value) { - values.put(castNonNull(getLastKey()), value); + values.put(castNonNull(lastKey), value); + } + + @Nullable + String getLastKey() { + return lastKey; } @Override Object getValue() { return values; } + + void setLastKey(@Nullable final String lastKey) { + this.lastKey = lastKey; + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java index 3013056fc..ab650d8d5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java @@ -18,22 +18,10 @@ abstract class PListObject { @Nullable final PListObject parent; - @Nullable - private String lastKey; - PListObject(@Nullable final PListObject parent) { this.parent = parent; } - @Nullable - String getLastKey() { - return lastKey; - } - - void setLastKey(@Nullable final String lastKey) { - this.lastKey = lastKey; - } - abstract void addValue(Object value); abstract Object getValue(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java index fd0dd54c8..67ffbe31b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java @@ -51,8 +51,8 @@ public void startElement(@Nullable final String uri, @Nullable final String loca currObject = new PListArray(currObject); break; case "key": - if (currObject != null) { - currObject.setLastKey(null); + if (currObject instanceof PListDict) { + ((PListDict) currObject).setLastKey(null); } break; } @@ -80,7 +80,7 @@ private void endElement(final String tagName) { errors.add(" tag can only be used inside an open element"); return; } - currObject.setLastKey(text); + ((PListDict) currObject).setLastKey(text); return; case "dict": case "array": @@ -140,7 +140,7 @@ private void endElement(final String tagName) { final var t = (T) value; result = t; } else if (currObject instanceof PListDict) { - if (currObject.getLastKey() != null) { + if (((PListDict) currObject).getLastKey() != null) { currObject.addValue(value); } else { errors.add("Dictionary key missing for value " + value); From ef41c5e99bc33afc6efded2d979ad9f91648f0f2 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 12:37:12 +0200 Subject: [PATCH 137/202] Improve PListParser performance --- .../parser/PListParserContentHandler.java | 35 ++++++++----------- .../core/internal/parser/PListParserJSON.java | 6 ++-- .../core/internal/parser/PListParserYAML.java | 6 ++-- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java index 67ffbe31b..8a06662de 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java @@ -58,34 +58,28 @@ public void startElement(@Nullable final String uri, @Nullable final String loca } text.setLength(0); - super.startElement(uri, localName, qName, attributes); } @Override public void endElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName) throws SAXException { assert localName != null; - endElement(localName); - super.endElement(uri, localName, qName); - } - private void endElement(final String tagName) { Object value = null; - final String text = this.text.toString(); var currObject = this.currObject; - switch (tagName) { + switch (localName) { case "key": if (!(currObject instanceof PListDict)) { errors.add(" tag can only be used inside an open element"); return; } - ((PListDict) currObject).setLastKey(text); + ((PListDict) currObject).setLastKey(text.toString()); return; case "dict": case "array": if (currObject == null) { - errors.add("Closing tag found, without opening tag"); + errors.add("Closing tag found, without opening tag"); return; } value = currObject.getValue(); @@ -93,12 +87,12 @@ private void endElement(final String tagName) { break; case "string": case "data": - value = text; + value = text.toString(); break; case "date": // e.g. 2007-10-25T12:36:35Z try { - value = ZonedDateTime.parse(text); + value = ZonedDateTime.parse(text.toString()); } catch (final DateTimeParseException ex) { errors.add("Failed to parse date '" + text + "'. " + ex); return; @@ -106,7 +100,7 @@ private void endElement(final String tagName) { break; case "integer": try { - value = Integer.parseInt(text); + value = Integer.parseInt(text.toString()); } catch (final NumberFormatException ex) { errors.add("Failed to parse integer '" + text + "'. " + ex); return; @@ -114,27 +108,25 @@ private void endElement(final String tagName) { break; case "real": try { - value = Float.parseFloat(text); + value = Float.parseFloat(text.toString()); } catch (final NumberFormatException ex) { errors.add("Failed to parse real as float '" + text + "'. " + ex); return; } break; case "true": - value = true; + value = Boolean.TRUE; break; case "false": - value = false; + value = Boolean.FALSE; break; case "plist": return; default: - errors.add("Invalid tag name: " + tagName); + errors.add("Invalid tag name: " + localName); return; } - assert value != null; - if (currObject == null) { @SuppressWarnings("unchecked") final var t = (T) value; @@ -152,8 +144,11 @@ private void endElement(final String tagName) { @Override public void characters(final char @Nullable [] ch, final int start, final int length) throws SAXException { - this.text.append(String.valueOf(ch, start, length)); - super.characters(ch, start, length); + text.append(ch, start, length); + } + + void characters(final String chars) { + text.append(chars); } public T getResult() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java index 1b39ce9c1..823dd5adf 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java @@ -54,9 +54,8 @@ public T parse(final InputStream contents) throws IOException, SAXException { reader.endObject(); break; case NAME: - final var lastName = reader.nextName(); pList.startElement(null, "key", null, null); - pList.characters(lastName.toCharArray(), 0, lastName.length()); + pList.characters(reader.nextName()); pList.endElement(null, "key", null); break; case NULL: @@ -69,9 +68,8 @@ public T parse(final InputStream contents) throws IOException, SAXException { reader.nextLong(); break; case STRING: - final var value = reader.nextString(); pList.startElement(null, "string", null, null); - pList.characters(value.toCharArray(), 0, value.length()); + pList.characters(reader.nextString()); pList.endElement(null, "string", null); break; case END_DOCUMENT: diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java index 25b14604d..ab1ff6c5d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java @@ -55,9 +55,9 @@ private void addMapToPList(final PListParserContentHandler pList, final Map entry : map.entrySet()) { + for (final Entry entry : map.entrySet()) { pList.startElement(null, "key", null, null); - pList.characters(castNonNull(entry.getKey()).toCharArray(), 0, castNonNull(entry.getKey()).length()); + pList.characters(entry.getKey()); pList.endElement(null, "key", null); if (entry.getValue() instanceof List) { addListToPList(pList, (List) entry.getValue()); @@ -73,7 +73,7 @@ private void addMapToPList(final PListParserContentHandler pList, final Map pList, final String value) throws SAXException { pList.startElement(null, "string", null, null); - pList.characters(value.toCharArray(), 0, value.length()); + pList.characters(value); pList.endElement(null, "string", null); } From 8644cd30d085c4e10fc013fdf605795a27091c9f Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 13:51:52 +0200 Subject: [PATCH 138/202] Adapt BalancedBracketSelectors and TokenTypeMatcher from upstream --- .../grammar/BalancedBracketSelectors.java | 70 +++++++++++++++ .../tm4e/core/internal/grammar/Grammar.java | 30 ++++++- .../core/internal/grammar/LineTokens.java | 78 +++++++++++++++-- .../core/internal/grammar/MetadataConsts.java | 21 +++-- .../grammar/OptionalStandardTokenType.java | 36 ++++++++ .../internal/grammar/ScopeListElement.java | 2 +- .../grammar/StackElementMetadata.java | 37 +++++--- .../internal/grammar/StandardTokenType.java | 2 +- .../internal/grammar/TokenTypeMatcher.java | 28 ++++++ .../core/internal/matcher/IMatchesName.java | 7 +- .../core/internal/registry/SyncRegistry.java | 8 +- .../eclipse/tm4e/core/registry/Registry.java | 6 +- .../core/internal/grammar/GrammarTest.java | 85 +++++++++---------- 13 files changed, 332 insertions(+), 78 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java new file mode 100644 index 000000000..a924a3a04 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/Microsoft/vscode-textmate/ + * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. + * Initial license: MIT + * + * Contributors: + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Sebastian Thomschke - translation and adaptation to Java + */ +package org.eclipse.tm4e.core.internal.grammar; + +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.eclipse.tm4e.core.internal.matcher.Matcher; + +public class BalancedBracketSelectors { + private final Predicate>[] balancedBracketScopes; + private final Predicate>[] unbalancedBracketScopes; + + private boolean allowAny = false; + + BalancedBracketSelectors(List balancedBracketScopes, List unbalancedBracketScopes) { + this.balancedBracketScopes = balancedBracketScopes.stream() + .flatMap(selector -> { + if ("*".equals(selector)) { + this.allowAny = true; + return Stream.empty(); + } + return Matcher.createMatchers(selector).stream(); + }) + .map(m -> m.matcher).toArray(Predicate[]::new); + + this.unbalancedBracketScopes = unbalancedBracketScopes.stream() + .flatMap(selector -> Matcher.createMatchers(selector).stream()) + .map(m -> m.matcher).toArray(Predicate[]::new); + } + + boolean matchesAlways() { + return this.allowAny && this.unbalancedBracketScopes.length == 0; + } + + boolean matchesNever() { + return !this.allowAny && this.balancedBracketScopes.length == 0; + } + + boolean match(final List scopes) { + for (final var excluder : this.unbalancedBracketScopes) { + if (excluder.test(scopes)) { + return false; + } + } + + for (final var includer : this.balancedBracketScopes) { + if (includer.test(scopes)) { + return true; + } + } + return this.allowAny; + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index da9ca8b85..057207b7e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Objects; import java.util.function.IntFunction; +import java.util.function.Predicate; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -66,18 +67,43 @@ public final class Grammar implements IGrammar, IRuleFactoryHelper { @Nullable private List injections; private final ScopeMetadataProvider scopeMetadataProvider; + private final List tokenTypeMatchers = new ArrayList<>(); + + @Nullable + private final BalancedBracketSelectors balancedBracketSelectors; public Grammar( final String scopeName, final IRawGrammar grammar, final int initialLanguage, @Nullable final Map embeddedLanguages, + @Nullable Map tokenTypes, + @Nullable BalancedBracketSelectors balancedBracketSelectors, final IGrammarRepository grammarRepository, final IThemeProvider themeProvider) { this.scopeName = scopeName; this.scopeMetadataProvider = new ScopeMetadataProvider(initialLanguage, themeProvider, embeddedLanguages); + this.balancedBracketSelectors = balancedBracketSelectors; this.grammarRepository = grammarRepository; this.grammar = initGrammar(grammar, null); + + if (tokenTypes != null) { + for (final var selector : tokenTypes.keySet()) { + for (final var matcher : Matcher.createMatchers(selector)) { + tokenTypeMatchers.add(new TokenTypeMatcher() { + @Override + public int getType() { + return tokenTypes.get(selector); + } + + @Override + public Predicate> getMatcher() { + return matcher.matcher; + } + }); + } + } + } } public void onDidChangeTheme() { @@ -248,7 +274,7 @@ private T tokenize(String lineText, @Nullable StackElement prevState, final final var themeData = rawDefaultMetadata.themeData; final var defaultTheme = themeData == null ? null : themeData.get(0); final int defaultMetadata = StackElementMetadata.set(0, rawDefaultMetadata.languageId, - rawDefaultMetadata.tokenType, defaultTheme.fontStyle, defaultTheme.foreground, + rawDefaultMetadata.tokenType, null, defaultTheme.fontStyle, defaultTheme.foreground, defaultTheme.background); final var rootRule = castNonNull(this.getRule(this.rootId)); @@ -271,7 +297,7 @@ private T tokenize(String lineText, @Nullable StackElement prevState, final } final var onigLineText = OnigString.of(lineText); final int lineLength = lineText.length(); - final var lineTokens = new LineTokens(emitBinaryTokens, lineText); + final var lineTokens = new LineTokens(emitBinaryTokens, lineText, tokenTypeMatchers, balancedBracketSelectors); final var nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, lineTokens); if (emitBinaryTokens) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index e28d8dced..1210a863d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -29,29 +29,39 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IToken; import org.eclipse.tm4e.core.grammar.StackElement; +import org.eclipse.tm4e.core.theme.FontStyle; final class LineTokens { private static final Logger LOGGER = System.getLogger(LineTokens.class.getName()); + /** + * defined only if `LOGGER.isLoggable(TRACE)`. + */ @Nullable private final String lineText; /** - * used only if `_emitBinaryTokens` is false. + * used only if `emitBinaryTokens` is false. */ private final List tokens; private final boolean emitBinaryTokens; /** - * used only if `_emitBinaryTokens` is true. + * used only if `emitBinaryTokens` is true. */ private final List binaryTokens; private int lastTokenEndIndex = 0; - LineTokens(final boolean emitBinaryTokens, final String lineText) { + private final List tokenTypeOverrides; + + @Nullable + private final BalancedBracketSelectors balancedBracketSelectors; + + LineTokens(final boolean emitBinaryTokens, final String lineText, List tokenTypeOverrides, + @Nullable BalancedBracketSelectors balancedBracketSelectors) { this.emitBinaryTokens = emitBinaryTokens; this.lineText = LOGGER.isLoggable(TRACE) ? lineText : null; // store line only if it's logged if (this.emitBinaryTokens) { @@ -61,6 +71,8 @@ final class LineTokens { this.tokens = new ArrayList<>(); this.binaryTokens = Collections.emptyList(); } + this.tokenTypeOverrides = tokenTypeOverrides; + this.balancedBracketSelectors = balancedBracketSelectors; } void produce(final StackElement stack, final int endIndex) { @@ -73,13 +85,63 @@ void produceFromScopes(final ScopeListElement scopesList, final int endIndex) { } if (this.emitBinaryTokens) { - final int metadata = scopesList.metadata; + int metadata = scopesList.metadata; + var containsBalancedBrackets = false; + final var balancedBracketSelectors = this.balancedBracketSelectors; + if (balancedBracketSelectors != null && balancedBracketSelectors.matchesAlways()) { + containsBalancedBrackets = true; + } + + if (!tokenTypeOverrides.isEmpty() || (balancedBracketSelectors != null + && !balancedBracketSelectors.matchesAlways() && !balancedBracketSelectors.matchesNever())) { + // Only generate scope array when required to improve performance + final var scopes = scopesList.generateScopes(); + for (final var tokenType : tokenTypeOverrides) { + if (tokenType.getMatcher().test(scopes)) { + metadata = StackElementMetadata.set( + metadata, + 0, + tokenType.getType(), // toOptionalTokenType(tokenType.type), + null, + FontStyle.NotSet, + 0, + 0); + } + } + if (balancedBracketSelectors != null) { + containsBalancedBrackets = balancedBracketSelectors.match(scopes); + } + } + + if (containsBalancedBrackets) { + metadata = StackElementMetadata.set( + metadata, + 0, + OptionalStandardTokenType.NotSet, + containsBalancedBrackets, + FontStyle.NotSet, + 0, + 0); + } + if (!this.binaryTokens.isEmpty() && getLastElement(this.binaryTokens) == metadata) { // no need to push a token with the same metadata this.lastTokenEndIndex = endIndex; return; } + if (LOGGER.isLoggable(TRACE)) { + final List scopes = scopesList.generateScopes(); + LOGGER.log(TRACE, " token: |" + + castNonNull(this.lineText) + .substring(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex) + .replace("\n", "\\n") + + '|'); + for (final String scope : scopes) { + LOGGER.log(TRACE, " * " + scope); + } + } + this.binaryTokens.add(this.lastTokenEndIndex); this.binaryTokens.add(metadata); @@ -89,7 +151,7 @@ void produceFromScopes(final ScopeListElement scopesList, final int endIndex) { final List scopes = scopesList.generateScopes(); - if (this.lineText != null && LOGGER.isLoggable(TRACE)) { + if (LOGGER.isLoggable(TRACE)) { LOGGER.log(TRACE, " token: |" + castNonNull(this.lineText) .substring(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex) @@ -99,7 +161,11 @@ void produceFromScopes(final ScopeListElement scopesList, final int endIndex) { LOGGER.log(TRACE, " * " + scope); } } - this.tokens.add(new Token(this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, endIndex, scopes)); + + this.tokens.add(new Token( + this.lastTokenEndIndex >= 0 ? this.lastTokenEndIndex : 0, + endIndex, + scopes)); this.lastTokenEndIndex = endIndex; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java index a261959d3..1a93039c5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/MetadataConsts.java @@ -23,13 +23,18 @@ * 1098 7654 3210 9876 5432 1098 7654 3210 * - ------------------------------------------- * xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - * bbbb bbbb bfff ffff ffFF FFTT LLLL LLLL + * bbbb bbbb ffff ffff fFFF FBTT LLLL LLLL * - ------------------------------------------- * - L = LanguageId (8 bits) * - T = StandardTokenType (2 bits) + * - B = Balanced bracket (1 bit) * - F = FontStyle (4 bits) * - f = foreground color (9 bits) * - b = background color (9 bits) + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/metadata.ts */ final class MetadataConsts { @@ -41,13 +46,15 @@ private MetadataConsts() { static final int LANGUAGEID_MASK = 0b00000000000000000000000011111111; static final int TOKEN_TYPE_MASK = 0b00000000000000000000001100000000; - static final int FONT_STYLE_MASK = 0b00000000000000000011110000000000; - static final int FOREGROUND_MASK = 0b00000000011111111100000000000000; - static final int BACKGROUND_MASK = 0b11111111100000000000000000000000; + static final int BALANCED_BRACKETS_MASK = 0b00000000000000000000010000000000; + static final int FONT_STYLE_MASK = 0b00000000000000000111100000000000; + static final int FOREGROUND_MASK = 0b00000000111111111000000000000000; + static final int BACKGROUND_MASK = 0b11111111000000000000000000000000; static final int LANGUAGEID_OFFSET = 0; static final int TOKEN_TYPE_OFFSET = 8; - static final int FONT_STYLE_OFFSET = 10; - static final int FOREGROUND_OFFSET = 14; - static final int BACKGROUND_OFFSET = 23; + static final int BALANCED_BRACKETS_OFFSET = 10; + static final int FONT_STYLE_OFFSET = 11; + static final int FOREGROUND_OFFSET = 15; + static final int BACKGROUND_OFFSET = 24; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java new file mode 100644 index 000000000..71e7f9078 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/Microsoft/vscode-textmate/ + * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. + * Initial license: MIT + * + * Contributors: + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Sebastian Thomschke - translation and adaptation to Java + */ +package org.eclipse.tm4e.core.internal.grammar; + +/** + * Standard TextMate token type. + */ +final class OptionalStandardTokenType { + + /** + * Content should be accessed statically + */ + private OptionalStandardTokenType() { + } + + static final int Other = StandardTokenType.Other; + static final int Comment = StandardTokenType.Comment; + static final int String = StandardTokenType.String; + static final int RegEx = StandardTokenType.RegEx; + static final int NotSet = 8; +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index 7a9936d4b..8e48fd1c7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -148,7 +148,7 @@ public static int mergeMetadata(final int metadata, @Nullable final ScopeListEle } } - return StackElementMetadata.set(metadata, source.languageId, source.tokenType, fontStyle, foreground, + return StackElementMetadata.set(metadata, source.languageId, source.tokenType, null, fontStyle, foreground, background); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index 5e48609d9..cd0425078 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -11,11 +11,16 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.theme.FontStyle; /** * Metadata for {@link StackElement}. + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/metadata.ts */ public final class StackElementMetadata { @@ -39,6 +44,10 @@ static int getTokenType(final int metadata) { return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET; } + static boolean containsBalancedBrackets(final int metadata) { + return (metadata & MetadataConsts.BALANCED_BRACKETS_MASK) != 0; + } + static int getFontStyle(final int metadata) { return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET; } @@ -51,17 +60,21 @@ static int getBackground(final int metadata) { return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET; } - static int set(final int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { - languageId = languageId == 0 ? StackElementMetadata.getLanguageId(metadata) : languageId; - tokenType = tokenType == StandardTokenType.Other ? StackElementMetadata.getTokenType(metadata) : tokenType; - fontStyle = fontStyle == FontStyle.NotSet ? StackElementMetadata.getFontStyle(metadata) : fontStyle; - foreground = foreground == 0 ? StackElementMetadata.getForeground(metadata) : foreground; - background = background == 0 ? StackElementMetadata.getBackground(metadata) : background; - return ((languageId << MetadataConsts.LANGUAGEID_OFFSET) - | (tokenType << MetadataConsts.TOKEN_TYPE_OFFSET) - | (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) - | (foreground << MetadataConsts.FOREGROUND_OFFSET) - | (background << MetadataConsts.BACKGROUND_OFFSET)) >>> 0; - } + static int set(final int metadata, final int languageId, final int tokenType, + @Nullable Boolean containsBalancedBrackets, final int fontStyle, final int foreground, int background) { + final var _languageId = languageId == 0 ? getLanguageId(metadata) : languageId; + final var _tokenType = tokenType == StandardTokenType.Other ? getTokenType(metadata) : tokenType; + final var _containsBalancedBracketsBit = (containsBalancedBrackets == null ? containsBalancedBrackets(metadata) + : containsBalancedBrackets) ? 1 : 0; + final var _fontStyle = fontStyle == FontStyle.NotSet ? getFontStyle(metadata) : fontStyle; + final var _foreground = foreground == 0 ? getForeground(metadata) : foreground; + final var _background = background == 0 ? getBackground(metadata) : background; + return ((_languageId << MetadataConsts.LANGUAGEID_OFFSET) + | (_tokenType << MetadataConsts.TOKEN_TYPE_OFFSET) + | (_containsBalancedBracketsBit << MetadataConsts.BALANCED_BRACKETS_OFFSET) + | (_fontStyle << MetadataConsts.FONT_STYLE_OFFSET) + | (_foreground << MetadataConsts.FOREGROUND_OFFSET) + | (_background << MetadataConsts.BACKGROUND_OFFSET)) >>> 0; + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java index b106bbac5..914406d18 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StandardTokenType.java @@ -14,7 +14,7 @@ /** * Standard TextMate token type. */ -class StandardTokenType { +final class StandardTokenType { /** * Content should be accessed statically diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java new file mode 100644 index 000000000..7f37dc7ce --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/Microsoft/vscode-textmate/ + * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. + * Initial license: MIT + * + * Contributors: + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Sebastian Thomschke - translation and adaptation to Java + */ +package org.eclipse.tm4e.core.internal.grammar; + +import java.util.List; +import java.util.function.Predicate; + +public interface TokenTypeMatcher { + + Predicate> getMatcher(); + + int /*StandardTokenType*/ getType(); +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java index 6f5c3858e..bfcfae850 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java @@ -21,7 +21,12 @@ import org.eclipse.jdt.annotation.Nullable; -interface IMatchesName { +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts + */ +public interface IMatchesName { IMatchesName> NAME_MATCHER = new IMatchesName<>() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java index d620448e6..21b9a536a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java @@ -27,6 +27,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.internal.grammar.BalancedBracketSelectors; import org.eclipse.tm4e.core.internal.grammar.Grammar; import org.eclipse.tm4e.core.internal.grammar.Raw; import org.eclipse.tm4e.core.internal.types.IRawGrammar; @@ -112,14 +113,17 @@ public List themeMatch(final String scopeName) { */ @Nullable public IGrammar grammarForScopeName(final String scopeName, final int initialLanguage, - @Nullable final Map embeddedLanguages) { + @Nullable final Map embeddedLanguages, + @Nullable final Map tokenTypes, + @Nullable BalancedBracketSelectors balancedBracketSelectors) { if (!this.grammars.containsKey(scopeName)) { final var rawGrammar = lookup(scopeName); if (rawGrammar == null) { return null; } this.grammars.put(scopeName, - new Grammar(scopeName, rawGrammar, initialLanguage, embeddedLanguages, this, this)); + new Grammar(scopeName, rawGrammar, initialLanguage, embeddedLanguages, tokenTypes, + balancedBracketSelectors, this, this)); } return this.grammars.get(scopeName); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index d3824a485..1127730e0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -35,7 +35,8 @@ /** * The registry that will hold all grammars. * - * TODO outdated compared to upstream as of: https://github.com/microsoft/vscode-textmate/commit/b166b75fa72d2dd3efce0d68c98c2bd10adc1ef1 + * TODO outdated compared to upstream as of: + * https://github.com/microsoft/vscode-textmate/commit/b166b75fa72d2dd3efce0d68c98c2bd10adc1ef1 * * @see @@ -152,7 +153,8 @@ public IGrammar grammarForScopeName(final String scopeName) { @Nullable public IGrammar grammarForScopeName(final String scopeName, final int initialLanguage, @Nullable final Map embeddedLanguages) { - return this.syncRegistry.grammarForScopeName(scopeName, initialLanguage, embeddedLanguages); + return this.syncRegistry.grammarForScopeName(scopeName, initialLanguage, embeddedLanguages, /*TODO*/null, + /*TODO*/null); } public IRegistryOptions getLocator() { diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java index 10fb9f049..5674a6e82 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java @@ -11,7 +11,8 @@ */ package org.eclipse.tm4e.core.internal.grammar; -import org.eclipse.tm4e.core.theme.FontStyle; +import static org.eclipse.tm4e.core.theme.FontStyle.*; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -25,68 +26,62 @@ public class GrammarTest { @Test public void testWorks() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, - 102); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); } @Test public void testCanOverwriteLanguageId() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, - 102); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 2, StandardTokenType.Other, FontStyle.NotSet, 0, 0); - assertEquals(value, 2, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); + value = StackElementMetadata.set(value, 2, StandardTokenType.Other, null, NotSet, 0, 0); + assertEquals(value, 2, StandardTokenType.RegEx, Underline | Bold, 101, 102); } @Test public void testCanOverwriteTokenType() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, - 102); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Comment, FontStyle.NotSet, 0, 0); - assertEquals(value, 1, StandardTokenType.Comment, FontStyle.Underline | FontStyle.Bold, 101, 102); + value = StackElementMetadata.set(value, 0, StandardTokenType.Comment, null, NotSet, 0, 0); + assertEquals(value, 1, StandardTokenType.Comment, Underline | Bold, 101, 102); } @Test public void testCanOverwriteFontStyle() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, - 102); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.None, 0, 0); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102); + value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, None, 0, 0); + assertEquals(value, 1, StandardTokenType.RegEx, None, 101, 102); } @Test public void testCanOverwriteFontStyleWithStrikethrough() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102); + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Strikethrough, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, Strikethrough, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.None, 0, 0); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102); + value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, None, 0, 0); + assertEquals(value, 1, StandardTokenType.RegEx, None, 101, 102); } @Test public void testCanOverwriteForeground() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, - 102); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 5, 0); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 5, 102); + value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, NotSet, 5, 0); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 5, 102); } @Test public void testCanOverwriteBackground() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, - 102); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 0, 7); - assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 7); + value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, NotSet, 0, 7); + assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 7); } @Test @@ -94,22 +89,24 @@ public void testCanWorkAtMaxValues() { int maxLangId = 255; int maxTokenType = StandardTokenType.Comment | StandardTokenType.Other | StandardTokenType.RegEx | StandardTokenType.String; - int maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline; + int maxFontStyle = Bold | Italic | Underline; int maxForeground = 511; - int maxBackground = 511; + int maxBackground = 254; - int value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground); + int value = StackElementMetadata.set(0, maxLangId, maxTokenType, null, maxFontStyle, maxForeground, + maxBackground); assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground); } - private static void assertEquals(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { + private static void assertEquals(int metadata, int languageId, int tokenType, int fontStyle, int foreground, + int background) { String actual = "{\n" + - "languageId: " + StackElementMetadata.getLanguageId(metadata) + ",\n" + - "tokenType: " + StackElementMetadata.getTokenType(metadata) + ",\n" + - "fontStyle: " + StackElementMetadata.getFontStyle(metadata) + ",\n" + - "foreground: " + StackElementMetadata.getForeground(metadata) + ",\n" + - "background: " + StackElementMetadata.getBackground(metadata) + ",\n" + - "}"; + "languageId: " + StackElementMetadata.getLanguageId(metadata) + ",\n" + + "tokenType: " + StackElementMetadata.getTokenType(metadata) + ",\n" + + "fontStyle: " + StackElementMetadata.getFontStyle(metadata) + ",\n" + + "foreground: " + StackElementMetadata.getForeground(metadata) + ",\n" + + "background: " + StackElementMetadata.getBackground(metadata) + ",\n" + + "}"; String expected = "{\n" + "languageId: " + languageId + ",\n" + @@ -117,7 +114,7 @@ private static void assertEquals(int metadata, int languageId, int tokenType, in "fontStyle: " + fontStyle + ",\n" + "foreground: " + foreground + ",\n" + "background: " + background + ",\n" + - "}"; + "}"; Assertions.assertEquals(expected, actual, "equals for " + StackElementMetadata.toBinaryStr(metadata)); } From 787c96682f6fb7e7f3ad3441a7b95cca37a3c94a Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 14:15:17 +0200 Subject: [PATCH 139/202] Align usage of OptionalStandardTokenType with upstream --- .../grammar/OptionalStandardTokenType.java | 4 +++ .../core/internal/grammar/ScopeMetadata.java | 6 +++-- .../grammar/ScopeMetadataProvider.java | 18 ++++++------- .../grammar/StackElementMetadata.java | 4 +-- .../core/internal/grammar/GrammarTest.java | 26 +++++++++---------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java index 71e7f9078..b1139aefc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/OptionalStandardTokenType.java @@ -32,5 +32,9 @@ private OptionalStandardTokenType() { static final int Comment = StandardTokenType.Comment; static final int String = StandardTokenType.String; static final int RegEx = StandardTokenType.RegEx; + + /** + * Indicates that no token type is set. + */ static final int NotSet = 8; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java index 3cec3927b..4af964032 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java @@ -20,12 +20,14 @@ public final class ScopeMetadata { final String scopeName; final int languageId; - final int tokenType; + final int /*OptionalStandardTokenType*/ tokenType; @Nullable final List themeData; - public ScopeMetadata(final String scopeName, final int languageId, final int tokenType, @Nullable final List themeData) { + public ScopeMetadata(final String scopeName, final int languageId, + final int /*OptionalStandardTokenType*/ tokenType, + @Nullable final List themeData) { this.scopeName = scopeName; this.languageId = languageId; this.tokenType = tokenType; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java index 0afe7fcfd..45c0a0ab2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java @@ -31,7 +31,7 @@ */ final class ScopeMetadataProvider { - private static final ScopeMetadata NULL_SCOPE_METADATA = new ScopeMetadata("", 0, StandardTokenType.Other, null); + private static final ScopeMetadata NULL_SCOPE_METADATA = new ScopeMetadata("", 0, 0, null); private static final Pattern STANDARD_TOKEN_TYPE_REGEXP = Pattern.compile("\\b(comment|string|regex)\\b"); private static final String COMMENT_TOKEN_TYPE = "comment"; @@ -57,7 +57,7 @@ final class ScopeMetadataProvider { this.defaultMetaData = new ScopeMetadata( "", this.initialLanguage, - StandardTokenType.Other, + OptionalStandardTokenType.NotSet, List.of(this.themeProvider.getDefaults())); // embeddedLanguages handling @@ -85,7 +85,7 @@ void onDidChangeTheme() { this.defaultMetaData = new ScopeMetadata( "", this.initialLanguage, - StandardTokenType.Other, + OptionalStandardTokenType.NotSet, List.of(this.themeProvider.getDefaults())); } @@ -138,21 +138,21 @@ private int scopeToLanguage(@Nullable final String scope) { return embeddedLanguages.getOrDefault(m.group(1), 0); } - private static int toStandardTokenType(final String tokenType) { + private static int /*OptionalStandardTokenType*/ toStandardTokenType(final String tokenType) { final var m = STANDARD_TOKEN_TYPE_REGEXP.matcher(tokenType); if (!m.find()) { - return StandardTokenType.Other; + return OptionalStandardTokenType.NotSet; } final String group = m.group(1); switch (group) { case COMMENT_TOKEN_TYPE: - return StandardTokenType.Comment; + return OptionalStandardTokenType.Comment; case STRING_TOKEN_TYPE: - return StandardTokenType.String; + return OptionalStandardTokenType.String; case REGEX_TOKEN_TYPE: - return StandardTokenType.RegEx; + return OptionalStandardTokenType.RegEx; case META_EMBEDDED_TOKEN_TYPE: - return StandardTokenType.Other; + return OptionalStandardTokenType.Other; default: throw new TMException("Unexpected match for standard token type: " + group); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index cd0425078..0c9d058c2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -60,10 +60,10 @@ static int getBackground(final int metadata) { return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET; } - static int set(final int metadata, final int languageId, final int tokenType, + static int set(final int metadata, final int languageId, final /*OptionalStandardTokenType*/ int tokenType, @Nullable Boolean containsBalancedBrackets, final int fontStyle, final int foreground, int background) { final var _languageId = languageId == 0 ? getLanguageId(metadata) : languageId; - final var _tokenType = tokenType == StandardTokenType.Other ? getTokenType(metadata) : tokenType; + final var _tokenType = tokenType == OptionalStandardTokenType.NotSet ? getTokenType(metadata) : tokenType; final var _containsBalancedBracketsBit = (containsBalancedBrackets == null ? containsBalancedBrackets(metadata) : containsBalancedBrackets) ? 1 : 0; final var _fontStyle = fontStyle == FontStyle.NotSet ? getFontStyle(metadata) : fontStyle; diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java index 5674a6e82..f3b370504 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java @@ -26,61 +26,61 @@ public class GrammarTest { @Test public void testWorks() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); } @Test public void testCanOverwriteLanguageId() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 2, StandardTokenType.Other, null, NotSet, 0, 0); + value = StackElementMetadata.set(value, 2, OptionalStandardTokenType.NotSet, null, NotSet, 0, 0); assertEquals(value, 2, StandardTokenType.RegEx, Underline | Bold, 101, 102); } @Test public void testCanOverwriteTokenType() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Comment, null, NotSet, 0, 0); + value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.Comment, null, NotSet, 0, 0); assertEquals(value, 1, StandardTokenType.Comment, Underline | Bold, 101, 102); } @Test public void testCanOverwriteFontStyle() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, None, 0, 0); + value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, None, 0, 0); assertEquals(value, 1, StandardTokenType.RegEx, None, 101, 102); } @Test public void testCanOverwriteFontStyleWithStrikethrough() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Strikethrough, 101, 102); + int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Strikethrough, 101, 102); assertEquals(value, 1, StandardTokenType.RegEx, Strikethrough, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, None, 0, 0); + value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, None, 0, 0); assertEquals(value, 1, StandardTokenType.RegEx, None, 101, 102); } @Test public void testCanOverwriteForeground() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, NotSet, 5, 0); + value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, NotSet, 5, 0); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 5, 102); } @Test public void testCanOverwriteBackground() { - int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, null, Underline | Bold, 101, 102); + int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); - value = StackElementMetadata.set(value, 0, StandardTokenType.Other, null, NotSet, 0, 7); + value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, NotSet, 0, 7); assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 7); } From 10eaf795efd6de92398992f364c365b6cc036537 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 15:15:15 +0200 Subject: [PATCH 140/202] Align matcher implementation better with upstream --- .../grammar/internal/MatcherTestImpl.java | 2 +- .../grammar/BalancedBracketSelectors.java | 13 +- .../tm4e/core/internal/grammar/Grammar.java | 3 +- .../tm4e/core/internal/grammar/Injection.java | 8 +- .../core/internal/grammar/LineTokens.java | 5 +- .../internal/grammar/TokenTypeMatcher.java | 5 +- .../tm4e/core/internal/matcher/Matcher.java | 189 +---------------- .../core/internal/matcher/MatcherBuilder.java | 199 ++++++++++++++++++ .../internal/matcher/MatcherWithPriority.java | 6 +- .../{IMatchesName.java => NameMatcher.java} | 12 +- 10 files changed, 233 insertions(+), 209 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/{IMatchesName.java => NameMatcher.java} (83%) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java index 15591e48a..813720055 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/MatcherTestImpl.java @@ -31,7 +31,7 @@ public MatcherTestImpl() { public void executeTest() { Collection>> matcher = Matcher.createMatchers(expression); - boolean result = matcher.stream().anyMatch(m -> m.matcher.test(input)); + boolean result = matcher.stream().anyMatch(m -> m.matcher.matches(input)); assertEquals(result, this.result); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java index a924a3a04..81081c901 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java @@ -18,14 +18,13 @@ package org.eclipse.tm4e.core.internal.grammar; import java.util.List; -import java.util.function.Predicate; import java.util.stream.Stream; import org.eclipse.tm4e.core.internal.matcher.Matcher; public class BalancedBracketSelectors { - private final Predicate>[] balancedBracketScopes; - private final Predicate>[] unbalancedBracketScopes; + private final Matcher>[] balancedBracketScopes; + private final Matcher>[] unbalancedBracketScopes; private boolean allowAny = false; @@ -38,11 +37,11 @@ public class BalancedBracketSelectors { } return Matcher.createMatchers(selector).stream(); }) - .map(m -> m.matcher).toArray(Predicate[]::new); + .map(m -> m.matcher).toArray(Matcher[]::new); this.unbalancedBracketScopes = unbalancedBracketScopes.stream() .flatMap(selector -> Matcher.createMatchers(selector).stream()) - .map(m -> m.matcher).toArray(Predicate[]::new); + .map(m -> m.matcher).toArray(Matcher[]::new); } boolean matchesAlways() { @@ -55,13 +54,13 @@ boolean matchesNever() { boolean match(final List scopes) { for (final var excluder : this.unbalancedBracketScopes) { - if (excluder.test(scopes)) { + if (excluder.matches(scopes)) { return false; } } for (final var includer : this.balancedBracketScopes) { - if (includer.test(scopes)) { + if (includer.matches(scopes)) { return true; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 057207b7e..606dfff21 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Objects; import java.util.function.IntFunction; -import java.util.function.Predicate; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -97,7 +96,7 @@ public int getType() { } @Override - public Predicate> getMatcher() { + public Matcher> getMatcher() { return matcher.matcher; } }); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java index 01db316f2..c76713741 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java @@ -17,18 +17,18 @@ package org.eclipse.tm4e.core.internal.grammar; import java.util.List; -import java.util.function.Predicate; +import org.eclipse.tm4e.core.internal.matcher.Matcher; import org.eclipse.tm4e.core.internal.types.IRawGrammar; class Injection { - private final Predicate> matcher; + private final Matcher> matcher; public final int priority; // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R' public final int ruleId; public final IRawGrammar grammar; - public Injection(final Predicate> matcher, final int ruleId, final IRawGrammar grammar, final int priority) { + public Injection(final Matcher> matcher, final int ruleId, final IRawGrammar grammar, final int priority) { this.matcher = matcher; this.ruleId = ruleId; this.grammar = grammar; @@ -36,6 +36,6 @@ public Injection(final Predicate> matcher, final int ruleId, final } public boolean match(final List states) { - return matcher.test(states); + return matcher.matches(states); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 1210a863d..967072999 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -16,11 +16,10 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static java.lang.System.Logger.Level.*; import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; -import static java.lang.System.Logger.Level.*; - import java.lang.System.Logger; import java.util.ArrayList; import java.util.Collections; @@ -97,7 +96,7 @@ void produceFromScopes(final ScopeListElement scopesList, final int endIndex) { // Only generate scope array when required to improve performance final var scopes = scopesList.generateScopes(); for (final var tokenType : tokenTypeOverrides) { - if (tokenType.getMatcher().test(scopes)) { + if (tokenType.getMatcher().matches(scopes)) { metadata = StackElementMetadata.set( metadata, 0, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java index 7f37dc7ce..66d4bd725 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenTypeMatcher.java @@ -18,11 +18,12 @@ package org.eclipse.tm4e.core.internal.grammar; import java.util.List; -import java.util.function.Predicate; + +import org.eclipse.tm4e.core.internal.matcher.Matcher; public interface TokenTypeMatcher { - Predicate> getMatcher(); + Matcher> getMatcher(); int /*StandardTokenType*/ getType(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java index 0ed87268b..a48c00bfa 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/Matcher.java @@ -16,190 +16,19 @@ */ package org.eclipse.tm4e.core.internal.matcher; -import static java.lang.System.Logger.Level.*; - -import java.lang.System.Logger; -import java.util.ArrayList; import java.util.List; -import java.util.function.Predicate; -import java.util.regex.Pattern; - -import org.eclipse.jdt.annotation.Nullable; - -/** - * Matcher utilities. - * - * @see - * github.com/Microsoft/vscode-textmate/blob/master/src/matcher.ts - */ -public final class Matcher { - - private static final Logger LOGGER = System.getLogger(Matcher.class.getName()); - public static List>> createMatchers(final String expression) { - return new Matcher<>(expression, IMatchesName.NAME_MATCHER).results; - } - - private final List> results = new ArrayList<>(); - private final Tokenizer tokenizer; - private final IMatchesName matchesName; - - @Nullable - private String token; - - private Matcher(final String expression, final IMatchesName matchesName) { - tokenizer = new Tokenizer(expression); - this.matchesName = matchesName; +@FunctionalInterface +public interface Matcher { - // defining local token variable for annotation-based null analysis - var token = this.token = tokenizer.next(); - while (token != null) { - int priority = 0; - if (token.length() == 2 && token.charAt(1) == ':') { - switch (token.charAt(0)) { - case 'R': - priority = 1; - break; - case 'L': - priority = -1; - break; - default: - LOGGER.log(WARNING, "Unknown priority %s in scope selector %s", token, expression); - } - this.token = tokenizer.next(); - } - final Predicate matcher = parseConjunction(); - results.add(new MatcherWithPriority<>(matcher, priority)); - if (!",".equals(this.token)) { - break; - } - token = this.token = tokenizer.next(); - } + public static List>> createMatchers(final String selector) { + return createMatchers(selector, NameMatcher.DEFAULT); } - private Predicate parseInnerExpression() { - final var matchers = new ArrayList>(); - Predicate matcher = parseConjunction(); - while (true) { - matchers.add(matcher); - if ("|".equals(token) || ",".equals(token)) { - do { - token = tokenizer.next(); - } while ("|".equals(token) || ",".equals(token)); // ignore subsequent commas - } else { - break; - } - matcher = parseConjunction(); - } - - // some (or) - return matcherInput -> { - // same as 'matchers.stream().anyMatch(m -> m.test(matcherInput))' but more memory friendly - for (final Predicate matcher1 : matchers) { - if (matcher1.test(matcherInput)) { - return true; - } - } - return false; - }; + public static List>> createMatchers(final String selector, + final NameMatcher> matchesName) { + return new MatcherBuilder<>(selector, matchesName).results; } - private Predicate parseConjunction() { - final var matchers = new ArrayList>(); - Predicate matcher = parseOperand(); - while (matcher != null) { - matchers.add(matcher); - matcher = parseOperand(); - } - - // every (and) - return matcherInput -> { - // same as 'matchers.stream().allMatch(m -> m.test(matcherInput))' but more memory friendly - for (final Predicate matcher1 : matchers) { - if (!matcher1.test(matcherInput)) { - return false; - } - } - return true; - }; - } - - @Nullable - private Predicate parseOperand() { - if ("-".equals(token)) { - token = tokenizer.next(); - final var expressionToNegate = parseOperand(); - return matcherInput -> expressionToNegate != null && !expressionToNegate.test(matcherInput); - } - - if ("(".equals(token)) { - token = tokenizer.next(); - final var expressionInParents = parseInnerExpression(); - if (")".equals(token)) { - token = tokenizer.next(); - } - return expressionInParents; - } - - // defining local token variable for annotation-based null analysis - var token = this.token; - if (token != null && isIdentifier(token)) { - final var identifiers = new ArrayList(); - do { - identifiers.add(token); - token = this.token = tokenizer.next(); - } while (token != null && isIdentifier(token)); - return matcherInput -> matchesName.match(identifiers, matcherInput); - } - return null; - } - - /** - * https://github.com/microsoft/vscode-textmate/blob/master/src/matcher.ts#L89 - */ - private boolean isIdentifier(String token) { - if (token.isEmpty()) - return false; - - /* Aprox. 2-3 times faster than: - * static final Pattern IDENTIFIER_REGEXP = Pattern.compile("[\\w\\.:]+"); - * IDENTIFIER_REGEXP.matcher(token).matches(); - * - * Aprox. 10% faster than: - * token.chars().allMatch(ch -> ... ) - */ - for (int i = 0; i < token.length(); i++) { - final char ch = token.charAt(i); - if (ch == '.' || ch == ':' || ch == '_' - || (ch >= 'a' && ch <= 'z') - || (ch >= 'A' && ch <= 'Z') - || (ch >= '0' && ch <= '9')) - continue; - return false; - } - return true; - } - - private static final class Tokenizer { - - /** - * https://github.com/microsoft/vscode-textmate/blob/master/src/matcher.ts#L94 - */ - private static final Pattern TOKEN_PATTERN = Pattern - .compile("([LR]:|[\\w\\.:][\\w\\.:\\-]*|[\\,\\|\\-\\(\\)])"); - - private final java.util.regex.Matcher regex; - - private Tokenizer(final String input) { - regex = TOKEN_PATTERN.matcher(input); - } - - @Nullable - private String next() { - if (regex.find()) { - return regex.group(); - } - return null; - } - } -} \ No newline at end of file + boolean matches(T t); +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java new file mode 100644 index 000000000..765c8e010 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java @@ -0,0 +1,199 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/Microsoft/vscode-textmate/ + * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. + * Initial license: MIT + * + * Contributors: + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java + */ +package org.eclipse.tm4e.core.internal.matcher; + +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import org.eclipse.jdt.annotation.Nullable; + +/** + * Matcher utilities. + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/matcher.ts + */ +final class MatcherBuilder { + + private static final Logger LOGGER = System.getLogger(MatcherBuilder.class.getName()); + + final List> results = new ArrayList<>(); + private final Tokenizer tokenizer; + private final NameMatcher matchesName; + + @Nullable + private String token; + + MatcherBuilder(final String selector, final NameMatcher matchesName) { + tokenizer = new Tokenizer(selector); + this.matchesName = matchesName; + + // defining local token variable for annotation-based null analysis + var token = this.token = tokenizer.next(); + while (token != null) { + int priority = 0; + if (token.length() == 2 && token.charAt(1) == ':') { + switch (token.charAt(0)) { + case 'R': + priority = 1; + break; + case 'L': + priority = -1; + break; + default: + LOGGER.log(WARNING, "Unknown priority %s in scope selector %s", token, selector); + } + this.token = tokenizer.next(); + } + final Matcher matcher = parseConjunction(); + results.add(new MatcherWithPriority<>(matcher, priority)); + if (!",".equals(this.token)) { + break; + } + token = this.token = tokenizer.next(); + } + } + + @Nullable + private Matcher parseOperand() { + if ("-".equals(token)) { + token = tokenizer.next(); + final var expressionToNegate = parseOperand(); + return matcherInput -> expressionToNegate != null && !expressionToNegate.matches(matcherInput); + } + + if ("(".equals(token)) { + token = tokenizer.next(); + final var expressionInParents = parseInnerExpression(); + if (")".equals(token)) { + token = tokenizer.next(); + } + return expressionInParents; + } + + // defining local token variable for annotation-based null analysis + var token = this.token; + if (token != null && isIdentifier(token)) { + final var identifiers = new ArrayList(); + do { + identifiers.add(token); + token = this.token = tokenizer.next(); + } while (token != null && isIdentifier(token)); + return matcherInput -> matchesName.matches(identifiers, matcherInput); + } + return null; + } + + private Matcher parseConjunction() { + final var matchers = new ArrayList>(); + Matcher matcher = parseOperand(); + while (matcher != null) { + matchers.add(matcher); + matcher = parseOperand(); + } + + // every (and) + return matcherInput -> { + // same as 'matchers.stream().allMatch(m -> m.test(matcherInput))' but more memory friendly + for (final Matcher matcher1 : matchers) { + if (!matcher1.matches(matcherInput)) { + return false; + } + } + return true; + }; + } + + private Matcher parseInnerExpression() { + final var matchers = new ArrayList>(); + Matcher matcher = parseConjunction(); + while (true) { + matchers.add(matcher); + if ("|".equals(token) || ",".equals(token)) { + do { + token = tokenizer.next(); + } while ("|".equals(token) || ",".equals(token)); // ignore subsequent commas + } else { + break; + } + matcher = parseConjunction(); + } + + // some (or) + return matcherInput -> { + // same as 'matchers.stream().anyMatch(m -> m.test(matcherInput))' but more memory friendly + for (final Matcher matcher1 : matchers) { + if (matcher1.matches(matcherInput)) { + return true; + } + } + return false; + }; + } + + /** + * https://github.com/microsoft/vscode-textmate/blob/master/src/matcher.ts#L89 + */ + private boolean isIdentifier(String token) { + if (token.isEmpty()) + return false; + + /* Aprox. 2-3 times faster than: + * static final Pattern IDENTIFIER_REGEXP = Pattern.compile("[\\w\\.:]+"); + * IDENTIFIER_REGEXP.matcher(token).matches(); + * + * Aprox. 10% faster than: + * token.chars().allMatch(ch -> ... ) + */ + for (int i = 0; i < token.length(); i++) { + final char ch = token.charAt(i); + if (ch == '.' || ch == ':' || ch == '_' + || (ch >= 'a' && ch <= 'z') + || (ch >= 'A' && ch <= 'Z') + || (ch >= '0' && ch <= '9')) + continue; + return false; + } + return true; + } + + private static final class Tokenizer { + + /** + * https://github.com/microsoft/vscode-textmate/blob/master/src/matcher.ts#L94 + */ + static final Pattern TOKEN_PATTERN = Pattern.compile("([LR]:|[\\w\\.:][\\w\\.:\\-]*|[\\,\\|\\-\\(\\)])"); + + final java.util.regex.Matcher regex; + + Tokenizer(final String input) { + regex = TOKEN_PATTERN.matcher(input); + } + + @Nullable + String next() { + if (!regex.find()) { + return null; + } + return regex.group(); + } + } +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java index 3365b05d6..742865f40 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherWithPriority.java @@ -16,14 +16,12 @@ */ package org.eclipse.tm4e.core.internal.matcher; -import java.util.function.Predicate; - public final class MatcherWithPriority { - public final Predicate matcher; + public final Matcher matcher; public final int priority; - MatcherWithPriority(final Predicate matcher, final int priority) { + MatcherWithPriority(final Matcher matcher, final int priority) { this.matcher = matcher; this.priority = priority; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/NameMatcher.java similarity index 83% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/NameMatcher.java index bfcfae850..439f82d1e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/IMatchesName.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/NameMatcher.java @@ -26,17 +26,17 @@ * "https://github.com/microsoft/vscode-textmate/blob/9157c7f869219dbaf9a5a5607f099c00fe694a29/src/grammar.ts#L276"> * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts */ -public interface IMatchesName { +public interface NameMatcher { - IMatchesName> NAME_MATCHER = new IMatchesName<>() { + NameMatcher> DEFAULT = new NameMatcher<>() { @Override - public boolean match(final Collection identifers, final List scopes) { - if (scopes.size() < identifers.size()) { + public boolean matches(final Collection identifiers, final List scopes) { + if (scopes.size() < identifiers.size()) { return false; } final int[] lastIndex = { 0 }; - return identifers.stream().allMatch(identifier -> { + return identifiers.stream().allMatch(identifier -> { for (int i = lastIndex[0]; i < scopes.size(); i++) { if (scopesAreMatching(scopes.get(i), identifier)) { lastIndex[0]++; @@ -61,5 +61,5 @@ private boolean scopesAreMatching(@Nullable final String thisScopeName, final St } }; - boolean match(Collection names, T scopes); + boolean matches(Collection names, T scopes); } \ No newline at end of file From 20ea268f913d457fae634e1bee6592e144af449c Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 17:19:52 +0200 Subject: [PATCH 141/202] Add logging --- .../tm4e/core/internal/grammar/Grammar.java | 14 +++++++- .../tm4e/core/internal/grammar/Injection.java | 15 +++++---- .../core/internal/grammar/LineTokenizer.java | 33 +++++++++++++------ .../tm4e/core/internal/rule/CompiledRule.java | 14 +++++--- .../core/internal/rule/RegExpSourceList.java | 5 ++- 5 files changed, 56 insertions(+), 25 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 606dfff21..a7a335537 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -19,6 +19,8 @@ import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -54,6 +56,8 @@ */ public final class Grammar implements IGrammar, IRuleFactoryHelper { + private static final Logger LOGGER = System.getLogger(RuleFactory.class.getName()); + private final String scopeName; private int rootId = -1; @@ -119,7 +123,7 @@ private void collectInjections(final List result, final String select final int ruleId = RuleFactory.getCompiledRuleId(rule, ruleFactoryHelper, this.grammar.getRepositorySafe()); for (final var matcher : matchers) { - result.add(new Injection(matcher.matcher, ruleId, grammar, matcher.priority)); + result.add(new Injection(selector, matcher.matcher, ruleId, grammar, matcher.priority)); } } @@ -186,6 +190,14 @@ List getInjections() { var injections = this.injections; if (injections == null) { injections = this.injections = this.collectInjections(); + + if (LOGGER.isLoggable(Level.TRACE) && !injections.isEmpty()) { + LOGGER.log(Level.TRACE, + "Grammar " + scopeName + " contains the following injections:"); + for (final var injection : injections) { + LOGGER.log(Level.TRACE, " - " + injection.debugSelector); + } + } } return injections; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java index c76713741..f6fc0bc13 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Injection.java @@ -21,21 +21,24 @@ import org.eclipse.tm4e.core.internal.matcher.Matcher; import org.eclipse.tm4e.core.internal.types.IRawGrammar; -class Injection { +final class Injection { + final String debugSelector; private final Matcher> matcher; - public final int priority; // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R' - public final int ruleId; - public final IRawGrammar grammar; + final int priority; // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R' + final int ruleId; + final IRawGrammar grammar; - public Injection(final Matcher> matcher, final int ruleId, final IRawGrammar grammar, final int priority) { + Injection(final String debugSelector, final Matcher> matcher, final int ruleId, + final IRawGrammar grammar, final int priority) { + this.debugSelector = debugSelector; this.matcher = matcher; this.ruleId = ruleId; this.grammar = grammar; this.priority = priority; } - public boolean match(final List states) { + boolean matches(final List states) { return matcher.matches(states); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 55bc70542..7446ff3f1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -16,12 +16,12 @@ */ package org.eclipse.tm4e.core.internal.grammar; +import static java.lang.System.Logger.Level.*; import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; -import static java.lang.System.Logger.Level.*; - import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; @@ -278,10 +278,10 @@ private void scanNext() { @Nullable private IMatchResult matchRule(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, - final int linePos, - final StackElement stack, final int anchorPosition) { + final int linePos, final StackElement stack, final int anchorPosition) { final Rule rule = stack.getRule(grammar); final CompiledRule ruleScanner = rule.compileAG(grammar, stack.endRule, isFirstLine, linePos == anchorPosition); + final OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); if (r != null) { @@ -354,7 +354,7 @@ private IMatchInjectionsResult matchInjections(final List injections, final List scopes = stack.contentNameScopesList.generateScopes(); for (final Injection injection : injections) { - if (!injection.match(scopes)) { + if (!injection.matches(scopes)) { // injection selector doesn't match stack continue; } @@ -367,6 +367,10 @@ private IMatchInjectionsResult matchInjections(final List injections, continue; } + if (LOGGER.isLoggable(Level.TRACE)) { + LOGGER.log(Level.TRACE, " matched injection: " + injection.debugSelector); + LOGGER.log(Level.TRACE, debugCompiledRuleToString(ruleScanner)); + } final int matchRating = matchResult.getCaptureIndices()[0].start; if (matchRating > bestMatchRating) { @@ -508,15 +512,16 @@ private WhileCheckResult checkWhileConditions(final Grammar grammar, final OnigS whileRules.add(new WhileStack(node, (BeginWhileRule) nodeRule)); } } + for (int i = whileRules.size() - 1; i >= 0; i--) { - final var whileRule = castNonNull(whileRules.get(i)); + final var whileRule = whileRules.get(i); final var ruleScanner = whileRule.rule.compileWhileAG(whileRule.stack.endRule, isFirstLine, currentanchorPosition == linePos); final var r = ruleScanner.scanner.findNextMatchSync(lineText, linePos); - // if (IN_DEBUG_MODE) { - // console.log(' scanning for while rule'); - // console.log(debugCompiledRuleToString(ruleScanner)); - // } + if (LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, " scanning for while rule"); + LOGGER.log(TRACE, debugCompiledRuleToString(ruleScanner)); + } if (r != null) { final int matchedRuleId = ruleScanner.rules[r.getIndex()]; @@ -549,4 +554,12 @@ static StackElement tokenizeString(final Grammar grammar, final OnigString lineT final int linePos, final StackElement stack, final LineTokens lineTokens) { return new LineTokenizer(grammar, lineText, isFirstLine, linePos, stack, lineTokens).scan(); } + + static String debugCompiledRuleToString(CompiledRule ruleScanner) { + final var r = new ArrayList(); + for (int i = 0, l = ruleScanner.rules.length; i < l; i++) { + r.add(" - " + ruleScanner.rules[i] + ": " + ruleScanner.debugRegExps.get(i)); + } + return String.join(System.lineSeparator(), r); + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java index ff3552b5d..e4a91483b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,11 +11,13 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.rule; +import java.util.List; + import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner; /** @@ -25,11 +27,13 @@ */ public final class CompiledRule { + public final List debugRegExps; public final OnigScanner scanner; public final int[] rules; - CompiledRule(OnigScanner scanner, int[] rules) { - this.scanner = scanner; + CompiledRule(List regExps, int[] rules) { + this.debugRegExps = regExps; this.rules = rules; + this.scanner = new OnigScanner(regExps); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java index 689fcff7c..5e6d71733 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSourceList.java @@ -22,7 +22,6 @@ import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.internal.oniguruma.OnigScanner; /** * @see regexps = items.stream().map(RegExpSource::getSource).collect(Collectors.toList()); - cached = this.cached = new CompiledRule(new OnigScanner(regexps), getRules()); + cached = this.cached = new CompiledRule(regexps, getRules()); } return cached; } @@ -99,7 +98,7 @@ CompiledRule compileAG(final boolean allowA, final boolean allowG) { private CompiledRule resolveAnchors(final boolean allowA, final boolean allowG) { final List regexps = items.stream().map(e -> e.resolveAnchors(allowA, allowG)) .collect(Collectors.toList()); - return new CompiledRule(new OnigScanner(regexps), getRules()); + return new CompiledRule(regexps, getRules()); } private int[] getRules() { From d392635f7ea79abeef38552a906b0ec12d7d4fbb Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 17:26:54 +0200 Subject: [PATCH 142/202] Avoid unnecessary auto-boxing --- .../org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java | 2 +- .../org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index 141255d61..3964beedc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -63,7 +63,7 @@ public String getWhileWithResolvedBackReferences(String lineText, OnigCaptureInd public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { if (isFirst) { Rule rule; - for (Integer pattern : patterns) { + for (int pattern : patterns) { rule = grammar.getRule(pattern); rule.collectPatternsRecursive(grammar, out, false); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java index 51c788bf2..bf987d5b5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java @@ -41,7 +41,7 @@ final class IncludeOnlyRule extends Rule { @Override public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSourceList out, final boolean isFirst) { - for (final Integer pattern : this.patterns) { + for (final int pattern : this.patterns) { final Rule rule = grammar.getRule(pattern); rule.collectPatternsRecursive(grammar, out, false); } From 4e0f7fe90885102eddf4691641225dcdc9d12d7f Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 17:53:29 +0200 Subject: [PATCH 143/202] Ensure even capture rules starting at position 0 are not checked for while conditions See https://github.com/microsoft/vscode-textmate/commit/2d17859597a71c4694e7def67d0beaa59c07f78a --- .../tm4e/core/internal/grammar/Grammar.java | 2 +- .../core/internal/grammar/LineTokenizer.java | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index a7a335537..e59219df5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -309,7 +309,7 @@ private T tokenize(String lineText, @Nullable StackElement prevState, final final var onigLineText = OnigString.of(lineText); final int lineLength = lineText.length(); final var lineTokens = new LineTokens(emitBinaryTokens, lineText, tokenTypeMatchers, balancedBracketSelectors); - final var nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, lineTokens); + final var nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, lineTokens, true); if (emitBinaryTokens) { return (T) new TokenizeLineResult2(lineTokens.getBinaryResult(nextState, lineLength), nextState); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 7446ff3f1..55caeb11f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -93,8 +93,7 @@ private WhileCheckResult(final StackElement stack, final int linePos, final int private boolean stop; private LineTokenizer(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, - final int linePos, final StackElement stack, - final LineTokens lineTokens) { + final int linePos, final StackElement stack, final LineTokens lineTokens) { this.grammar = grammar; this.lineText = lineText; this.isFirstLine = isFirstLine; @@ -103,15 +102,17 @@ private LineTokenizer(final Grammar grammar, final OnigString lineText, final bo this.lineTokens = lineTokens; } - private StackElement scan() { + private StackElement scan(boolean checkWhileConditions) { stop = false; - final WhileCheckResult whileCheckResult = checkWhileConditions(grammar, lineText, isFirstLine, linePos, stack, - lineTokens); - stack = whileCheckResult.stack; - linePos = whileCheckResult.linePos; - isFirstLine = whileCheckResult.isFirstLine; - anchorPosition = whileCheckResult.anchorPosition; + if (checkWhileConditions) { + final var whileCheckResult = checkWhileConditions(grammar, lineText, isFirstLine, linePos, stack, + lineTokens); + stack = whileCheckResult.stack; + linePos = whileCheckResult.linePos; + isFirstLine = whileCheckResult.isFirstLine; + anchorPosition = whileCheckResult.anchorPosition; + } while (!stop) { scanNext(); // potentially modifies linePos && anchorPosition @@ -474,7 +475,7 @@ private void handleCaptures(final Grammar grammar, final OnigString lineText, fi null, nameScopesList, contentNameScopesList); final var onigSubStr = OnigString.of(lineText.string.substring(0, captureIndex.end)); tokenizeString(grammar, onigSubStr, (isFirstLine && captureIndex.start == 0), - captureIndex.start, stackClone, lineTokens); + captureIndex.start, stackClone, lineTokens, false); continue; } @@ -551,8 +552,9 @@ private WhileCheckResult checkWhileConditions(final Grammar grammar, final OnigS } static StackElement tokenizeString(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, - final int linePos, final StackElement stack, final LineTokens lineTokens) { - return new LineTokenizer(grammar, lineText, isFirstLine, linePos, stack, lineTokens).scan(); + final int linePos, final StackElement stack, final LineTokens lineTokens, + final boolean checkWhileConditions) { + return new LineTokenizer(grammar, lineText, isFirstLine, linePos, stack, lineTokens).scan(checkWhileConditions); } static String debugCompiledRuleToString(CompiledRule ruleScanner) { From 95212d1dec5600fc5ad38baa04f09d4a243ac736 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 18:26:46 +0200 Subject: [PATCH 144/202] Test containsBalancedBrackets bit --- .../grammar/StackElementMetadata.java | 4 +++ .../core/internal/grammar/GrammarTest.java | 36 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index 0c9d058c2..97f9c4d60 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -60,6 +60,10 @@ static int getBackground(final int metadata) { return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET; } + /** + * Updates the fields in `metadata`. + * A value of `0`, `NotSet` or `null` indicates that the corresponding field should be left as is. + */ static int set(final int metadata, final int languageId, final /*OptionalStandardTokenType*/ int tokenType, @Nullable Boolean containsBalancedBrackets, final int fontStyle, final int foreground, int background) { final var _languageId = languageId == 0 ? getLanguageId(metadata) : languageId; diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java index f3b370504..e2803b324 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java @@ -27,61 +27,61 @@ public class GrammarTest { @Test public void testWorks() { int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 101, 102); } @Test public void testCanOverwriteLanguageId() { int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 101, 102); value = StackElementMetadata.set(value, 2, OptionalStandardTokenType.NotSet, null, NotSet, 0, 0); - assertEquals(value, 2, StandardTokenType.RegEx, Underline | Bold, 101, 102); + assertEquals(value, 2, StandardTokenType.RegEx, false, Underline | Bold, 101, 102); } @Test public void testCanOverwriteTokenType() { int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 101, 102); value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.Comment, null, NotSet, 0, 0); - assertEquals(value, 1, StandardTokenType.Comment, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.Comment, false, Underline | Bold, 101, 102); } @Test public void testCanOverwriteFontStyle() { int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 101, 102); value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, None, 0, 0); - assertEquals(value, 1, StandardTokenType.RegEx, None, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, None, 101, 102); } @Test public void testCanOverwriteFontStyleWithStrikethrough() { int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Strikethrough, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, Strikethrough, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Strikethrough, 101, 102); value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, None, 0, 0); - assertEquals(value, 1, StandardTokenType.RegEx, None, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, None, 101, 102); } @Test public void testCanOverwriteForeground() { int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 101, 102); value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, NotSet, 5, 0); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 5, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 5, 102); } @Test public void testCanOverwriteBackground() { int value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, null, Underline | Bold, 101, 102); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 102); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 101, 102); value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, null, NotSet, 0, 7); - assertEquals(value, 1, StandardTokenType.RegEx, Underline | Bold, 101, 7); + assertEquals(value, 1, StandardTokenType.RegEx, false, Underline | Bold, 101, 7); } @Test @@ -93,16 +93,17 @@ public void testCanWorkAtMaxValues() { int maxForeground = 511; int maxBackground = 254; - int value = StackElementMetadata.set(0, maxLangId, maxTokenType, null, maxFontStyle, maxForeground, + int value = StackElementMetadata.set(0, maxLangId, maxTokenType, true, maxFontStyle, maxForeground, maxBackground); - assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground); + assertEquals(value, maxLangId, maxTokenType, true, maxFontStyle, maxForeground, maxBackground); } - private static void assertEquals(int metadata, int languageId, int tokenType, int fontStyle, int foreground, - int background) { + private static void assertEquals(int metadata, int languageId, int /*StandardTokenType*/ tokenType, + boolean containsBalancedBrackets, int /*FontStyle*/ fontStyle, int foreground, int background) { String actual = "{\n" + "languageId: " + StackElementMetadata.getLanguageId(metadata) + ",\n" + "tokenType: " + StackElementMetadata.getTokenType(metadata) + ",\n" + + "containsBalancedBrackets: " + StackElementMetadata.containsBalancedBrackets(metadata) + ",\n" + "fontStyle: " + StackElementMetadata.getFontStyle(metadata) + ",\n" + "foreground: " + StackElementMetadata.getForeground(metadata) + ",\n" + "background: " + StackElementMetadata.getBackground(metadata) + ",\n" + @@ -111,6 +112,7 @@ private static void assertEquals(int metadata, int languageId, int tokenType, in String expected = "{\n" + "languageId: " + languageId + ",\n" + "tokenType: " + tokenType + ",\n" + + "containsBalancedBrackets: " + containsBalancedBrackets + ",\n" + "fontStyle: " + fontStyle + ",\n" + "foreground: " + foreground + ",\n" + "background: " + background + ",\n" + From fe5ccf80ea04f2f7d6d5ee116b1a6c6a406633ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 May 2022 11:30:38 +0000 Subject: [PATCH 145/202] fix(deps): bump tycho-version from 2.7.1 to 2.7.2 Bumps `tycho-version` from 2.7.1 to 2.7.2. Updates `tycho-buildtimestamp-jgit` from 2.7.1 to 2.7.2 Updates `tycho-sourceref-jgit` from 2.7.1 to 2.7.2 Updates `tycho-maven-plugin` from 2.7.1 to 2.7.2 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.1...tycho-2.7.2) Updates `target-platform-configuration` from 2.7.1 to 2.7.2 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.1...tycho-2.7.2) Updates `tycho-source-plugin` from 2.7.1 to 2.7.2 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.1...tycho-2.7.2) Updates `tycho-p2-plugin` from 2.7.1 to 2.7.2 Updates `tycho-packaging-plugin` from 2.7.1 to 2.7.2 - [Release notes](https://github.com/eclipse/tycho/releases) - [Changelog](https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md) - [Commits](https://github.com/eclipse/tycho/compare/tycho-2.7.1...tycho-2.7.2) Updates `tycho-p2-extras-plugin` from 2.7.1 to 2.7.2 Updates `tycho-surefire-plugin` from 2.7.1 to 2.7.2 --- updated-dependencies: - dependency-name: org.eclipse.tycho.extras:tycho-buildtimestamp-jgit dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho.extras:tycho-sourceref-jgit dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:target-platform-configuration dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-source-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-p2-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-packaging-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho.extras:tycho-p2-extras-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.eclipse.tycho:tycho-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d8efdf5af..f6c57e14c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ UTF-8 - 2.7.1 + 2.7.2 ../target/jacoco.exec scm:git:https://github.com/eclipse/tm4e.git true From 9147f1d0655e0036e12a8e65e88eaf8d780a8821 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sun, 1 May 2022 22:46:05 +0200 Subject: [PATCH 146/202] Refactor RawTestImpl and slightly improve error reporting --- .../core/grammar/internal/RawTestImpl.java | 105 ++++++++++-------- .../core/grammar/internal/RawTestLine.java | 28 ----- .../tm4e/core/grammar/internal/RawToken.java | 5 + 3 files changed, 62 insertions(+), 76 deletions(-) delete mode 100644 org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java index 964932827..9da3a36cf 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java @@ -1,35 +1,42 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.grammar.internal; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static java.util.stream.Collectors.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.grammar.IToken; -import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.registry.IRegistryOptions; import org.eclipse.tm4e.core.registry.Registry; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/tests/tokenization.tests.ts + */ public class RawTestImpl { + private static final class RawTestLine { + String line; + List tokens; + } + private String desc; private List grammars; private String grammarPath; @@ -63,20 +70,20 @@ public List getLines() { } public void executeTest() throws Exception { - IRegistryOptions locator = new IRegistryOptions() { + final var options = new IRegistryOptions() { @Override - public String getFilePath(String scopeName) { + public String getFilePath(final String scopeName) { return null; } @Override - public InputStream getInputStream(String scopeName) throws IOException { + public InputStream getInputStream(final String scopeName) throws IOException { return null; } @Override - public Collection getInjections(String scopeName) { + public Collection getInjections(final String scopeName) { if (scopeName.equals(getGrammarScopeName())) { return getGrammarInjections(); } @@ -84,27 +91,25 @@ public Collection getInjections(String scopeName) { } }; - Registry registry = new Registry(locator); + final Registry registry = new Registry(options); IGrammar grammar = getGrammar(registry, testLocation.getParentFile()); - if (getGrammarScopeName() != null) { grammar = registry.grammarForScopeName(getGrammarScopeName()); } - if (grammar == null) { throw new Exception("I HAVE NO GRAMMAR FOR TEST"); } StackElement prevState = null; - for (RawTestLine testLine : getLines()) { + for (final var testLine : lines) { prevState = assertLineTokenization(grammar, testLine, prevState); } } - private IGrammar getGrammar(Registry registry, File testLocation) throws Exception { + private IGrammar getGrammar(final Registry registry, final File testLocation) throws Exception { IGrammar grammar = null; - for (String grammarPath : getGrammars()) { - IGrammar tmpGrammar = registry.loadGrammarFromPathSync(new File(testLocation, grammarPath)); + for (final String grammarPath : getGrammars()) { + final IGrammar tmpGrammar = registry.loadGrammarFromPathSync(new File(testLocation, grammarPath)); if (grammarPath.equals(getGrammarPath())) { grammar = tmpGrammar; } @@ -112,49 +117,53 @@ private IGrammar getGrammar(Registry registry, File testLocation) throws Excepti return grammar; } - private static StackElement assertLineTokenization(IGrammar grammar, RawTestLine testCase, StackElement prevState) { - ITokenizeLineResult actual = grammar.tokenizeLine(testCase.getLine(), prevState); - - List actualTokens = getActualTokens(actual.getTokens(), testCase); - - List expectedTokens = testCase.getTokens(); - // // TODO@Alex: fix tests instead of working around - if (!testCase.getLine().isEmpty()) { + private static StackElement assertLineTokenization(final IGrammar grammar, final RawTestLine testCase, + final StackElement prevState) { + final var line = testCase.line; + final var actual = grammar.tokenizeLine(line, prevState); + + final var actualTokens = Arrays.stream(actual.getTokens()) + .map(token -> new RawToken( + line.substring( + token.getStartIndex(), + Math.min(token.getEndIndex(), line.length())), // TODO Math.min not required in upstream why? + token.getScopes())) + .collect(toList()); + + // TODO@Alex: fix tests instead of working around + if (!line.isEmpty()) { // Remove empty tokens... - expectedTokens = testCase.getTokens().stream().filter(token -> !token.getValue().isEmpty()) - .collect(Collectors.toList()); + testCase.tokens = testCase.tokens.stream().filter(token -> !token.getValue().isEmpty()).collect(toList()); } - deepEqual(actualTokens, expectedTokens, "Tokenizing line '" + testCase.getLine() + "'"); + + deepEqual(actualTokens, testCase.tokens, "Tokenizing line '" + line + "'"); return actual.getRuleStack(); } - private static void deepEqual(List actualTokens, List expextedTokens, String message) { + private static void deepEqual(final List actualTokens, final List expextedTokens, + final String message) { + // compare collection size - assertEquals(expextedTokens.size(), actualTokens.size(), message + " (collection size problem)"); + if (expextedTokens.size() != actualTokens.size()) { + final var actualTokensStr = actualTokens.stream().map(Object::toString).collect(joining("\n")); + final var expextedTokensStr = expextedTokens.stream().map(Object::toString).collect(joining("\n")); + + assertEquals(expextedTokensStr, actualTokensStr, + message + " (collection size problem: actual=" + actualTokens.size() + " expected=" + + expextedTokens.size() + ")"); + } + // compare item for (int i = 0; i < expextedTokens.size(); i++) { - RawToken expected = expextedTokens.get(i); - RawToken actual = actualTokens.get(i); + final var expected = expextedTokens.get(i); + final var actual = actualTokens.get(i); assertEquals(expected.getValue(), actual.getValue(), message + " (value of item '" + i + "' problem)"); assertEquals(expected.getScopes(), actual.getScopes(), message + " (tokens of item '" + i + "' problem)"); } - } - private static List getActualTokens(IToken[] tokens, RawTestLine testCase) { - List actualTokens = new ArrayList<>(); - for (IToken token : tokens) { - String value = testCase.getLine().substring(token.getStartIndex(), - token.getEndIndex() < testCase.getLine().length() ? token.getEndIndex() - : testCase.getLine().length()); - actualTokens.add(new RawToken(value, token.getScopes())); - } - return actualTokens; - } - - public void setTestLocation(File testLocation) { + public void setTestLocation(final File testLocation) { this.testLocation = testLocation; } - } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java deleted file mode 100644 index 1afc9b679..000000000 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestLine.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.grammar.internal; - -import java.util.List; - -public class RawTestLine { - - private String line; - private List tokens; - - public String getLine() { - return line; - } - - public List getTokens() { - return tokens; - } -} diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java index be1447b1b..211c3550a 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawToken.java @@ -54,4 +54,9 @@ public int hashCode() { result = prime * result + (value == null ? 0 : value.hashCode()); return result; } + + @Override + public String toString() { + return "RawToken{\n value:" + value + "\n scopes:" + scopes + "\n}"; + } } From 2b93b4a802d0d84f3f36096bf61d1902fd305d3a Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 16:07:29 +0200 Subject: [PATCH 147/202] Fix resource leak compiler warning in test suite --- .../tm4e/core/grammar/GrammarSuiteTest.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java index 8f79e4302..677573a77 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java @@ -12,7 +12,6 @@ package org.eclipse.tm4e.core.grammar; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.lang.reflect.Type; import java.util.ArrayList; @@ -26,13 +25,10 @@ import org.junit.jupiter.api.TestFactory; import com.google.gson.GsonBuilder; -import com.google.gson.JsonIOException; -import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; /** - * VSCode TextMate grammar tests which uses same vscode-textmate tests located - * at src\test\resources\test-cases + * VSCode TextMate grammar tests which uses same vscode-textmate tests located at src\test\resources\test-cases * * @see * github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts @@ -64,33 +60,35 @@ Collection whileTests() throws Exception { return createVSCodeTestSuite(new File(REPO_ROOT, "test-cases/suite1/whileTests.json")); } - private List createVSCodeTestSuite(File testLocation) throws Exception { - Type listType = new TypeToken>() { - }.getType(); - List tests = new GsonBuilder().create().fromJson(new FileReader(testLocation), listType); - List dynamicTests = new ArrayList<>(); - for (RawTestImpl test : tests) { - if (!IGNORE_TESTS.contains(test.getDesc())) { - test.setTestLocation(testLocation); - dynamicTests.add(DynamicTest.dynamicTest(test.getDesc(), test::executeTest)); + private List createVSCodeTestSuite(final File testLocation) throws Exception { + try (var fileReader = new FileReader(testLocation)) { + final Type listType = new TypeToken>() { + }.getType(); + final List tests = new GsonBuilder().create().fromJson(fileReader, listType); + final var dynamicTests = new ArrayList(); + for (final RawTestImpl test : tests) { + if (!IGNORE_TESTS.contains(test.getDesc())) { + test.setTestLocation(testLocation); + dynamicTests.add(DynamicTest.dynamicTest(test.getDesc(), test::executeTest)); + } } + return dynamicTests; } - return dynamicTests; } @TestFactory @DisplayName("Matcher tests") - Collection dynamicTestsWithCollection() throws JsonIOException, JsonSyntaxException, FileNotFoundException { - Type listType = new TypeToken>() { - }.getType(); - List tests = new GsonBuilder().create() - .fromJson(new FileReader(new File(REPO_ROOT, "matcher-tests.json")), listType); - List dynamicTests = new ArrayList<>(); - int i = 0; - for (MatcherTestImpl test : tests) { - dynamicTests.add(DynamicTest.dynamicTest("Test #" + (i++), test::executeTest)); + Collection dynamicTestsWithCollection() throws Exception { + try (var fileReader = new FileReader(new File(REPO_ROOT, "matcher-tests.json"))) { + final Type listType = new TypeToken>() { + }.getType(); + final List tests = new GsonBuilder().create().fromJson(fileReader, listType); + final var dynamicTests = new ArrayList(); + int i = 0; + for (final MatcherTestImpl test : tests) { + dynamicTests.add(DynamicTest.dynamicTest("Test #" + (i++), test::executeTest)); + } + return dynamicTests; } - return dynamicTests; } - } From 146bfc99abb4b6427a07799a2085ad98bffc9227 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 16:21:42 +0200 Subject: [PATCH 148/202] Make XML parser invulnerable to XXE attacks --- .../tm4e/core/internal/parser/PListParserXML.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java index 4a62fda61..fb6c5660d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java @@ -15,11 +15,13 @@ import java.io.IOException; import java.io.InputStream; +import javax.xml.XMLConstants; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; public final class PListParserXML implements PListParser { @@ -33,7 +35,18 @@ public PListParserXML(final MapFactory mapFactory) { public T parse(final InputStream contents) throws IOException, ParserConfigurationException, SAXException { final var spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); - final var xmlReader = spf.newSAXParser().getXMLReader(); + + // make parser invulnerable to XXE attacks, see https://rules.sonarsource.com/java/RSPEC-2755 + spf.setFeature("http://xml.org/sax/features/external-general-entities", false); + spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + + final var saxParser = spf.newSAXParser(); + + // make parser invulnerable to XXE attacks, see https://rules.sonarsource.com/java/RSPEC-2755 + saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); + + final XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setEntityResolver((publicId, systemId) -> new InputSource( new ByteArrayInputStream("".getBytes()))); final var result = new PListParserContentHandler(mapFactory); From 2dd1dfe5d233e4bb891f6fe3b1916f8db26ee9bc Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 19:05:51 +0200 Subject: [PATCH 149/202] Move StackElement to internal package and add public IStackElement StackElement references internal classes in it's public methods signatures. --- .../core/grammar/internal/RawTestImpl.java | 8 ++-- .../eclipse/tm4e/core/grammar/IGrammar.java | 4 +- .../tm4e/core/grammar/IStackElement.java | 32 ++++++++++++++++ .../core/grammar/ITokenizeLineResult.java | 3 +- .../core/grammar/ITokenizeLineResult2.java | 3 +- .../tm4e/core/internal/grammar/Grammar.java | 10 ++--- .../core/internal/grammar/LineTokenizer.java | 1 - .../core/internal/grammar/LineTokens.java | 1 - .../{ => internal}/grammar/StackElement.java | 37 +++++++++++-------- .../grammar/StackElementMetadata.java | 1 - .../internal/grammar/TokenizeLineResult.java | 1 - .../internal/grammar/TokenizeLineResult2.java | 1 - .../org/eclipse/tm4e/core/model/TMState.java | 10 ++--- .../tm4e/core/grammar/GrammarTest.java | 2 +- .../tm4e/core/grammar/GrammarTest2.java | 2 +- .../eclipse/tm4e/core/grammar/MarkDown.java | 2 +- 16 files changed, 74 insertions(+), 44 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IStackElement.java rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/grammar/StackElement.java (89%) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java index 9da3a36cf..8685757f6 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java @@ -22,7 +22,7 @@ import java.util.List; import org.eclipse.tm4e.core.grammar.IGrammar; -import org.eclipse.tm4e.core.grammar.StackElement; +import org.eclipse.tm4e.core.grammar.IStackElement; import org.eclipse.tm4e.core.registry.IRegistryOptions; import org.eclipse.tm4e.core.registry.Registry; @@ -100,7 +100,7 @@ public Collection getInjections(final String scopeName) { throw new Exception("I HAVE NO GRAMMAR FOR TEST"); } - StackElement prevState = null; + IStackElement prevState = null; for (final var testLine : lines) { prevState = assertLineTokenization(grammar, testLine, prevState); } @@ -117,8 +117,8 @@ private IGrammar getGrammar(final Registry registry, final File testLocation) th return grammar; } - private static StackElement assertLineTokenization(final IGrammar grammar, final RawTestLine testCase, - final StackElement prevState) { + private static IStackElement assertLineTokenization(final IGrammar grammar, final RawTestLine testCase, + final IStackElement prevState) { final var line = testCase.line; final var actual = grammar.tokenizeLine(line, prevState); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java index 2e799f090..f9ddaf457 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IGrammar.java @@ -69,7 +69,7 @@ public interface IGrammar { * previous line state. * @return the result of the tokenization. */ - ITokenizeLineResult tokenizeLine(String lineText, @Nullable StackElement prevState); + ITokenizeLineResult tokenizeLine(String lineText, @Nullable IStackElement prevState); /** * Tokenize `lineText` using previous line state `prevState`. @@ -93,6 +93,6 @@ public interface IGrammar { * - background color * e.g. for getting the languageId: `(metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET` */ - ITokenizeLineResult2 tokenizeLine2(String lineText, @Nullable StackElement prevState); + ITokenizeLineResult2 tokenizeLine2(String lineText, @Nullable IStackElement prevState); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IStackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IStackElement.java new file mode 100644 index 000000000..fb7143d6d --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/IStackElement.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Initial code from https://github.com/Microsoft/vscode-textmate/ + * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. + * Initial license: MIT + * + * Contributors: + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java + */ +package org.eclipse.tm4e.core.grammar; + +import org.eclipse.tm4e.core.internal.grammar.StackElement; + +/** + * Represents a "pushed" state on the stack (as a linked list element). + * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/main.ts + */ +public interface IStackElement { + IStackElement INITIAL = StackElement.NULL; + + int getDepth(); +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java index 288e7d632..5e51122fe 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult.java @@ -31,6 +31,5 @@ public interface ITokenizeLineResult { * * @return the `prevState` to be passed on to the next line tokenization. */ - StackElement getRuleStack(); - + IStackElement getRuleStack(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java index d22948895..3dce2c5dc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/ITokenizeLineResult2.java @@ -36,6 +36,5 @@ public interface ITokenizeLineResult2 { * * @return the `prevState` to be passed on to the next line tokenization. */ - StackElement getRuleStack(); - + IStackElement getRuleStack(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index e59219df5..b87f90e83 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -33,9 +33,9 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.grammar.IStackElement; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; -import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.matcher.Matcher; import org.eclipse.tm4e.core.internal.oniguruma.OnigString; import org.eclipse.tm4e.core.internal.registry.IGrammarRepository; @@ -257,8 +257,8 @@ public ITokenizeLineResult tokenizeLine(final String lineText) { } @Override - public ITokenizeLineResult tokenizeLine(final String lineText, @Nullable final StackElement prevState) { - return tokenize(lineText, prevState, false); + public ITokenizeLineResult tokenizeLine(final String lineText, @Nullable final IStackElement prevState) { + return tokenize(lineText, (StackElement) prevState, false); } @Override @@ -267,8 +267,8 @@ public ITokenizeLineResult2 tokenizeLine2(final String lineText) { } @Override - public ITokenizeLineResult2 tokenizeLine2(final String lineText, @Nullable final StackElement prevState) { - return tokenize(lineText, prevState, true); + public ITokenizeLineResult2 tokenizeLine2(final String lineText, @Nullable final IStackElement prevState) { + return tokenize(lineText, (StackElement) prevState, true); } @SuppressWarnings("unchecked") diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 55caeb11f..ef33a20b3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -26,7 +26,6 @@ import java.util.List; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.internal.oniguruma.OnigCaptureIndex; import org.eclipse.tm4e.core.internal.oniguruma.OnigNextMatchResult; import org.eclipse.tm4e.core.internal.oniguruma.OnigString; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 967072999..9f305d962 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -27,7 +27,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IToken; -import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.theme.FontStyle; final class LineTokens { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElement.java similarity index 89% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElement.java index 45c81971e..1e5a23c47 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElement.java @@ -14,7 +14,7 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.grammar; +package org.eclipse.tm4e.core.internal.grammar; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; @@ -23,18 +23,18 @@ import java.util.Objects; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.internal.grammar.ScopeListElement; +import org.eclipse.tm4e.core.grammar.IStackElement; import org.eclipse.tm4e.core.internal.rule.IRuleRegistry; import org.eclipse.tm4e.core.internal.rule.Rule; /** * Represents a "pushed" state on the stack (as a linked list element). * - * @see + * @see * github.com/Microsoft/vscode-textmate/blob/master/src/grammar.ts - * */ -public class StackElement { +public final class StackElement implements IStackElement { public static final StackElement NULL = new StackElement(null, 0, 0, 0, false, null, new ScopeListElement(null, "", 0), new ScopeListElement(null, "", 0)); @@ -92,7 +92,7 @@ public class StackElement { */ public final ScopeListElement contentNameScopesList; - public StackElement( + StackElement( @Nullable final StackElement parent, final int ruleId, final int enterPos, @@ -160,6 +160,11 @@ public boolean equals(@Nullable final Object other) { return equals(this, (StackElement) other); } + @Override + public int getDepth() { + return depth; + } + @Override public int hashCode() { final int prime = 31; @@ -170,7 +175,7 @@ public int hashCode() { return result; } - public void reset() { + void reset() { StackElement el = this; while (el != null) { el.enterPosition = -1; @@ -180,17 +185,17 @@ public void reset() { } @Nullable - public StackElement pop() { + StackElement pop() { return parent; } - public StackElement safePop() { + StackElement safePop() { if (parent != null) return parent; return this; } - public StackElement push(final int ruleId, + StackElement push(final int ruleId, final int enterPos, final int anchorPos, final boolean beginRuleCapturedEOL, @@ -207,15 +212,15 @@ public StackElement push(final int ruleId, contentNameScopesList); } - public int getAnchorPos() { + int getAnchorPos() { return anchorPos; } - public int getEnterPos() { + int getEnterPos() { return enterPosition; } - public Rule getRule(final IRuleRegistry grammar) { + Rule getRule(final IRuleRegistry grammar) { return grammar.getRule(ruleId); } @@ -234,7 +239,7 @@ public String toString() { return '[' + String.join(", ", r) + ']'; } - public StackElement setContentNameScopesList(final ScopeListElement contentNameScopesList) { + StackElement setContentNameScopesList(final ScopeListElement contentNameScopesList) { if (this.contentNameScopesList.equals(contentNameScopesList)) { return this; } @@ -247,7 +252,7 @@ public StackElement setContentNameScopesList(final ScopeListElement contentNameS contentNameScopesList); } - public StackElement setEndRule(final String endRule) { + StackElement setEndRule(final String endRule) { if (this.endRule != null && this.endRule.equals(endRule)) { return this; } @@ -261,7 +266,7 @@ public StackElement setEndRule(final String endRule) { this.contentNameScopesList); } - public boolean hasSameRuleAs(final StackElement other) { + boolean hasSameRuleAs(final StackElement other) { var el = this; while (el != null && el.enterPosition == other.enterPosition) { if (el.ruleId == other.ruleId) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index 97f9c4d60..2c5408c3f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -12,7 +12,6 @@ package org.eclipse.tm4e.core.internal.grammar; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.grammar.StackElement; import org.eclipse.tm4e.core.theme.FontStyle; /** diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java index eab6bd926..574901605 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult.java @@ -18,7 +18,6 @@ import org.eclipse.tm4e.core.grammar.IToken; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; -import org.eclipse.tm4e.core.grammar.StackElement; /** * Result of the line tokenization implementation. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java index 26f67ff4a..c81759308 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/TokenizeLineResult2.java @@ -17,7 +17,6 @@ package org.eclipse.tm4e.core.internal.grammar; import org.eclipse.tm4e.core.grammar.ITokenizeLineResult2; -import org.eclipse.tm4e.core.grammar.StackElement; /** * Result of the line tokenization2 implementation. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java index 594e6cb4a..e9d989b87 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMState.java @@ -19,7 +19,7 @@ import java.util.Objects; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.grammar.StackElement; +import org.eclipse.tm4e.core.grammar.IStackElement; public class TMState { @@ -27,19 +27,19 @@ public class TMState { private final TMState parentEmbedderState; @Nullable - private StackElement ruleStack; + private IStackElement ruleStack; - public TMState(@Nullable final TMState parentEmbedderState, @Nullable final StackElement ruleStatck) { + public TMState(@Nullable final TMState parentEmbedderState, @Nullable final IStackElement ruleStatck) { this.parentEmbedderState = parentEmbedderState; this.ruleStack = ruleStatck; } - public void setRuleStack(final StackElement ruleStack) { + public void setRuleStack(final IStackElement ruleStack) { this.ruleStack = ruleStack; } @Nullable - public StackElement getRuleStack() { + public IStackElement getRuleStack() { return ruleStack; } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java index 7da49b48c..e1606a8f5 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest.java @@ -79,7 +79,7 @@ public void tokenizeLines() throws Exception { String path = "JavaScript.tmLanguage"; IGrammar grammar = registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path)); - StackElement ruleStack = null; + IStackElement ruleStack = null; int i = 0; int j = 0; String[] lines = { "function add(a,b)", "{ return a+b; }" }; diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java index dce646d42..62e3e099d 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java @@ -34,7 +34,7 @@ void tokenizeLines() throws Exception { String path = "JavaScript.tmLanguage"; IGrammar grammar = castNonNull(registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path))); - StackElement ruleStack = null; + IStackElement ruleStack = null; int i = 0; List lines = new ArrayList<>(); diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java index d31a4c0a2..51dcabc2d 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/MarkDown.java @@ -41,7 +41,7 @@ public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); - StackElement ruleStack = null; + IStackElement ruleStack = null; int i = 0; for (String line : lines) { ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack); From 932e2bc08714d9c6907154d6aa5ba73295b22efe Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 17:16:10 +0200 Subject: [PATCH 150/202] Add final modifier to internal css package where applicable --- .../theme/css/AbstractAttributeCondition.java | 2 +- .../css/AbstractCombinatorCondition.java | 2 +- .../theme/css/AbstractElementSelector.java | 2 +- .../internal/theme/css/CSSAndCondition.java | 4 +- .../theme/css/CSSAttributeCondition.java | 4 +- .../internal/theme/css/CSSClassCondition.java | 8 ++-- .../theme/css/CSSConditionFactory.java | 28 +++++++------- .../theme/css/CSSConditionalSelector.java | 4 +- .../theme/css/CSSDocumentHandler.java | 38 +++++++++---------- .../theme/css/CSSElementSelector.java | 4 +- .../theme/css/CSSSelectorFactory.java | 22 +++++------ .../core/internal/theme/css/CSSValueImpl.java | 8 ++-- .../tm4e/core/internal/theme/css/Measure.java | 8 ++-- .../core/internal/theme/css/RGBColorImpl.java | 2 +- .../theme/css/SACParserFactoryImpl.java | 10 ++--- 15 files changed, 73 insertions(+), 73 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractAttributeCondition.java index 779fdbee2..0eb5cd168 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractAttributeCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractAttributeCondition.java @@ -23,7 +23,7 @@ public abstract class AbstractAttributeCondition implements AttributeCondition, /** * Creates a new AbstractAttributeCondition object. */ - protected AbstractAttributeCondition(String value) { + protected AbstractAttributeCondition(final String value) { this.value = value; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractCombinatorCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractCombinatorCondition.java index 32727d52f..e6ab55e74 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractCombinatorCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractCombinatorCondition.java @@ -22,7 +22,7 @@ public abstract class AbstractCombinatorCondition implements CombinatorCondition /** * Creates a new CombinatorCondition object. */ - protected AbstractCombinatorCondition(Condition c1, Condition c2) { + protected AbstractCombinatorCondition(final Condition c1, final Condition c2) { firstCondition = c1; secondCondition = c2; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java index ad1ab9b2d..537233e4a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java @@ -28,7 +28,7 @@ public abstract class AbstractElementSelector implements ElementSelector, Extend /** * Creates a new ElementSelector object. */ - protected AbstractElementSelector(String uri, String name) { + protected AbstractElementSelector(final String uri, final String name) { namespaceURI = uri; localName = name; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAndCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAndCondition.java index 36bd7a7a3..6edc17550 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAndCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAndCondition.java @@ -18,7 +18,7 @@ final class CSSAndCondition extends AbstractCombinatorCondition { /** * Creates a new CombinatorCondition object. */ - CSSAndCondition(Condition c1, Condition c2) { + CSSAndCondition(final Condition c1, final Condition c2) { super(c1, c2); } @@ -28,7 +28,7 @@ public short getConditionType() { } @Override - public int nbMatch(String... names) { + public int nbMatch(final String... names) { return ((ExtendedCondition) getFirstCondition()).nbMatch(names) + ((ExtendedCondition) getSecondCondition()).nbMatch(names); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java index 4263e4257..b8a41a4b5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java @@ -28,7 +28,7 @@ class CSSAttributeCondition extends AbstractAttributeCondition { */ private final boolean specified; - protected CSSAttributeCondition(String localName, String namespaceURI, boolean specified, String value) { + protected CSSAttributeCondition(final String localName, final String namespaceURI, final boolean specified, final String value) { super(value); this.localName = localName; this.namespaceURI = namespaceURI; @@ -56,7 +56,7 @@ public short getConditionType() { } @Override - public int nbMatch(String... names) { + public int nbMatch(final String... names) { // String val = getValue(); // if (val == null) { // return !e.getAttribute(getLocalName()).equals(""); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java index 10d62e152..9e6245ce9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java @@ -13,14 +13,14 @@ final class CSSClassCondition extends CSSAttributeCondition { - CSSClassCondition(String localName, String namespaceURI, String value) { + CSSClassCondition(final String localName, final String namespaceURI, final String value) { super(localName, namespaceURI, true, value); } @Override - public int nbMatch(String... names) { - String value = getValue(); - for (String name : names) { + public int nbMatch(final String... names) { + final String value = getValue(); + for (final String name : names) { if (name.equals(value)) { return 1; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java index 2540e0155..f4bc76e1b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java @@ -26,50 +26,50 @@ public final class CSSConditionFactory implements ConditionFactory { public static final ConditionFactory INSTANCE = new CSSConditionFactory(); @Override - public AttributeCondition createClassCondition(String namespaceURI, String value) throws CSSException { + public AttributeCondition createClassCondition(final String namespaceURI, final String value) throws CSSException { return new CSSClassCondition(null, "class", value); } @Override - public AttributeCondition createAttributeCondition(String localName, String namespaceURI, boolean specified, - String value) throws CSSException { + public AttributeCondition createAttributeCondition(final String localName, final String namespaceURI, final boolean specified, + final String value) throws CSSException { return new CSSAttributeCondition(localName, namespaceURI, specified, value); } @Override - public CombinatorCondition createAndCondition(Condition first, - Condition second) throws CSSException { + public CombinatorCondition createAndCondition(final Condition first, + final Condition second) throws CSSException { return new CSSAndCondition(first, second); } @Override - public AttributeCondition createBeginHyphenAttributeCondition(String arg0, String arg1, boolean arg2, String arg3) + public AttributeCondition createBeginHyphenAttributeCondition(final String arg0, final String arg1, final boolean arg2, final String arg3) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @Override - public ContentCondition createContentCondition(String arg0) throws CSSException { + public ContentCondition createContentCondition(final String arg0) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @Override - public AttributeCondition createIdCondition(String arg0) throws CSSException { + public AttributeCondition createIdCondition(final String arg0) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @Override - public LangCondition createLangCondition(String arg0) throws CSSException { + public LangCondition createLangCondition(final String arg0) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @Override - public NegativeCondition createNegativeCondition(Condition arg0) throws CSSException { + public NegativeCondition createNegativeCondition(final Condition arg0) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @Override - public AttributeCondition createOneOfAttributeCondition(String arg0, String arg1, boolean arg2, String arg3) + public AttributeCondition createOneOfAttributeCondition(final String arg0, final String arg1, final boolean arg2, final String arg3) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @@ -85,17 +85,17 @@ public Condition createOnlyTypeCondition() throws CSSException { } @Override - public CombinatorCondition createOrCondition(Condition arg0, Condition arg1) throws CSSException { + public CombinatorCondition createOrCondition(final Condition arg0, final Condition arg1) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @Override - public PositionalCondition createPositionalCondition(int arg0, boolean arg1, boolean arg2) throws CSSException { + public PositionalCondition createPositionalCondition(final int arg0, final boolean arg1, final boolean arg2) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @Override - public AttributeCondition createPseudoClassCondition(String arg0, String arg1) throws CSSException { + public AttributeCondition createPseudoClassCondition(final String arg0, final String arg1) throws CSSException { throw new CSSException("Not implemented in CSS2"); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionalSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionalSelector.java index 8d6bf46ca..43c12fa5a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionalSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionalSelector.java @@ -30,7 +30,7 @@ final class CSSConditionalSelector implements ConditionalSelector, ExtendedSelec /** * Creates a new ConditionalSelector object. */ - CSSConditionalSelector(SimpleSelector simpleSelector, Condition condition) { + CSSConditionalSelector(final SimpleSelector simpleSelector, final Condition condition) { this.simpleSelector = simpleSelector; this.condition = condition; } @@ -57,7 +57,7 @@ public int getSpecificity() { } @Override - public int nbMatch(String... names) { + public int nbMatch(final String... names) { return ((ExtendedSelector)getSimpleSelector()).nbMatch(names) + ((ExtendedCondition)getCondition()).nbMatch(names); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java index 78e9ee998..c07c218f8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java @@ -32,12 +32,12 @@ public final class CSSDocumentHandler implements DocumentHandler { private CSSStyle currentStyle; @Override - public void comment(String arg0) throws CSSException { + public void comment(final String arg0) throws CSSException { } @Override - public void endDocument(InputSource arg0) throws CSSException { + public void endDocument(final InputSource arg0) throws CSSException { // TODO Auto-generated method stub } @@ -47,37 +47,37 @@ public void endFontFace() throws CSSException { } @Override - public void endMedia(SACMediaList arg0) throws CSSException { + public void endMedia(final SACMediaList arg0) throws CSSException { // TODO Auto-generated method stub } @Override - public void endPage(String arg0, String arg1) throws CSSException { + public void endPage(final String arg0, final String arg1) throws CSSException { // TODO Auto-generated method stub } @Override - public void endSelector(SelectorList selector) throws CSSException { + public void endSelector(final SelectorList selector) throws CSSException { currentStyle = null; } @Override - public void ignorableAtRule(String arg0) throws CSSException { + public void ignorableAtRule(final String arg0) throws CSSException { // TODO Auto-generated method stub } @Override - public void importStyle(String arg0, SACMediaList arg1, String arg2) throws CSSException { + public void importStyle(final String arg0, final SACMediaList arg1, final String arg2) throws CSSException { // TODO Auto-generated method stub } @Override - public void namespaceDeclaration(String arg0, String arg1) throws CSSException { + public void namespaceDeclaration(final String arg0, final String arg1) throws CSSException { // TODO Auto-generated method stub } @Override - public void property(String name, LexicalUnit value, boolean arg2) throws CSSException { + public void property(final String name, final LexicalUnit value, final boolean arg2) throws CSSException { if (currentStyle != null && name != null) { switch (name) { case "color": @@ -93,7 +93,7 @@ public void property(String name, LexicalUnit value, boolean arg2) throws CSSExc currentStyle.setItalic(value.getStringValue().toUpperCase().contains("ITALIC")); break; case "text-decoration": - String decoration = value.getStringValue().toUpperCase(); + final String decoration = value.getStringValue().toUpperCase(); if (decoration.contains("UNDERLINE")) { currentStyle.setUnderline(true); } @@ -105,16 +105,16 @@ public void property(String name, LexicalUnit value, boolean arg2) throws CSSExc } } - private RGB createRGB(LexicalUnit value) { - RGBColor rgbColor = new RGBColorImpl(value); - int green = ((int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); - int red = ((int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); - int blue = ((int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); + private RGB createRGB(final LexicalUnit value) { + final RGBColor rgbColor = new RGBColorImpl(value); + final int green = ((int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); + final int red = ((int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); + final int blue = ((int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); return new RGB(red, green, blue); } @Override - public void startDocument(InputSource arg0) throws CSSException { + public void startDocument(final InputSource arg0) throws CSSException { // TODO Auto-generated method stub } @@ -124,17 +124,17 @@ public void startFontFace() throws CSSException { } @Override - public void startMedia(SACMediaList arg0) throws CSSException { + public void startMedia(final SACMediaList arg0) throws CSSException { // TODO Auto-generated method stub } @Override - public void startPage(String arg0, String arg1) throws CSSException { + public void startPage(final String arg0, final String arg1) throws CSSException { // TODO Auto-generated method stub } @Override - public void startSelector(SelectorList selector) throws CSSException { + public void startSelector(final SelectorList selector) throws CSSException { currentStyle = new CSSStyle(selector); list.add(currentStyle); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java index 09a8827be..b0ce620d5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java @@ -13,7 +13,7 @@ final class CSSElementSelector extends AbstractElementSelector { - CSSElementSelector(String uri, String name) { + CSSElementSelector(final String uri, final String name) { super(uri, name); } @@ -28,7 +28,7 @@ public int getSpecificity() { } @Override - public int nbMatch(String... names) { + public int nbMatch(final String... names) { return 0; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java index 528c403ab..735a16e0e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java @@ -35,55 +35,55 @@ public SimpleSelector createAnyNodeSelector() throws CSSException { } @Override - public CharacterDataSelector createCDataSectionSelector(String arg0) throws CSSException { + public CharacterDataSelector createCDataSectionSelector(final String arg0) throws CSSException { throw new UnsupportedOperationException("CSS CDATA section is not supported"); } @Override - public DescendantSelector createChildSelector(Selector arg0, SimpleSelector arg1) throws CSSException { + public DescendantSelector createChildSelector(final Selector arg0, final SimpleSelector arg1) throws CSSException { throw new UnsupportedOperationException("CSS child selector is not supported"); } @Override - public CharacterDataSelector createCommentSelector(String arg0) throws CSSException { + public CharacterDataSelector createCommentSelector(final String arg0) throws CSSException { throw new UnsupportedOperationException("CSS comment is not supported"); } @Override - public ConditionalSelector createConditionalSelector(SimpleSelector selector, Condition condition) + public ConditionalSelector createConditionalSelector(final SimpleSelector selector, final Condition condition) throws CSSException { return new CSSConditionalSelector(selector, condition); } @Override - public DescendantSelector createDescendantSelector(Selector arg0, SimpleSelector arg1) throws CSSException { + public DescendantSelector createDescendantSelector(final Selector arg0, final SimpleSelector arg1) throws CSSException { throw new UnsupportedOperationException("CSS descendant selector is not supported"); } @Override - public SiblingSelector createDirectAdjacentSelector(short arg0, Selector arg1, SimpleSelector arg2) + public SiblingSelector createDirectAdjacentSelector(final short arg0, final Selector arg1, final SimpleSelector arg2) throws CSSException { throw new UnsupportedOperationException("CSS direct adjacent selector is not supported"); } @Override - public ElementSelector createElementSelector(String uri, String name) throws CSSException { + public ElementSelector createElementSelector(final String uri, final String name) throws CSSException { return new CSSElementSelector(uri, name); } @Override - public NegativeSelector createNegativeSelector(SimpleSelector arg0) throws CSSException { + public NegativeSelector createNegativeSelector(final SimpleSelector arg0) throws CSSException { throw new UnsupportedOperationException("CSS negative selector is not supported"); } @Override - public ProcessingInstructionSelector createProcessingInstructionSelector(String arg0, String arg1) + public ProcessingInstructionSelector createProcessingInstructionSelector(final String arg0, final String arg1) throws CSSException { throw new UnsupportedOperationException("CSS processing instruction is not supported"); } @Override - public ElementSelector createPseudoElementSelector(String arg0, String arg1) throws CSSException { + public ElementSelector createPseudoElementSelector(final String arg0, final String arg1) throws CSSException { throw new UnsupportedOperationException("CSS pseudo element selector is not supported"); } @@ -93,7 +93,7 @@ public SimpleSelector createRootNodeSelector() throws CSSException { } @Override - public CharacterDataSelector createTextNodeSelector(String arg0) throws CSSException { + public CharacterDataSelector createTextNodeSelector(final String arg0) throws CSSException { throw new UnsupportedOperationException("CSS text node selector is not supported"); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java index 92a920dd4..976dab283 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java @@ -33,7 +33,7 @@ public short getCssValueType() { } @Override - public void setCssText(String cssText) throws DOMException { + public void setCssText(final String cssText) throws DOMException { // TODO Auto-generated method stub throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); } @@ -68,13 +68,13 @@ public String getStringValue() throws DOMException { } @Override - public void setFloatValue(short arg0, float arg1) throws DOMException { + public void setFloatValue(final short arg0, final float arg1) throws DOMException { // TODO Auto-generated method stub throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); } @Override - public void setStringValue(short arg0, String arg1) throws DOMException { + public void setStringValue(final short arg0, final String arg1) throws DOMException { // TODO Auto-generated method stub throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); } @@ -82,7 +82,7 @@ public void setStringValue(short arg0, String arg1) throws DOMException { // Additional methods @Override - public float getFloatValue(short valueType) throws DOMException { + public float getFloatValue(final short valueType) throws DOMException { // TODO Auto-generated method stub throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java index 920361d13..8bfb37218 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java @@ -18,7 +18,7 @@ final class Measure extends CSSValueImpl { private final LexicalUnit value; - Measure(LexicalUnit value) { + Measure(final LexicalUnit value) { this.value = value; } @@ -30,7 +30,7 @@ final class Measure extends CSSValueImpl { * {@link CSSValue#getCssValueType()} */ @Override - public float getFloatValue(short valueType) throws DOMException { + public float getFloatValue(final short valueType) throws DOMException { // If it's actually a SAC_INTEGER return the integer value, callers tend // to expect and cast // There is no getIntegerFloat(short) @@ -52,13 +52,13 @@ public float getFloatValue(short valueType) throws DOMException { * a short representing the value type, see * {@link CSSValue#getCssValueType()} */ - private int getIntegerValue(short valueType) throws DOMException { + private int getIntegerValue(final short valueType) throws DOMException { return value.getIntegerValue(); } @Override public String getStringValue() throws DOMException { - short lexicalUnit = value.getLexicalUnitType(); + final short lexicalUnit = value.getLexicalUnitType(); if ((lexicalUnit == LexicalUnit.SAC_IDENT) || (lexicalUnit == LexicalUnit.SAC_STRING_VALUE) || (lexicalUnit == LexicalUnit.SAC_URI)) return value.getStringValue(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/RGBColorImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/RGBColorImpl.java index d0c6d8760..f3e920c4f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/RGBColorImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/RGBColorImpl.java @@ -22,7 +22,7 @@ final class RGBColorImpl extends CSSValueImpl implements RGBColor { private final CSSPrimitiveValue green; private final CSSPrimitiveValue blue; - RGBColorImpl(LexicalUnit lexicalUnit) { + RGBColorImpl(final LexicalUnit lexicalUnit) { LexicalUnit nextUnit = lexicalUnit.getParameters(); red = new Measure(nextUnit); nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java index d9ab54729..c7133a244 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java @@ -43,11 +43,11 @@ public SACParserFactoryImpl() { } @Override - public Parser makeParser(String name) throws ClassNotFoundException, IllegalAccessException, InstantiationException, + public Parser makeParser(final String name) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NullPointerException, ClassCastException { - String classNameParser = parsers.get(name); + final String classNameParser = parsers.get(name); if (classNameParser != null) { - Class classParser = super.getClass().getClassLoader().loadClass(classNameParser); + final Class classParser = super.getClass().getClassLoader().loadClass(classNameParser); try { return (Parser) classParser.getDeclaredConstructor().newInstance(); } catch (InvocationTargetException|NoSuchMethodException ex) { @@ -63,7 +63,7 @@ public Parser makeParser(String name) throws ClassNotFoundException, IllegalAcce * * @param parser */ - private static void registerSACParser(String parser) { + private static void registerSACParser(final String parser) { registerSACParser(parser, parser); } @@ -74,7 +74,7 @@ private static void registerSACParser(String parser) { * @param name * @param classNameParser */ - private static void registerSACParser(String name, String classNameParser) { + private static void registerSACParser(final String name, final String classNameParser) { parsers.put(name, classNameParser); } } From 63d5ddab543c53fb8395df0a124d71472a524668 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 17:43:57 +0200 Subject: [PATCH 151/202] Enable annotation-based null analysis for theme.css package --- .../theme/css/AbstractElementSelector.java | 13 +++++-- .../theme/css/CSSAttributeCondition.java | 11 +++++- .../internal/theme/css/CSSClassCondition.java | 4 +- .../theme/css/CSSConditionFactory.java | 27 ++++++------- .../theme/css/CSSDocumentHandler.java | 38 ++++++++++--------- .../theme/css/CSSElementSelector.java | 4 +- .../theme/css/CSSSelectorFactory.java | 25 +++++++----- .../core/internal/theme/css/CSSValueImpl.java | 5 ++- .../tm4e/core/internal/theme/css/Measure.java | 11 ------ .../theme/css/SACParserFactoryImpl.java | 18 +++++---- .../core/internal/theme/css/package-info.java | 4 ++ 11 files changed, 92 insertions(+), 68 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java index 537233e4a..58077fee4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/AbstractElementSelector.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.theme.css; +import org.eclipse.jdt.annotation.Nullable; import org.w3c.css.sac.ElementSelector; public abstract class AbstractElementSelector implements ElementSelector, ExtendedSelector { @@ -18,26 +19,30 @@ public abstract class AbstractElementSelector implements ElementSelector, Extend /** * The namespace URI. */ + @Nullable private final String namespaceURI; /** * The local name. */ + @Nullable private final String localName; /** * Creates a new ElementSelector object. */ - protected AbstractElementSelector(final String uri, final String name) { + protected AbstractElementSelector(@Nullable final String uri, @Nullable final String name) { namespaceURI = uri; localName = name; } + @Nullable @Override public String getNamespaceURI() { return namespaceURI; } + @Nullable @Override public String getLocalName() { return localName; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java index b8a41a4b5..5b5de2957 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSAttributeCondition.java @@ -11,16 +11,20 @@ */ package org.eclipse.tm4e.core.internal.theme.css; +import org.eclipse.jdt.annotation.Nullable; + class CSSAttributeCondition extends AbstractAttributeCondition { /** * The attribute's local name. */ + @Nullable private final String localName; /** * The attribute's namespace URI. */ + @Nullable private final String namespaceURI; /** @@ -28,18 +32,20 @@ class CSSAttributeCondition extends AbstractAttributeCondition { */ private final boolean specified; - protected CSSAttributeCondition(final String localName, final String namespaceURI, final boolean specified, final String value) { + protected CSSAttributeCondition(@Nullable final String localName, @Nullable final String namespaceURI, final boolean specified, final String value) { super(value); this.localName = localName; this.namespaceURI = namespaceURI; this.specified = specified; } + @Nullable @Override public String getLocalName() { return localName; } + @Nullable @Override public String getNamespaceURI() { return namespaceURI; @@ -57,7 +63,8 @@ public short getConditionType() { @Override public int nbMatch(final String... names) { -// String val = getValue(); +// TODO +// String val = getValue(); // if (val == null) { // return !e.getAttribute(getLocalName()).equals(""); // } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java index 9e6245ce9..ec941c6c6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSClassCondition.java @@ -11,9 +11,11 @@ */ package org.eclipse.tm4e.core.internal.theme.css; +import org.eclipse.jdt.annotation.Nullable; + final class CSSClassCondition extends CSSAttributeCondition { - CSSClassCondition(final String localName, final String namespaceURI, final String value) { + CSSClassCondition(@Nullable final String localName, final String namespaceURI, final String value) { super(localName, namespaceURI, true, value); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java index f4bc76e1b..cab7041c0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSConditionFactory.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.internal.theme.css; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.w3c.css.sac.AttributeCondition; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.CombinatorCondition; @@ -21,6 +22,7 @@ import org.w3c.css.sac.NegativeCondition; import org.w3c.css.sac.PositionalCondition; +@NonNullByDefault({}) public final class CSSConditionFactory implements ConditionFactory { public static final ConditionFactory INSTANCE = new CSSConditionFactory(); @@ -31,20 +33,19 @@ public AttributeCondition createClassCondition(final String namespaceURI, final } @Override - public AttributeCondition createAttributeCondition(final String localName, final String namespaceURI, final boolean specified, - final String value) throws CSSException { + public AttributeCondition createAttributeCondition(final String localName, final String namespaceURI, + final boolean specified, final String value) throws CSSException { return new CSSAttributeCondition(localName, namespaceURI, specified, value); } @Override - public CombinatorCondition createAndCondition(final Condition first, - final Condition second) throws CSSException { + public CombinatorCondition createAndCondition(final Condition first, final Condition second) throws CSSException { return new CSSAndCondition(first, second); } @Override - public AttributeCondition createBeginHyphenAttributeCondition(final String arg0, final String arg1, final boolean arg2, final String arg3) - throws CSSException { + public AttributeCondition createBeginHyphenAttributeCondition(final String arg0, final String arg1, + final boolean arg2, final String arg3) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @@ -69,8 +70,8 @@ public NegativeCondition createNegativeCondition(final Condition arg0) throws CS } @Override - public AttributeCondition createOneOfAttributeCondition(final String arg0, final String arg1, final boolean arg2, final String arg3) - throws CSSException { + public AttributeCondition createOneOfAttributeCondition(final String arg0, final String arg1, final boolean arg2, + final String arg3) throws CSSException { throw new CSSException("Not implemented in CSS2"); } @@ -90,7 +91,8 @@ public CombinatorCondition createOrCondition(final Condition arg0, final Conditi } @Override - public PositionalCondition createPositionalCondition(final int arg0, final boolean arg1, final boolean arg2) throws CSSException { + public PositionalCondition createPositionalCondition(final int arg0, final boolean arg1, final boolean arg2) + throws CSSException { throw new CSSException("Not implemented in CSS2"); } @@ -98,5 +100,4 @@ public PositionalCondition createPositionalCondition(final int arg0, final boole public AttributeCondition createPseudoClassCondition(final String arg0, final String arg1) throws CSSException { throw new CSSException("Not implemented in CSS2"); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java index c07c218f8..439d1394a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IStyle; import org.eclipse.tm4e.core.theme.RGB; import org.eclipse.tm4e.core.theme.css.CSSStyle; @@ -24,20 +25,20 @@ import org.w3c.css.sac.SACMediaList; import org.w3c.css.sac.SelectorList; import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.RGBColor; public final class CSSDocumentHandler implements DocumentHandler { private final List list = new ArrayList<>(); + + @Nullable private CSSStyle currentStyle; @Override - public void comment(final String arg0) throws CSSException { - + public void comment(@Nullable final String arg0) throws CSSException { } @Override - public void endDocument(final InputSource arg0) throws CSSException { + public void endDocument(@Nullable final InputSource arg0) throws CSSException { // TODO Auto-generated method stub } @@ -47,38 +48,41 @@ public void endFontFace() throws CSSException { } @Override - public void endMedia(final SACMediaList arg0) throws CSSException { + public void endMedia(@Nullable final SACMediaList arg0) throws CSSException { // TODO Auto-generated method stub } @Override - public void endPage(final String arg0, final String arg1) throws CSSException { + public void endPage(@Nullable final String arg0, @Nullable final String arg1) throws CSSException { // TODO Auto-generated method stub } @Override - public void endSelector(final SelectorList selector) throws CSSException { + public void endSelector(@Nullable final SelectorList selector) throws CSSException { currentStyle = null; } @Override - public void ignorableAtRule(final String arg0) throws CSSException { + public void ignorableAtRule(@Nullable final String arg0) throws CSSException { // TODO Auto-generated method stub } @Override - public void importStyle(final String arg0, final SACMediaList arg1, final String arg2) throws CSSException { + public void importStyle(@Nullable final String arg0, @Nullable final SACMediaList arg1, @Nullable final String arg2) + throws CSSException { // TODO Auto-generated method stub } @Override - public void namespaceDeclaration(final String arg0, final String arg1) throws CSSException { + public void namespaceDeclaration(@Nullable final String arg0, @Nullable final String arg1) throws CSSException { // TODO Auto-generated method stub } @Override - public void property(final String name, final LexicalUnit value, final boolean arg2) throws CSSException { - if (currentStyle != null && name != null) { + public void property(@Nullable final String name, @Nullable final LexicalUnit value, final boolean arg2) + throws CSSException { + final var currentStyle = this.currentStyle; + if (currentStyle != null && name != null && value != null) { switch (name) { case "color": currentStyle.setColor(createRGB(value)); @@ -106,7 +110,7 @@ public void property(final String name, final LexicalUnit value, final boolean a } private RGB createRGB(final LexicalUnit value) { - final RGBColor rgbColor = new RGBColorImpl(value); + final var rgbColor = new RGBColorImpl(value); final int green = ((int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); final int red = ((int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); final int blue = ((int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); @@ -114,7 +118,7 @@ private RGB createRGB(final LexicalUnit value) { } @Override - public void startDocument(final InputSource arg0) throws CSSException { + public void startDocument(@Nullable final InputSource arg0) throws CSSException { // TODO Auto-generated method stub } @@ -124,17 +128,17 @@ public void startFontFace() throws CSSException { } @Override - public void startMedia(final SACMediaList arg0) throws CSSException { + public void startMedia(@Nullable final SACMediaList arg0) throws CSSException { // TODO Auto-generated method stub } @Override - public void startPage(final String arg0, final String arg1) throws CSSException { + public void startPage(@Nullable final String arg0, @Nullable final String arg1) throws CSSException { // TODO Auto-generated method stub } @Override - public void startSelector(final SelectorList selector) throws CSSException { + public void startSelector(@Nullable final SelectorList selector) throws CSSException { currentStyle = new CSSStyle(selector); list.add(currentStyle); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java index b0ce620d5..9943be8e5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSElementSelector.java @@ -11,9 +11,11 @@ */ package org.eclipse.tm4e.core.internal.theme.css; +import org.eclipse.jdt.annotation.Nullable; + final class CSSElementSelector extends AbstractElementSelector { - CSSElementSelector(final String uri, final String name) { + CSSElementSelector(@Nullable final String uri, @Nullable final String name) { super(uri, name); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java index 735a16e0e..667a61db0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSSelectorFactory.java @@ -1,17 +1,18 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation - * Jochen Ulrich - exception messages + * Contributors: + * Angelo Zerr - initial API and implementation + * Jochen Ulrich - exception messages */ package org.eclipse.tm4e.core.internal.theme.css; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.CharacterDataSelector; import org.w3c.css.sac.Condition; @@ -25,6 +26,7 @@ import org.w3c.css.sac.SiblingSelector; import org.w3c.css.sac.SimpleSelector; +@NonNullByDefault({}) public final class CSSSelectorFactory implements SelectorFactory { public static final SelectorFactory INSTANCE = new CSSSelectorFactory(); @@ -40,7 +42,8 @@ public CharacterDataSelector createCDataSectionSelector(final String arg0) throw } @Override - public DescendantSelector createChildSelector(final Selector arg0, final SimpleSelector arg1) throws CSSException { + public DescendantSelector createChildSelector(final Selector arg0, final SimpleSelector arg1) + throws CSSException { throw new UnsupportedOperationException("CSS child selector is not supported"); } @@ -56,12 +59,14 @@ public ConditionalSelector createConditionalSelector(final SimpleSelector select } @Override - public DescendantSelector createDescendantSelector(final Selector arg0, final SimpleSelector arg1) throws CSSException { + public DescendantSelector createDescendantSelector(final Selector arg0, + final SimpleSelector arg1) throws CSSException { throw new UnsupportedOperationException("CSS descendant selector is not supported"); } @Override - public SiblingSelector createDirectAdjacentSelector(final short arg0, final Selector arg1, final SimpleSelector arg2) + public SiblingSelector createDirectAdjacentSelector(final short arg0, final Selector arg1, + final SimpleSelector arg2) throws CSSException { throw new UnsupportedOperationException("CSS direct adjacent selector is not supported"); } @@ -77,13 +82,15 @@ public NegativeSelector createNegativeSelector(final SimpleSelector arg0) throws } @Override - public ProcessingInstructionSelector createProcessingInstructionSelector(final String arg0, final String arg1) + public ProcessingInstructionSelector createProcessingInstructionSelector(final String arg0, + final String arg1) throws CSSException { throw new UnsupportedOperationException("CSS processing instruction is not supported"); } @Override - public ElementSelector createPseudoElementSelector(final String arg0, final String arg1) throws CSSException { + public ElementSelector createPseudoElementSelector(final String arg0, final String arg1) + throws CSSException { throw new UnsupportedOperationException("CSS pseudo element selector is not supported"); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java index 976dab283..857435437 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSValueImpl.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.tm4e.core.internal.theme.css; +import org.eclipse.jdt.annotation.Nullable; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.Counter; @@ -33,7 +34,7 @@ public short getCssValueType() { } @Override - public void setCssText(final String cssText) throws DOMException { + public void setCssText(@Nullable final String cssText) throws DOMException { // TODO Auto-generated method stub throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); } @@ -74,7 +75,7 @@ public void setFloatValue(final short arg0, final float arg1) throws DOMExceptio } @Override - public void setStringValue(final short arg0, final String arg1) throws DOMException { + public void setStringValue(final short arg0, @Nullable final String arg1) throws DOMException { // TODO Auto-generated method stub throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java index 8bfb37218..424e5e55e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/Measure.java @@ -45,17 +45,6 @@ public float getFloatValue(final short valueType) throws DOMException { return value.getFloatValue(); } - /** - * Return an int representation of the receiver's value. - * - * @param valueType - * a short representing the value type, see - * {@link CSSValue#getCssValueType()} - */ - private int getIntegerValue(final short valueType) throws DOMException { - return value.getIntegerValue(); - } - @Override public String getStringValue() throws DOMException { final short lexicalUnit = value.getLexicalUnitType(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java index c7133a244..a7fb120ff 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Angelo Zerr - initial API and implementation + * Angelo Zerr - initial API and implementation *******************************************************************************/ package org.eclipse.tm4e.core.internal.theme.css; @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.css.SACConstants; import org.eclipse.tm4e.core.theme.css.SACParserFactory; import org.w3c.css.sac.Parser; @@ -24,7 +25,7 @@ */ public final class SACParserFactoryImpl extends SACParserFactory { - private static Map parsers = new HashMap<>(); + private static Map parsers = new HashMap<>(); static { // Register Flute SAC Parser @@ -42,20 +43,21 @@ public SACParserFactoryImpl() { super.setPreferredParserName(SACConstants.SACPARSER_BATIK); } + @Nullable @Override - public Parser makeParser(final String name) throws ClassNotFoundException, IllegalAccessException, InstantiationException, - NullPointerException, ClassCastException { + public Parser makeParser(@Nullable final String name) throws ClassNotFoundException, IllegalAccessException, + InstantiationException, NullPointerException, ClassCastException { final String classNameParser = parsers.get(name); if (classNameParser != null) { final Class classParser = super.getClass().getClassLoader().loadClass(classNameParser); try { return (Parser) classParser.getDeclaredConstructor().newInstance(); - } catch (InvocationTargetException|NoSuchMethodException ex) { - throw (InstantiationException)((new InstantiationException()).initCause(ex)); + } catch (InvocationTargetException | NoSuchMethodException ex) { + throw (InstantiationException) ((new InstantiationException()).initCause(ex)); } } - throw new IllegalAccessException("SAC parser with name=" + name - + " was not registered into SAC parser factory."); + throw new IllegalAccessException( + "SAC parser with name=" + name + " was not registered into SAC parser factory."); } /** diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/package-info.java new file mode 100644 index 000000000..f2ef4ad38 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.theme.css; + +import org.eclipse.jdt.annotation.NonNullByDefault; From 66cb26f0617d65849e89c6b2d81148ec7e92ff01 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 18:02:45 +0200 Subject: [PATCH 152/202] Refactor internal theme.reader package, enable null analysis --- .../tm4e/core/theme/ThemeMatchingTest.java | 12 ++--- .../tm4e/core/theme/ThemeParsingTest.java | 2 +- .../tm4e/core/theme/ThemeResolvingTest.java | 2 +- .../internal/theme/reader/IThemeParser.java | 31 ------------ .../theme/reader/SyncThemeReader.java | 11 +++-- .../internal/theme/reader/ThemeReader.java | 48 +++++++++---------- .../internal/theme/reader/package-info.java | 4 ++ 7 files changed, 40 insertions(+), 70 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/IThemeParser.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/package-info.java diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java index 428a8c622..ac327eb57 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java @@ -34,7 +34,7 @@ class ThemeMatchingTest { @Test void testGivesHigherPriorityToDeeperMatches() throws Exception { - Theme theme = loadTheme("{" + + Theme theme = loadTheme("{" + "\"settings\": ["+ "{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+ "{ \"scope\": \"punctuation.definition.string.begin.html\", \"settings\": { \"foreground\": \"#300000\" } },"+ @@ -60,7 +60,7 @@ void testGivesHigherPriorityToDeeperMatches() throws Exception { @Test void testGivesHigherPriorityToParentMatches1() throws Exception { - Theme theme = loadTheme("{" + + Theme theme = loadTheme("{" + "\"settings\": ["+ "{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+ "{ \"scope\": \"c a\", \"settings\": { \"foreground\": \"#300000\" } },"+ @@ -88,7 +88,7 @@ void testGivesHigherPriorityToParentMatches1() throws Exception { @Test void testGivesHigherPriorityToParentMatches2() throws Exception { - Theme theme = loadTheme("{" + + Theme theme = loadTheme("{" + "\"settings\": ["+ "{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+ "{ \"scope\": \"meta.tag entity\", \"settings\": { \"foreground\": \"#300000\" } },"+ @@ -194,9 +194,9 @@ void testCanMatch() throws Exception { @Test void testMicrosoft_vscode_23460() throws Exception { - Theme theme = loadTheme("{" + + Theme theme = loadTheme("{" + "\"settings\": ["+ - "{" + + "{" + "\"settings\": {"+ "\"foreground\": \"#aec2e0\","+ "\"background\": \"#14191f\""+ @@ -270,6 +270,6 @@ private void assertNoMatch(Theme theme, String scopeName) { } private Theme loadTheme(String theme) throws Exception { - return Theme.createFromRawTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes()))); + return Theme.createFromRawTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes()))); } } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java index 1fd72baad..0f050ad3f 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java @@ -65,6 +65,6 @@ public void testCanParse() throws Exception { } private List parseTheme(String theme) throws Exception { - return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes()))); + return Theme.parseTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes()))); } } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java index 662612d73..bc13d38fc 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java @@ -401,6 +401,6 @@ private void assertStrArrCmp(String testCase, List a, List b, in } private List parseTheme(String theme) throws Exception { - return Theme.parseTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes()))); + return Theme.parseTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes()))); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/IThemeParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/IThemeParser.java deleted file mode 100644 index a5701b1fe..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/IThemeParser.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Initial code from https://github.com/Microsoft/vscode-textmate/ - * Initial copyright Copyright (C) Microsoft Corporation. All rights reserved. - * Initial license: MIT - * - * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java - */ -package org.eclipse.tm4e.core.internal.theme.reader; - -import java.io.InputStream; - -import org.eclipse.tm4e.core.theme.IRawTheme; - -/** - * TextMate Theme parser. - * - */ -@FunctionalInterface -public interface IThemeParser { - - IRawTheme parse(InputStream contents) throws Exception; -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java index 3514997a7..1d4a7500a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,21 +11,22 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.theme.reader; import java.io.InputStream; +import org.eclipse.tm4e.core.internal.parser.PListParser; import org.eclipse.tm4e.core.theme.IRawTheme; final class SyncThemeReader { private final InputStream in; - private final IThemeParser parser; + private final PListParser parser; - SyncThemeReader(InputStream in, IThemeParser parser) { + SyncThemeReader(final InputStream in, final PListParser parser) { this.in = in; this.parser = parser; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java index cf352e067..74aa9343b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,15 +11,17 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.theme.reader; import java.io.InputStream; +import org.eclipse.tm4e.core.internal.parser.PListParser; import org.eclipse.tm4e.core.internal.parser.PListParserJSON; import org.eclipse.tm4e.core.internal.parser.PListParserXML; +import org.eclipse.tm4e.core.internal.parser.PListParserYAML; import org.eclipse.tm4e.core.internal.theme.ThemeRaw; import org.eclipse.tm4e.core.theme.IRawTheme; @@ -35,35 +37,29 @@ public final class ThemeReader { private ThemeReader() { } - private static final IThemeParser XML_PARSER = new IThemeParser() { + private static final PListParserJSON JSON_PARSER = new PListParserJSON<>(ThemeRaw::new); + private static final PListParserYAML YAML_PARSER = new PListParserYAML<>(ThemeRaw::new); + private static final PListParserXML XML_PARSER = new PListParserXML<>(ThemeRaw::new); - private final PListParserXML parser = new PListParserXML<>(ThemeRaw::new); - - @Override - public IRawTheme parse(InputStream contents) throws Exception { - return parser.parse(contents); - } - }; + public static IRawTheme readThemeSync(final String filePath, final InputStream in) throws Exception { + final var reader = new SyncThemeReader(in, getThemeParser(filePath)); + return reader.load(); + } - public static final IThemeParser JSON_PARSER = new IThemeParser() { + private static PListParser getThemeParser(final String filePath) { + String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); - private final PListParserJSON parser = new PListParserJSON<>(ThemeRaw::new); + switch (extension) { - @Override - public IRawTheme parse(InputStream contents) throws Exception { - return parser.parse(contents); - } - }; + case "json": + return JSON_PARSER; - private static IRawTheme readThemeSync(String filePath, InputStream in) throws Exception { - SyncThemeReader reader = new SyncThemeReader(in, getThemeParser(filePath)); - return reader.load(); - } + case "yaml": + case "yml": + return YAML_PARSER; - private static IThemeParser getThemeParser(String filePath) { - if (filePath.endsWith(".json")) { - return JSON_PARSER; + default: + return XML_PARSER; } - return XML_PARSER; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/package-info.java new file mode 100644 index 000000000..8f8b39774 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.theme.reader; + +import org.eclipse.jdt.annotation.NonNullByDefault; From 30304d78eb1f502fa2f57462f6b0e3ffd7b0a4b8 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 19:07:44 +0200 Subject: [PATCH 153/202] Add final modifier to theme package where applicable --- .../org/eclipse/tm4e/core/theme/ColorMap.java | 8 +-- .../tm4e/core/theme/ParsedThemeRule.java | 8 +-- .../java/org/eclipse/tm4e/core/theme/RGB.java | 2 +- .../org/eclipse/tm4e/core/theme/Theme.java | 56 +++++++++---------- .../tm4e/core/theme/ThemeTrieElement.java | 48 ++++++++-------- .../tm4e/core/theme/ThemeTrieElementRule.java | 14 ++--- .../tm4e/core/theme/css/CSSParser.java | 24 ++++---- .../eclipse/tm4e/core/theme/css/CSSStyle.java | 14 ++--- .../theme/css/ParserNotFoundException.java | 2 +- .../tm4e/core/theme/css/SACParserFactory.java | 4 +- 10 files changed, 91 insertions(+), 89 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java index ee95a3431..03fc130d7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java @@ -36,8 +36,8 @@ public int getId(String color) { return value; } - public String getColor(int id) { - for (Entry entry : color2id.entrySet()) { + public String getColor(final int id) { + for (final Entry entry : color2id.entrySet()) { if (id == entry.getValue()) { return entry.getKey(); } @@ -55,7 +55,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -65,7 +65,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - ColorMap other = (ColorMap) obj; + final ColorMap other = (ColorMap) obj; return Objects.equals(color2id, other.color2id) && lastColorId == other.lastColorId; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java index 91fdd5920..47dfc13a0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java @@ -28,8 +28,8 @@ public class ParsedThemeRule { public final String foreground; public final String background; - public ParsedThemeRule(String scope, List parentScopes, int index, int fontStyle, String foreground, - String background) { + public ParsedThemeRule(final String scope, final List parentScopes, final int index, final int fontStyle, final String foreground, + final String background) { this.scope = scope; this.parentScopes = parentScopes; this.index = index; @@ -52,14 +52,14 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; - ParsedThemeRule other = (ParsedThemeRule) obj; + final ParsedThemeRule other = (ParsedThemeRule) obj; if (background == null) { if (other.background != null) return false; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java index d544d6e2d..17a239684 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/RGB.java @@ -17,7 +17,7 @@ public class RGB { public final int green; public final int blue; - public RGB(int red, int green, int blue) { + public RGB(final int red, final int green, final int blue) { this.red = red; this.green = green; this.blue = blue; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index b29510588..7865a0584 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -47,27 +47,27 @@ public class Theme { private final ThemeTrieElementRule defaults; private final Map> cache = new HashMap<>(); - public static Theme createFromRawTheme(IRawTheme source) { + public static Theme createFromRawTheme(final IRawTheme source) { return createFromParsedTheme(parseTheme(source)); } - public static List parseTheme(IRawTheme source) { + public static List parseTheme(final IRawTheme source) { if (source == null || source.getSettings() == null) { return Collections.emptyList(); } // if (!source.settings || !Array.isArray(source.settings)) { // return []; // } - Collection settings = source.getSettings(); - List result = new ArrayList<>(); + final Collection settings = source.getSettings(); + final List result = new ArrayList<>(); int i = 0; - for (IRawThemeSetting entry : settings) { + for (final IRawThemeSetting entry : settings) { if (entry.getSetting() == null) { continue; } - Object settingScope = entry.getScope(); + final Object settingScope = entry.getScope(); List scopes; if (settingScope instanceof String) { String scope = (String) settingScope; @@ -86,12 +86,12 @@ public static List parseTheme(IRawTheme source) { } int fontStyle = FontStyle.NotSet; - Object settingsFontStyle = entry.getSetting().getFontStyle(); + final Object settingsFontStyle = entry.getSetting().getFontStyle(); if (settingsFontStyle instanceof String) { fontStyle = FontStyle.None; - Iterable segments = BY_SPACE_SPLITTER.split((String) settingsFontStyle); - for (String segment : segments) { + final Iterable segments = BY_SPACE_SPLITTER.split((String) settingsFontStyle); + for (final String segment : segments) { switch (segment) { case "italic": fontStyle = fontStyle | FontStyle.Italic; @@ -110,29 +110,29 @@ public static List parseTheme(IRawTheme source) { } String foreground = null; - Object settingsForeground = entry.getSetting().getForeground(); + final Object settingsForeground = entry.getSetting().getForeground(); if (settingsForeground instanceof String && isValidHexColor((String) settingsForeground)) { foreground = (String) settingsForeground; } String background = null; - Object settingsBackground = entry.getSetting().getBackground(); + final Object settingsBackground = entry.getSetting().getBackground(); if (settingsBackground instanceof String && isValidHexColor((String) settingsBackground)) { background = (String) settingsBackground; } for (int j = 0, lenJ = scopes.size(); j < lenJ; j++) { - String _scope = scopes.get(j).trim(); + final String _scope = scopes.get(j).trim(); - List segments = BY_SPACE_SPLITTER.splitToList(_scope); + final List segments = BY_SPACE_SPLITTER.splitToList(_scope); - String scope = getLastElement(segments); + final String scope = getLastElement(segments); List parentScopes = null; if (segments.size() > 1) { parentScopes = segments.subList(0, segments.size() - 1); parentScopes = Lists.reverse(parentScopes); } - ParsedThemeRule t = new ParsedThemeRule(scope, parentScopes, i, fontStyle, foreground, background); + final ParsedThemeRule t = new ParsedThemeRule(scope, parentScopes, i, fontStyle, foreground, background); result.add(t); } i++; @@ -141,7 +141,7 @@ public static List parseTheme(IRawTheme source) { return result; } - private static boolean isValidHexColor(String hex) { + private static boolean isValidHexColor(final String hex) { if (hex == null || hex.isEmpty()) { return false; } @@ -169,14 +169,14 @@ private static boolean isValidHexColor(String hex) { return false; } - public static Theme createFromParsedTheme(List source) { + public static Theme createFromParsedTheme(final List source) { return resolveParsedThemeRules(source); } /** * Resolve rules (i.e. inheritance). */ - public static Theme resolveParsedThemeRules(List parsedThemeRules) { + public static Theme resolveParsedThemeRules(final List parsedThemeRules) { // Sort rules lexicographically, and then by index if necessary parsedThemeRules.sort((a, b) -> { int r = CompareUtils.strcmp(a.scope, b.scope); @@ -195,7 +195,7 @@ public static Theme resolveParsedThemeRules(List parsedThemeRul String defaultForeground = "#000000"; String defaultBackground = "#ffffff"; while (!parsedThemeRules.isEmpty() && "".equals(parsedThemeRules.get(0).scope)) { - ParsedThemeRule incomingDefaults = parsedThemeRules.remove(0); // shift(); + final ParsedThemeRule incomingDefaults = parsedThemeRules.remove(0); // shift(); if (incomingDefaults.fontStyle != FontStyle.NotSet) { defaultFontStyle = incomingDefaults.fontStyle; } @@ -206,13 +206,13 @@ public static Theme resolveParsedThemeRules(List parsedThemeRul defaultBackground = incomingDefaults.background; } } - ColorMap colorMap = new ColorMap(); - ThemeTrieElementRule defaults = new ThemeTrieElementRule(0, null, defaultFontStyle, + final ColorMap colorMap = new ColorMap(); + final ThemeTrieElementRule defaults = new ThemeTrieElementRule(0, null, defaultFontStyle, colorMap.getId(defaultForeground), colorMap.getId(defaultBackground)); - ThemeTrieElement root = new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0), + final ThemeTrieElement root = new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0), Collections.emptyList()); - for (ParsedThemeRule rule : parsedThemeRules) { + for (final ParsedThemeRule rule : parsedThemeRules) { root.insert(0, rule.scope, rule.parentScopes, rule.fontStyle, colorMap.getId(rule.foreground), colorMap.getId(rule.background)); } @@ -220,7 +220,7 @@ public static Theme resolveParsedThemeRules(List parsedThemeRul return new Theme(colorMap, defaults, root); } - public Theme(ColorMap colorMap, ThemeTrieElementRule defaults, ThemeTrieElement root) { + public Theme(final ColorMap colorMap, final ThemeTrieElementRule defaults, final ThemeTrieElement root) { this.colorMap = colorMap; this.root = root; this.defaults = defaults; @@ -230,7 +230,7 @@ public Set getColorMap() { return this.colorMap.getColorMap(); } - public String getColor(int id) { + public String getColor(final int id) { return this.colorMap.getColor(id); } @@ -238,7 +238,7 @@ public ThemeTrieElementRule getDefaults() { return this.defaults; } - public List match(String scopeName) { + public List match(final String scopeName) { if (!this.cache.containsKey(scopeName)) { this.cache.put(scopeName, this.root.match(scopeName)); } @@ -251,7 +251,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -261,7 +261,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - Theme other = (Theme) obj; + final Theme other = (Theme) obj; return Objects.equals(cache, other.cache) && Objects.equals(colorMap, other.colorMap) && Objects.equals(defaults, other.defaults) && Objects.equals(root, other.root); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java index 334aa43b2..d9a595167 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java @@ -27,22 +27,22 @@ public class ThemeTrieElement { private final List rulesWithParentScopes; private final Map children; - public ThemeTrieElement(ThemeTrieElementRule mainRule) { + public ThemeTrieElement(final ThemeTrieElementRule mainRule) { this(mainRule, new ArrayList<>(), new HashMap<>()); } - public ThemeTrieElement(ThemeTrieElementRule mainRule, List rulesWithParentScopes) { + public ThemeTrieElement(final ThemeTrieElementRule mainRule, final List rulesWithParentScopes) { this(mainRule, rulesWithParentScopes, new HashMap<>()); } - public ThemeTrieElement(ThemeTrieElementRule mainRule, List rulesWithParentScopes, - Map children) { + public ThemeTrieElement(final ThemeTrieElementRule mainRule, final List rulesWithParentScopes, + final Map children) { this.mainRule = mainRule; this.rulesWithParentScopes = rulesWithParentScopes; this.children = children; } - private static List sortBySpecificity(List arr) { + private static List sortBySpecificity(final List arr) { if (arr.size() == 1) { return arr; } @@ -50,20 +50,22 @@ private static List sortBySpecificity(List aParentScopes = a.parentScopes; - List bParentScopes = b.parentScopes; - int aParentScopesLen = aParentScopes == null ? 0 : aParentScopes.size(); - int bParentScopesLen = bParentScopes == null ? 0 : bParentScopes.size(); + final List aParentScopes = a.parentScopes; + final List bParentScopes = b.parentScopes; + final int aParentScopesLen = aParentScopes == null ? 0 : aParentScopes.size(); + final int bParentScopesLen = bParentScopes == null ? 0 : bParentScopes.size(); if (aParentScopesLen == bParentScopesLen) { for (int i = 0; i < aParentScopesLen; i++) { @SuppressWarnings("null") + final String aScope = aParentScopes.get(i); @SuppressWarnings("null") + final String bScope = bParentScopes.get(i); - int aLen = aScope.length(); - int bLen = bScope.length(); + final int aLen = aScope.length(); + final int bLen = bScope.length(); if (aLen != bLen) { return bLen - aLen; } @@ -74,15 +76,15 @@ private static int cmpBySpecificity(ThemeTrieElementRule a, ThemeTrieElementRule return b.scopeDepth - a.scopeDepth; } - public List match(String scope) { + public List match(final String scope) { if ("".equals(scope)) { - List arr = new ArrayList<>(); + final List arr = new ArrayList<>(); arr.add(this.mainRule); arr.addAll(this.rulesWithParentScopes); return ThemeTrieElement.sortBySpecificity(arr); } - int dotIndex = scope.indexOf('.'); + final int dotIndex = scope.indexOf('.'); String head; String tail; if (dotIndex == -1) { @@ -97,20 +99,20 @@ public List match(String scope) { return this.children.get(head).match(tail); } - List arr = new ArrayList<>(); + final List arr = new ArrayList<>(); arr.add(this.mainRule); arr.addAll(this.rulesWithParentScopes); return ThemeTrieElement.sortBySpecificity(arr); } - public void insert(int scopeDepth, String scope, List parentScopes, int fontStyle, int foreground, - int background) { + public void insert(final int scopeDepth, final String scope, final List parentScopes, final int fontStyle, final int foreground, + final int background) { if ("".equals(scope)) { this.doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background); return; } - int dotIndex = scope.indexOf('.'); + final int dotIndex = scope.indexOf('.'); String head; String tail; if (dotIndex == -1) { @@ -133,7 +135,7 @@ public void insert(int scopeDepth, String scope, List parentScopes, int child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background); } - private void doInsertHere(int scopeDepth, List parentScopes, int fontStyle, int foreground, + private void doInsertHere(final int scopeDepth, final List parentScopes, int fontStyle, int foreground, int background) { if (parentScopes == null) { @@ -143,7 +145,7 @@ private void doInsertHere(int scopeDepth, List parentScopes, int fontSty } // Try to merge into existing rule - for (ThemeTrieElementRule rule : this.rulesWithParentScopes) { + for (final ThemeTrieElementRule rule : this.rulesWithParentScopes) { if (CompareUtils.strArrCmp(rule.parentScopes, parentScopes) == 0) { // bingo! => we get to merge this into an existing one rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background); @@ -174,7 +176,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -184,7 +186,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - ThemeTrieElement other = (ThemeTrieElement) obj; + final ThemeTrieElement other = (ThemeTrieElement) obj; return Objects.equals(children, other.children) && Objects.equals(mainRule, other.mainRule) && Objects.equals(rulesWithParentScopes, other.rulesWithParentScopes); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java index f810fadfc..1aa008968 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java @@ -25,8 +25,8 @@ public class ThemeTrieElementRule { public int foreground; public int background; - public ThemeTrieElementRule(int scopeDepth, List parentScopes, int fontStyle, int foreground, - int background) { + public ThemeTrieElementRule(final int scopeDepth, final List parentScopes, final int fontStyle, final int foreground, + final int background) { this.scopeDepth = scopeDepth; this.parentScopes = parentScopes; this.fontStyle = fontStyle; @@ -40,15 +40,15 @@ public ThemeTrieElementRule clone() { this.background); } - public static List cloneArr(List arr) { - List r = new ArrayList<>(); + public static List cloneArr(final List arr) { + final List r = new ArrayList<>(); for (int i = 0, len = arr.size(); i < len; i++) { r.add(arr.get(i).clone()); } return r; } - public void acceptOverwrite(int scopeDepth, int fontStyle, int foreground, int background) { + public void acceptOverwrite(final int scopeDepth, final int fontStyle, final int foreground, final int background) { if (this.scopeDepth > scopeDepth) { // TODO!!! // console.log('how did this happen?'); @@ -74,7 +74,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -84,7 +84,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - ThemeTrieElementRule other = (ThemeTrieElementRule) obj; + final ThemeTrieElementRule other = (ThemeTrieElementRule) obj; return background == other.background && fontStyle == other.fontStyle && foreground == other.foreground && Objects.equals(parentScopes, other.parentScopes) && scopeDepth == other.scopeDepth; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java index 1a503aadb..352865e66 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java @@ -35,25 +35,25 @@ public class CSSParser { private final CSSDocumentHandler handler; - public CSSParser(InputStream source) throws Exception { + public CSSParser(final InputStream source) throws Exception { this(toSource(source)); } - private static InputSource toSource(InputStream source) { - InputSource in = new InputSource(); + private static InputSource toSource(final InputStream source) { + final InputSource in = new InputSource(); in.setByteStream(source); return in; } - public CSSParser(InputSource source) throws Exception { + public CSSParser(final InputSource source) throws Exception { this(source, SACParserFactory.newInstance().makeParser()); } - public CSSParser(String source) throws Exception { + public CSSParser(final String source) throws Exception { this(new InputSource(new StringReader(source))); } - public CSSParser(InputSource source, Parser parser) throws CSSException, IOException { + public CSSParser(final InputSource source, final Parser parser) throws CSSException, IOException { this.handler = new CSSDocumentHandler(); parser.setDocumentHandler(handler); parser.setConditionFactory(CSSConditionFactory.INSTANCE); @@ -61,16 +61,16 @@ public CSSParser(InputSource source, Parser parser) throws CSSException, IOExcep parser.parseStyleSheet(source); } - public IStyle getBestStyle(String... names) { + public IStyle getBestStyle(final String... names) { int bestSpecificity = 0; IStyle bestStyle = null; - for (IStyle style : handler.getList()) { - SelectorList list = ((CSSStyle) style).getSelectorList(); + for (final IStyle style : handler.getList()) { + final SelectorList list = ((CSSStyle) style).getSelectorList(); for (int i = 0; i < list.getLength(); i++) { - Selector selector = list.item(i); + final Selector selector = list.item(i); if (selector instanceof ExtendedSelector) { - ExtendedSelector s = ((ExtendedSelector) selector); - int nbMatch = s.nbMatch(names); + final ExtendedSelector s = ((ExtendedSelector) selector); + final int nbMatch = s.nbMatch(names); if (nbMatch > 0 && nbMatch == s.nbClass()) { if (bestStyle == null || (nbMatch >= bestSpecificity)) { bestStyle = style; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java index 81162d5bc..9fba0dd33 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java @@ -26,11 +26,11 @@ public class CSSStyle implements IStyle { private boolean underline; private boolean strikeThrough; - public CSSStyle(SelectorList selector) { + public CSSStyle(final SelectorList selector) { this.selector = selector; } - public void setColor(RGB color) { + public void setColor(final RGB color) { this.color = color; } @@ -44,7 +44,7 @@ public RGB getBackgroundColor() { return backgroundColor; } - public void setBackgroundColor(RGB backgroundColor) { + public void setBackgroundColor(final RGB backgroundColor) { this.backgroundColor = backgroundColor; } @@ -52,7 +52,7 @@ public SelectorList getSelectorList() { return selector; } - public void setBold(boolean bold) { + public void setBold(final boolean bold) { this.bold = bold; } @@ -61,7 +61,7 @@ public boolean isBold() { return bold; } - public void setItalic(boolean italic) { + public void setItalic(final boolean italic) { this.italic = italic; } @@ -75,7 +75,7 @@ public boolean isUnderline() { return underline; } - public void setUnderline(boolean underline) { + public void setUnderline(final boolean underline) { this.underline = underline; } @@ -84,7 +84,7 @@ public boolean isStrikeThrough() { return strikeThrough; } - public void setStrikeThrough(boolean strikeThrough) { + public void setStrikeThrough(final boolean strikeThrough) { this.strikeThrough = strikeThrough; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java index e80f95d56..f390a0703 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java @@ -18,7 +18,7 @@ public class ParserNotFoundException extends RuntimeException { private static final long serialVersionUID = 4339161134287845644L; - public ParserNotFoundException(Throwable throwable) { + public ParserNotFoundException(final Throwable throwable) { super(throwable); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java index 0b0fefb96..6c6e5d050 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java @@ -40,7 +40,7 @@ public Parser makeParser() throws ClassNotFoundException, IllegalAccessException if (preferredParserName != null) { return makeParser(preferredParserName); } - } catch (Throwable ex) { + } catch (final Throwable ex) { LOGGER.log(ERROR, ex.getMessage(), ex); } return super.makeParser(); @@ -60,7 +60,7 @@ public String getPreferredParserName() { * * @param preferredParserName */ - public void setPreferredParserName(String preferredParserName) { + public void setPreferredParserName(final String preferredParserName) { this.preferredParserName = preferredParserName; } From 9dfbf9cbb6584fd9ad2977c58fed7a08e5f95242 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 19:20:10 +0200 Subject: [PATCH 154/202] Enable annotation-based null analysis for theme.css package --- .../theme/css/CSSDocumentHandler.java | 1 + .../theme/css/SACParserFactoryImpl.java | 9 ++-- .../tm4e/core/theme/css/CSSParser.java | 2 + .../eclipse/tm4e/core/theme/css/CSSStyle.java | 17 +++++--- .../core/theme/css/ISACParserFactory.java | 43 +++++++++++-------- .../tm4e/core/theme/css/SACParserFactory.java | 23 ++++------ .../tm4e/core/theme/css/package-info.java | 4 ++ 7 files changed, 57 insertions(+), 42 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java index 439d1394a..90f6bc658 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java @@ -139,6 +139,7 @@ public void startPage(@Nullable final String arg0, @Nullable final String arg1) @Override public void startSelector(@Nullable final SelectorList selector) throws CSSException { + assert selector != null; currentStyle = new CSSStyle(selector); list.add(currentStyle); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java index a7fb120ff..ecdf954de 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java @@ -43,15 +43,16 @@ public SACParserFactoryImpl() { super.setPreferredParserName(SACConstants.SACPARSER_BATIK); } - @Nullable @Override - public Parser makeParser(@Nullable final String name) throws ClassNotFoundException, IllegalAccessException, - InstantiationException, NullPointerException, ClassCastException { + public Parser makeParser(final String name) throws ClassNotFoundException, IllegalAccessException, + InstantiationException, ClassCastException { final String classNameParser = parsers.get(name); if (classNameParser != null) { final Class classParser = super.getClass().getClassLoader().loadClass(classNameParser); try { - return (Parser) classParser.getDeclaredConstructor().newInstance(); + final var parser = (Parser) classParser.getDeclaredConstructor().newInstance(); + assert parser != null; + return parser; } catch (InvocationTargetException | NoSuchMethodException ex) { throw (InstantiationException) ((new InstantiationException()).initCause(ex)); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java index 352865e66..ad2dcaf04 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java @@ -16,6 +16,7 @@ import java.io.StringReader; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.theme.css.CSSConditionFactory; import org.eclipse.tm4e.core.internal.theme.css.CSSDocumentHandler; import org.eclipse.tm4e.core.internal.theme.css.CSSSelectorFactory; @@ -61,6 +62,7 @@ public CSSParser(final InputSource source, final Parser parser) throws CSSExcept parser.parseStyleSheet(source); } + @Nullable public IStyle getBestStyle(final String... names) { int bestSpecificity = 0; IStyle bestStyle = null; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java index 9fba0dd33..49a3f683e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.core.theme.css; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IStyle; import org.eclipse.tm4e.core.theme.RGB; import org.w3c.css.sac.SelectorList; @@ -18,9 +19,13 @@ public class CSSStyle implements IStyle { private final SelectorList selector; + + @Nullable private RGB color; + + @Nullable private RGB backgroundColor; - + private boolean bold; private boolean italic; private boolean underline; @@ -34,20 +39,22 @@ public void setColor(final RGB color) { this.color = color; } + @Nullable @Override public RGB getColor() { return color; } + @Nullable @Override public RGB getBackgroundColor() { return backgroundColor; } - + public void setBackgroundColor(final RGB backgroundColor) { - this.backgroundColor = backgroundColor; + this.backgroundColor = backgroundColor; } - + public SelectorList getSelectorList() { return selector; } @@ -83,7 +90,7 @@ public void setUnderline(final boolean underline) { public boolean isStrikeThrough() { return strikeThrough; } - + public void setStrikeThrough(final boolean strikeThrough) { this.strikeThrough = strikeThrough; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java index 1f9959ca8..ef0ea88cd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java @@ -6,10 +6,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Angelo Zerr - initial API and implementation + * Angelo Zerr - initial API and implementation *******************************************************************************/ package org.eclipse.tm4e.core.theme.css; +import org.eclipse.jdt.annotation.Nullable; import org.w3c.css.sac.Parser; /** @@ -18,28 +19,34 @@ public interface ISACParserFactory { /** - * Return default instance of SAC Parser. If preferredParserName is filled, - * it return the instance of SAC Parser registered with this name, otherwise - * this method search teh SAC Parser class name to instanciate into System - * property with key org.w3c.css.sac.parser. + * Return preferred SAC parser name if it is filled and null otherwise. */ - Parser makeParser() throws ClassNotFoundException, - IllegalAccessException, InstantiationException, - NullPointerException, ClassCastException; + @Nullable + String getPreferredParserName(); /** - * Return instance of SAC Parser registered into the factory with name - * name. + * Set the preferred SAC parser name to use when makeParser is called. + * + * @param preferredParserName + */ + void setPreferredParserName(@Nullable final String preferredParserName); + + /** + * Return default instance of SAC Parser. + * + * If preferredParserName is filled, it return the instance of SAC Parser registered with this name, + * otherwise this method search the SAC Parser class name to instantiate into System property with key + * org.w3c.css.sac.parser. + */ + Parser makeParser() + throws ClassNotFoundException, IllegalAccessException, InstantiationException, ClassCastException; + + /** + * Return instance of SAC Parser registered into the factory with name name. * * @param name - * @return - * @throws ClassNotFoundException - * @throws IllegalAccessException - * @throws InstantiationException - * @throws NullPointerException - * @throws ClassCastException + * @see SACConstants */ Parser makeParser(String name) - throws ClassNotFoundException, IllegalAccessException, - InstantiationException, NullPointerException, ClassCastException; + throws ClassNotFoundException, IllegalAccessException, InstantiationException, ClassCastException; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java index 6c6e5d050..b22b14fa2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Angelo Zerr - initial API and implementation + * Angelo Zerr - initial API and implementation *******************************************************************************/ package org.eclipse.tm4e.core.theme.css; @@ -14,6 +14,7 @@ import java.lang.System.Logger; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.theme.css.SACParserFactoryImpl; import org.w3c.css.sac.Parser; import org.w3c.css.sac.helpers.ParserFactory; @@ -25,6 +26,7 @@ public abstract class SACParserFactory extends ParserFactory implements ISACPars private static final Logger LOGGER = System.getLogger(SACParserFactory.class.getName()); + @Nullable private String preferredParserName; /** @@ -46,28 +48,19 @@ public Parser makeParser() throws ClassNotFoundException, IllegalAccessException return super.makeParser(); } - /** - * Return preferred SAC parser name if it is filled and null otherwise. - * - * @return - */ + @Nullable + @Override public String getPreferredParserName() { return preferredParserName; } - /** - * Set the preferred SAC parser name to use when makeParser is called. - * - * @param preferredParserName - */ - public void setPreferredParserName(final String preferredParserName) { + @Override + public void setPreferredParserName(@Nullable final String preferredParserName) { this.preferredParserName = preferredParserName; } /** - * Return instance of SACParserFactory - * - * @return + * @return instance of SACParserFactory */ public static ISACParserFactory newInstance() { // TODO : manage new instance of SAC Parser Factory like diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/package-info.java new file mode 100644 index 000000000..fc68ac204 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.theme.css; + +import org.eclipse.jdt.annotation.NonNullByDefault; From 8c54585094607a8fb4e25ffccb266424643596d2 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 20:13:18 +0200 Subject: [PATCH 155/202] Refactor theme package, enable annotation-based null analysis --- .../tm4e/core/internal/theme/ThemeRaw.java | 19 ++-- .../core/internal/theme/package-info.java | 4 + .../org/eclipse/tm4e/core/theme/ColorMap.java | 30 +++--- .../eclipse/tm4e/core/theme/IRawTheme.java | 8 +- .../tm4e/core/theme/IRawThemeSetting.java | 5 + .../org/eclipse/tm4e/core/theme/IStyle.java | 4 + .../tm4e/core/theme/IThemeProvider.java | 5 +- .../tm4e/core/theme/IThemeSetting.java | 9 +- .../tm4e/core/theme/ParsedThemeRule.java | 59 +++++------ .../org/eclipse/tm4e/core/theme/Theme.java | 97 +++++++++++-------- .../tm4e/core/theme/ThemeTrieElement.java | 71 +++++++------- .../tm4e/core/theme/ThemeTrieElementRule.java | 45 ++++++--- .../eclipse/tm4e/core/theme/package-info.java | 4 + 13 files changed, 205 insertions(+), 155 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/package-info.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/package-info.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index ad04b416d..021d29b04 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -11,51 +11,58 @@ */ package org.eclipse.tm4e.core.internal.theme; -import java.util.Collection; import java.util.HashMap; +import java.util.List; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IRawTheme; import org.eclipse.tm4e.core.theme.IRawThemeSetting; import org.eclipse.tm4e.core.theme.IThemeSetting; -public final class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting { +public final class ThemeRaw extends HashMap + implements IRawTheme, IRawThemeSetting, IThemeSetting { - private static final long serialVersionUID = -3622927264735492387L; + private static final long serialVersionUID = 1L; + @Nullable @Override public String getName() { return (String) super.get("name"); } + @Nullable @Override - public Collection getSettings() { - return (Collection) super.get("settings"); + public List getSettings() { + return (List) super.get("settings"); } + @Nullable @Override public Object getScope() { return super.get("scope"); } + @Nullable @Override public IThemeSetting getSetting() { return (IThemeSetting) super.get("settings"); } + @Nullable @Override public Object getFontStyle() { return super.get("fontStyle"); } + @Nullable @Override public String getBackground() { return (String) super.get("background"); } + @Nullable @Override public String getForeground() { return (String) super.get("foreground"); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/package-info.java new file mode 100644 index 000000000..869577ab7 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.internal.theme; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java index 03fc130d7..0d37ae764 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java @@ -11,33 +11,37 @@ */ package org.eclipse.tm4e.core.theme; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.Objects; import java.util.Set; +import org.eclipse.jdt.annotation.Nullable; + public class ColorMap { private int lastColorId = 0; - private final Map color2id = new HashMap<>(); + private final Map color2id = new HashMap<>(); - public int getId(String color) { + public int getId(@Nullable String color) { if (color == null) { return 0; } color = color.toUpperCase(); - Integer value = this.color2id.get(color); + Integer value = color2id.get(color); if (value != null) { return value; } - value = ++this.lastColorId; - this.color2id.put(color, value); + value = ++lastColorId; + color2id.put(castNonNull(color), value); return value; } + @Nullable public String getColor(final int id) { - for (final Entry entry : color2id.entrySet()) { + for (final var entry : color2id.entrySet()) { if (id == entry.getValue()) { return entry.getKey(); } @@ -46,16 +50,20 @@ public String getColor(final int id) { } public Set getColorMap() { - return this.color2id.keySet(); + return color2id.keySet(); } @Override public int hashCode() { - return Objects.hash(color2id, lastColorId); + final int prime = 31; + int result = 1; + result = prime * result + color2id.hashCode(); + result = prime * result + lastColorId; + return result; } @Override - public boolean equals(final Object obj) { + public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } @@ -68,6 +76,4 @@ public boolean equals(final Object obj) { final ColorMap other = (ColorMap) obj; return Objects.equals(color2id, other.color2id) && lastColorId == other.lastColorId; } - - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java index 72dfec225..48aa97c32 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java @@ -11,12 +11,16 @@ */ package org.eclipse.tm4e.core.theme; -import java.util.Collection; +import java.util.List; + +import org.eclipse.jdt.annotation.Nullable; public interface IRawTheme { + @Nullable String getName(); - Collection getSettings(); + @Nullable + List getSettings(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java index f833b7698..32565430d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.core.theme; +import org.eclipse.jdt.annotation.Nullable; + /** * A single theme setting. * @@ -19,10 +21,13 @@ */ public interface IRawThemeSetting { + @Nullable String getName(); + @Nullable Object getScope(); + @Nullable IThemeSetting getSetting(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java index e9c84b1ec..096caff31 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IStyle.java @@ -11,10 +11,14 @@ */ package org.eclipse.tm4e.core.theme; +import org.eclipse.jdt.annotation.Nullable; + public interface IStyle { + @Nullable RGB getColor(); + @Nullable RGB getBackgroundColor(); boolean isBold(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java index 08692964a..b26c341d3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java @@ -13,12 +13,9 @@ import java.util.List; -import org.eclipse.jdt.annotation.NonNull; - public interface IThemeProvider { - @NonNull - List themeMatch(@NonNull String scopeName); + List themeMatch(String scopeName); ThemeTrieElementRule getDefaults(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java index e16f96976..0a342fb42 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java @@ -11,11 +11,16 @@ */ package org.eclipse.tm4e.core.theme; +import org.eclipse.jdt.annotation.Nullable; + public interface IThemeSetting { + @Nullable Object getFontStyle(); - + + @Nullable String getBackground(); - + + @Nullable String getForeground(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java index 47dfc13a0..a1d8caf25 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java @@ -12,24 +12,37 @@ package org.eclipse.tm4e.core.theme; import java.util.List; +import java.util.Objects; +import org.eclipse.jdt.annotation.Nullable; + +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts + */ public class ParsedThemeRule { - // _parsedThemeRuleBrand: void; - public final String scope; + + @Nullable public final List parentScopes; + public final int index; /** * -1 if not set. An or mask of `FontStyle` otherwise. */ public final int fontStyle; + + @Nullable public final String foreground; + + @Nullable public final String background; - public ParsedThemeRule(final String scope, final List parentScopes, final int index, final int fontStyle, final String foreground, - final String background) { + public ParsedThemeRule(final String scope, @Nullable final List parentScopes, final int index, + final int fontStyle, @Nullable final String foreground, @Nullable final String background) { this.scope = scope; this.parentScopes = parentScopes; this.index = index; @@ -42,49 +55,23 @@ public ParsedThemeRule(final String scope, final List parentScopes, fina public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((background == null) ? 0 : background.hashCode()); result = prime * result + fontStyle; - result = prime * result + ((foreground == null) ? 0 : foreground.hashCode()); result = prime * result + index; - result = prime * result + ((parentScopes == null) ? 0 : parentScopes.hashCode()); - result = prime * result + ((scope == null) ? 0 : scope.hashCode()); + result = prime * result + Objects.hash(background, foreground, parentScopes, scope); return result; } @Override - public boolean equals(final Object obj) { + public boolean equals(@Nullable Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; - final ParsedThemeRule other = (ParsedThemeRule) obj; - if (background == null) { - if (other.background != null) - return false; - } else if (!background.equals(other.background)) - return false; - if (fontStyle != other.fontStyle) - return false; - if (foreground == null) { - if (other.foreground != null) - return false; - } else if (!foreground.equals(other.foreground)) - return false; - if (index != other.index) - return false; - if (parentScopes == null) { - if (other.parentScopes != null) - return false; - } else if (!parentScopes.equals(other.parentScopes)) - return false; - if (scope == null) { - if (other.scope != null) - return false; - } else if (!scope.equals(other.scope)) - return false; - return true; + ParsedThemeRule other = (ParsedThemeRule) obj; + return Objects.equals(background, other.background) && fontStyle == other.fontStyle + && Objects.equals(foreground, other.foreground) && index == other.index + && Objects.equals(parentScopes, other.parentScopes) && Objects.equals(scope, other.scope); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index 7865a0584..f37099295 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -12,9 +12,9 @@ package org.eclipse.tm4e.core.theme; import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; + import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -23,6 +23,7 @@ import java.util.Set; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.utils.CompareUtils; import com.google.common.base.Splitter; @@ -31,39 +32,45 @@ /** * TextMate theme. * + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts */ public class Theme { private static final Splitter BY_COMMA_SPLITTER = Splitter.on(','); private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' '); - private static final Pattern rrggbb = Pattern.compile("^#[0-9a-f]{6}", Pattern.CASE_INSENSITIVE); - private static final Pattern rrggbbaa = Pattern.compile("^#[0-9a-f]{8}", Pattern.CASE_INSENSITIVE); - private static final Pattern rgb = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE); - private static final Pattern rgba = Pattern.compile("^#[0-9a-f]{4}", Pattern.CASE_INSENSITIVE); + private static final Pattern RRGGBB = Pattern.compile("^#[0-9a-f]{6}", Pattern.CASE_INSENSITIVE); + private static final Pattern RRGGBBAA = Pattern.compile("^#[0-9a-f]{8}", Pattern.CASE_INSENSITIVE); + private static final Pattern RGB = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE); + private static final Pattern RGBA = Pattern.compile("^#[0-9a-f]{4}", Pattern.CASE_INSENSITIVE); private final ColorMap colorMap; private final ThemeTrieElement root; private final ThemeTrieElementRule defaults; private final Map> cache = new HashMap<>(); - public static Theme createFromRawTheme(final IRawTheme source) { + public static Theme createFromRawTheme(@Nullable final IRawTheme source) { return createFromParsedTheme(parseTheme(source)); } - public static List parseTheme(final IRawTheme source) { - if (source == null || source.getSettings() == null) { + public static List parseTheme(@Nullable final IRawTheme source) { + if (source == null) { return Collections.emptyList(); } - // if (!source.settings || !Array.isArray(source.settings)) { - // return []; - // } - final Collection settings = source.getSettings(); + + final List settings = source.getSettings(); + if (settings == null) { + return Collections.emptyList(); + } + final List result = new ArrayList<>(); - int i = 0; - for (final IRawThemeSetting entry : settings) { + for (int i = 0, len = settings.size(); i < len; i++) { + final var entry = settings.get(i); - if (entry.getSetting() == null) { + final var entrySetting = entry.getSetting(); + if (entrySetting == null) { continue; } @@ -75,7 +82,7 @@ public static List parseTheme(final IRawTheme source) { // remove leading commas scope = scope.replaceAll("^[,]+", ""); - // remove trailing commans + // remove trailing commas scope = scope.replaceAll("[,]+$", ""); scopes = BY_COMMA_SPLITTER.splitToList(scope); @@ -86,7 +93,7 @@ public static List parseTheme(final IRawTheme source) { } int fontStyle = FontStyle.NotSet; - final Object settingsFontStyle = entry.getSetting().getFontStyle(); + final Object settingsFontStyle = entrySetting.getFontStyle(); if (settingsFontStyle instanceof String) { fontStyle = FontStyle.None; @@ -110,16 +117,17 @@ public static List parseTheme(final IRawTheme source) { } String foreground = null; - final Object settingsForeground = entry.getSetting().getForeground(); + final Object settingsForeground = entrySetting.getForeground(); if (settingsForeground instanceof String && isValidHexColor((String) settingsForeground)) { foreground = (String) settingsForeground; } String background = null; - final Object settingsBackground = entry.getSetting().getBackground(); + final Object settingsBackground = entrySetting.getBackground(); if (settingsBackground instanceof String && isValidHexColor((String) settingsBackground)) { background = (String) settingsBackground; } + for (int j = 0, lenJ = scopes.size(); j < lenJ; j++) { final String _scope = scopes.get(j).trim(); @@ -132,36 +140,34 @@ public static List parseTheme(final IRawTheme source) { parentScopes = Lists.reverse(parentScopes); } - final ParsedThemeRule t = new ParsedThemeRule(scope, parentScopes, i, fontStyle, foreground, background); - result.add(t); + result.add(new ParsedThemeRule(scope, parentScopes, i, fontStyle, foreground, background)); } - i++; } return result; } private static boolean isValidHexColor(final String hex) { - if (hex == null || hex.isEmpty()) { + if (hex.isEmpty()) { return false; } - if (rrggbb.matcher(hex).matches()) { + if (RRGGBB.matcher(hex).matches()) { // #rrggbb return true; } - if (rrggbbaa.matcher(hex).matches()) { + if (RRGGBBAA.matcher(hex).matches()) { // #rrggbbaa return true; } - if (rgb.matcher(hex).matches()) { + if (RGB.matcher(hex).matches()) { // #rgb return true; } - if (rgba.matcher(hex).matches()) { + if (RGBA.matcher(hex).matches()) { // #rgba return true; } @@ -194,8 +200,8 @@ public static Theme resolveParsedThemeRules(final List parsedTh int defaultFontStyle = FontStyle.None; String defaultForeground = "#000000"; String defaultBackground = "#ffffff"; - while (!parsedThemeRules.isEmpty() && "".equals(parsedThemeRules.get(0).scope)) { - final ParsedThemeRule incomingDefaults = parsedThemeRules.remove(0); // shift(); + while (!parsedThemeRules.isEmpty() && parsedThemeRules.get(0).scope.isEmpty()) { + final var incomingDefaults = parsedThemeRules.remove(0); if (incomingDefaults.fontStyle != FontStyle.NotSet) { defaultFontStyle = incomingDefaults.fontStyle; } @@ -206,13 +212,13 @@ public static Theme resolveParsedThemeRules(final List parsedTh defaultBackground = incomingDefaults.background; } } - final ColorMap colorMap = new ColorMap(); - final ThemeTrieElementRule defaults = new ThemeTrieElementRule(0, null, defaultFontStyle, - colorMap.getId(defaultForeground), colorMap.getId(defaultBackground)); + final var colorMap = new ColorMap(); + final var defaults = new ThemeTrieElementRule(0, null, defaultFontStyle, colorMap.getId(defaultForeground), + colorMap.getId(defaultBackground)); - final ThemeTrieElement root = new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0), + final var root = new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0), Collections.emptyList()); - for (final ParsedThemeRule rule : parsedThemeRules) { + for (final var rule : parsedThemeRules) { root.insert(0, rule.scope, rule.parentScopes, rule.fontStyle, colorMap.getId(rule.foreground), colorMap.getId(rule.background)); } @@ -230,6 +236,7 @@ public Set getColorMap() { return this.colorMap.getColorMap(); } + @Nullable public String getColor(final int id) { return this.colorMap.getColor(id); } @@ -247,23 +254,27 @@ public List match(final String scopeName) { @Override public int hashCode() { - return Objects.hash(cache, colorMap, defaults, root); + final int prime = 31; + int result = 1; + result = prime * result + cache.hashCode(); + result = prime * result + colorMap.hashCode(); + result = prime * result + defaults.hashCode(); + result = prime * result + root.hashCode(); + return result; } @Override - public boolean equals(final Object obj) { + public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final Theme other = (Theme) obj; - return Objects.equals(cache, other.cache) && Objects.equals(colorMap, other.colorMap) && - Objects.equals(defaults, other.defaults) && Objects.equals(root, other.root); + return Objects.equals(cache, other.cache) + && Objects.equals(colorMap, other.colorMap) + && Objects.equals(defaults, other.defaults) + && Objects.equals(root, other.root); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java index d9a595167..df582c4d9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; @@ -15,14 +15,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.utils.CompareUtils; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts + */ public class ThemeTrieElement { - // _themeTrieElementBrand: void; - private final ThemeTrieElementRule mainRule; private final List rulesWithParentScopes; private final Map children; @@ -31,7 +34,8 @@ public ThemeTrieElement(final ThemeTrieElementRule mainRule) { this(mainRule, new ArrayList<>(), new HashMap<>()); } - public ThemeTrieElement(final ThemeTrieElementRule mainRule, final List rulesWithParentScopes) { + public ThemeTrieElement(final ThemeTrieElementRule mainRule, + final List rulesWithParentScopes) { this(mainRule, rulesWithParentScopes, new HashMap<>()); } @@ -52,18 +56,16 @@ private static List sortBySpecificity(final List aParentScopes = a.parentScopes; - final List bParentScopes = b.parentScopes; + final var aParentScopes = a.parentScopes; + final var bParentScopes = b.parentScopes; final int aParentScopesLen = aParentScopes == null ? 0 : aParentScopes.size(); final int bParentScopesLen = bParentScopes == null ? 0 : bParentScopes.size(); if (aParentScopesLen == bParentScopesLen) { for (int i = 0; i < aParentScopesLen; i++) { @SuppressWarnings("null") - final - String aScope = aParentScopes.get(i); + final String aScope = aParentScopes.get(i); @SuppressWarnings("null") - final - String bScope = bParentScopes.get(i); + final String bScope = bParentScopes.get(i); final int aLen = aScope.length(); final int bLen = bScope.length(); if (aLen != bLen) { @@ -78,7 +80,7 @@ private static int cmpBySpecificity(final ThemeTrieElementRule a, final ThemeTri public List match(final String scope) { if ("".equals(scope)) { - final List arr = new ArrayList<>(); + final var arr = new ArrayList(); arr.add(this.mainRule); arr.addAll(this.rulesWithParentScopes); return ThemeTrieElement.sortBySpecificity(arr); @@ -99,15 +101,15 @@ public List match(final String scope) { return this.children.get(head).match(tail); } - final List arr = new ArrayList<>(); + final var arr = new ArrayList(); arr.add(this.mainRule); arr.addAll(this.rulesWithParentScopes); return ThemeTrieElement.sortBySpecificity(arr); } - public void insert(final int scopeDepth, final String scope, final List parentScopes, final int fontStyle, final int foreground, - final int background) { - if ("".equals(scope)) { + public void insert(final int scopeDepth, final String scope, @Nullable final List parentScopes, + final int fontStyle, final int foreground, final int background) { + if (scope.isEmpty()) { this.doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background); return; } @@ -135,8 +137,8 @@ public void insert(final int scopeDepth, final String scope, final List child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background); } - private void doInsertHere(final int scopeDepth, final List parentScopes, int fontStyle, int foreground, - int background) { + private void doInsertHere(final int scopeDepth, @Nullable final List parentScopes, int fontStyle, + int foreground, int background) { if (parentScopes == null) { // Merge into the main rule @@ -166,28 +168,29 @@ private void doInsertHere(final int scopeDepth, final List parentScopes, background = this.mainRule.background; } - this.rulesWithParentScopes - .add(new ThemeTrieElementRule(scopeDepth, parentScopes, fontStyle, foreground, background)); + this.rulesWithParentScopes.add( + new ThemeTrieElementRule(scopeDepth, parentScopes, fontStyle, foreground, background)); } @Override public int hashCode() { - return Objects.hash(children, mainRule, rulesWithParentScopes); + final int prime = 31; + int result = 1; + result = prime * result + children.hashCode(); + result = prime * result + mainRule.hashCode(); + result = prime * result + rulesWithParentScopes.hashCode(); + return result; } @Override - public boolean equals(final Object obj) { - if (this == obj) { + public boolean equals(@Nullable Object obj) { + if (this == obj) return true; - } - if (obj == null) { + if (obj == null || getClass() != obj.getClass()) return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final ThemeTrieElement other = (ThemeTrieElement) obj; - return Objects.equals(children, other.children) && Objects.equals(mainRule, other.mainRule) && Objects.equals(rulesWithParentScopes, other.rulesWithParentScopes); + ThemeTrieElement other = (ThemeTrieElement) obj; + return children.equals(other.children) + && mainRule.equals(other.mainRule) + && rulesWithParentScopes.equals(other.rulesWithParentScopes); } - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java index 1aa008968..f8184fe45 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.theme; @@ -15,17 +15,26 @@ import java.util.List; import java.util.Objects; -public class ThemeTrieElementRule { +import org.eclipse.jdt.annotation.Nullable; - // _themeTrieElementRuleBrand: void; +/** + * @see + * github.com/Microsoft/vscode-textmate/blob/master/src/theme.ts + */ +public class ThemeTrieElementRule { public int scopeDepth; + + @Nullable public final List parentScopes; + public int fontStyle; public int foreground; public int background; - public ThemeTrieElementRule(final int scopeDepth, final List parentScopes, final int fontStyle, final int foreground, + public ThemeTrieElementRule(final int scopeDepth, @Nullable final List parentScopes, final int fontStyle, + final int foreground, final int background) { this.scopeDepth = scopeDepth; this.parentScopes = parentScopes; @@ -41,9 +50,9 @@ public ThemeTrieElementRule clone() { } public static List cloneArr(final List arr) { - final List r = new ArrayList<>(); - for (int i = 0, len = arr.size(); i < len; i++) { - r.add(arr.get(i).clone()); + final var r = new ArrayList(arr.size()); + for (var e : arr) { + r.add(e.clone()); } return r; } @@ -55,8 +64,7 @@ public void acceptOverwrite(final int scopeDepth, final int fontStyle, final int } else { this.scopeDepth = scopeDepth; } - // console.log('TODO -> my depth: ' + this.scopeDepth + ', overwriting - // depth: ' + scopeDepth); + // console.log('TODO -> my depth: ' + this.scopeDepth + ', overwriting depth: ' + scopeDepth); if (fontStyle != FontStyle.NotSet) { this.fontStyle = fontStyle; } @@ -70,11 +78,18 @@ public void acceptOverwrite(final int scopeDepth, final int fontStyle, final int @Override public int hashCode() { - return Objects.hash(background, fontStyle, foreground, parentScopes, scopeDepth); + final int prime = 31; + int result = 1; + result = prime * result + background; + result = prime * result + fontStyle; + result = prime * result + foreground; + result = prime * result + Objects.hashCode(parentScopes); + result = prime * result + scopeDepth; + return result; } @Override - public boolean equals(final Object obj) { + public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } @@ -86,8 +101,6 @@ public boolean equals(final Object obj) { } final ThemeTrieElementRule other = (ThemeTrieElementRule) obj; return background == other.background && fontStyle == other.fontStyle && foreground == other.foreground && - Objects.equals(parentScopes, other.parentScopes) && scopeDepth == other.scopeDepth; + Objects.equals(parentScopes, other.parentScopes) && scopeDepth == other.scopeDepth; } - - } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/package-info.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/package-info.java new file mode 100644 index 000000000..4401cf1c8 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.core.theme; + +import org.eclipse.jdt.annotation.NonNullByDefault; From a4b5db707d2e07fd9bdb7108e51518e9f60a1c29 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 20:19:52 +0200 Subject: [PATCH 156/202] Reorder methods in Theme class to match structure of upstream project --- .../org/eclipse/tm4e/core/theme/Theme.java | 107 +++++++++--------- 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index f37099295..a9ed304fb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -46,15 +46,43 @@ public class Theme { private static final Pattern RGB = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE); private static final Pattern RGBA = Pattern.compile("^#[0-9a-f]{4}", Pattern.CASE_INSENSITIVE); + public static Theme createFromRawTheme(@Nullable final IRawTheme source) { + return createFromParsedTheme(parseTheme(source)); + } + + public static Theme createFromParsedTheme(final List source) { + return resolveParsedThemeRules(source); + } + private final ColorMap colorMap; private final ThemeTrieElement root; private final ThemeTrieElementRule defaults; private final Map> cache = new HashMap<>(); - public static Theme createFromRawTheme(@Nullable final IRawTheme source) { - return createFromParsedTheme(parseTheme(source)); + public Theme(final ColorMap colorMap, final ThemeTrieElementRule defaults, final ThemeTrieElement root) { + this.colorMap = colorMap; + this.root = root; + this.defaults = defaults; } + public Set getColorMap() { + return this.colorMap.getColorMap(); + } + + public ThemeTrieElementRule getDefaults() { + return this.defaults; + } + + public List match(final String scopeName) { + if (!this.cache.containsKey(scopeName)) { + this.cache.put(scopeName, this.root.match(scopeName)); + } + return this.cache.get(scopeName); + } + + /** + * Parse a raw theme into rules. + */ public static List parseTheme(@Nullable final IRawTheme source) { if (source == null) { return Collections.emptyList(); @@ -147,38 +175,6 @@ public static List parseTheme(@Nullable final IRawTheme source) return result; } - private static boolean isValidHexColor(final String hex) { - if (hex.isEmpty()) { - return false; - } - - if (RRGGBB.matcher(hex).matches()) { - // #rrggbb - return true; - } - - if (RRGGBBAA.matcher(hex).matches()) { - // #rrggbbaa - return true; - } - - if (RGB.matcher(hex).matches()) { - // #rgb - return true; - } - - if (RGBA.matcher(hex).matches()) { - // #rgba - return true; - } - - return false; - } - - public static Theme createFromParsedTheme(final List source) { - return resolveParsedThemeRules(source); - } - /** * Resolve rules (i.e. inheritance). */ @@ -226,14 +222,32 @@ public static Theme resolveParsedThemeRules(final List parsedTh return new Theme(colorMap, defaults, root); } - public Theme(final ColorMap colorMap, final ThemeTrieElementRule defaults, final ThemeTrieElement root) { - this.colorMap = colorMap; - this.root = root; - this.defaults = defaults; - } + private static boolean isValidHexColor(final String hex) { + if (hex.isEmpty()) { + return false; + } - public Set getColorMap() { - return this.colorMap.getColorMap(); + if (RRGGBB.matcher(hex).matches()) { + // #rrggbb + return true; + } + + if (RRGGBBAA.matcher(hex).matches()) { + // #rrggbbaa + return true; + } + + if (RGB.matcher(hex).matches()) { + // #rgb + return true; + } + + if (RGBA.matcher(hex).matches()) { + // #rgba + return true; + } + + return false; } @Nullable @@ -241,17 +255,6 @@ public String getColor(final int id) { return this.colorMap.getColor(id); } - public ThemeTrieElementRule getDefaults() { - return this.defaults; - } - - public List match(final String scopeName) { - if (!this.cache.containsKey(scopeName)) { - this.cache.put(scopeName, this.root.match(scopeName)); - } - return this.cache.get(scopeName); - } - @Override public int hashCode() { final int prime = 31; From ede866ae8cccbeddeb67c5f58266d4a0844da137 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 22:37:40 +0200 Subject: [PATCH 157/202] implement IRegistryOptions#getColorMap --- .../tm4e/core/theme/ThemeMatchingTest.java | 2 +- .../tm4e/core/theme/ThemeResolvingTest.java | 453 +++++++++--------- .../tm4e/core/registry/IRegistryOptions.java | 6 + .../eclipse/tm4e/core/registry/Registry.java | 20 +- .../org/eclipse/tm4e/core/theme/ColorMap.java | 33 +- .../tm4e/core/theme/ParsedThemeRule.java | 6 + .../org/eclipse/tm4e/core/theme/Theme.java | 17 +- 7 files changed, 286 insertions(+), 251 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java index ac327eb57..9d7d16ce7 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java @@ -270,6 +270,6 @@ private void assertNoMatch(Theme theme, String scopeName) { } private Theme loadTheme(String theme) throws Exception { - return Theme.createFromRawTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes()))); + return Theme.createFromRawTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes())), null); } } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java index bc13d38fc..bd69d87fc 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java @@ -11,35 +11,48 @@ */ package org.eclipse.tm4e.core.theme; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; import org.eclipse.tm4e.core.internal.utils.CompareUtils; import org.junit.jupiter.api.Test; /** - * * @see * github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts - * */ public class ThemeResolvingTest { + private static final int NOT_SET = 0; + private static final ThemeTrieElementRule NOTSET_THEME_TRIE_ELEMENT_RULE = new ThemeTrieElementRule(0, null, + FontStyle.NotSet, NOT_SET, NOT_SET); + private static final ThemeTrieElement NOTSET_THEME_TRIE_ELEMENT = new ThemeTrieElement( + NOTSET_THEME_TRIE_ELEMENT_RULE); + + private static void assertStrArrCmp(String testCase, List a, List b, int expected) { + assertEquals(expected, CompareUtils.strArrCmp(a, b), testCase); + } + + private static Theme createTheme(ParsedThemeRule... rules) { + return Theme.createFromParsedTheme(List.of(rules), null); + } + + private static List parseTheme(String theme) throws Exception { + return Theme.parseTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes()))); + } + @Test public void testStrcmpWorks() { - List actual = Arrays.asList("bar", "z", "zu", "a", "ab", ""); + var actual = Arrays.asList("bar", "z", "zu", "a", "ab", ""); actual.sort(CompareUtils::strcmp); - List expected = Arrays.asList("", "a", "ab", "bar", "z", "zu"); + var expected = List.of("", "a", "ab", "bar", "z", "zu"); assertArrayEquals(expected.toArray(), actual.toArray()); } @@ -47,194 +60,179 @@ public void testStrcmpWorks() { public void testStrArrCmpWorks() { assertStrArrCmp("001", null, null, 0); assertStrArrCmp("002", null, Collections.emptyList(), -1); - assertStrArrCmp("003", null, Arrays.asList("a"), -1); + assertStrArrCmp("003", null, List.of("a"), -1); assertStrArrCmp("004", Collections.emptyList(), null, 1); - assertStrArrCmp("005", Arrays.asList("a"), null, 1); + assertStrArrCmp("005", List.of("a"), null, 1); assertStrArrCmp("006", Collections.emptyList(), Collections.emptyList(), 0); - assertStrArrCmp("007", Collections.emptyList(), Arrays.asList("a"), -1); - assertStrArrCmp("008", Arrays.asList("a"), Collections.emptyList(), 1); - assertStrArrCmp("009", Arrays.asList("a"), Arrays.asList("a"), 0); - assertStrArrCmp("010", Arrays.asList("a", "b"), Arrays.asList("a"), 1); - assertStrArrCmp("011", Arrays.asList("a"), Arrays.asList("a", "b"), -1); - assertStrArrCmp("012", Arrays.asList("a", "b"), Arrays.asList("a", "b"), 0); - assertStrArrCmp("013", Arrays.asList("a", "b"), Arrays.asList("a", "c"), -1); - assertStrArrCmp("014", Arrays.asList("a", "c"), Arrays.asList("a", "b"), 1); + assertStrArrCmp("007", Collections.emptyList(), List.of("a"), -1); + assertStrArrCmp("008", List.of("a"), Collections.emptyList(), 1); + assertStrArrCmp("009", List.of("a"), List.of("a"), 0); + assertStrArrCmp("010", List.of("a", "b"), List.of("a"), 1); + assertStrArrCmp("011", List.of("a"), List.of("a", "b"), -1); + assertStrArrCmp("012", List.of("a", "b"), List.of("a", "b"), 0); + assertStrArrCmp("013", List.of("a", "b"), List.of("a", "c"), -1); + assertStrArrCmp("014", List.of("a", "c"), List.of("a", "b"), 1); } @Test public void testAlwaysHasDefaults() { - Theme actual = Theme.createFromParsedTheme(Collections.emptyList()); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme(); + var colorMap = new ColorMap(); int _A = colorMap.getId("#000000"); int _B = colorMap.getId("#ffffff"); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))); + var expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), NOTSET_THEME_TRIE_ELEMENT); assertEquals(actual, expected); } @Test public void testRespectsIncomingDefaults1() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#000000"); int _B = colorMap.getId("#ffffff"); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))); + var expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), NOTSET_THEME_TRIE_ELEMENT); assertEquals(actual, expected); } @Test public void testRespectsIncomingDefaults2() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.None, null, null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + Theme actual = createTheme(new ParsedThemeRule("", null, -1, FontStyle.None, null, null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#000000"); int _B = colorMap.getId("#ffffff"); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))); + Theme expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), NOTSET_THEME_TRIE_ELEMENT); assertEquals(actual, expected); } @Test public void testRespectsIncomingDefaults3() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme(new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#000000"); int _B = colorMap.getId("#ffffff"); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))); + var expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B), NOTSET_THEME_TRIE_ELEMENT); assertEquals(actual, expected); } @Test public void testRespectsIncomingDefaults4() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#ff0000", null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#ff0000", null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#ff0000"); int _B = colorMap.getId("#ffffff"); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))); + var expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), + NOTSET_THEME_TRIE_ELEMENT); assertEquals(actual, expected); } @Test public void testRespectsIncomingDefaults5() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"), - new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null), - new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme( + new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"), + new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null), + new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#00ff00"); int _B = colorMap.getId("#ff0000"); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))); + var expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B), + NOTSET_THEME_TRIE_ELEMENT); assertEquals(actual, expected); } @Test public void testCanMergeIncomingDefaults() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"), - new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null), - new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme( + new ParsedThemeRule("", null, -1, FontStyle.NotSet, null, "#ff0000"), + new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#00ff00", null), + new ParsedThemeRule("", null, -1, FontStyle.Bold, null, null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#00ff00"); int _B = colorMap.getId("#ff0000"); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))); + var expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B), + NOTSET_THEME_TRIE_ELEMENT); assertEquals(actual, expected); } @Test public void testDefaultsAreInherited() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), - new ParsedThemeRule("var", null, -1, FontStyle.NotSet, "#ff0000", null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + Theme actual = createTheme( + new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), + new ParsedThemeRule("var", null, -1, FontStyle.NotSet, "#ff0000", null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#F8F8F2"); int _B = colorMap.getId("#272822"); int _C = colorMap.getId("#ff0000"); - Map map = new HashMap<>(); - map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET))); + var map = new HashMap(); + map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, NOT_SET))); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET), - Collections.emptyList(), map)); + Theme expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), + new ThemeTrieElement(NOTSET_THEME_TRIE_ELEMENT_RULE, Collections.emptyList(), map)); assertEquals(actual, expected); } @Test public void testSameRulesGetMerged() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), - new ParsedThemeRule("var", null, 1, FontStyle.Bold, null, null), - new ParsedThemeRule("var", null, 0, FontStyle.NotSet, "#ff0000", null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme( + new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), + new ParsedThemeRule("var", null, 1, FontStyle.Bold, null, null), + new ParsedThemeRule("var", null, 0, FontStyle.NotSet, "#ff0000", null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#F8F8F2"); int _B = colorMap.getId("#272822"); int _C = colorMap.getId("#ff0000"); - Map map = new HashMap<>(); - map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET))); + var map = new HashMap(); + map.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, NOT_SET))); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET), - Collections.emptyList(), map)); + var expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), + new ThemeTrieElement(NOTSET_THEME_TRIE_ELEMENT_RULE, Collections.emptyList(), map)); assertEquals(actual, expected); } @Test public void testRulesAreInherited1() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), - new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null), - new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme( + new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), + new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null), + new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#F8F8F2"); int _B = colorMap.getId("#272822"); int _C = colorMap.getId("#ff0000"); int _D = colorMap.getId("#00ff00"); - Map map1_1 = new HashMap<>(); - map1_1.put("identifier", new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _D, _NOT_SET))); - Map map1 = new HashMap<>(); - map1.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET), + var map1_1 = new HashMap(); + map1_1.put("identifier", new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _D, NOT_SET))); + var map1 = new HashMap(); + map1.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, NOT_SET), Collections.emptyList(), map1_1)); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET), - Collections.emptyList(), map1)); + var expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), + new ThemeTrieElement(NOTSET_THEME_TRIE_ELEMENT_RULE, Collections.emptyList(), map1)); assertEquals(actual, expected); } @Test public void testRulesAreInherited2() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), - new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null), - new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null), - new ParsedThemeRule("constant", null, 4, FontStyle.Italic, "#100000", null), - new ParsedThemeRule("constant.numeric", null, 5, FontStyle.NotSet, "#200000", null), - new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null), - new ParsedThemeRule("constant.numeric.oct", null, 7, - FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null), - new ParsedThemeRule("constant.numeric.dec", null, 8, FontStyle.None, "#300000", null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme( + new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), + new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#ff0000", null), + new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#00ff00", null), + new ParsedThemeRule("constant", null, 4, FontStyle.Italic, "#100000", null), + new ParsedThemeRule("constant.numeric", null, 5, FontStyle.NotSet, "#200000", null), + new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null), + new ParsedThemeRule("constant.numeric.oct", null, 7, + FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null), + new ParsedThemeRule("constant.numeric.dec", null, 8, FontStyle.None, "#300000", null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#F8F8F2"); int _B = colorMap.getId("#272822"); int _C = colorMap.getId("#100000"); @@ -243,164 +241,155 @@ public void testRulesAreInherited2() { int _F = colorMap.getId("#ff0000"); int _G = colorMap.getId("#00ff00"); - Map mapOfVar = new HashMap<>(); + var mapOfVar = new HashMap(); mapOfVar.put("identifier", - new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _G, _NOT_SET))); + new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _G, NOT_SET))); - Map mapOfNumeric = new HashMap<>(); - mapOfNumeric.put("hex", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold, _D, _NOT_SET))); + var mapOfNumeric = new HashMap(); + mapOfNumeric.put("hex", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold, _D, NOT_SET))); mapOfNumeric.put("oct", new ThemeTrieElement(new ThemeTrieElementRule(3, null, - FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _D, _NOT_SET))); - mapOfNumeric.put("dec", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.None, _E, _NOT_SET))); - - Map mapOfConstant = new HashMap<>(); - mapOfConstant.put("numeric", - new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Italic, _D, _NOT_SET), - Collections.emptyList(), mapOfNumeric)); - - Map mapRoot = new HashMap<>(); - mapRoot.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _F, _NOT_SET), - Collections.emptyList(), mapOfVar)); - mapRoot.put("constant", new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Italic, _C, _NOT_SET), - Collections.emptyList(), mapOfConstant)); - - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET), - Collections.emptyList(), mapRoot)); + FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _D, NOT_SET))); + mapOfNumeric.put("dec", new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.None, _E, NOT_SET))); + + var mapOfConstant = new HashMap(); + mapOfConstant.put("numeric", new ThemeTrieElement(new ThemeTrieElementRule(2, null, + FontStyle.Italic, _D, NOT_SET), Collections.emptyList(), mapOfNumeric)); + + var mapRoot = new HashMap(); + mapRoot.put("var", new ThemeTrieElement(new ThemeTrieElementRule(1, null, + FontStyle.Bold, _F, NOT_SET), Collections.emptyList(), mapOfVar)); + mapRoot.put("constant", new ThemeTrieElement(new ThemeTrieElementRule(1, null, + FontStyle.Italic, _C, NOT_SET), Collections.emptyList(), mapOfConstant)); + + var expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), + new ThemeTrieElement(NOTSET_THEME_TRIE_ELEMENT_RULE, Collections.emptyList(), mapRoot)); assertEquals(actual, expected); } @Test public void testRulesWithParentScopes() { - Theme actual = Theme.createFromParsedTheme( - new ArrayList<>(Arrays.asList(new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), - new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#100000", null), - new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#200000", null), - new ParsedThemeRule("var", Arrays.asList("source.css"), 1, FontStyle.Italic, "#300000", null), - new ParsedThemeRule("var", Arrays.asList("source.css"), 2, FontStyle.Underline, null, null)))); - ColorMap colorMap = new ColorMap(); - int _NOT_SET = 0; + var actual = createTheme( + new ParsedThemeRule("", null, -1, FontStyle.NotSet, "#F8F8F2", "#272822"), + new ParsedThemeRule("var", null, -1, FontStyle.Bold, "#100000", null), + new ParsedThemeRule("var.identifier", null, -1, FontStyle.NotSet, "#200000", null), + new ParsedThemeRule("var", List.of("source.css"), 1, FontStyle.Italic, "#300000", null), + new ParsedThemeRule("var", List.of("source.css"), 2, FontStyle.Underline, null, null)); + var colorMap = new ColorMap(); int _A = colorMap.getId("#F8F8F2"); int _B = colorMap.getId("#272822"); int _C = colorMap.getId("#100000"); int _D = colorMap.getId("#300000"); int _E = colorMap.getId("#200000"); - Map mapOfVar = new HashMap<>(); + var mapOfVar = new HashMap(); mapOfVar.put("identifier", - new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _E, _NOT_SET), Arrays.asList( - new ThemeTrieElementRule(1, Arrays.asList("source.css"), FontStyle.Underline, _D, _NOT_SET)))); + new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _E, NOT_SET), List.of( + new ThemeTrieElementRule(1, List.of("source.css"), FontStyle.Underline, _D, NOT_SET)))); - Map mapRoot = new HashMap<>(); + var mapRoot = new HashMap(); mapRoot.put("var", - new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET), Arrays.asList( - new ThemeTrieElementRule(1, Arrays.asList("source.css"), FontStyle.Underline, _D, _NOT_SET)), + new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, NOT_SET), List.of( + new ThemeTrieElementRule(1, List.of("source.css"), FontStyle.Underline, _D, NOT_SET)), mapOfVar)); - Theme expected = new Theme(colorMap, new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET), - Collections.emptyList(), mapRoot)); + var expected = new Theme(colorMap, + new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B), + new ThemeTrieElement(NOTSET_THEME_TRIE_ELEMENT_RULE, Collections.emptyList(), mapRoot)); assertEquals(actual, expected); } @Test public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception { - List actual = parseTheme("{" + - "\"settings\": [{"+ - " \"settings\": {"+ - " \"background\": \"#222222\","+ - " \"foreground\": \"#cccccc\""+ - " }"+ - "}, {"+ - " \"name\": \"Variable\","+ - " \"scope\": \"variable\","+ - " \"settings\": {"+ - " \"fontStyle\": \"\""+ - " }"+ - "}, {"+ - " \"name\": \"Function argument\","+ - " \"scope\": \"variable.parameter\","+ - " \"settings\": {"+ - " \"fontStyle\": \"italic\","+ - " \"foreground\": \"\""+ - " }"+ - "}, {"+ - " \"name\": \"Library variable\","+ - " \"scope\": \"support.other.variable\","+ - " \"settings\": {"+ - " \"fontStyle\": \"\""+ - " }"+ - "}, {"+ - " \"name\": \"Function argument\","+ - " \"scope\": \"variable.other\","+ - " \"settings\": {"+ - " \"foreground\": \"\","+ - " \"fontStyle\": \"normal\""+ - " }"+ - "}, {"+ - " \"name\": \"Coffeescript Function argument\","+ - " \"scope\": \"variable.parameter.function.coffee\","+ - " \"settings\": {"+ - " \"foreground\": \"#F9D423\","+ - " \"fontStyle\": \"italic\""+ - " }"+ - "}]"+ - "}"); - - List expected = Arrays.asList( - new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#cccccc", "#222222"), - new ParsedThemeRule("variable", null, 1, FontStyle.None, null, null), - new ParsedThemeRule("variable.parameter", null, 2, FontStyle.Italic, null, null), - new ParsedThemeRule("support.other.variable", null, 3, FontStyle.None, null, null), - new ParsedThemeRule("variable.other", null, 4, FontStyle.None, null, null), - new ParsedThemeRule("variable.parameter.function.coffee", null, 5, FontStyle.Italic, "#F9D423", null) - ); + var actual = parseTheme(("{" + + "'settings': [{" + + " 'settings': {" + + " 'background': '#222222'," + + " 'foreground': '#cccccc'" + + " }" + + "}, {" + + " 'name': 'Variable'," + + " 'scope': 'variable'," + + " 'settings': {" + + " 'fontStyle': ''" + + " }" + + "}, {" + + " 'name': 'Function argument'," + + " 'scope': 'variable.parameter'," + + " 'settings': {" + + " 'fontStyle': 'italic'," + + " 'foreground': ''" + + " }" + + "}, {" + + " 'name': 'Library variable'," + + " 'scope': 'support.other.variable'," + + " 'settings': {" + + " 'fontStyle': ''" + + " }" + + "}, {" + + " 'name': 'Function argument'," + + " 'scope': 'variable.other'," + + " 'settings': {" + + " 'foreground': ''," + + " 'fontStyle': 'normal'" + + " }" + + "}, {" + + " 'name': 'Coffeescript Function argument'," + + " 'scope': 'variable.parameter.function.coffee'," + + " 'settings': {" + + " 'foreground': '#F9D423'," + + " 'fontStyle': 'italic'" + + " }" + + "}]" + + "}").replace('\'', '"')); + + var expected = List.of( + new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#cccccc", "#222222"), + new ParsedThemeRule("variable", null, 1, FontStyle.None, null, null), + new ParsedThemeRule("variable.parameter", null, 2, FontStyle.Italic, null, null), + new ParsedThemeRule("support.other.variable", null, 3, FontStyle.None, null, null), + new ParsedThemeRule("variable.other", null, 4, FontStyle.None, null, null), + new ParsedThemeRule("variable.parameter.function.coffee", null, 5, FontStyle.Italic, "#F9D423", null)); assertArrayEquals(expected.toArray(), actual.toArray()); } @Test public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exception { - List actual = parseTheme("{" + - "\"settings\": [{"+ - " \"settings\": {"+ - " \"background\": \"#25292C\","+ - " \"foreground\": \"#EFEFEF\""+ - " }"+ - "}, {"+ - " \"name\": \"CSS at-rule keyword control\","+ - " \"scope\": \""+ - " meta.at-rule.return.scss,\n"+ - " meta.at-rule.return.scss punctuation.definition,\n"+ - " meta.at-rule.else.scss,\n"+ - " meta.at-rule.else.scss punctuation.definition,\n"+ - " meta.at-rule.if.scss,\n"+ - " meta.at-rule.if.scss punctuation.definition\n"+ - " \","+ - " \"settings\": {"+ - " \"foreground\": \"#CC7832\""+ - " }"+ - "}]"+ - "}"); - - List expected = Arrays.asList( + var actual = parseTheme(("{" + + "'settings': [{" + + " 'settings': {" + + " 'background': '#25292C'," + + " 'foreground': '#EFEFEF'" + + " }" + + "}, {" + + " 'name': 'CSS at-rule keyword control'," + + " 'scope': '" + + " meta.at-rule.return.scss,\n" + + " meta.at-rule.return.scss punctuation.definition,\n" + + " meta.at-rule.else.scss,\n" + + " meta.at-rule.else.scss punctuation.definition,\n" + + " meta.at-rule.if.scss,\n" + + " meta.at-rule.if.scss punctuation.definition\n" + + " '," + + " 'settings': {" + + " 'foreground': '#CC7832'" + + " }" + + "}]" + + "}").replace('\'', '"')); + + var expected = List.of( new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#EFEFEF", "#25292C"), new ParsedThemeRule("meta.at-rule.return.scss", null, 1, FontStyle.NotSet, "#CC7832", null), - new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.return.scss"), 1, FontStyle.NotSet, "#CC7832", null), + new ParsedThemeRule("punctuation.definition", List.of("meta.at-rule.return.scss"), 1, + FontStyle.NotSet, "#CC7832", null), new ParsedThemeRule("meta.at-rule.else.scss", null, 1, FontStyle.NotSet, "#CC7832", null), - new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.else.scss"), 1, FontStyle.NotSet, "#CC7832", null), + new ParsedThemeRule("punctuation.definition", List.of("meta.at-rule.else.scss"), 1, + FontStyle.NotSet, "#CC7832", null), new ParsedThemeRule("meta.at-rule.if.scss", null, 1, FontStyle.NotSet, "#CC7832", null), - new ParsedThemeRule("punctuation.definition", Arrays.asList("meta.at-rule.if.scss"), 1, FontStyle.NotSet, "#CC7832", null) - ); + new ParsedThemeRule("punctuation.definition", List.of("meta.at-rule.if.scss"), 1, + FontStyle.NotSet, "#CC7832", null)); assertArrayEquals(expected.toArray(), actual.toArray()); } - - private void assertStrArrCmp(String testCase, List a, List b, int expected) { - assertEquals(expected, CompareUtils.strArrCmp(a, b), testCase); - } - - private List parseTheme(String theme) throws Exception { - return Theme.parseTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes()))); - } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java index 857ecf0e4..8d960e202 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Collection; +import java.util.List; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -58,6 +59,11 @@ default IRawTheme getTheme() { return null; } + @Nullable + default List getColorMap() { + return null; + } + @Nullable String getFilePath(String scopeName); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java index 1127730e0..20281ee03 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/Registry.java @@ -45,23 +45,23 @@ */ public class Registry { - private final IRegistryOptions locator; + private final IRegistryOptions options; private final SyncRegistry syncRegistry; public Registry() { this(IRegistryOptions.DEFAULT_LOCATOR); } - public Registry(final IRegistryOptions locator) { - this.locator = locator; - this.syncRegistry = new SyncRegistry(Theme.createFromRawTheme(locator.getTheme())); + public Registry(final IRegistryOptions options) { + this.options = options; + this.syncRegistry = new SyncRegistry(Theme.createFromRawTheme(options.getTheme(), options.getColorMap())); } /** * Change the theme. Once called, no previous `ruleStack` should be used anymore. */ public void setTheme(final IRawTheme theme) { - this.syncRegistry.setTheme(Theme.createFromRawTheme(theme)); + this.syncRegistry.setTheme(Theme.createFromRawTheme(theme, options.getColorMap())); } /** @@ -86,7 +86,7 @@ public IGrammar loadGrammar(final String initialScopeName) { continue; } - final String filePath = this.locator.getFilePath(scopeName); + final String filePath = this.options.getFilePath(scopeName); if (filePath == null) { if (scopeName.equals(initialScopeName)) { throw new TMException("Unknown location for grammar <" + initialScopeName + ">"); @@ -94,12 +94,12 @@ public IGrammar loadGrammar(final String initialScopeName) { continue; } - try (InputStream in = this.locator.getInputStream(scopeName)) { + try (InputStream in = this.options.getInputStream(scopeName)) { if (in == null) { throw new TMException("Unknown location for grammar <" + initialScopeName + ">"); } final var grammar = GrammarReader.readGrammarSync(filePath, in); - final var injections = this.locator.getInjections(scopeName); + final var injections = this.options.getInjections(scopeName); final var deps = this.syncRegistry.addGrammar(grammar, injections); for (final String dep : deps) { @@ -136,7 +136,7 @@ public IGrammar loadGrammarFromPathSync(final String path, final InputStream in) public IGrammar loadGrammarFromPathSync(final String path, final InputStream in, final int initialLanguage, @Nullable final Map embeddedLanguages) throws Exception { final var rawGrammar = GrammarReader.readGrammarSync(path, in); - final var injections = this.locator.getInjections(rawGrammar.getScopeName()); + final var injections = this.options.getInjections(rawGrammar.getScopeName()); this.syncRegistry.addGrammar(rawGrammar, injections); return this.grammarForScopeName(rawGrammar.getScopeName(), initialLanguage, embeddedLanguages); } @@ -158,6 +158,6 @@ public IGrammar grammarForScopeName(final String scopeName, final int initialLan } public IRegistryOptions getLocator() { - return locator; + return options; } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java index 0d37ae764..5a12cbd7b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java @@ -13,17 +13,38 @@ import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.TMException; public class ColorMap { + private boolean isFrozen; private int lastColorId = 0; - private final Map color2id = new HashMap<>(); + private final List id2color = new ArrayList<>(); + private final Map color2id = new LinkedHashMap<>(); + + public ColorMap() { + this(null); + } + + public ColorMap(@Nullable List colorMap) { + if (colorMap != null) { + this.isFrozen = true; + for (int i = 0, len = colorMap.size(); i < len; i++) { + this.color2id.put(colorMap.get(i), i); + this.id2color.add(colorMap.get(i)); + } + } else { + this.isFrozen = false; + } + } public int getId(@Nullable String color) { if (color == null) { @@ -34,8 +55,16 @@ public int getId(@Nullable String color) { if (value != null) { return value; } + if (this.isFrozen) { + throw new TMException("Missing color in color map - " + color); + } value = ++lastColorId; color2id.put(castNonNull(color), value); + if (value >= id2color.size()) { + id2color.add(castNonNull(color)); + } else { + id2color.set(value, castNonNull(color)); + } return value; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java index a1d8caf25..9b31cc96a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java @@ -74,4 +74,10 @@ public boolean equals(@Nullable Object obj) { && Objects.equals(foreground, other.foreground) && index == other.index && Objects.equals(parentScopes, other.parentScopes) && Objects.equals(scope, other.scope); } + + @Override + public String toString() { + return "ParsedThemeRule [scope=" + scope + ", parentScopes=" + parentScopes + ", index=" + index + + ", fontStyle=" + fontStyle + ", foreground=" + foreground + ", background=" + background + "]"; + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index a9ed304fb..b99b29c58 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -46,12 +46,12 @@ public class Theme { private static final Pattern RGB = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE); private static final Pattern RGBA = Pattern.compile("^#[0-9a-f]{4}", Pattern.CASE_INSENSITIVE); - public static Theme createFromRawTheme(@Nullable final IRawTheme source) { - return createFromParsedTheme(parseTheme(source)); + public static Theme createFromRawTheme(@Nullable final IRawTheme source, @Nullable List colorMap) { + return createFromParsedTheme(parseTheme(source), colorMap); } - public static Theme createFromParsedTheme(final List source) { - return resolveParsedThemeRules(source); + public static Theme createFromParsedTheme(final List source, @Nullable List colorMap) { + return resolveParsedThemeRules(source, colorMap); } private final ColorMap colorMap; @@ -178,7 +178,12 @@ public static List parseTheme(@Nullable final IRawTheme source) /** * Resolve rules (i.e. inheritance). */ - public static Theme resolveParsedThemeRules(final List parsedThemeRules) { + public static Theme resolveParsedThemeRules(final List _parsedThemeRules, + @Nullable List _colorMap) { + + // copy the list since we cannot be sure the given list is mutable + final var parsedThemeRules = new ArrayList<>(_parsedThemeRules); + // Sort rules lexicographically, and then by index if necessary parsedThemeRules.sort((a, b) -> { int r = CompareUtils.strcmp(a.scope, b.scope); @@ -208,7 +213,7 @@ public static Theme resolveParsedThemeRules(final List parsedTh defaultBackground = incomingDefaults.background; } } - final var colorMap = new ColorMap(); + final var colorMap = new ColorMap(_colorMap); final var defaults = new ThemeTrieElementRule(0, null, defaultFontStyle, colorMap.getId(defaultForeground), colorMap.getId(defaultBackground)); From 10cad94ee99734baf305722ce6c20b2364e4e4dd Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 22:40:22 +0200 Subject: [PATCH 158/202] add port of ThemeParsingCanParse test case --- .../tm4e/core/theme/ThemeResolvingTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java index bd69d87fc..f32a17bbd 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java @@ -47,6 +47,44 @@ private static List parseTheme(String theme) throws Exception { return Theme.parseTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes()))); } + @Test + public void testThemeParsingCanParse() throws Exception { + var actual = parseTheme(("{" + + "'settings': [" + + "{ 'settings': { 'foreground': '#F8F8F2', 'background': '#272822' } }," + + "{ 'scope': 'source, something', 'settings': { 'background': '#100000' } }," + + "{ 'scope': ['bar', 'baz'], 'settings': { 'background': '#010000' } }," + + "{ 'scope': 'source.css selector bar', 'settings': { 'fontStyle': 'bold' } }," + + "{ 'scope': 'constant', 'settings': { 'fontStyle': 'italic', 'foreground': '#ff0000' } }," + + "{ 'scope': 'constant.numeric', 'settings': { 'foreground': '#00ff00' } }," + + "{ 'scope': 'constant.numeric.hex', 'settings': { 'fontStyle': 'bold' } }," + + "{ 'scope': 'constant.numeric.oct', 'settings': { 'fontStyle': 'bold italic underline' } }," + + "{ 'scope': 'constant.numeric.bin', 'settings': { 'fontStyle': 'bold strikethrough' } }," + + "{ 'scope': 'constant.numeric.dec', 'settings': { 'fontStyle': '', 'foreground': '#0000ff' } }," + + "{ 'scope': 'foo', 'settings': { 'fontStyle': '', 'foreground': '#CFA' } }" + + "]" + + "}").replace('\'', '"')); + + var expected = List.of( + new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#F8F8F2", "#272822"), + new ParsedThemeRule("source", null, 1, FontStyle.NotSet, null, "#100000"), + new ParsedThemeRule("something", null, 1, FontStyle.NotSet, null, "#100000"), + new ParsedThemeRule("bar", null, 2, FontStyle.NotSet, null, "#010000"), + new ParsedThemeRule("baz", null, 2, FontStyle.NotSet, null, "#010000"), + new ParsedThemeRule("bar", List.of("selector", "source.css"), 3, FontStyle.Bold, null, null), + new ParsedThemeRule("constant", null, 4, FontStyle.Italic, "#ff0000", null), + new ParsedThemeRule("constant.numeric", null, 5, FontStyle.NotSet, "#00ff00", null), + new ParsedThemeRule("constant.numeric.hex", null, 6, FontStyle.Bold, null, null), + new ParsedThemeRule("constant.numeric.oct", null, 7, + FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null), + new ParsedThemeRule("constant.numeric.bin", null, 8, FontStyle.Bold | FontStyle.Strikethrough, null, + null), + new ParsedThemeRule("constant.numeric.dec", null, 9, FontStyle.None, "#0000ff", null), + new ParsedThemeRule("foo", null, 10, FontStyle.None, "#CFA", null)); + + assertArrayEquals(expected.toArray(), actual.toArray()); + } + @Test public void testStrcmpWorks() { var actual = Arrays.asList("bar", "z", "zu", "a", "ab", ""); From 65ea717db991a7781f3876ff124cb3d6d7e1c3ca Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 22:46:45 +0200 Subject: [PATCH 159/202] Suppress unchecked compiler warnings --- .../java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java | 1 + .../src/main/java/org/eclipse/tm4e/core/theme/Theme.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index 021d29b04..e0ba8a4f6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -30,6 +30,7 @@ public String getName() { return (String) super.get("name"); } + @SuppressWarnings("unchecked") @Nullable @Override public List getSettings() { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index b99b29c58..bef5f28bd 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -115,7 +115,9 @@ public static List parseTheme(@Nullable final IRawTheme source) scopes = BY_COMMA_SPLITTER.splitToList(scope); } else if (settingScope instanceof List) { - scopes = (List) settingScope; + @SuppressWarnings("unchecked") + final var settingScopes = (List) settingScope; + scopes = settingScopes; } else { scopes = Arrays.asList(""); } From ca976bbc352cd4c8b5e44d56c1a68f85f43cc4eb Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 2 May 2022 23:00:41 +0200 Subject: [PATCH 160/202] Revert return type change of IRawTheme#getSettings back to Collection --- .../org/eclipse/tm4e/core/internal/theme/ThemeRaw.java | 6 +++--- .../main/java/org/eclipse/tm4e/core/theme/IRawTheme.java | 4 ++-- .../src/main/java/org/eclipse/tm4e/core/theme/Theme.java | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index e0ba8a4f6..a0259203a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -11,8 +11,8 @@ */ package org.eclipse.tm4e.core.internal.theme; +import java.util.Collection; import java.util.HashMap; -import java.util.List; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IRawTheme; @@ -33,8 +33,8 @@ public String getName() { @SuppressWarnings("unchecked") @Nullable @Override - public List getSettings() { - return (List) super.get("settings"); + public Collection getSettings() { + return (Collection) super.get("settings"); } @Nullable diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java index 48aa97c32..f577ef769 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.core.theme; -import java.util.List; +import java.util.Collection; import org.eclipse.jdt.annotation.Nullable; @@ -21,6 +21,6 @@ public interface IRawTheme { String getName(); @Nullable - List getSettings(); + Collection getSettings(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index bef5f28bd..0487e110a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -88,20 +88,21 @@ public static List parseTheme(@Nullable final IRawTheme source) return Collections.emptyList(); } - final List settings = source.getSettings(); + final var settings = source.getSettings(); if (settings == null) { return Collections.emptyList(); } final List result = new ArrayList<>(); - for (int i = 0, len = settings.size(); i < len; i++) { - final var entry = settings.get(i); - + int i = -1; + for (final IRawThemeSetting entry : settings) { final var entrySetting = entry.getSetting(); if (entrySetting == null) { continue; } + i++; + final Object settingScope = entry.getScope(); List scopes; if (settingScope instanceof String) { From 1b9f5837b24646af7b9857d80f772d96cc716308 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Tue, 3 May 2022 15:10:16 +0200 Subject: [PATCH 161/202] PGP signature for external artifacts #359 --- Jenkinsfile | 19 +++++- org.eclipse.tm4e.repository/pom.xml | 89 ++++++----------------------- pom.xml | 46 +++++++++------ 3 files changed, 62 insertions(+), 92 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7992cda8b..91891ef14 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,12 +10,25 @@ pipeline { buildDiscarder(logRotator(numToKeepStr:'10')) } stages { + stage('initialize PGP') { + steps { + withCredentials([file(credentialsId: 'secret-subkeys.asc', variable: 'KEYRING')]) { + sh 'gpg --batch --import "${KEYRING}"' + sh 'for fpr in $(gpg --list-keys --with-colons | awk -F: \'/fpr:/ {print $10}\' | sort -u); do echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key ${fpr} trust; done' + } + } + } stage('Build') { steps { withMaven(maven:'apache-maven-latest', mavenLocalRepo: '$WORKSPACE/.m2') { - wrap([$class: 'Xvnc', useXauthority: true]) { - sh 'mvn clean verify -Dmaven.test.error.ignore=true -Dmaven.test.failure.ignore=true -PpackAndSign' - } + withCredentials([string(credentialsId: 'gpg-passphrase', variable: 'KEYRING_PASSPHRASE')]) { + wrap([$class: 'Xvnc', useXauthority: true]) { + sh 'mvn clean verify \ + -Dmaven.test.error.ignore=true -Dmaven.test.failure.ignore=true \ + -Psign -Dgpg.passphrase="${KEYRING_PASSPHRASE}"' + + } + } } } post { diff --git a/org.eclipse.tm4e.repository/pom.xml b/org.eclipse.tm4e.repository/pom.xml index a47d1ff4a..b5ea25fb6 100644 --- a/org.eclipse.tm4e.repository/pom.xml +++ b/org.eclipse.tm4e.repository/pom.xml @@ -1,53 +1,30 @@ - 4.0.0 - org.eclipse.tm4e.repository - eclipse-repository - - org.eclipse - org.eclipse.tm4e - 0.3.2-SNAPSHOT - - - - - - org.apache.maven.wagon - wagon-ftp - 3.5.1 - - - + 4.0.0 + org.eclipse.tm4e.repository + eclipse-repository + + org.eclipse + org.eclipse.tm4e + 0.3.2-SNAPSHOT + + - - uploadRepo - - - ftp://ftp.online.net - /oss/textmate/${project.version} - - ${project.build.directory}/repository/ - - - - - - org.codehaus.mojo - wagon-maven-plugin - 2.0.2 + sign + + + + org.eclipse.tycho + tycho-gpg-plugin + ${tycho-version} - upload-repo - install + pgpsigner - upload + sign-p2-artifacts - ${repo.path} - ** - ${ftp.toDir} - ${ftp.url} - p2Repo + 27617A05E2DB057F @@ -55,33 +32,5 @@ - - release - - - - de.jutzig - github-release-plugin - 1.4.0 - - - github-upload - verify - - release - - false - - - - true - ${project.artifactId}-${project.version} - ${project.artifactId}-${project.version} - ${project.build.directory}/${project.artifactId}-${project.version}.zip - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index f6c57e14c..638eaa627 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ UTF-8 - 2.7.2 + 3.0.0-SNAPSHOT ../target/jacoco.exec scm:git:https://github.com/eclipse/tm4e.git true @@ -131,20 +131,6 @@ - - org.eclipse.cbi.maven.plugins - eclipse-jarsigner-plugin - 1.3.2 - - - sign - package - - sign - - - - org.eclipse.tycho tycho-p2-plugin @@ -280,10 +266,25 @@ - packAndSign - - false - + sign + + + + org.eclipse.cbi.maven.plugins + eclipse-jarsigner-plugin + 1.3.2 + + + jarsigner + package + + sign + + + + + + @@ -303,5 +304,12 @@ true + + tycho-snapshots + https://repo.eclipse.org/content/repositories/tycho-snapshots/ + + true + + From 8351d7281274f8ae5726a261fbbea58106305ce0 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Tue, 3 May 2022 16:29:47 +0200 Subject: [PATCH 162/202] Skip PGP signatures if jarsigned --- org.eclipse.tm4e.repository/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/org.eclipse.tm4e.repository/pom.xml b/org.eclipse.tm4e.repository/pom.xml index b5ea25fb6..283537b4e 100644 --- a/org.eclipse.tm4e.repository/pom.xml +++ b/org.eclipse.tm4e.repository/pom.xml @@ -25,6 +25,7 @@ 27617A05E2DB057F + true From 527b3b2d72a2b51e8bbd2a0fccee292950914f06 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 4 May 2022 14:37:51 +0200 Subject: [PATCH 163/202] Fix logger class --- .../java/org/eclipse/tm4e/core/internal/grammar/Grammar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index b87f90e83..bf119698a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -56,7 +56,7 @@ */ public final class Grammar implements IGrammar, IRuleFactoryHelper { - private static final Logger LOGGER = System.getLogger(RuleFactory.class.getName()); + private static final Logger LOGGER = System.getLogger(Grammar.class.getName()); private final String scopeName; From ebb8d30c195967306e6569279860ffa2219af8ec Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 4 May 2022 18:12:35 +0200 Subject: [PATCH 164/202] Split Raw into distinct types --- .../tm4e/core/internal/grammar/Grammar.java | 27 +- .../tm4e/core/internal/grammar/Raw.java | 348 ------------------ .../core/internal/grammar/RawCaptures.java | 46 +++ .../core/internal/grammar/RawGrammar.java | 179 +++++++++ .../core/internal/grammar/RawRepository.java | 86 +++++ .../tm4e/core/internal/grammar/RawRule.java | 193 ++++++++++ .../grammar/ScopeDependencyProcessor.java | 8 +- .../grammar/reader/GrammarReader.java | 41 ++- .../tm4e/core/internal/parser/PListArray.java | 37 -- .../internal/parser/PListContentHandler.java | 233 ++++++++++++ .../tm4e/core/internal/parser/PListDict.java | 51 --- .../core/internal/parser/PListObject.java | 28 -- .../parser/PListParserContentHandler.java | 158 -------- .../core/internal/parser/PListParserJSON.java | 10 +- .../core/internal/parser/PListParserXML.java | 8 +- .../core/internal/parser/PListParserYAML.java | 19 +- .../tm4e/core/internal/parser/PListPath.java | 32 ++ ...{MapFactory.java => PropertySettable.java} | 11 +- .../core/internal/registry/SyncRegistry.java | 19 +- .../tm4e/core/internal/rule/RuleFactory.java | 24 +- .../tm4e/core/internal/theme/ThemeRaw.java | 8 +- .../theme/reader/SyncThemeReader.java | 4 +- .../internal/theme/reader/ThemeReader.java | 22 +- .../core/internal/types/IRawCaptures.java | 10 +- .../tm4e/core/internal/types/IRawGrammar.java | 19 +- .../core/internal/types/IRawRepository.java | 20 +- .../tm4e/core/internal/types/IRawRule.java | 10 - .../core/internal/utils/DeepCloneable.java | 105 ++++++ .../grammar/parser/PListParserTest.java | 11 +- 29 files changed, 1026 insertions(+), 741 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawCaptures.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRepository.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRule.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListPath.java rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/{MapFactory.java => PropertySettable.java} (71%) create mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index bf119698a..38aa3af2d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -120,7 +120,7 @@ ScopeMetadata getMetadataForScope(final String scope) { private void collectInjections(final List result, final String selector, final IRawRule rule, final IRuleFactoryHelper ruleFactoryHelper, final IRawGrammar grammar) { final var matchers = Matcher.createMatchers(selector); - final int ruleId = RuleFactory.getCompiledRuleId(rule, ruleFactoryHelper, this.grammar.getRepositorySafe()); + final int ruleId = RuleFactory.getCompiledRuleId(rule, ruleFactoryHelper, this.grammar.getRepository()); for (final var matcher : matchers) { result.add(new Injection(selector, matcher.matcher, ruleId, grammar, matcher.priority)); @@ -173,7 +173,7 @@ private List collectInjections() { if (injectionGrammar != null) { final var selector = injectionGrammar.getInjectionSelector(); if (selector != null) { - collectInjections(result, selector, (IRawRule) injectionGrammar, this, + collectInjections(result, selector, injectionGrammar.toRawRule(), this, injectionGrammar); } } @@ -237,13 +237,17 @@ public IRawGrammar getExternalGrammar(final String scopeName, @Nullable final IR } private IRawGrammar initGrammar(IRawGrammar grammar, @Nullable final IRawRule base) { - grammar = grammar.clone(); - var repo = grammar.getRepository(); - if (repo == null) { - repo = new Raw(); - ((IRawRule) grammar).setRepository(repo); + grammar = grammar.deepClone(); + + final IRawRepository repo; + if (grammar.isRepositorySet()) { + repo = grammar.getRepository(); + } else { + repo = new RawRepository(); + grammar.setRepository(repo); } - final var self = new Raw(); + + final var self = new RawRule(); self.setPatterns(grammar.getPatterns()); self.setName(grammar.getScopeName()); repo.setSelf(self); @@ -274,8 +278,8 @@ public ITokenizeLineResult2 tokenizeLine2(final String lineText, @Nullable final @SuppressWarnings("unchecked") private T tokenize(String lineText, @Nullable StackElement prevState, final boolean emitBinaryTokens) { if (this.rootId == -1) { - this.rootId = RuleFactory.getCompiledRuleId(this.grammar.getRepositorySafe().getSelf(), this, - this.grammar.getRepositorySafe()); + this.rootId = RuleFactory.getCompiledRuleId(this.grammar.getRepository().getSelf(), this, + this.grammar.getRepository()); } boolean isFirstLine; @@ -309,7 +313,8 @@ private T tokenize(String lineText, @Nullable StackElement prevState, final final var onigLineText = OnigString.of(lineText); final int lineLength = lineText.length(); final var lineTokens = new LineTokens(emitBinaryTokens, lineText, tokenTypeMatchers, balancedBracketSelectors); - final var nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, lineTokens, true); + final var nextState = LineTokenizer.tokenizeString(this, onigLineText, isFirstLine, 0, prevState, lineTokens, + true); if (emitBinaryTokens) { return (T) new TokenizeLineResult2(lineTokens.getBinaryResult(nextState, lineLength), nextState); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java deleted file mode 100644 index 6042fa7e0..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Raw.java +++ /dev/null @@ -1,348 +0,0 @@ -/** - * Copyright (c) 2015-2019 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes - */ -package org.eclipse.tm4e.core.internal.grammar; - -import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.internal.types.IRawCaptures; -import org.eclipse.tm4e.core.internal.types.IRawGrammar; -import org.eclipse.tm4e.core.internal.types.IRawRepository; -import org.eclipse.tm4e.core.internal.types.IRawRule; - -/** - * Raw - */ -public final class Raw extends HashMap - implements IRawRepository, IRawRule, IRawGrammar, IRawCaptures { - - public static final String DOLLAR_BASE = "$base"; - public static final String DOLLAR_SELF = "$self"; - - private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast"; - private static final String BEGIN = "begin"; - private static final String BEGIN_CAPTURES = "beginCaptures"; - private static final String CAPTURES = "captures"; - private static final String CONTENT_NAME = "contentName"; - private static final String END = "end"; - private static final String END_CAPTURES = "endCaptures"; - private static final String FILE_TYPES = "fileTypes"; - private static final String FIRST_LINE_MATCH = "firstLineMatch"; - private static final String ID = "id"; - private static final String INCLUDE = "include"; - private static final String INJECTIONS = "injections"; - private static final String INJECTION_SELECTOR = "injectionSelector"; - private static final String MATCH = "match"; - private static final String NAME = "name"; - private static final String PATTERNS = "patterns"; - private static final String REPOSITORY = "repository"; - private static final String SCOPE_NAME = "scopeName"; - private static final String WHILE = "while"; - private static final String WHILE_CAPTURES = "whileCaptures"; - - private static final long serialVersionUID = 1L; - - @Nullable - private transient List fileTypes; - - private Object getSafe(@Nullable final Object key) { - @SuppressWarnings("unlikely-arg-type") - final var obj = get(key); - if (obj == null) { - throw new IllegalArgumentException("Key '" + key + "' does not exit found"); - } - return obj; - } - - @Override - @Nullable - public IRawRule getProp(final String name) { - return (IRawRule) get(name); - } - - @Override - public IRawRule getBase() { - return (IRawRule) getSafe(DOLLAR_BASE); - } - - @Override - public void setBase(final IRawRule base) { - super.put(DOLLAR_BASE, base); - } - - @Override - public IRawRule getSelf() { - return (IRawRule) getSafe(DOLLAR_SELF); - } - - @Override - public void setSelf(final IRawRule self) { - super.put(DOLLAR_SELF, self); - } - - @Nullable - @Override - public Integer getId() { - return (Integer) get(ID); - } - - @Override - public void setId(final Integer id) { - super.put(ID, id); - } - - @Nullable - @Override - public String getName() { - return (String) get(NAME); - } - - @Override - public void setName(final String name) { - super.put(NAME, name); - } - - @Nullable - @Override - public String getContentName() { - return (String) get(CONTENT_NAME); - } - - @Nullable - @Override - public String getMatch() { - return (String) get(MATCH); - } - - @Nullable - @Override - public IRawCaptures getCaptures() { - updateCaptures(CAPTURES); - return (IRawCaptures) get(CAPTURES); - } - - public void updateCaptures(final String name) { - final Object captures = get(name); - if (captures instanceof List) { - final Raw rawCaptures = new Raw(); - int i = 0; - for (final Object capture : (List) captures) { - i++; - rawCaptures.put(i + "", capture); - } - super.put(name, rawCaptures); - } - } - - @Nullable - @Override - public String getBegin() { - return (String) get(BEGIN); - } - - @Nullable - @Override - public String getWhile() { - return (String) get(WHILE); - } - - @Nullable - @Override - public String getInclude() { - return (String) get(INCLUDE); - } - - @Override - public void setInclude(@Nullable final String include) { - super.put(INCLUDE, include); - } - - @Nullable - @Override - public IRawCaptures getBeginCaptures() { - updateCaptures(BEGIN_CAPTURES); - return (IRawCaptures) get(BEGIN_CAPTURES); - } - - @Override - public void setBeginCaptures(@Nullable final IRawCaptures beginCaptures) { - super.put(BEGIN_CAPTURES, beginCaptures); - } - - @Nullable - @Override - public String getEnd() { - return (String) get(END); - } - - @Nullable - @Override - public IRawCaptures getEndCaptures() { - updateCaptures(END_CAPTURES); - return (IRawCaptures) get(END_CAPTURES); - } - - @Nullable - @Override - public IRawCaptures getWhileCaptures() { - updateCaptures(WHILE_CAPTURES); - return (IRawCaptures) get(WHILE_CAPTURES); - } - - @Nullable - @Override - @SuppressWarnings("unchecked") - public Collection getPatterns() { - return (Collection) get(PATTERNS); - } - - @Override - public void setPatterns(final @Nullable Collection patterns) { - super.put(PATTERNS, patterns); - } - - @Nullable - @Override - @SuppressWarnings("unchecked") - public Map getInjections() { - return (Map) get(INJECTIONS); - } - - @Nullable - @Override - public String getInjectionSelector() { - return (String) get(INJECTION_SELECTOR); - } - - @Nullable - @Override - public IRawRepository getRepository() { - return (IRawRepository) get(REPOSITORY); - } - - @Override - public IRawRepository getRepositorySafe() { - return (IRawRepository) getSafe(REPOSITORY); - } - - @Override - public void setRepository(@Nullable final IRawRepository repository) { - super.put(REPOSITORY, repository); - } - - @Override - public boolean isApplyEndPatternLast() { - final Object applyEndPatternLast = get(APPLY_END_PATTERN_LAST); - if (applyEndPatternLast == null) { - return false; - } - if (applyEndPatternLast instanceof Boolean) { - return (Boolean) applyEndPatternLast; - } - if (applyEndPatternLast instanceof Integer) { - return ((Integer) applyEndPatternLast).equals(1); - } - return false; - } - - @Override - public String getScopeName() { - return (String) getSafe(SCOPE_NAME); - } - - @Override - public Collection getFileTypes() { - List result = fileTypes; - if (result == null) { - result = new ArrayList<>(); - final Collection unparsedFileTypes = (Collection) get(FILE_TYPES); - if (unparsedFileTypes != null) { - for (final Object o : unparsedFileTypes) { - String str = Objects.toString(o); - // #202 - if (str.startsWith(".")) { - str = str.substring(1); - } - result.add(str); - } - } - fileTypes = result; - } - return result; - } - - @Override - @Nullable - public String getFirstLineMatch() { - return (String) get(FIRST_LINE_MATCH); - } - - @Override - public IRawRule getCapture(final String captureId) { - return (IRawRule) getSafe(captureId); - } - - @Override - public Iterator iterator() { - final Iterator it = castNonNull(super.keySet().iterator()); - return castNonNull(it); - } - - @Override - public Raw clone() { - final var clone = (Raw) clone(this); - return castNonNull(clone); - } - - @Nullable - private Object clone(@Nullable final Object value) { - if (value instanceof Raw) { - final Raw rowToClone = (Raw) value; - final Raw raw = new Raw(); - for (final var entry : rowToClone.entrySet()) { - raw.put(entry.getKey(), clone(entry.getValue())); - } - return raw; - } - if (value instanceof List) { - return ((List) value).stream().map(this::clone).collect(Collectors.toList()); - } - return value; - } - - @Nullable - @Override - public Object put(final String key, @Nullable final Object value) { - if (FILE_TYPES.equals(key)) - fileTypes = null; - - return super.put(key, value); - } - - @Override - @SuppressWarnings("unlikely-arg-type") - public void putAll(@Nullable final Map m) { - if (m != null && m.containsKey(FILE_TYPES)) - fileTypes = null; - super.putAll(m); - } -} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawCaptures.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawCaptures.java new file mode 100644 index 000000000..2d86b8bc8 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawCaptures.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.tm4e.core.internal.grammar; + +import java.util.HashMap; + +import org.eclipse.tm4e.core.internal.parser.PropertySettable; +import org.eclipse.tm4e.core.internal.types.IRawCaptures; +import org.eclipse.tm4e.core.internal.types.IRawRule; +import org.eclipse.tm4e.core.internal.utils.DeepCloneable; + +public class RawCaptures extends HashMap implements IRawCaptures, DeepCloneable, PropertySettable { + + private static final long serialVersionUID = 1L; + + @Override + public RawCaptures deepClone() { + final var clone = new RawCaptures(); + for (final var entry : entrySet()) { + clone.put(entry.getKey(), DeepCloneable.deepClone(entry.getValue())); + } + return clone; + } + + @Override + public IRawRule getCapture(final String captureId) { + return get(captureId); + } + + @Override + public Iterable getCaptureIds() { + return keySet(); + } + + @Override + public void setProperty(final String name, final IRawRule value) { + put(name, value); + } +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java new file mode 100644 index 000000000..f6cc1f3ca --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java @@ -0,0 +1,179 @@ +/** + * Copyright (c) 2015-2019 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes + */ +package org.eclipse.tm4e.core.internal.grammar; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; +import org.eclipse.tm4e.core.internal.types.IRawGrammar; +import org.eclipse.tm4e.core.internal.types.IRawRepository; +import org.eclipse.tm4e.core.internal.types.IRawRule; +import org.eclipse.tm4e.core.internal.utils.DeepCloneable; + +public class RawGrammar extends HashMap + implements IRawGrammar, DeepCloneable, PropertySettable { + + private static final String FILE_TYPES = "fileTypes"; + private static final String FIRST_LINE_MATCH = "firstLineMatch"; + private static final String INJECTIONS = "injections"; + private static final String INJECTION_SELECTOR = "injectionSelector"; + private static final String NAME = "name"; + private static final String PATTERNS = "patterns"; + private static final String SCOPE_NAME = "scopeName"; + + private static final long serialVersionUID = 1L; + + @Nullable + private transient List fileTypes; + + @Override + public RawGrammar deepClone() { + final var clone = new RawGrammar(); + for (final var entry : entrySet()) { + clone.put(entry.getKey(), DeepCloneable.deepClone(entry.getValue())); + } + return clone; + } + + @Override + public Collection getFileTypes() { + List result = fileTypes; + if (result == null) { + result = new ArrayList<>(); + final Collection unparsedFileTypes = (Collection) get(FILE_TYPES); + if (unparsedFileTypes != null) { + for (final Object o : unparsedFileTypes) { + String str = Objects.toString(o); + // #202 + if (str.startsWith(".")) { + str = str.substring(1); + } + result.add(str); + } + } + fileTypes = result; + } + return result; + } + + @Override + @Nullable + public String getFirstLineMatch() { + return (String) get(FIRST_LINE_MATCH); + } + + @Nullable + @Override + @SuppressWarnings("unchecked") + public Map getInjections() { + return (Map) get(INJECTIONS); + } + + @Nullable + @Override + public String getInjectionSelector() { + return (String) get(INJECTION_SELECTOR); + } + + @Nullable + @Override + public String getName() { + return (String) get(NAME); + } + + @SuppressWarnings("unchecked") + @Override + public @Nullable Collection getPatterns() { + return (Collection) get(PATTERNS); + } + + @Override + public boolean isRepositorySet() { + return containsKey(RawRule.REPOSITORY); + } + + @Override + public IRawRepository getRepository() { + return (IRawRepository) getSafe(RawRule.REPOSITORY); + } + + private Object getSafe(@Nullable final Object key) { + @SuppressWarnings("unlikely-arg-type") + final var obj = get(key); + if (obj == null) { + throw new NoSuchElementException("Key '" + key + "' does not exit found"); + } + return obj; + } + + @Override + public String getScopeName() { + return (String) getSafe(SCOPE_NAME); + } + + @Nullable + @Override + public Object put(final String key, @Nullable final Object value) { + if (FILE_TYPES.equals(key)) + fileTypes = null; + + return super.put(key, value); + } + + @Override + @SuppressWarnings("unlikely-arg-type") + public void putAll(@Nullable final Map m) { + if (m != null && m.containsKey(FILE_TYPES)) + fileTypes = null; + super.putAll(m); + } + + @Override + public void setProperty(String name, Object value) { + put(name, value); + } + + @Override + public void setRepository(final IRawRepository repository) { + super.put(RawRule.REPOSITORY, repository); + } + + @Override + public IRawRule toRawRule() { + return new RawRule() { + private static final long serialVersionUID = 1L; + + @Override + public @Nullable String getName() { + return RawGrammar.this.getName(); + } + + @Override + public @Nullable Collection getPatterns() { + return RawGrammar.this.getPatterns(); + } + + @Override + public @Nullable IRawRepository getRepository() { + return isRepositorySet() ? RawGrammar.this.getRepository() : null; + } + }; + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRepository.java new file mode 100644 index 000000000..9435a9449 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRepository.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2015-2019 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.core.internal.grammar; + +import java.util.HashMap; +import java.util.NoSuchElementException; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; +import org.eclipse.tm4e.core.internal.types.IRawRepository; +import org.eclipse.tm4e.core.internal.types.IRawRule; +import org.eclipse.tm4e.core.internal.utils.DeepCloneable; + +public class RawRepository extends HashMap + implements IRawRepository, DeepCloneable, PropertySettable { + + private static final long serialVersionUID = 1L; + + public static final String DOLLAR_BASE = "$base"; + public static final String DOLLAR_SELF = "$self"; + + @Override + public RawRepository deepClone() { + final var clone = new RawRepository(); + for (final var entry : entrySet()) { + clone.put(entry.getKey(), DeepCloneable.deepClone(entry.getValue())); + } + return clone; + } + + @SuppressWarnings({ "null", "unused" }) + private IRawRule getSafe(final String key) { + final IRawRule obj = get(key); + if (obj == null) { + throw new NoSuchElementException("Key '" + key + "' does not exit found"); + } + return obj; + } + + @Override + @Nullable + public IRawRule getRule(final String name) { + return get(name); + } + + @Override + public IRawRule getBase() { + return getSafe(DOLLAR_BASE); + } + + @Override + public void setBase(final IRawRule base) { + super.put(DOLLAR_BASE, base); + } + + @Override + public IRawRule getSelf() { + return getSafe(DOLLAR_SELF); + } + + @Override + public void setSelf(final IRawRule self) { + super.put(DOLLAR_SELF, self); + } + + @Override + public void putEntries(PropertySettable target) { + for (final var entry : entrySet()) { + target.setProperty(entry.getKey(), entry.getValue()); + } + } + + @Override + public void setProperty(final String name, final IRawRule value) { + put(name, value); + } +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRule.java new file mode 100644 index 000000000..e7047cbe5 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawRule.java @@ -0,0 +1,193 @@ +/** + * Copyright (c) 2015-2019 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.core.internal.grammar; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; +import org.eclipse.tm4e.core.internal.types.IRawCaptures; +import org.eclipse.tm4e.core.internal.types.IRawRepository; +import org.eclipse.tm4e.core.internal.types.IRawRule; +import org.eclipse.tm4e.core.internal.utils.DeepCloneable; + +public class RawRule extends HashMap + implements IRawRule, DeepCloneable, PropertySettable { + + private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast"; + private static final String BEGIN = "begin"; + public static final String BEGIN_CAPTURES = "beginCaptures"; + public static final String CAPTURES = "captures"; + private static final String CONTENT_NAME = "contentName"; + private static final String END = "end"; + public static final String END_CAPTURES = "endCaptures"; + private static final String ID = "id"; + private static final String INCLUDE = "include"; + private static final String MATCH = "match"; + private static final String NAME = "name"; + private static final String PATTERNS = "patterns"; + public static final String REPOSITORY = "repository"; + private static final String WHILE = "while"; + public static final String WHILE_CAPTURES = "whileCaptures"; + + private static final long serialVersionUID = 1L; + + @Override + public RawRule deepClone() { + final var clone = new RawRule(); + for (final var entry : entrySet()) { + clone.put(entry.getKey(), DeepCloneable.deepClone(entry.getValue())); + } + return clone; + } + + @Nullable + @Override + public Integer getId() { + return (Integer) get(ID); + } + + @Override + public void setId(final Integer id) { + super.put(ID, id); + } + + @Nullable + @Override + public String getName() { + return (String) get(NAME); + } + + public void setName(final String name) { + super.put(NAME, name); + } + + @Nullable + @Override + public String getContentName() { + return (String) get(CONTENT_NAME); + } + + @Nullable + @Override + public String getMatch() { + return (String) get(MATCH); + } + + @Nullable + @Override + public IRawCaptures getCaptures() { + updateCaptures(CAPTURES); + return (IRawCaptures) get(CAPTURES); + } + + private void updateCaptures(final String name) { + final Object captures = get(name); + if (captures instanceof List) { + final RawRule rawCaptures = new RawRule(); + int i = 0; + for (final Object capture : (List) captures) { + i++; + rawCaptures.put(Integer.toString(i), capture); + } + super.put(name, rawCaptures); + } + } + + @Nullable + @Override + public String getBegin() { + return (String) get(BEGIN); + } + + @Nullable + @Override + public String getWhile() { + return (String) get(WHILE); + } + + @Nullable + @Override + public String getInclude() { + return (String) get(INCLUDE); + } + + public void setInclude(@Nullable final String include) { + super.put(INCLUDE, include); + } + + @Nullable + @Override + public IRawCaptures getBeginCaptures() { + updateCaptures(BEGIN_CAPTURES); + return (IRawCaptures) get(BEGIN_CAPTURES); + } + + @Nullable + @Override + public String getEnd() { + return (String) get(END); + } + + @Nullable + @Override + public IRawCaptures getEndCaptures() { + updateCaptures(END_CAPTURES); + return (IRawCaptures) get(END_CAPTURES); + } + + @Nullable + @Override + public IRawCaptures getWhileCaptures() { + updateCaptures(WHILE_CAPTURES); + return (IRawCaptures) get(WHILE_CAPTURES); + } + + @Nullable + @Override + @SuppressWarnings("unchecked") + public Collection getPatterns() { + return (Collection) get(PATTERNS); + } + + public void setPatterns(final @Nullable Collection patterns) { + super.put(PATTERNS, patterns); + } + + @Nullable + @Override + public IRawRepository getRepository() { + return (IRawRepository) get(REPOSITORY); + } + + @Override + public boolean isApplyEndPatternLast() { + final Object applyEndPatternLast = get(APPLY_END_PATTERN_LAST); + if (applyEndPatternLast == null) { + return false; + } + if (applyEndPatternLast instanceof Boolean) { + return (Boolean) applyEndPatternLast; + } + if (applyEndPatternLast instanceof Integer) { + return ((Integer) applyEndPatternLast) == 1; + } + return false; + } + + @Override + public void setProperty(final String name, final Object value) { + put(name, value); + } +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java index c24efd606..11d8c5abf 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java @@ -173,11 +173,11 @@ void collectDependenciesForDep( void collectSpecificDependencies(final ScopeDependencyCollector result, final IRawGrammar baseGrammar, final IRawGrammar selfGrammar, final String include, @Nullable IRawRepository repository) { - if (repository == null) { + if (repository == null && selfGrammar.isRepositorySet()) { repository = selfGrammar.getRepository(); } if (repository != null) { - final var rule = repository.getProp(include); + final var rule = repository.getRule(include); if (rule != null) { extractIncludedScopesInPatterns(result, baseGrammar, selfGrammar, List.of(rule), repository); } @@ -228,9 +228,9 @@ void extractIncludedScopesInPatterns( continue; } - if (include.equals(Raw.DOLLAR_BASE) || include.equals(baseGrammar.getScopeName())) { + if (include.equals(RawRepository.DOLLAR_BASE) || include.equals(baseGrammar.getScopeName())) { collectDependencies(result, baseGrammar, baseGrammar); - } else if (include.equals(Raw.DOLLAR_SELF) || include.equals(selfGrammar.getScopeName())) { + } else if (include.equals(RawRepository.DOLLAR_SELF) || include.equals(selfGrammar.getScopeName())) { collectDependencies(result, baseGrammar, selfGrammar); } else if (include.charAt(0) == '#') { collectSpecificDependencies(result, baseGrammar, selfGrammar, include.substring(1), patternRepository); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java index ea6b1b6af..77003339d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java @@ -18,11 +18,16 @@ import java.io.InputStream; -import org.eclipse.tm4e.core.internal.grammar.Raw; +import org.eclipse.tm4e.core.internal.grammar.RawRule; +import org.eclipse.tm4e.core.internal.grammar.RawCaptures; +import org.eclipse.tm4e.core.internal.grammar.RawGrammar; +import org.eclipse.tm4e.core.internal.grammar.RawRepository; import org.eclipse.tm4e.core.internal.parser.PListParser; import org.eclipse.tm4e.core.internal.parser.PListParserJSON; import org.eclipse.tm4e.core.internal.parser.PListParserXML; import org.eclipse.tm4e.core.internal.parser.PListParserYAML; +import org.eclipse.tm4e.core.internal.parser.PListPath; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; import org.eclipse.tm4e.core.internal.types.IRawGrammar; /** @@ -30,21 +35,31 @@ */ public final class GrammarReader { - /** - * methods should be accessed statically - */ - private GrammarReader() { - } + public static final PropertySettable.Factory OBJECT_FACTORY = path -> { + if (path.size() == 0) { + return new RawGrammar(); + } + switch (path.last()) { + case RawRule.REPOSITORY: + return new RawRepository(); + case RawRule.BEGIN_CAPTURES: + case RawRule.CAPTURES: + case RawRule.END_CAPTURES: + case RawRule.WHILE_CAPTURES: + return new RawCaptures(); + } + return new RawRule(); + }; - private static final PListParser JSON_PARSER = new PListParserJSON<>(Raw::new); - private static final PListParser XML_PARSER = new PListParserXML<>(Raw::new); - private static final PListParser YAML_PARSER = new PListParserYAML<>(Raw::new); + private static final PListParser JSON_PARSER = new PListParserJSON<>(OBJECT_FACTORY); + private static final PListParser XML_PARSER = new PListParserXML<>(OBJECT_FACTORY); + private static final PListParser YAML_PARSER = new PListParserYAML<>(OBJECT_FACTORY); public static IRawGrammar readGrammarSync(final String filePath, final InputStream in) throws Exception { return getGrammarParser(filePath).parse(in); } - private static PListParser getGrammarParser(final String filePath) { + private static PListParser getGrammarParser(final String filePath) { String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); switch (extension) { @@ -61,4 +76,10 @@ private static PListParser getGrammarParser(final String filePath) return XML_PARSER; } } + + /** + * methods should be accessed statically + */ + private GrammarReader() { + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java deleted file mode 100644 index fb72ccf93..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListArray.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2022 Sebastian Thomschke and others. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Sebastian Thomschke - initial implementation - */ -package org.eclipse.tm4e.core.internal.parser; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jdt.annotation.Nullable; - -final class PListArray extends PListObject { - - private final List values = new ArrayList<>(); - - PListArray(@Nullable final PListObject parent) { - super(parent); - } - - @Override - void addValue(final Object value) { - values.add(value); - } - - @Override - Object getValue() { - return values; - } -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java new file mode 100644 index 000000000..602cb7681 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java @@ -0,0 +1,233 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.core.internal.parser; + +import static java.lang.System.Logger.Level.*; + +import java.lang.System.Logger; +import java.time.ZonedDateTime; +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.jdt.annotation.Nullable; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import com.google.common.collect.Iterators; + +final class PListContentHandler extends DefaultHandler { + + private static final Logger LOGGER = System.getLogger(PListContentHandler.class.getName()); + + private static final class PListPathImpl implements PListPath { + final LinkedList keys = new LinkedList<>(); + final List keysDepths = new ArrayList<>(); + int depth = 0; + + void add(String key) { + trim(); + keysDepths.add(depth); + keys.add(key); + } + + void trim() { + for (int i = keysDepths.size() - 1; i >= 0; i--) { + if (keysDepths.get(i) >= depth) { + keysDepths.remove(i); + keys.remove(i); + } + } + } + + @Override + public String get(int index) { + return keys.get(index); + } + + @Override + public String first() { + return keys.getFirst(); + } + + @Override + public String last() { + return keys.getLast(); + } + + @Override + public Iterator iterator() { + return Iterators.unmodifiableIterator(keys.iterator()); + } + + @Override + public int size() { + return keys.size(); + } + + @Override + public String toString() { + return String.join("/", keys.toArray(String[]::new)); + } + } + + private final class PListObject { + + @Nullable + final PListObject parent; + final Object values; + + PListObject(@Nullable final PListObject parent, final Object values) { + this.parent = parent; + this.values = values; + } + + @SuppressWarnings("unchecked") + void addValue(final Object value) { + if (values instanceof PropertySettable) { + ((PropertySettable) values).setProperty(path.last(), value); + } else if (values instanceof List) { + ((List) values).add(value); + } + } + } + + @Nullable + private PListObject currObject; + + @Nullable + private T result; + + private final PropertySettable.Factory objectFactory; + private final PListPathImpl path = new PListPathImpl(); + + /** captures the text content of an XML node */ + private final StringBuilder text = new StringBuilder(); + + PListContentHandler(final PropertySettable.Factory objectFactory) { + this.objectFactory = objectFactory; + } + + @SuppressWarnings("unchecked") + @Override + public void startElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName, + @Nullable final Attributes attributes) throws SAXException { + assert localName != null; + + path.depth++; + + switch (localName) { + case "dict": + if (result == null) { + result = (T) objectFactory.create(path); + currObject = new PListObject(currObject, result); + } else { + currObject = new PListObject(currObject, objectFactory.create(path)); + } + break; + case "array": + if (result == null) { + result = (T) new ArrayList<>(); + currObject = new PListObject(currObject, result); + } else { + currObject = new PListObject(currObject, new ArrayList<>()); + } + break; + } + + text.setLength(0); + } + + @Override + public void endElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName) + throws SAXException { + assert localName != null; + + var currObject = this.currObject; + if (currObject == null) { + throw new SAXException("Root or element not found!"); + } + + path.trim(); + path.depth--; + + switch (localName) { + case "key": + if (!(currObject.values instanceof PropertySettable)) { + LOGGER.log(WARNING, " tag can only be used inside an open element"); + break; + } + path.add(text.toString()); + break; + case "dict": + case "array": + final var parent = currObject.parent; + if (parent != null) { + parent.addValue(currObject.values); + this.currObject = parent; + } + break; + case "string": + case "data": + currObject.addValue(text.toString()); + break; + case "date": // e.g. 2007-10-25T12:36:35Z + try { + currObject.addValue(ZonedDateTime.parse(text.toString())); + } catch (final DateTimeParseException ex) { + LOGGER.log(WARNING, "Failed to parse date '" + text + "'. " + ex); + } + break; + case "integer": + try { + currObject.addValue(Integer.parseInt(text.toString())); + } catch (final NumberFormatException ex) { + LOGGER.log(WARNING, "Failed to parse integer '" + text + "'. " + ex); + } + break; + case "real": + try { + currObject.addValue(Float.parseFloat(text.toString())); + } catch (final NumberFormatException ex) { + LOGGER.log(WARNING, "Failed to parse real as float '" + text + "'. " + ex); + } + break; + case "true": + currObject.addValue(Boolean.TRUE); + break; + case "false": + currObject.addValue(Boolean.FALSE); + break; + case "plist": + break; + default: + LOGGER.log(WARNING, "Invalid tag name: " + localName); + } + } + + @Override + public void characters(final char @Nullable [] ch, final int start, final int length) throws SAXException { + text.append(ch, start, length); + } + + void characters(final String chars) { + text.append(chars); + } + + public T getResult() { + assert result != null; + return result; + } +} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java deleted file mode 100644 index 425bb272e..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListDict.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (c) 2022 Sebastian Thomschke and others. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Sebastian Thomschke - initial implementation - */ -package org.eclipse.tm4e.core.internal.parser; - -import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; - -import java.util.Map; - -import org.eclipse.jdt.annotation.Nullable; - -final class PListDict extends PListObject { - - private final Map values; - - @Nullable - private String lastKey; - - PListDict(@Nullable final PListObject parent, final MapFactory mapFactory) { - super(parent); - values = mapFactory.createMap(); - } - - @Override - void addValue(final Object value) { - values.put(castNonNull(lastKey), value); - } - - @Nullable - String getLastKey() { - return lastKey; - } - - @Override - Object getValue() { - return values; - } - - void setLastKey(@Nullable final String lastKey) { - this.lastKey = lastKey; - } -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java deleted file mode 100644 index ab650d8d5..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListObject.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.parser; - -import org.eclipse.jdt.annotation.Nullable; - -abstract class PListObject { - - @Nullable - final PListObject parent; - - PListObject(@Nullable final PListObject parent) { - this.parent = parent; - } - - abstract void addValue(Object value); - - abstract Object getValue(); -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java deleted file mode 100644 index 8a06662de..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserContentHandler.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.parser; - -import java.time.ZonedDateTime; -import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jdt.annotation.Nullable; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -final class PListParserContentHandler extends DefaultHandler { - - private final MapFactory mapFactory; - - private final List errors = new ArrayList<>(); - - @Nullable - private PListObject currObject; - - @Nullable - private T result; - - private final StringBuilder text = new StringBuilder(); - - PListParserContentHandler(final MapFactory mapFactory) { - this.mapFactory = mapFactory; - } - - @Override - public void startElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName, - @Nullable final Attributes attributes) throws SAXException { - assert localName != null; - switch (localName) { - case "dict": - currObject = new PListDict(currObject, mapFactory); - break; - case "array": - currObject = new PListArray(currObject); - break; - case "key": - if (currObject instanceof PListDict) { - ((PListDict) currObject).setLastKey(null); - } - break; - } - - text.setLength(0); - } - - @Override - public void endElement(@Nullable final String uri, @Nullable final String localName, @Nullable final String qName) - throws SAXException { - assert localName != null; - - Object value = null; - - var currObject = this.currObject; - switch (localName) { - case "key": - if (!(currObject instanceof PListDict)) { - errors.add(" tag can only be used inside an open element"); - return; - } - ((PListDict) currObject).setLastKey(text.toString()); - return; - case "dict": - case "array": - if (currObject == null) { - errors.add("Closing tag found, without opening tag"); - return; - } - value = currObject.getValue(); - currObject = this.currObject = currObject.parent; - break; - case "string": - case "data": - value = text.toString(); - break; - case "date": - // e.g. 2007-10-25T12:36:35Z - try { - value = ZonedDateTime.parse(text.toString()); - } catch (final DateTimeParseException ex) { - errors.add("Failed to parse date '" + text + "'. " + ex); - return; - } - break; - case "integer": - try { - value = Integer.parseInt(text.toString()); - } catch (final NumberFormatException ex) { - errors.add("Failed to parse integer '" + text + "'. " + ex); - return; - } - break; - case "real": - try { - value = Float.parseFloat(text.toString()); - } catch (final NumberFormatException ex) { - errors.add("Failed to parse real as float '" + text + "'. " + ex); - return; - } - break; - case "true": - value = Boolean.TRUE; - break; - case "false": - value = Boolean.FALSE; - break; - case "plist": - return; - default: - errors.add("Invalid tag name: " + localName); - return; - } - - if (currObject == null) { - @SuppressWarnings("unchecked") - final var t = (T) value; - result = t; - } else if (currObject instanceof PListDict) { - if (((PListDict) currObject).getLastKey() != null) { - currObject.addValue(value); - } else { - errors.add("Dictionary key missing for value " + value); - } - } else { // PListArray - currObject.addValue(value); - } - } - - @Override - public void characters(final char @Nullable [] ch, final int start, final int length) throws SAXException { - text.append(ch, start, length); - } - - void characters(final String chars) { - text.append(chars); - } - - public T getResult() { - assert result != null; - return result; - } -} diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java index 823dd5adf..b1e792483 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserJSON.java @@ -22,18 +22,19 @@ public final class PListParserJSON implements PListParser { - private final MapFactory mapFactory; + private final PropertySettable.Factory objectFactory; - public PListParserJSON(final MapFactory mapFactory) { - this.mapFactory = mapFactory; + public PListParserJSON(final PropertySettable.Factory objectFactory) { + this.objectFactory = objectFactory; } @Override public T parse(final InputStream contents) throws IOException, SAXException { - final var pList = new PListParserContentHandler(mapFactory); + final var pList = new PListContentHandler(objectFactory); try (final var reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8))) { // reader.setLenient(true); boolean parsing = true; + pList.startElement(null, "plist", null, null); while (parsing) { final var nextToken = reader.peek(); switch (nextToken) { @@ -79,6 +80,7 @@ public T parse(final InputStream contents) throws IOException, SAXException { break; } } + pList.endElement(null, "plist", null); } return pList.getResult(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java index fb6c5660d..f001af3d4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserXML.java @@ -25,10 +25,10 @@ public final class PListParserXML implements PListParser { - private final MapFactory mapFactory; + private final PropertySettable.Factory objectFactory; - public PListParserXML(final MapFactory mapFactory) { - this.mapFactory = mapFactory; + public PListParserXML(final PropertySettable.Factory objectFactory) { + this.objectFactory = objectFactory; } @Override @@ -49,7 +49,7 @@ public T parse(final InputStream contents) throws IOException, ParserConfigurati final XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setEntityResolver((publicId, systemId) -> new InputSource( new ByteArrayInputStream("".getBytes()))); - final var result = new PListParserContentHandler(mapFactory); + final var result = new PListContentHandler(objectFactory); xmlReader.setContentHandler(result); xmlReader.parse(new InputSource(contents)); return result.getResult(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java index ab1ff6c5d..0d0ef99fc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListParserYAML.java @@ -12,7 +12,8 @@ */ package org.eclipse.tm4e.core.internal.parser; -import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.castNonNull; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.io.InputStream; import java.util.List; import java.util.Map; @@ -27,14 +28,14 @@ */ public final class PListParserYAML implements PListParser { - private final MapFactory mapFactory; + private final PropertySettable.Factory objectFactory; - public PListParserYAML(final MapFactory mapFactory) { - this.mapFactory = mapFactory; + public PListParserYAML(final PropertySettable.Factory objectFactory) { + this.objectFactory = objectFactory; } @SuppressWarnings("unchecked") - private void addListToPList(final PListParserContentHandler pList, final List list) throws SAXException { + private void addListToPList(final PListContentHandler pList, final List list) throws SAXException { pList.startElement(null, "array", null, null); for (final Object item : list) { @@ -51,7 +52,7 @@ private void addListToPList(final PListParserContentHandler pList, final List } @SuppressWarnings("unchecked") - private void addMapToPList(final PListParserContentHandler pList, final Map map) + private void addMapToPList(final PListContentHandler pList, final Map map) throws SAXException { pList.startElement(null, "dict", null, null); @@ -71,7 +72,7 @@ private void addMapToPList(final PListParserContentHandler pList, final Map pList, final String value) throws SAXException { + private void addStringToPList(final PListContentHandler pList, final String value) throws SAXException { pList.startElement(null, "string", null, null); pList.characters(value); pList.endElement(null, "string", null); @@ -79,8 +80,10 @@ private void addStringToPList(final PListParserContentHandler pList, final St @Override public T parse(final InputStream contents) throws SAXException, YAMLException { - final var pList = new PListParserContentHandler(mapFactory); + final var pList = new PListContentHandler(objectFactory); + pList.startElement(null, "plist", null, null); addMapToPList(pList, new Yaml().loadAs(contents, Map.class)); + pList.endElement(null, "plist", null); return pList.getResult(); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListPath.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListPath.java new file mode 100644 index 000000000..bdc82438f --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListPath.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.internal.parser; + +/** + * Represents the hierarchical path of an PList value calculated based on the <key> tags. E.g. + *
  • fileTypes + *
  • scopeName + *
  • repository/constants/patterns/patterns + *
  • repository/statements/patterns/include + *
  • repository/var-single-variable/beginCaptures + */ +public interface PListPath extends Iterable { + + String first(); + + String get(int index); + + String last(); + + int size(); +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PropertySettable.java similarity index 71% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PropertySettable.java index f0f8dece7..20091d74d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/MapFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PropertySettable.java @@ -12,12 +12,11 @@ */ package org.eclipse.tm4e.core.internal.parser; -import java.util.Map; +public interface PropertySettable { -import org.eclipse.jdt.annotation.Nullable; + public interface Factory { + PropertySettable create(I args); + } -@FunctionalInterface -public interface MapFactory { - - Map createMap(); + void setProperty(String name, V value); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java index 21b9a536a..90f7c2c3e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java @@ -29,7 +29,8 @@ import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.internal.grammar.BalancedBracketSelectors; import org.eclipse.tm4e.core.internal.grammar.Grammar; -import org.eclipse.tm4e.core.internal.grammar.Raw; +import org.eclipse.tm4e.core.internal.grammar.RawRepository; +import org.eclipse.tm4e.core.internal.grammar.RawRule; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; import org.eclipse.tm4e.core.internal.types.IRawRule; @@ -129,13 +130,13 @@ public IGrammar grammarForScopeName(final String scopeName, final int initialLan } private static void collectIncludedScopes(final Collection result, final IRawGrammar grammar) { - final var grammarPattners = grammar.getPatterns(); - if (grammarPattners != null) { - extractIncludedScopesInPatterns(result, grammarPattners); + final var grammarPatterns = grammar.getPatterns(); + if (grammarPatterns != null) { + extractIncludedScopesInPatterns(result, grammarPatterns); } - final IRawRepository repository = grammar.getRepository(); - if (repository != null) { + if (grammar.isRepositorySet()) { + final IRawRepository repository = grammar.getRepository(); extractIncludedScopesInRepository(result, repository); } @@ -159,7 +160,7 @@ private static void extractIncludedScopesInPatterns(final Collection res continue; } - if (include.equals(Raw.DOLLAR_BASE) || include.equals(Raw.DOLLAR_SELF)) { + if (include.equals(RawRepository.DOLLAR_BASE) || include.equals(RawRepository.DOLLAR_SELF)) { // Special includes that can be resolved locally in this grammar continue; } @@ -189,10 +190,10 @@ private static void addIncludedScope(final String scopeName, final Collection result, final IRawRepository repository) { - if (!(repository instanceof Raw)) { + if (!(repository instanceof RawRule)) { return; } - final Raw rawRepository = (Raw) repository; + final RawRule rawRepository = (RawRule) repository; for (final var entry : rawRepository.values()) { final IRawRule rule = (IRawRule) castNonNull(entry); final var patterns = rule.getPatterns(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index e9b910c2c..4adc263fc 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -16,9 +16,8 @@ */ package org.eclipse.tm4e.core.internal.rule; -import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; - import static java.lang.System.Logger.Level.*; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; import java.lang.System.Logger; import java.util.ArrayList; @@ -27,7 +26,8 @@ import java.util.List; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.internal.grammar.Raw; +import org.eclipse.tm4e.core.internal.grammar.RawRepository; +import org.eclipse.tm4e.core.internal.grammar.RawRule; import org.eclipse.tm4e.core.internal.types.IRawCaptures; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; @@ -66,7 +66,7 @@ public static int getCompiledRuleId(final IRawRule desc, final IRuleFactoryHelpe : IRawRepository.merge(repository, desc.getRepository()); var patterns = desc.getPatterns(); if (patterns == null && desc.getInclude() != null) { - final var includeRule = new Raw(); + final var includeRule = new RawRule(); includeRule.setInclude(desc.getInclude()); patterns = List.of(includeRule); } @@ -120,7 +120,7 @@ begin, compileCaptures( // Find the maximum capture id int maximumCaptureId = 0; - for (final String captureId : captures) { + for (final String captureId : captures.getCaptureIds()) { final int numericCaptureId = parseInt(captureId, 10); if (numericCaptureId > maximumCaptureId) { maximumCaptureId = numericCaptureId; @@ -134,7 +134,7 @@ begin, compileCaptures( } // Fill out result - for (String captureId : captures) { + for (String captureId : captures.getCaptureIds()) { final int numericCaptureId = parseInt(captureId, 10); final IRawRule rule = captures.getCapture(captureId); final Integer retokenizeCapturedWithRuleId = rule.getPatterns() == null @@ -169,16 +169,18 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< } else { if (patternInclude.charAt(0) == '#') { // Local include found in `repository` - final IRawRule localIncludedRule = repository.getProp(patternInclude.substring(1)); + final IRawRule localIncludedRule = repository.getRule(patternInclude.substring(1)); if (localIncludedRule != null) { patternId = getCompiledRuleId(localIncludedRule, helper, repository); } else if (LOGGER.isLoggable(DEBUG)) { LOGGER.log(DEBUG, "CANNOT find rule for scopeName: %s, I am: %s", patternInclude, repository.getBase().getName()); } - } else if (patternInclude.equals(Raw.DOLLAR_BASE)) { // Special include also found in `repository` + } else if (patternInclude.equals(RawRepository.DOLLAR_BASE)) { // Special include also found in + // `repository` patternId = getCompiledRuleId(repository.getBase(), helper, repository); - } else if (patternInclude.equals(Raw.DOLLAR_SELF)) { // Special include also found in `repository` + } else if (patternInclude.equals(RawRepository.DOLLAR_SELF)) { // Special include also found in + // `repository` patternId = getCompiledRuleId(repository.getSelf(), helper, repository); } else { final String externalGrammarName; @@ -195,9 +197,9 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< // External include final IRawGrammar externalGrammar = helper.getExternalGrammar(externalGrammarName, repository); if (externalGrammar != null) { - final var externalGrammarRepo = externalGrammar.getRepositorySafe(); + final var externalGrammarRepo = externalGrammar.getRepository(); if (externalGrammarInclude != null) { - final IRawRule externalIncludedRule = externalGrammarRepo.getProp(externalGrammarInclude); + final IRawRule externalIncludedRule = externalGrammarRepo.getRule(externalGrammarInclude); if (externalIncludedRule != null) { patternId = getCompiledRuleId(externalIncludedRule, helper, externalGrammarRepo); } else if (LOGGER.isLoggable(DEBUG)) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index a0259203a..1b5497a4f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -15,12 +15,13 @@ import java.util.HashMap; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; import org.eclipse.tm4e.core.theme.IRawTheme; import org.eclipse.tm4e.core.theme.IRawThemeSetting; import org.eclipse.tm4e.core.theme.IThemeSetting; public final class ThemeRaw extends HashMap - implements IRawTheme, IRawThemeSetting, IThemeSetting { + implements IRawTheme, IRawThemeSetting, IThemeSetting, PropertySettable { private static final long serialVersionUID = 1L; @@ -66,4 +67,9 @@ public String getBackground() { public String getForeground() { return (String) super.get("foreground"); } + + @Override + public void setProperty(String name, Object value) { + put(name, value); + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java index 1d4a7500a..401869fe4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java @@ -24,9 +24,9 @@ final class SyncThemeReader { private final InputStream in; - private final PListParser parser; + private final PListParser parser; - SyncThemeReader(final InputStream in, final PListParser parser) { + SyncThemeReader(final InputStream in, final PListParser parser) { this.in = in; this.parser = parser; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java index 74aa9343b..3fe79a69e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java @@ -18,6 +18,8 @@ import java.io.InputStream; +import org.eclipse.tm4e.core.internal.parser.PListPath; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; import org.eclipse.tm4e.core.internal.parser.PListParser; import org.eclipse.tm4e.core.internal.parser.PListParserJSON; import org.eclipse.tm4e.core.internal.parser.PListParserXML; @@ -31,22 +33,18 @@ */ public final class ThemeReader { - /** - * Helper class, use methods statically - */ - private ThemeReader() { - } + private static final PropertySettable.Factory OBJECT_FACTORY = path -> new ThemeRaw(); - private static final PListParserJSON JSON_PARSER = new PListParserJSON<>(ThemeRaw::new); - private static final PListParserYAML YAML_PARSER = new PListParserYAML<>(ThemeRaw::new); - private static final PListParserXML XML_PARSER = new PListParserXML<>(ThemeRaw::new); + private static final PListParserJSON JSON_PARSER = new PListParserJSON<>(OBJECT_FACTORY); + private static final PListParserYAML YAML_PARSER = new PListParserYAML<>(OBJECT_FACTORY); + private static final PListParserXML XML_PARSER = new PListParserXML<>(OBJECT_FACTORY); public static IRawTheme readThemeSync(final String filePath, final InputStream in) throws Exception { final var reader = new SyncThemeReader(in, getThemeParser(filePath)); return reader.load(); } - private static PListParser getThemeParser(final String filePath) { + private static PListParser getThemeParser(final String filePath) { String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); switch (extension) { @@ -62,4 +60,10 @@ private static PListParser getThemeParser(final String filePath) { return XML_PARSER; } } + + /** + * Helper class, use methods statically + */ + private ThemeReader() { + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java index 8b14408d0..25e0a6ec9 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawCaptures.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,12 +11,14 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.types; -public interface IRawCaptures extends Iterable { +public interface IRawCaptures { IRawRule getCapture(String captureId); + + Iterable getCaptureIds(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java index 7d65d1d70..6a884c9c5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawGrammar.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.core.internal.types; @@ -28,16 +28,14 @@ */ public interface IRawGrammar { - IRawGrammar clone(); + IRawGrammar deepClone(); - @Nullable + boolean isRepositorySet(); IRawRepository getRepository(); - IRawRepository getRepositorySafe(); - String getScopeName(); - @Nullable + @Nullable // TODO non-null in upstream project Collection getPatterns(); @Nullable @@ -53,4 +51,9 @@ public interface IRawGrammar { @Nullable String getFirstLineMatch(); + + void setRepository(IRawRepository repository); + + IRawRule toRawRule(); + } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java index 9861be3cb..3895fa8de 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java @@ -16,32 +16,26 @@ */ package org.eclipse.tm4e.core.internal.types; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.internal.grammar.Raw; +import org.eclipse.tm4e.core.internal.grammar.RawRepository; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; public interface IRawRepository { static IRawRepository merge(@Nullable IRawRepository... sources) { - final Raw merged = new Raw(); - for (final IRawRepository source : sources) { + final RawRepository merged = new RawRepository(); + for (final var source : sources) { if (source == null) continue; - final Set> entries = source.entrySet(); - for (final Entry entry : entries) { - merged.put(entry.getKey(), entry.getValue()); - } + source.putEntries(merged); } return merged; } - Set> entrySet(); + void putEntries(PropertySettable target); @Nullable - IRawRule getProp(String name); + IRawRule getRule(String name); IRawRule getBase(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java index 23009ed23..db38f861d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRule.java @@ -30,13 +30,9 @@ public interface IRawRule { @Nullable String getInclude(); - void setInclude(@Nullable String include); - @Nullable String getName(); - void setName(String name); - @Nullable String getContentName(); @@ -52,8 +48,6 @@ public interface IRawRule { @Nullable IRawCaptures getBeginCaptures(); - void setBeginCaptures(@Nullable IRawCaptures beginCaptures); - @Nullable String getEnd(); @@ -69,12 +63,8 @@ public interface IRawRule { @Nullable Collection getPatterns(); - void setPatterns(@Nullable Collection patterns); - @Nullable IRawRepository getRepository(); - void setRepository(@Nullable IRawRepository repository); - boolean isApplyEndPatternLast(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java new file mode 100644 index 000000000..bed9fe1a4 --- /dev/null +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.tm4e.core.internal.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.eclipse.jdt.annotation.Nullable; + +public interface DeepCloneable { + + @SuppressWarnings("unchecked") + public static T deepClone(T obj) { + if (obj instanceof DeepCloneable) { + return (T) ((DeepCloneable) obj).deepClone(); + } + + if (obj instanceof List) { + final List<@Nullable Object> clone; + if (obj instanceof ArrayList) { + final var source = (ArrayList<@Nullable Object>) obj; + clone = (ArrayList<@Nullable Object>) source.clone(); + } else if (obj instanceof LinkedList) { + final var source = (LinkedList<@Nullable Object>) obj; + clone = (LinkedList<@Nullable Object>) source.clone(); + } else { + final var source = (List<@Nullable Object>) obj; + clone = new ArrayList<>(source); + } + clone.replaceAll(DeepCloneable::deepCloneNullable); + return (T) clone; + } + + if (obj instanceof Set) { + final Set<@Nullable Object> source; + final Set<@Nullable Object> clone; + if (obj instanceof TreeSet) { + final var cloneable = (TreeSet<@Nullable Object>) obj; + source = cloneable; + clone = (Set<@Nullable Object>) cloneable.clone(); + } else if (obj instanceof HashSet) { + final var cloneable = (HashSet<@Nullable Object>) obj; + source = cloneable; + clone = (Set<@Nullable Object>) cloneable.clone(); + } else { + source = (Set<@Nullable Object>) obj; + clone = new HashSet<>(); + } + clone.clear(); + for (final var e : source) { + clone.add(deepCloneNullable(e)); + } + return (T) clone; + } + + if (obj instanceof Map) { + if (obj instanceof HashMap) { + final var source = (HashMap) obj; + final var clone = (Map) source.clone(); + clone.replaceAll((k, v) -> deepCloneNullable(v)); + return (T) clone; + } + if (obj instanceof IdentityHashMap) { + final var source = (IdentityHashMap) obj; + final var clone = (Map) source.clone(); + clone.replaceAll((k, v) -> deepCloneNullable(v)); + return (T) clone; + } + if (obj instanceof TreeMap) { + final var source = (TreeMap) obj; + final var clone = (Map) source.clone(); + clone.replaceAll((k, v) -> deepCloneNullable(v)); + return (T) clone; + } + } + + // probably immutable + return obj; + } + + @Nullable + public static T deepCloneNullable(@Nullable T obj) { + if (obj == null) { + return null; + } + return deepClone(obj); + } + + Object deepClone(); +} diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java index 6b8a7ad20..71ca823a2 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java @@ -14,18 +14,19 @@ import static org.junit.jupiter.api.Assertions.*; import org.eclipse.tm4e.core.Data; -import org.eclipse.tm4e.core.internal.grammar.Raw; +import org.eclipse.tm4e.core.internal.grammar.RawGrammar; +import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; +import org.eclipse.tm4e.core.internal.parser.PListParser; import org.eclipse.tm4e.core.internal.parser.PListParserJSON; import org.eclipse.tm4e.core.internal.parser.PListParserXML; import org.eclipse.tm4e.core.internal.parser.PListParserYAML; -import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.junit.jupiter.api.Test; public class PListParserTest { @Test void testParseJSONPList() throws Exception { - final var parser = new PListParserJSON(Raw::new); + final PListParser parser = new PListParserJSON<>(GrammarReader.OBJECT_FACTORY); try (final var is = Data.class.getResourceAsStream("csharp.json")) { final var grammar = parser.parse(is); assertNotNull(grammar); @@ -36,7 +37,7 @@ void testParseJSONPList() throws Exception { @Test void testParseYAMLPlist() throws Exception { - final var parser = new PListParserYAML(Raw::new); + final PListParser parser = new PListParserYAML<>(GrammarReader.OBJECT_FACTORY); try (final var is = Data.class.getResourceAsStream("JavaScript.tmLanguage.yaml")) { final var grammar = parser.parse(is); assertNotNull(grammar); @@ -47,7 +48,7 @@ void testParseYAMLPlist() throws Exception { @Test void testParseXMLPlist() throws Exception { - final var parser = new PListParserXML(Raw::new); + final PListParser parser = new PListParserXML<>(GrammarReader.OBJECT_FACTORY); try (final var is = Data.class.getResourceAsStream("JavaScript.tmLanguage")) { final var grammar = parser.parse(is); assertNotNull(grammar); From 3a7e384d55922dbed5dde908e8324d84de408b4c Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 4 May 2022 18:15:39 +0200 Subject: [PATCH 165/202] Add final modifier where applicable --- .../org/eclipse/tm4e/core/TMException.java | 4 +- .../grammar/BalancedBracketSelectors.java | 2 +- .../tm4e/core/internal/grammar/Grammar.java | 4 +- .../core/internal/grammar/LineTokenizer.java | 4 +- .../core/internal/grammar/LineTokens.java | 4 +- .../core/internal/grammar/RawGrammar.java | 2 +- .../core/internal/grammar/RawRepository.java | 2 +- .../grammar/StackElementMetadata.java | 2 +- .../grammar/reader/GrammarReader.java | 2 +- .../core/internal/matcher/MatcherBuilder.java | 2 +- .../core/internal/matcher/NameMatcher.java | 2 +- .../internal/oniguruma/OnigCaptureIndex.java | 2 +- .../core/internal/oniguruma/OnigRegExp.java | 2 +- .../core/internal/oniguruma/OnigString.java | 2 +- .../internal/parser/PListContentHandler.java | 6 +-- .../core/internal/registry/SyncRegistry.java | 2 +- .../tm4e/core/internal/rule/BeginEndRule.java | 12 ++--- .../core/internal/rule/BeginWhileRule.java | 20 ++++---- .../tm4e/core/internal/rule/CaptureRule.java | 12 ++--- .../internal/rule/CompilePatternsResult.java | 2 +- .../tm4e/core/internal/rule/CompiledRule.java | 2 +- .../core/internal/rule/IncludeOnlyRule.java | 6 +-- .../tm4e/core/internal/rule/MatchRule.java | 6 +-- .../tm4e/core/internal/rule/RegExpSource.java | 2 +- .../tm4e/core/internal/rule/RuleFactory.java | 8 +-- .../tm4e/core/internal/theme/ThemeRaw.java | 2 +- .../internal/theme/reader/ThemeReader.java | 2 +- .../core/internal/types/IRawRepository.java | 2 +- .../core/internal/utils/CompareUtils.java | 8 +-- .../core/internal/utils/DeepCloneable.java | 4 +- .../core/internal/utils/MoreCollections.java | 6 +-- .../core/internal/utils/NullSafetyHelper.java | 4 +- .../org/eclipse/tm4e/core/model/TMModel.java | 2 +- .../eclipse/tm4e/core/model/Tokenizer.java | 2 +- .../org/eclipse/tm4e/core/theme/ColorMap.java | 2 +- .../tm4e/core/theme/ParsedThemeRule.java | 4 +- .../org/eclipse/tm4e/core/theme/Theme.java | 6 +-- .../tm4e/core/theme/ThemeTrieElement.java | 4 +- .../tm4e/core/theme/ThemeTrieElementRule.java | 2 +- .../tm4e/core/internal/grammar/parser/Foo.xml | 11 +++++ .../core/internal/grammar/parser/FooTest.java | 49 +++++++++++++++++++ 41 files changed, 142 insertions(+), 82 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java index 68d8810a2..dcafe20ae 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/TMException.java @@ -19,11 +19,11 @@ public class TMException extends RuntimeException { private static final long serialVersionUID = 1L; - public TMException(String message) { + public TMException(final String message) { super(message); } - public TMException(String message, Throwable cause) { + public TMException(final String message, final Throwable cause) { super(message, cause); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java index 81081c901..6c33439ae 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BalancedBracketSelectors.java @@ -28,7 +28,7 @@ public class BalancedBracketSelectors { private boolean allowAny = false; - BalancedBracketSelectors(List balancedBracketScopes, List unbalancedBracketScopes) { + BalancedBracketSelectors(final List balancedBracketScopes, final List unbalancedBracketScopes) { this.balancedBracketScopes = balancedBracketScopes.stream() .flatMap(selector -> { if ("*".equals(selector)) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index 38aa3af2d..c1e6c2c4e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -80,8 +80,8 @@ public Grammar( final IRawGrammar grammar, final int initialLanguage, @Nullable final Map embeddedLanguages, - @Nullable Map tokenTypes, - @Nullable BalancedBracketSelectors balancedBracketSelectors, + @Nullable final Map tokenTypes, + @Nullable final BalancedBracketSelectors balancedBracketSelectors, final IGrammarRepository grammarRepository, final IThemeProvider themeProvider) { this.scopeName = scopeName; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index ef33a20b3..976581741 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -101,7 +101,7 @@ private LineTokenizer(final Grammar grammar, final OnigString lineText, final bo this.lineTokens = lineTokens; } - private StackElement scan(boolean checkWhileConditions) { + private StackElement scan(final boolean checkWhileConditions) { stop = false; if (checkWhileConditions) { @@ -556,7 +556,7 @@ static StackElement tokenizeString(final Grammar grammar, final OnigString lineT return new LineTokenizer(grammar, lineText, isFirstLine, linePos, stack, lineTokens).scan(checkWhileConditions); } - static String debugCompiledRuleToString(CompiledRule ruleScanner) { + static String debugCompiledRuleToString(final CompiledRule ruleScanner) { final var r = new ArrayList(); for (int i = 0, l = ruleScanner.rules.length; i < l; i++) { r.add(" - " + ruleScanner.rules[i] + ": " + ruleScanner.debugRegExps.get(i)); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 9f305d962..0a21ff1a6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -58,8 +58,8 @@ final class LineTokens { @Nullable private final BalancedBracketSelectors balancedBracketSelectors; - LineTokens(final boolean emitBinaryTokens, final String lineText, List tokenTypeOverrides, - @Nullable BalancedBracketSelectors balancedBracketSelectors) { + LineTokens(final boolean emitBinaryTokens, final String lineText, final List tokenTypeOverrides, + @Nullable final BalancedBracketSelectors balancedBracketSelectors) { this.emitBinaryTokens = emitBinaryTokens; this.lineText = LOGGER.isLoggable(TRACE) ? lineText : null; // store line only if it's logged if (this.emitBinaryTokens) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java index f6cc1f3ca..876e5f225 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/RawGrammar.java @@ -146,7 +146,7 @@ public void putAll(@Nullable final Map target) { + public void putEntries(final PropertySettable target) { for (final var entry : entrySet()) { target.setProperty(entry.getKey(), entry.getValue()); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java index 2c5408c3f..895939052 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadata.java @@ -64,7 +64,7 @@ static int getBackground(final int metadata) { * A value of `0`, `NotSet` or `null` indicates that the corresponding field should be left as is. */ static int set(final int metadata, final int languageId, final /*OptionalStandardTokenType*/ int tokenType, - @Nullable Boolean containsBalancedBrackets, final int fontStyle, final int foreground, int background) { + @Nullable final Boolean containsBalancedBrackets, final int fontStyle, final int foreground, final int background) { final var _languageId = languageId == 0 ? getLanguageId(metadata) : languageId; final var _tokenType = tokenType == OptionalStandardTokenType.NotSet ? getTokenType(metadata) : tokenType; final var _containsBalancedBracketsBit = (containsBalancedBrackets == null ? containsBalancedBrackets(metadata) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java index 77003339d..5c8dc42b8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/reader/GrammarReader.java @@ -60,7 +60,7 @@ public static IRawGrammar readGrammarSync(final String filePath, final InputStre } private static PListParser getGrammarParser(final String filePath) { - String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); + final String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); switch (extension) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java index 765c8e010..b450a3d5e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherBuilder.java @@ -152,7 +152,7 @@ private Matcher parseInnerExpression() { /** * https://github.com/microsoft/vscode-textmate/blob/master/src/matcher.ts#L89 */ - private boolean isIdentifier(String token) { + private boolean isIdentifier(final String token) { if (token.isEmpty()) return false; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/NameMatcher.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/NameMatcher.java index 439f82d1e..5faca95c2 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/NameMatcher.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/matcher/NameMatcher.java @@ -54,7 +54,7 @@ private boolean scopesAreMatching(@Nullable final String thisScopeName, final St if (thisScopeName.equals(scopeName)) { return true; } - int len = scopeName.length(); + final int len = scopeName.length(); return thisScopeName.length() > len && thisScopeName.substring(0, len).equals(scopeName) && thisScopeName.charAt(len) == '.'; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java index 57c9b3a67..fbd4398d6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigCaptureIndex.java @@ -24,7 +24,7 @@ public final class OnigCaptureIndex { public final int start; public final int end; - OnigCaptureIndex(final int index, int start, final int end) { + OnigCaptureIndex(final int index, final int start, final int end) { this.index = index; this.start = start >= 0 ? start : 0; this.end = end >= 0 ? end : 0; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java index 2997f5b97..77269b77f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java @@ -54,7 +54,7 @@ final class OnigRegExp { try { regex = new Regex(pattern, 0, pattern.length, Option.CAPTURE_GROUP, UTF8Encoding.INSTANCE, Syntax.DEFAULT, WarnCallback.DEFAULT); - } catch (SyntaxException ex) { + } catch (final SyntaxException ex) { throw new TMException("Parsing regex pattern \"" + source + "\" failed with " + ex, ex); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java index 9122036d0..363e158c3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigString.java @@ -83,7 +83,7 @@ private int[] getByteToCharOffsets() { while (byteIndex <= maxByteIndex) { final int charLenInBytes = UTF8Encoding.INSTANCE.length(bytesUTF8, byteIndex, bytesCount); // same as "Arrays.fill(offsets, byteIndex, byteIndex + charLenInBytes, charIndex)" but faster - for (int l = byteIndex + charLenInBytes; byteIndex < l; byteIndex++) { + for (final int l = byteIndex + charLenInBytes; byteIndex < l; byteIndex++) { offsets[byteIndex] = charIndex; } charIndex++; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java index 602cb7681..ec8455282 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/parser/PListContentHandler.java @@ -37,7 +37,7 @@ private static final class PListPathImpl implements PListPath { final List keysDepths = new ArrayList<>(); int depth = 0; - void add(String key) { + void add(final String key) { trim(); keysDepths.add(depth); keys.add(key); @@ -53,7 +53,7 @@ void trim() { } @Override - public String get(int index) { + public String get(final int index) { return keys.get(index); } @@ -155,7 +155,7 @@ public void endElement(@Nullable final String uri, @Nullable final String localN throws SAXException { assert localName != null; - var currObject = this.currObject; + final var currObject = this.currObject; if (currObject == null) { throw new SAXException("Root or element not found!"); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java index 90f7c2c3e..eb5bfac9c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java @@ -116,7 +116,7 @@ public List themeMatch(final String scopeName) { public IGrammar grammarForScopeName(final String scopeName, final int initialLanguage, @Nullable final Map embeddedLanguages, @Nullable final Map tokenTypes, - @Nullable BalancedBracketSelectors balancedBracketSelectors) { + @Nullable final BalancedBracketSelectors balancedBracketSelectors) { if (!this.grammars.containsKey(scopeName)) { final var rawGrammar = lookup(scopeName); if (rawGrammar == null) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java index 4c775a551..79525d380 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginEndRule.java @@ -42,10 +42,10 @@ public final class BeginEndRule extends Rule { @Nullable private RegExpSourceList cachedCompiledPatterns; - BeginEndRule(int id, @Nullable String name, @Nullable String contentName, String begin, - List<@Nullable CaptureRule> beginCaptures, @Nullable String end, List<@Nullable CaptureRule> endCaptures, - boolean applyEndPatternLast, - CompilePatternsResult patterns) { + BeginEndRule(final int id, @Nullable final String name, @Nullable final String contentName, final String begin, + final List<@Nullable CaptureRule> beginCaptures, @Nullable final String end, final List<@Nullable CaptureRule> endCaptures, + final boolean applyEndPatternLast, + final CompilePatternsResult patterns) { super(id, name, contentName); this.begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; @@ -57,7 +57,7 @@ public final class BeginEndRule extends Rule { this.hasMissingPatterns = patterns.hasMissingPatterns; } - public String getEndWithResolvedBackReferences(String lineText, OnigCaptureIndex[] captureIndices) { + public String getEndWithResolvedBackReferences(final String lineText, final OnigCaptureIndex[] captureIndices) { return this.end.resolveBackReferences(lineText, captureIndices); } @@ -75,7 +75,7 @@ public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSo } @Override - public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + public CompiledRule compile(final IRuleRegistry grammar, @Nullable final String endRegexSource) { return getCachedCompiledPatterns(grammar, endRegexSource).compile(); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java index 3964beedc..e8948f8be 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/BeginWhileRule.java @@ -42,9 +42,9 @@ public final class BeginWhileRule extends Rule { @Nullable private RegExpSourceList cachedCompiledWhilePatterns; - BeginWhileRule(int id, @Nullable String name, @Nullable String contentName, String begin, - List<@Nullable CaptureRule> beginCaptures, String _while, List<@Nullable CaptureRule> whileCaptures, - CompilePatternsResult patterns) { + BeginWhileRule(final int id, @Nullable final String name, @Nullable final String contentName, final String begin, + final List<@Nullable CaptureRule> beginCaptures, final String _while, final List<@Nullable CaptureRule> whileCaptures, + final CompilePatternsResult patterns) { super(/* $location, */id, name, contentName); this.begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; @@ -55,15 +55,15 @@ public final class BeginWhileRule extends Rule { this.hasMissingPatterns = patterns.hasMissingPatterns; } - public String getWhileWithResolvedBackReferences(String lineText, OnigCaptureIndex[] captureIndices) { + public String getWhileWithResolvedBackReferences(final String lineText, final OnigCaptureIndex[] captureIndices) { return this._while.resolveBackReferences(lineText, captureIndices); } @Override - public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSourceList out, final boolean isFirst) { if (isFirst) { Rule rule; - for (int pattern : patterns) { + for (final int pattern : patterns) { rule = grammar.getRule(pattern); rule.collectPatternsRecursive(grammar, out, false); } @@ -73,13 +73,13 @@ public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out } @Override - public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + public CompiledRule compile(final IRuleRegistry grammar, @Nullable final String endRegexSource) { return getCachedCompiledPatterns(grammar).compile(); } @Override - public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, - boolean allowG) { + public CompiledRule compileAG(final IRuleRegistry grammar, @Nullable final String endRegexSource, final boolean allowA, + final boolean allowG) { return getCachedCompiledPatterns(grammar).compileAG(allowA, allowG); } @@ -97,7 +97,7 @@ public CompiledRule compileWhile(@Nullable final String endRegexSource) { return getCachedCompiledWhilePatterns(endRegexSource).compile(); } - public CompiledRule compileWhileAG(@Nullable final String endRegexSource, boolean allowA, boolean allowG) { + public CompiledRule compileWhileAG(@Nullable final String endRegexSource, final boolean allowA, final boolean allowG) { return getCachedCompiledWhilePatterns(endRegexSource).compileAG(allowA, allowG); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java index b6f9959ed..991bea032 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CaptureRule.java @@ -28,25 +28,25 @@ public final class CaptureRule extends Rule { @Nullable public final Integer retokenizeCapturedWithRuleId; - CaptureRule(int id, @Nullable String name, @Nullable String contentName, - @Nullable Integer retokenizeCapturedWithRuleId) { + CaptureRule(final int id, @Nullable final String name, @Nullable final String contentName, + @Nullable final Integer retokenizeCapturedWithRuleId) { super(id, name, contentName); this.retokenizeCapturedWithRuleId = retokenizeCapturedWithRuleId; } @Override - public void collectPatternsRecursive(IRuleRegistry grammar, RegExpSourceList out, boolean isFirst) { + public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSourceList out, final boolean isFirst) { throw new UnsupportedOperationException(); } @Override - public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + public CompiledRule compile(final IRuleRegistry grammar, @Nullable final String endRegexSource) { throw new UnsupportedOperationException(); } @Override - public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, - boolean allowG) { + public CompiledRule compileAG(final IRuleRegistry grammar, @Nullable final String endRegexSource, final boolean allowA, + final boolean allowG) { throw new UnsupportedOperationException(); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java index ccda08333..582122ab8 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompilePatternsResult.java @@ -26,7 +26,7 @@ final class CompilePatternsResult { final int[] patterns; final boolean hasMissingPatterns; - CompilePatternsResult(int[] patterns, boolean hasMissingPatterns) { + CompilePatternsResult(final int[] patterns, final boolean hasMissingPatterns) { this.hasMissingPatterns = hasMissingPatterns; this.patterns = patterns; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java index e4a91483b..32d94b68a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/CompiledRule.java @@ -31,7 +31,7 @@ public final class CompiledRule { public final OnigScanner scanner; public final int[] rules; - CompiledRule(List regExps, int[] rules) { + CompiledRule(final List regExps, final int[] rules) { this.debugRegExps = regExps; this.rules = rules; this.scanner = new OnigScanner(regExps); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java index bf987d5b5..5e4b57a65 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/IncludeOnlyRule.java @@ -48,13 +48,13 @@ public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSo } @Override - public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + public CompiledRule compile(final IRuleRegistry grammar, @Nullable final String endRegexSource) { return getCachedCompiledPatterns(grammar).compile(); } @Override - public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, - boolean allowG) { + public CompiledRule compileAG(final IRuleRegistry grammar, @Nullable final String endRegexSource, final boolean allowA, + final boolean allowG) { return getCachedCompiledPatterns(grammar).compileAG(allowA, allowG); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java index e585638c3..3d71100f1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/MatchRule.java @@ -46,13 +46,13 @@ public void collectPatternsRecursive(final IRuleRegistry grammar, final RegExpSo } @Override - public CompiledRule compile(IRuleRegistry grammar, @Nullable String endRegexSource) { + public CompiledRule compile(final IRuleRegistry grammar, @Nullable final String endRegexSource) { return getCachedCompiledPatterns(grammar).compile(); } @Override - public CompiledRule compileAG(IRuleRegistry grammar, @Nullable String endRegexSource, boolean allowA, - boolean allowG) { + public CompiledRule compileAG(final IRuleRegistry grammar, @Nullable final String endRegexSource, final boolean allowA, + final boolean allowG) { return getCachedCompiledPatterns(grammar).compileAG(allowA, allowG); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java index 122a5ab62..0d1bbc3a4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RegExpSource.java @@ -117,7 +117,7 @@ String resolveBackReferences(final String lineText, final OnigCaptureIndex[] cap final var replacement = RegexSource.escapeRegExpCharacters(capturedValues.get(index)); return Matcher.quoteReplacement(replacement); // see https://stackoverflow.com/a/70785772/5116073 } - } catch (NumberFormatException ex) { + } catch (final NumberFormatException ex) { // ignore } return ""; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index 4adc263fc..077e2e3ff 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -134,7 +134,7 @@ begin, compileCaptures( } // Fill out result - for (String captureId : captures.getCaptureIds()) { + for (final String captureId : captures.getCaptureIds()) { final int numericCaptureId = parseInt(captureId, 10); final IRawRule rule = captures.getCapture(captureId); final Integer retokenizeCapturedWithRuleId = rule.getPatterns() == null @@ -149,7 +149,7 @@ begin, compileCaptures( private static int parseInt(final String string, final int base) { try { return Integer.parseInt(string, base); - } catch (NumberFormatException ex) { + } catch (final NumberFormatException ex) { return 0; } } @@ -185,7 +185,7 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< } else { final String externalGrammarName; final String externalGrammarInclude; - int sharpIndex = patternInclude.indexOf('#'); + final int sharpIndex = patternInclude.indexOf('#'); if (sharpIndex >= 0) { externalGrammarName = patternInclude.substring(0, sharpIndex); externalGrammarInclude = patternInclude.substring(sharpIndex + 1); @@ -220,7 +220,7 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< Rule rule; try { rule = helper.getRule(patternId); - } catch (IndexOutOfBoundsException ex) { + } catch (final IndexOutOfBoundsException ex) { rule = null; if (patternInclude != null) { // TODO currently happens if an include rule references another not yet parsed rule diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index 1b5497a4f..81ad2cede 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -69,7 +69,7 @@ public String getForeground() { } @Override - public void setProperty(String name, Object value) { + public void setProperty(final String name, final Object value) { put(name, value); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java index 3fe79a69e..8d2a15ac7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java @@ -45,7 +45,7 @@ public static IRawTheme readThemeSync(final String filePath, final InputStream i } private static PListParser getThemeParser(final String filePath) { - String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); + final String extension = filePath.substring(filePath.lastIndexOf('.') + 1).trim().toLowerCase(); switch (extension) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java index 3895fa8de..43d9905fe 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/types/IRawRepository.java @@ -22,7 +22,7 @@ public interface IRawRepository { - static IRawRepository merge(@Nullable IRawRepository... sources) { + static IRawRepository merge(@Nullable final IRawRepository... sources) { final RawRepository merged = new RawRepository(); for (final var source : sources) { if (source == null) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java index b0bbbe9b7..35c10479d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java @@ -16,7 +16,7 @@ public static int strcmp(@Nullable final String a, @Nullable final String b) { if (b == null) { return 1; } - int result = a.compareTo(b); + final int result = a.compareTo(b); if (result < 0) { return -1; } else if (result > 0) { @@ -35,11 +35,11 @@ public static int strArrCmp(@Nullable final List a, @Nullable final List if (b == null) { return 1; } - int len1 = a.size(); - int len2 = b.size(); + final int len1 = a.size(); + final int len2 = b.size(); if (len1 == len2) { for (int i = 0; i < len1; i++) { - int res = strcmp(a.get(i), b.get(i)); + final int res = strcmp(a.get(i), b.get(i)); if (res != 0) { return res; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java index bed9fe1a4..ca63d74b5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/DeepCloneable.java @@ -25,7 +25,7 @@ public interface DeepCloneable { @SuppressWarnings("unchecked") - public static T deepClone(T obj) { + public static T deepClone(final T obj) { if (obj instanceof DeepCloneable) { return (T) ((DeepCloneable) obj).deepClone(); } @@ -94,7 +94,7 @@ public static T deepClone(T obj) { } @Nullable - public static T deepCloneNullable(@Nullable T obj) { + public static T deepCloneNullable(@Nullable final T obj) { if (obj == null) { return null; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java index 2a5033f54..426cddcc6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/MoreCollections.java @@ -19,7 +19,7 @@ public final class MoreCollections { @Nullable - public static T findLastElement(@Nullable List list) { + public static T findLastElement(@Nullable final List list) { if (list == null || list.isEmpty()) return null; return getLastElement(list); @@ -28,7 +28,7 @@ public static T findLastElement(@Nullable List list) { /** * @param list a non-empty list with non-nullable elements */ - public static T getLastElement(List list) { + public static T getLastElement(final List list) { return list.get(list.size() - 1); } @@ -40,7 +40,7 @@ public static T getLastElement(List list) { * @throws UnsupportedOperationException if the {@code remove} operation is not supported by this list * @throws IndexOutOfBoundsException if the list is empty */ - public static T removeLastElement(List list) { + public static T removeLastElement(final List list) { return list.remove(list.size() - 1); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java index 931e0fbd1..513a5b3ea 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java @@ -19,13 +19,13 @@ public final class NullSafetyHelper { - public static Iterator<@NonNull T> castNonNull(@Nullable Iterator value) { + public static Iterator<@NonNull T> castNonNull(@Nullable final Iterator value) { assert value != null; return value; } @NonNull - public static T castNonNull(@Nullable T value) { + public static T castNonNull(@Nullable final T value) { assert value != null; return value; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index e7ee86427..e4e020438 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -288,7 +288,7 @@ public void dispose() { * Interrupt the thread. */ private synchronized void stop() { - var fThread = this.fThread; + final var fThread = this.fThread; if (fThread == null) { return; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java index fdb9eb2a9..f11ae8e4e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java @@ -43,7 +43,7 @@ public LineTokens tokenize(final String line, final TMState state) { } @Override - public LineTokens tokenize(final String line, @Nullable final TMState state, @Nullable Integer offsetDeltaOrNull, + public LineTokens tokenize(final String line, @Nullable final TMState state, @Nullable final Integer offsetDeltaOrNull, @Nullable final Integer stopAtOffset) { /* Do not attempt to tokenize if a line has over 20k or diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java index 5a12cbd7b..0d0428a65 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ColorMap.java @@ -34,7 +34,7 @@ public ColorMap() { this(null); } - public ColorMap(@Nullable List colorMap) { + public ColorMap(@Nullable final List colorMap) { if (colorMap != null) { this.isFrozen = true; for (int i = 0, len = colorMap.size(); i < len; i++) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java index 9b31cc96a..792e2a093 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java @@ -62,14 +62,14 @@ public int hashCode() { } @Override - public boolean equals(@Nullable Object obj) { + public boolean equals(@Nullable final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; - ParsedThemeRule other = (ParsedThemeRule) obj; + final ParsedThemeRule other = (ParsedThemeRule) obj; return Objects.equals(background, other.background) && fontStyle == other.fontStyle && Objects.equals(foreground, other.foreground) && index == other.index && Objects.equals(parentScopes, other.parentScopes) && Objects.equals(scope, other.scope); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java index 0487e110a..990d75a2d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java @@ -46,11 +46,11 @@ public class Theme { private static final Pattern RGB = Pattern.compile("^#[0-9a-f]{3}", Pattern.CASE_INSENSITIVE); private static final Pattern RGBA = Pattern.compile("^#[0-9a-f]{4}", Pattern.CASE_INSENSITIVE); - public static Theme createFromRawTheme(@Nullable final IRawTheme source, @Nullable List colorMap) { + public static Theme createFromRawTheme(@Nullable final IRawTheme source, @Nullable final List colorMap) { return createFromParsedTheme(parseTheme(source), colorMap); } - public static Theme createFromParsedTheme(final List source, @Nullable List colorMap) { + public static Theme createFromParsedTheme(final List source, @Nullable final List colorMap) { return resolveParsedThemeRules(source, colorMap); } @@ -182,7 +182,7 @@ public static List parseTheme(@Nullable final IRawTheme source) * Resolve rules (i.e. inheritance). */ public static Theme resolveParsedThemeRules(final List _parsedThemeRules, - @Nullable List _colorMap) { + @Nullable final List _colorMap) { // copy the list since we cannot be sure the given list is mutable final var parsedThemeRules = new ArrayList<>(_parsedThemeRules); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java index df582c4d9..dba44e47e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java @@ -183,12 +183,12 @@ public int hashCode() { } @Override - public boolean equals(@Nullable Object obj) { + public boolean equals(@Nullable final Object obj) { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; - ThemeTrieElement other = (ThemeTrieElement) obj; + final ThemeTrieElement other = (ThemeTrieElement) obj; return children.equals(other.children) && mainRule.equals(other.mainRule) && rulesWithParentScopes.equals(other.rulesWithParentScopes); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java index f8184fe45..77a333830 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java @@ -51,7 +51,7 @@ public ThemeTrieElementRule clone() { public static List cloneArr(final List arr) { final var r = new ArrayList(arr.size()); - for (var e : arr) { + for (final var e : arr) { r.add(e.clone()); } return r; diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml new file mode 100644 index 000000000..6bec4503f --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml @@ -0,0 +1,11 @@ + + + key1 + + key2 + + key3 + foo + + + \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java new file mode 100644 index 000000000..fb689622f --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2015-2017 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + */ +package org.eclipse.tm4e.core.internal.grammar.parser; + +import static org.junit.jupiter.api.Assertions.*; + +import org.eclipse.tm4e.core.internal.grammar.RawGrammar; +import org.eclipse.tm4e.core.internal.grammar.RawRule; +import org.eclipse.tm4e.core.internal.parser.PListParser; +import org.eclipse.tm4e.core.internal.parser.PListParserXML; +import org.eclipse.tm4e.core.internal.parser.PListPath; +import org.eclipse.tm4e.core.internal.parser.PropertySettable; +import org.junit.jupiter.api.Test; + +public class FooTest { + + private static final PropertySettable.Factory OBJECT_FACTORY = path -> { + switch (path.size()) { + case 0: + return new RawGrammar(); + case 1: + switch (path.last()) { + case "repository": + return new RawRule(); + } + } + return new RawRule(); + }; + + + @Test + void testParseXMLPlist() throws Exception { + final PListParser parser = new PListParserXML<>(OBJECT_FACTORY); + try (final var is = FooTest.class.getResourceAsStream("Foo.xml")) { + final var grammar = parser.parse(is); + assertNotNull(grammar); + System.out.println(grammar); + } + } +} From 51b21d2f29829c2e9d88431797df30187d65d6d7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 4 May 2022 18:17:24 +0200 Subject: [PATCH 166/202] Reduce field visibility --- .../tm4e/core/internal/grammar/StackElement.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElement.java index 1e5a23c47..7d1cbf435 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StackElement.java @@ -57,40 +57,39 @@ public final class StackElement implements IStackElement { * The previous state on the stack (or null for the root state). */ @Nullable - public final StackElement parent; + final StackElement parent; /** * The depth of the stack. */ - public final int depth; + final int depth; /** * The state (rule) that this element represents. */ - public final int ruleId; + final int ruleId; /** * The state has entered and captured \n. This means that the next line should have an anchorPosition of 0. */ - public final boolean beginRuleCapturedEOL; + final boolean beginRuleCapturedEOL; /** * The "pop" (end) condition for this state in case that it was dynamically generated through captured text. */ @Nullable - public final String endRule; + final String endRule; /** * The list of scopes containing the "name" for this state. */ - - public final ScopeListElement nameScopesList; + final ScopeListElement nameScopesList; /** * The list of scopes containing the "contentName" (besides "name") for this state. * This list **must** contain as an element `scopeName`. */ - public final ScopeListElement contentNameScopesList; + final ScopeListElement contentNameScopesList; StackElement( @Nullable final StackElement parent, From 591deb0acb594b813fb35b745b3d1e2fa78329cb Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 4 May 2022 19:40:06 +0200 Subject: [PATCH 167/202] Remove obsolete files --- .../tm4e/core/internal/grammar/parser/Foo.xml | 11 ----- .../core/internal/grammar/parser/FooTest.java | 49 ------------------- 2 files changed, 60 deletions(-) delete mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml delete mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml deleted file mode 100644 index 6bec4503f..000000000 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/Foo.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - key1 - - key2 - - key3 - foo - - - \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java deleted file mode 100644 index fb689622f..000000000 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/FooTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.core.internal.grammar.parser; - -import static org.junit.jupiter.api.Assertions.*; - -import org.eclipse.tm4e.core.internal.grammar.RawGrammar; -import org.eclipse.tm4e.core.internal.grammar.RawRule; -import org.eclipse.tm4e.core.internal.parser.PListParser; -import org.eclipse.tm4e.core.internal.parser.PListParserXML; -import org.eclipse.tm4e.core.internal.parser.PListPath; -import org.eclipse.tm4e.core.internal.parser.PropertySettable; -import org.junit.jupiter.api.Test; - -public class FooTest { - - private static final PropertySettable.Factory OBJECT_FACTORY = path -> { - switch (path.size()) { - case 0: - return new RawGrammar(); - case 1: - switch (path.last()) { - case "repository": - return new RawRule(); - } - } - return new RawRule(); - }; - - - @Test - void testParseXMLPlist() throws Exception { - final PListParser parser = new PListParserXML<>(OBJECT_FACTORY); - try (final var is = FooTest.class.getResourceAsStream("Foo.xml")) { - final var grammar = parser.parse(is); - assertNotNull(grammar); - System.out.println(grammar); - } - } -} From e3aac3274262c2e3b274294d2565c35f61c1f8d4 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Thu, 5 May 2022 11:25:02 +0200 Subject: [PATCH 168/202] Move attach-p2-metadata to verify phase So jarsigner runs before --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 638eaa627..6650f2840 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,6 @@ 3.0.0-SNAPSHOT ../target/jacoco.exec scm:git:https://github.com/eclipse/tm4e.git - true error @@ -138,7 +137,7 @@ attach-p2-metadata - package + verify p2-metadata From ec3ca2503b490206e313cda22792ad137419b57d Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 12:29:05 +0200 Subject: [PATCH 169/202] Rename GrammarTest to StackElementMetadataTest --- .../grammar/{GrammarTest.java => StackElementMetadataTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/{GrammarTest.java => StackElementMetadataTest.java} (99%) diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadataTest.java similarity index 99% rename from org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java rename to org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadataTest.java index e2803b324..9a28af891 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/GrammarTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/StackElementMetadataTest.java @@ -22,7 +22,7 @@ * @see * github.com/Microsoft/vscode-textmate/blob/master/src/tests/grammar.test.ts */ -public class GrammarTest { +public class StackElementMetadataTest { @Test public void testWorks() { From cd767c904242907a413f58e8bfc4dc9008384836 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 13:20:06 +0200 Subject: [PATCH 170/202] add multi-line yaml test --- .../tm4e/core/grammar/GrammarTest2.java | 89 ++- .../tm4e/core/grammar/TokenizationUtils.java | 82 +++ .../eclipse/tm4e/core/yaml.tmLanguage.json | 621 ++++++++++++++++++ 3 files changed, 757 insertions(+), 35 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/TokenizationUtils.java create mode 100644 org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/yaml.tmLanguage.json diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java index 62e3e099d..97b0fee52 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/GrammarTest2.java @@ -1,22 +1,23 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.core.grammar; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; import org.eclipse.tm4e.core.Data; import org.eclipse.tm4e.core.registry.Registry; @@ -30,42 +31,60 @@ class GrammarTest2 { @Test void tokenizeLines() throws Exception { - Registry registry = new Registry(); - String path = "JavaScript.tmLanguage"; - IGrammar grammar = castNonNull(registry.loadGrammarFromPathSync(path, Data.class.getResourceAsStream(path))); + final var registry = new Registry(); + final var path = "JavaScript.tmLanguage"; + try (var is = Data.class.getResourceAsStream(path)) { + final var grammar = castNonNull(registry.loadGrammarFromPathSync(path, is)); - IStackElement ruleStack = null; - int i = 0; + IStackElement ruleStack = null; + int i = 0; - List lines = new ArrayList<>(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Data.class.getResourceAsStream("raytracer.ts")));){ - String line = null; - while ((line = reader.readLine()) != null) { - lines.add(line); + final var lines = new ArrayList(); + try (var reader = new BufferedReader( + new InputStreamReader(Data.class.getResourceAsStream("raytracer.ts")));) { + String line = null; + while ((line = reader.readLine()) != null) { + lines.add(line); + } } - } catch (Exception e) { - e.printStackTrace(); - } - int t = 0; - boolean stop = false; - long start = System.currentTimeMillis(); - for (String line : lines) { - ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack); - if (stop) { - t = 1000; - Thread.sleep(t); - stop = false; - } - ruleStack = lineTokens.getRuleStack(); - for (i = 0; i < lineTokens.getTokens().length; i++) { - IToken token = lineTokens.getTokens()[i]; - String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes " - + token.getScopes(); - System.err.println(s); - // Assert.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s); + int t = 0; + boolean stop = false; + long start = System.currentTimeMillis(); + for (String line : lines) { + ITokenizeLineResult lineTokens = grammar.tokenizeLine(line, ruleStack); + if (stop) { + t = 1000; + Thread.sleep(t); + stop = false; + } + ruleStack = lineTokens.getRuleStack(); + for (i = 0; i < lineTokens.getTokens().length; i++) { + IToken token = lineTokens.getTokens()[i]; + String s = "Token from " + token.getStartIndex() + " to " + token.getEndIndex() + " with scopes " + + token.getScopes(); + // System.err.println(s); + // Assert.assertEquals(EXPECTED_MULTI_LINE_TOKENS[i + j], s); + } } + System.out.println(System.currentTimeMillis() - start - t); + } + } + + @Test + public void testYamlMultiline() throws Exception { + final var registry = new Registry(); + final var path = "yaml.tmLanguage.json"; + try (var in = Data.class.getResourceAsStream(path)) { + final var grammar = castNonNull(registry.loadGrammarFromPathSync(path, in)); + String lines = ">\n should.be.string.unquoted.block.yaml\n should.also.be.string.unquoted.block.yaml"; + final var result = TokenizationUtils.tokenizeText(lines, grammar).iterator(); + assertTrue(Arrays.stream(result.next().getTokens()) + .anyMatch(t -> t.getScopes().contains("keyword.control.flow.block-scalar.folded.yaml"))); + assertTrue(Arrays.stream(result.next().getTokens()) + .anyMatch(t -> t.getScopes().contains("string.unquoted.block.yaml"))); + assertTrue(Arrays.stream(result.next().getTokens()) + .anyMatch(t -> t.getScopes().contains("string.unquoted.block.yaml"))); } - System.out.println(System.currentTimeMillis() - start - t); } } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/TokenizationUtils.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/TokenizationUtils.java new file mode 100644 index 000000000..66991e7e5 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/grammar/TokenizationUtils.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Thomschke - initial implementation + */ +package org.eclipse.tm4e.core.grammar; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.function.Function; +import java.util.stream.Stream; + +import org.eclipse.jdt.annotation.Nullable; + +import com.google.common.base.Splitter; + +public class TokenizationUtils { + + private static final Splitter BY_LINE_SPLITTER = Splitter.onPattern("\\r?\\n"); + + /** + * Lazy tokenizes the given text. + * + * @param text the text to tokenize + * + * @return The stream of {@link ITokenizeLineResult}, each item covering 1 line of the text + */ + public static Stream tokenizeText(final CharSequence text, IGrammar grammar) { + if (text.length() == 0) { + return Stream.empty(); + } + + return BY_LINE_SPLITTER.splitToStream(text).map(new Function() { + @Nullable + IStackElement prevStack; + + @Override + public ITokenizeLineResult apply(String line) { + final var tokenized = grammar.tokenizeLine(line, prevStack); + prevStack = tokenized.getRuleStack(); + return tokenized; + } + }); + } + + /** + * Lazy tokenizes the text provided by the given input stream. + * + * @param text the text to tokenize + * + * @return The stream of {@link ITokenizeLineResult}, each item covering 1 line of the text + * + * @throws IOException + */ + public static Stream tokenizeText(final InputStream text, IGrammar grammar) + throws IOException { + var reader = new BufferedReader(new InputStreamReader(text)); + return reader.lines().map(new Function() { + @Nullable + IStackElement prevStack; + + @Override + public ITokenizeLineResult apply(String line) { + final var tokenized = grammar.tokenizeLine(line, prevStack); + prevStack = tokenized.getRuleStack(); + return tokenized; + } + }); + } + + private TokenizationUtils() { + } +} diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/yaml.tmLanguage.json b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/yaml.tmLanguage.json new file mode 100644 index 000000000..c3637dfc9 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/yaml.tmLanguage.json @@ -0,0 +1,621 @@ +{ + "information_for_contributors": [ + "This file has been converted from https://github.com/textmate/yaml.tmbundle/blob/master/Syntaxes/YAML.tmLanguage", + "If you want to provide a fix or improvement, please create a pull request against the original repository.", + "Once accepted there, we are happy to receive an update request." + ], + "version": "https://github.com/textmate/yaml.tmbundle/commit/e54ceae3b719506dba7e481a77cea4a8b576ae46", + "name": "YAML", + "scopeName": "source.yaml", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#property" + }, + { + "include": "#directive" + }, + { + "match": "^---", + "name": "entity.other.document.begin.yaml" + }, + { + "match": "^\\.{3}", + "name": "entity.other.document.end.yaml" + }, + { + "include": "#node" + } + ], + "repository": { + "block-collection": { + "patterns": [ + { + "include": "#block-sequence" + }, + { + "include": "#block-mapping" + } + ] + }, + "block-mapping": { + "patterns": [ + { + "include": "#block-pair" + } + ] + }, + "block-node": { + "patterns": [ + { + "include": "#prototype" + }, + { + "include": "#block-scalar" + }, + { + "include": "#block-collection" + }, + { + "include": "#flow-scalar-plain-out" + }, + { + "include": "#flow-node" + } + ] + }, + "block-pair": { + "patterns": [ + { + "begin": "\\?", + "beginCaptures": { + "1": { + "name": "punctuation.definition.key-value.begin.yaml" + } + }, + "end": "(?=\\?)|^ *(:)|(:)", + "endCaptures": { + "1": { + "name": "punctuation.separator.key-value.mapping.yaml" + }, + "2": { + "name": "invalid.illegal.expected-newline.yaml" + } + }, + "name": "meta.block-mapping.yaml", + "patterns": [ + { + "include": "#block-node" + } + ] + }, + { + "begin": "(?x)\n (?=\n (?x:\n [^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]\n | [?:-] \\S\n )\n (\n [^\\s:]\n | : \\S\n | \\s+ (?![#\\s])\n )*\n \\s*\n :\n\t\t\t\t\t\t\t(\\s|$)\n )\n ", + "end": "(?x)\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n )\n ", + "patterns": [ + { + "include": "#flow-scalar-plain-out-implicit-type" + }, + { + "begin": "(?x)\n [^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]\n | [?:-] \\S\n ", + "beginCaptures": { + "0": { + "name": "entity.name.tag.yaml" + } + }, + "contentName": "entity.name.tag.yaml", + "end": "(?x)\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n )\n ", + "name": "string.unquoted.plain.out.yaml" + } + ] + }, + { + "match": ":(?=\\s|$)", + "name": "punctuation.separator.key-value.mapping.yaml" + } + ] + }, + "block-scalar": { + "begin": "(?:(\\|)|(>))([1-9])?([-+])?(.*\\n?)", + "beginCaptures": { + "1": { + "name": "keyword.control.flow.block-scalar.literal.yaml" + }, + "2": { + "name": "keyword.control.flow.block-scalar.folded.yaml" + }, + "3": { + "name": "constant.numeric.indentation-indicator.yaml" + }, + "4": { + "name": "storage.modifier.chomping-indicator.yaml" + }, + "5": { + "patterns": [ + { + "include": "#comment" + }, + { + "match": ".+", + "name": "invalid.illegal.expected-comment-or-newline.yaml" + } + ] + } + }, + "end": "^(?=\\S)|(?!\\G)", + "patterns": [ + { + "begin": "^([ ]+)(?! )", + "end": "^(?!\\1|\\s*$)", + "name": "string.unquoted.block.yaml" + } + ] + }, + "block-sequence": { + "match": "(-)(?!\\S)", + "name": "punctuation.definition.block.sequence.item.yaml" + }, + "comment": { + "begin": "(?:(^[ \\t]*)|[ \\t]+)(?=#\\p{Print}*$)", + "beginCaptures": { + "1": { + "name": "punctuation.whitespace.comment.leading.yaml" + } + }, + "end": "(?!\\G)", + "patterns": [ + { + "begin": "#", + "beginCaptures": { + "0": { + "name": "punctuation.definition.comment.yaml" + } + }, + "end": "\\n", + "name": "comment.line.number-sign.yaml" + } + ] + }, + "directive": { + "begin": "^%", + "beginCaptures": { + "0": { + "name": "punctuation.definition.directive.begin.yaml" + } + }, + "end": "(?=$|[ \\t]+($|#))", + "name": "meta.directive.yaml", + "patterns": [ + { + "captures": { + "1": { + "name": "keyword.other.directive.yaml.yaml" + }, + "2": { + "name": "constant.numeric.yaml-version.yaml" + } + }, + "match": "\\G(YAML)[ \\t]+(\\d+\\.\\d+)" + }, + { + "captures": { + "1": { + "name": "keyword.other.directive.tag.yaml" + }, + "2": { + "name": "storage.type.tag-handle.yaml" + }, + "3": { + "name": "support.type.tag-prefix.yaml" + } + }, + "match": "(?x)\n \\G\n (TAG)\n (?:[ \\t]+\n ((?:!(?:[0-9A-Za-z\\-]*!)?))\n (?:[ \\t]+ (\n ! (?x: %[0-9A-Fa-f]{2} | [0-9A-Za-z\\-#;/?:@&=+$,_.!~*'()\\[\\]] )*\n | (?![,!\\[\\]{}]) (?x: %[0-9A-Fa-f]{2} | [0-9A-Za-z\\-#;/?:@&=+$,_.!~*'()\\[\\]] )+\n )\n )?\n )?\n " + }, + { + "captures": { + "1": { + "name": "support.other.directive.reserved.yaml" + }, + "2": { + "name": "string.unquoted.directive-name.yaml" + }, + "3": { + "name": "string.unquoted.directive-parameter.yaml" + } + }, + "match": "(?x) \\G (\\w+) (?:[ \\t]+ (\\w+) (?:[ \\t]+ (\\w+))? )?" + }, + { + "match": "\\S+", + "name": "invalid.illegal.unrecognized.yaml" + } + ] + }, + "flow-alias": { + "captures": { + "1": { + "name": "keyword.control.flow.alias.yaml" + }, + "2": { + "name": "punctuation.definition.alias.yaml" + }, + "3": { + "name": "variable.other.alias.yaml" + }, + "4": { + "name": "invalid.illegal.character.anchor.yaml" + } + }, + "match": "((\\*))([^\\s\\[\\]/{/},]+)([^\\s\\]},]\\S*)?" + }, + "flow-collection": { + "patterns": [ + { + "include": "#flow-sequence" + }, + { + "include": "#flow-mapping" + } + ] + }, + "flow-mapping": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.definition.mapping.begin.yaml" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.definition.mapping.end.yaml" + } + }, + "name": "meta.flow-mapping.yaml", + "patterns": [ + { + "include": "#prototype" + }, + { + "match": ",", + "name": "punctuation.separator.mapping.yaml" + }, + { + "include": "#flow-pair" + } + ] + }, + "flow-node": { + "patterns": [ + { + "include": "#prototype" + }, + { + "include": "#flow-alias" + }, + { + "include": "#flow-collection" + }, + { + "include": "#flow-scalar" + } + ] + }, + "flow-pair": { + "patterns": [ + { + "begin": "\\?", + "beginCaptures": { + "0": { + "name": "punctuation.definition.key-value.begin.yaml" + } + }, + "end": "(?=[},\\]])", + "name": "meta.flow-pair.explicit.yaml", + "patterns": [ + { + "include": "#prototype" + }, + { + "include": "#flow-pair" + }, + { + "include": "#flow-node" + }, + { + "begin": ":(?=\\s|$|[\\[\\]{},])", + "beginCaptures": { + "0": { + "name": "punctuation.separator.key-value.mapping.yaml" + } + }, + "end": "(?=[},\\]])", + "patterns": [ + { + "include": "#flow-value" + } + ] + } + ] + }, + { + "begin": "(?x)\n (?=\n (?:\n [^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]\n | [?:-] [^\\s[\\[\\]{},]]\n )\n (\n [^\\s:[\\[\\]{},]]\n | : [^\\s[\\[\\]{},]]\n | \\s+ (?![#\\s])\n )*\n \\s*\n :\n\t\t\t\t\t\t\t(\\s|$)\n )\n ", + "end": "(?x)\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n | \\s* : [\\[\\]{},]\n | \\s* [\\[\\]{},]\n )\n ", + "name": "meta.flow-pair.key.yaml", + "patterns": [ + { + "include": "#flow-scalar-plain-in-implicit-type" + }, + { + "begin": "(?x)\n [^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]\n | [?:-] [^\\s[\\[\\]{},]]\n ", + "beginCaptures": { + "0": { + "name": "entity.name.tag.yaml" + } + }, + "contentName": "entity.name.tag.yaml", + "end": "(?x)\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n | \\s* : [\\[\\]{},]\n | \\s* [\\[\\]{},]\n )\n ", + "name": "string.unquoted.plain.in.yaml" + } + ] + }, + { + "include": "#flow-node" + }, + { + "begin": ":(?=\\s|$|[\\[\\]{},])", + "captures": { + "0": { + "name": "punctuation.separator.key-value.mapping.yaml" + } + }, + "end": "(?=[},\\]])", + "name": "meta.flow-pair.yaml", + "patterns": [ + { + "include": "#flow-value" + } + ] + } + ] + }, + "flow-scalar": { + "patterns": [ + { + "include": "#flow-scalar-double-quoted" + }, + { + "include": "#flow-scalar-single-quoted" + }, + { + "include": "#flow-scalar-plain-in" + } + ] + }, + "flow-scalar-double-quoted": { + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.yaml" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.yaml" + } + }, + "name": "string.quoted.double.yaml", + "patterns": [ + { + "match": "\\\\([0abtnvfre \"/\\\\N_Lp]|x\\d\\d|u\\d{4}|U\\d{8})", + "name": "constant.character.escape.yaml" + }, + { + "match": "\\\\\\n", + "name": "constant.character.escape.double-quoted.newline.yaml" + } + ] + }, + "flow-scalar-plain-in": { + "patterns": [ + { + "include": "#flow-scalar-plain-in-implicit-type" + }, + { + "begin": "(?x)\n [^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]\n | [?:-] [^\\s[\\[\\]{},]]\n ", + "end": "(?x)\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n | \\s* : [\\[\\]{},]\n | \\s* [\\[\\]{},]\n )\n ", + "name": "string.unquoted.plain.in.yaml" + } + ] + }, + "flow-scalar-plain-in-implicit-type": { + "patterns": [ + { + "captures": { + "1": { + "name": "constant.language.null.yaml" + }, + "2": { + "name": "constant.language.boolean.yaml" + }, + "3": { + "name": "constant.numeric.integer.yaml" + }, + "4": { + "name": "constant.numeric.float.yaml" + }, + "5": { + "name": "constant.other.timestamp.yaml" + }, + "6": { + "name": "constant.language.value.yaml" + }, + "7": { + "name": "constant.language.merge.yaml" + } + }, + "match": "(?x)\n (?x:\n (null|Null|NULL|~)\n | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)\n | (\n (?:\n [-+]? 0b [0-1_]+ # (base 2)\n | [-+]? 0 [0-7_]+ # (base 8)\n | [-+]? (?: 0|[1-9][0-9_]*) # (base 10)\n | [-+]? 0x [0-9a-fA-F_]+ # (base 16)\n | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60)\n )\n )\n | (\n (?x:\n [-+]? (?: [0-9] [0-9_]*)? \\. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10)\n | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \\. [0-9_]* # (base 60)\n | [-+]? \\. (?: inf|Inf|INF) # (infinity)\n | \\. (?: nan|NaN|NAN) # (not a number)\n )\n )\n | (\n (?x:\n \\d{4} - \\d{2} - \\d{2} # (y-m-d)\n | \\d{4} # (year)\n - \\d{1,2} # (month)\n - \\d{1,2} # (day)\n (?: [Tt] | [ \\t]+) \\d{1,2} # (hour)\n : \\d{2} # (minute)\n : \\d{2} # (second)\n (?: \\.\\d*)? # (fraction)\n (?:\n (?:[ \\t]*) Z\n | [-+] \\d{1,2} (?: :\\d{1,2})?\n )? # (time zone)\n )\n )\n | (=)\n | (<<)\n )\n (?:\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n | \\s* : [\\[\\]{},]\n | \\s* [\\[\\]{},]\n )\n )\n " + } + ] + }, + "flow-scalar-plain-out": { + "patterns": [ + { + "include": "#flow-scalar-plain-out-implicit-type" + }, + { + "begin": "(?x)\n [^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]\n | [?:-] \\S\n ", + "end": "(?x)\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n )\n ", + "name": "string.unquoted.plain.out.yaml" + } + ] + }, + "flow-scalar-plain-out-implicit-type": { + "patterns": [ + { + "captures": { + "1": { + "name": "constant.language.null.yaml" + }, + "2": { + "name": "constant.language.boolean.yaml" + }, + "3": { + "name": "constant.numeric.integer.yaml" + }, + "4": { + "name": "constant.numeric.float.yaml" + }, + "5": { + "name": "constant.other.timestamp.yaml" + }, + "6": { + "name": "constant.language.value.yaml" + }, + "7": { + "name": "constant.language.merge.yaml" + } + }, + "match": "(?x)\n (?x:\n (null|Null|NULL|~)\n | (y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)\n | (\n (?:\n [-+]? 0b [0-1_]+ # (base 2)\n | [-+]? 0 [0-7_]+ # (base 8)\n | [-+]? (?: 0|[1-9][0-9_]*) # (base 10)\n | [-+]? 0x [0-9a-fA-F_]+ # (base 16)\n | [-+]? [1-9] [0-9_]* (?: :[0-5]?[0-9])+ # (base 60)\n )\n )\n | (\n (?x:\n [-+]? (?: [0-9] [0-9_]*)? \\. [0-9.]* (?: [eE] [-+] [0-9]+)? # (base 10)\n | [-+]? [0-9] [0-9_]* (?: :[0-5]?[0-9])+ \\. [0-9_]* # (base 60)\n | [-+]? \\. (?: inf|Inf|INF) # (infinity)\n | \\. (?: nan|NaN|NAN) # (not a number)\n )\n )\n | (\n (?x:\n \\d{4} - \\d{2} - \\d{2} # (y-m-d)\n | \\d{4} # (year)\n - \\d{1,2} # (month)\n - \\d{1,2} # (day)\n (?: [Tt] | [ \\t]+) \\d{1,2} # (hour)\n : \\d{2} # (minute)\n : \\d{2} # (second)\n (?: \\.\\d*)? # (fraction)\n (?:\n (?:[ \\t]*) Z\n | [-+] \\d{1,2} (?: :\\d{1,2})?\n )? # (time zone)\n )\n )\n | (=)\n | (<<)\n )\n (?x:\n (?=\n \\s* $\n | \\s+ \\#\n | \\s* : (\\s|$)\n )\n )\n " + } + ] + }, + "flow-scalar-single-quoted": { + "begin": "'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.yaml" + } + }, + "end": "'(?!')", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.yaml" + } + }, + "name": "string.quoted.single.yaml", + "patterns": [ + { + "match": "''", + "name": "constant.character.escape.single-quoted.yaml" + } + ] + }, + "flow-sequence": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "punctuation.definition.sequence.begin.yaml" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "punctuation.definition.sequence.end.yaml" + } + }, + "name": "meta.flow-sequence.yaml", + "patterns": [ + { + "include": "#prototype" + }, + { + "match": ",", + "name": "punctuation.separator.sequence.yaml" + }, + { + "include": "#flow-pair" + }, + { + "include": "#flow-node" + } + ] + }, + "flow-value": { + "patterns": [ + { + "begin": "\\G(?![},\\]])", + "end": "(?=[},\\]])", + "name": "meta.flow-pair.value.yaml", + "patterns": [ + { + "include": "#flow-node" + } + ] + } + ] + }, + "node": { + "patterns": [ + { + "include": "#block-node" + } + ] + }, + "property": { + "begin": "(?=!|&)", + "end": "(?!\\G)", + "name": "meta.property.yaml", + "patterns": [ + { + "captures": { + "1": { + "name": "keyword.control.property.anchor.yaml" + }, + "2": { + "name": "punctuation.definition.anchor.yaml" + }, + "3": { + "name": "entity.name.type.anchor.yaml" + }, + "4": { + "name": "invalid.illegal.character.anchor.yaml" + } + }, + "match": "\\G((&))([^\\s\\[\\]/{/},]+)(\\S+)?" + }, + { + "match": "(?x)\n \\G\n (?:\n ! < (?: %[0-9A-Fa-f]{2} | [0-9A-Za-z\\-#;/?:@&=+$,_.!~*'()\\[\\]] )+ >\n | (?:!(?:[0-9A-Za-z\\-]*!)?) (?: %[0-9A-Fa-f]{2} | [0-9A-Za-z\\-#;/?:@&=+$_.~*'()] )+\n | !\n )\n (?=\\ |\\t|$)\n ", + "name": "storage.type.tag-handle.yaml" + }, + { + "match": "\\S+", + "name": "invalid.illegal.tag-handle.yaml" + } + ] + }, + "prototype": { + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#property" + } + ] + } + } +} \ No newline at end of file From c9c48f7ada42a5274d382f72f54db5d1781cbcec Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 4 May 2022 20:30:03 +0200 Subject: [PATCH 171/202] add final modifier where applicable --- .../tm4e/registry/GrammarDefinition.java | 4 +- .../registry/TMEclipseRegistryPlugin.java | 8 +-- .../org/eclipse/tm4e/registry/TMResource.java | 12 ++-- .../WorkingCopyGrammarRegistryManager.java | 20 +++---- .../AbstractGrammarRegistryManager.java | 60 +++++++++---------- .../tm4e/registry/internal/GrammarCache.java | 16 ++--- .../internal/GrammarRegistryManager.java | 30 +++++----- .../preferences/PreferenceConstants.java | 1 - .../preferences/PreferenceHelper.java | 4 +- 9 files changed, 77 insertions(+), 78 deletions(-) diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java index 66b5dea1a..095e126a0 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java @@ -43,12 +43,12 @@ public GrammarDefinition() { * * @param scopeName */ - public GrammarDefinition(String scopeName, String path) { + public GrammarDefinition(final String scopeName, final String path) { super(path); this.scopeName = scopeName; } - public GrammarDefinition(IConfigurationElement ce) { + public GrammarDefinition(final IConfigurationElement ce) { super(ce); this.scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java index 138f167b8..06641fe76 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java @@ -31,12 +31,12 @@ static BundleContext getContext() { } @Override - public void start(BundleContext bundleContext) throws Exception { + public void start(final BundleContext bundleContext) throws Exception { TMEclipseRegistryPlugin.context = bundleContext; } @Override - public void stop(BundleContext bundleContext) throws Exception { + public void stop(final BundleContext bundleContext) throws Exception { TMEclipseRegistryPlugin.context = null; } @@ -56,8 +56,8 @@ public static IGrammarRegistryManager getGrammarRegistryManager() { * the option name * @return true if the debug option is enabled and false otherwise. */ - public static boolean isDebugOptionEnabled(String option) { - String enabled = Platform.getDebugOption(option); + public static boolean isDebugOptionEnabled(final String option) { + final String enabled = Platform.getDebugOption(option); return enabled != null && Boolean.parseBoolean(enabled); } } \ No newline at end of file diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index e637f5d45..534137f9b 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -42,16 +42,16 @@ public TMResource() { * * @param path */ - public TMResource(String path) { + public TMResource(final String path) { this.path = path; } - public TMResource(IConfigurationElement ce) { + public TMResource(final IConfigurationElement ce) { this(ce.getAttribute(XMLConstants.PATH_ATTR)); this.pluginId = ce.getNamespaceIdentifier(); } - public TMResource(String path, String pluginId) { + public TMResource(final String path, final String pluginId) { this.path = path; this.pluginId = pluginId; } @@ -72,7 +72,7 @@ public InputStream getInputStream() throws IOException { return null; } if (pluginId != null) { - URL url = new URL(PLATFORM_PLUGIN + pluginId + "/" + path); + final URL url = new URL(PLATFORM_PLUGIN + pluginId + "/" + path); return url.openStream(); } return new FileInputStream(new File(path)); @@ -84,13 +84,13 @@ protected String getResourceContent() { return null; } return convertStreamToString(in); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } return null; } - private static String convertStreamToString(InputStream is) { + private static String convertStreamToString(final InputStream is) { try (Scanner s = new Scanner(is)) { s.useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java index 26ac52771..22ca48deb 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java @@ -30,23 +30,23 @@ public class WorkingCopyGrammarRegistryManager extends AbstractGrammarRegistryMa private List removed; - public WorkingCopyGrammarRegistryManager(IGrammarRegistryManager manager) { + public WorkingCopyGrammarRegistryManager(final IGrammarRegistryManager manager) { this.manager = manager; load(); } private void load() { // Copy grammar definitions - IGrammarDefinition[] definitions = manager.getDefinitions(); - for (IGrammarDefinition definition : definitions) { + final IGrammarDefinition[] definitions = manager.getDefinitions(); + for (final IGrammarDefinition definition : definitions) { super.registerGrammarDefinition(definition); // Copy binding scope/content types - String scopeName = definition.getScopeName(); + final String scopeName = definition.getScopeName(); manager.getContentTypesForScope(scopeName).forEach(contentType -> super.registerContentTypeBinding(contentType, scopeName)); // Copy injection - Collection injections = manager.getInjections(scopeName); + final Collection injections = manager.getInjections(scopeName); if (injections != null) { - for (String injectFrom : injections) { + for (final String injectFrom : injections) { super.registerInjection(injectFrom, scopeName); } } @@ -54,7 +54,7 @@ private void load() { } @Override - public void registerGrammarDefinition(IGrammarDefinition definition) { + public void registerGrammarDefinition(final IGrammarDefinition definition) { super.registerGrammarDefinition(definition); if (added == null) { added = new ArrayList<>(); @@ -63,7 +63,7 @@ public void registerGrammarDefinition(IGrammarDefinition definition) { } @Override - public void unregisterGrammarDefinition(IGrammarDefinition definition) { + public void unregisterGrammarDefinition(final IGrammarDefinition definition) { super.unregisterGrammarDefinition(definition); if (added != null && added.contains(definition)) { added.remove(definition); @@ -78,12 +78,12 @@ public void unregisterGrammarDefinition(IGrammarDefinition definition) { @Override public void save() throws BackingStoreException { if (added != null) { - for (IGrammarDefinition definition : added) { + for (final IGrammarDefinition definition : added) { manager.registerGrammarDefinition(definition); } } if (removed != null) { - for (IGrammarDefinition definition : removed) { + for (final IGrammarDefinition definition : removed) { manager.unregisterGrammarDefinition(definition); } } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java index d68580c54..7a8f5ea73 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java @@ -38,24 +38,24 @@ private static final class EclipseRegistryOptions implements IRegistryOptions { private AbstractGrammarRegistryManager registry; - private void setRegistry(AbstractGrammarRegistryManager registry) { + private void setRegistry(final AbstractGrammarRegistryManager registry) { this.registry = registry; } @Override - public Collection getInjections(String scopeName) { + public Collection getInjections(final String scopeName) { return registry.getInjections(scopeName); } @Override - public String getFilePath(String scopeName) { - IGrammarDefinition info = registry.getDefinition(scopeName); + public String getFilePath(final String scopeName) { + final IGrammarDefinition info = registry.getDefinition(scopeName); return info != null ? info.getPath() : null; } @Override - public InputStream getInputStream(String scopeName) throws IOException { - IGrammarDefinition info = registry.getDefinition(scopeName); + public InputStream getInputStream(final String scopeName) throws IOException { + final IGrammarDefinition info = registry.getDefinition(scopeName); return info != null ? info.getInputStream() : null; } } @@ -65,22 +65,22 @@ protected AbstractGrammarRegistryManager() { ((EclipseRegistryOptions) getLocator()).setRegistry(this); } - protected AbstractGrammarRegistryManager(IRegistryOptions locator) { + protected AbstractGrammarRegistryManager(final IRegistryOptions locator) { super(locator); this.pluginCache = new GrammarCache(); this.userCache = new GrammarCache(); } @Override - public IGrammar getGrammarFor(IContentType[] contentTypes) { + public IGrammar getGrammarFor(final IContentType[] contentTypes) { if (contentTypes == null) { return null; } // Find grammar by content type - for (IContentType contentType : contentTypes) { - String scopeName = getScopeNameForContentType(contentType); + for (final IContentType contentType : contentTypes) { + final String scopeName = getScopeNameForContentType(contentType); if (scopeName != null) { - IGrammar grammar = getGrammarForScope(scopeName); + final IGrammar grammar = getGrammarForScope(scopeName); if (grammar != null) { return grammar; } @@ -90,26 +90,26 @@ public IGrammar getGrammarFor(IContentType[] contentTypes) { } @Override - public IGrammar getGrammarForScope(String scopeName) { + public IGrammar getGrammarForScope(final String scopeName) { return getGrammar(scopeName); } @Override public IGrammar getGrammarForFileType(String fileType) { // TODO: cache grammar by file types - IGrammarDefinition[] definitions = getDefinitions(); + final IGrammarDefinition[] definitions = getDefinitions(); // #202 if(fileType.startsWith(".")) { fileType=fileType.substring(1); } - for (IGrammarDefinition definition : definitions) { + for (final IGrammarDefinition definition : definitions) { // Not very optimized because it forces the load of the whole // grammar. // Extension Point grammar should perhaps stores file type bindings // like content type/scope binding? - IGrammar grammar = getGrammarForScope(definition.getScopeName()); + final IGrammar grammar = getGrammarForScope(definition.getScopeName()); if (grammar != null) { - Collection fileTypes = grammar.getFileTypes(); + final Collection fileTypes = grammar.getFileTypes(); if (fileTypes.contains(fileType)) { return grammar; } @@ -125,9 +125,9 @@ public IGrammar getGrammarForFileType(String fileType) { */ @Override public IGrammarDefinition[] getDefinitions() { - Collection pluginDefinitions = pluginCache.getDefinitions(); - Collection userDefinitions = userCache.getDefinitions(); - Collection definitions = new ArrayList<>(pluginDefinitions); + final Collection pluginDefinitions = pluginCache.getDefinitions(); + final Collection userDefinitions = userCache.getDefinitions(); + final Collection definitions = new ArrayList<>(pluginDefinitions); definitions.addAll(userDefinitions); return definitions.toArray(IGrammarDefinition[]::new); } @@ -140,11 +140,11 @@ public IGrammarDefinition[] getDefinitions() { * @return the loaded grammar from the given scopeName and null * otherwise. */ - private IGrammar getGrammar(String scopeName) { + private IGrammar getGrammar(final String scopeName) { if (scopeName == null) { return null; } - IGrammar grammar = super.grammarForScopeName(scopeName); + final IGrammar grammar = super.grammarForScopeName(scopeName); if (grammar != null) { return grammar; } @@ -159,8 +159,8 @@ private IGrammar getGrammar(String scopeName) { * @return the grammar definition from the given scopeName and * null otherwise. */ - private IGrammarDefinition getDefinition(String scopeName) { - IGrammarDefinition definition = userCache.getDefinition(scopeName); + private IGrammarDefinition getDefinition(final String scopeName) { + final IGrammarDefinition definition = userCache.getDefinition(scopeName); if (definition != null) { return definition; } @@ -176,7 +176,7 @@ private IGrammarDefinition getDefinition(String scopeName) { * scopeName and null otheriwse. */ @Override - public Collection getInjections(String scopeName) { + public Collection getInjections(final String scopeName) { return pluginCache.getInjections(scopeName); } @@ -187,7 +187,7 @@ public Collection getInjections(String scopeName) { * @param scopeName * @param injectTo */ - protected void registerInjection(String scopeName, String injectTo) { + protected void registerInjection(final String scopeName, final String injectTo) { pluginCache.registerInjection(scopeName, injectTo); } @@ -198,7 +198,7 @@ protected void registerInjection(String scopeName, String injectTo) { */ private String getScopeNameForContentType(IContentType contentType) { while (contentType != null) { - String scopeName = pluginCache.getScopeNameForContentType(contentType); + final String scopeName = pluginCache.getScopeNameForContentType(contentType); if (scopeName != null) { return scopeName; } @@ -208,16 +208,16 @@ private String getScopeNameForContentType(IContentType contentType) { } @Override - public List getContentTypesForScope(String scopeName) { + public List getContentTypesForScope(final String scopeName) { return pluginCache.getContentTypesForScope(scopeName); } - protected void registerContentTypeBinding(IContentType contentType, String scopeName) { + protected void registerContentTypeBinding(final IContentType contentType, final String scopeName) { pluginCache.registerContentTypeBinding(contentType, scopeName); } @Override - public void registerGrammarDefinition(IGrammarDefinition definition) { + public void registerGrammarDefinition(final IGrammarDefinition definition) { if (definition.getPluginId() == null) { userCache.registerGrammarDefinition(definition); } else { @@ -226,7 +226,7 @@ public void registerGrammarDefinition(IGrammarDefinition definition) { } @Override - public void unregisterGrammarDefinition(IGrammarDefinition definition) { + public void unregisterGrammarDefinition(final IGrammarDefinition definition) { if (definition.getPluginId() == null) { userCache.unregisterGrammarDefinition(definition); } else { diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java index 45b8497b4..19731b672 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java @@ -38,11 +38,11 @@ final class GrammarCache { * @param definition * the grammar definition to register. */ - void registerGrammarDefinition(IGrammarDefinition definition) { + void registerGrammarDefinition(final IGrammarDefinition definition) { definitions.put(definition.getScopeName(), definition); } - void unregisterGrammarDefinition(IGrammarDefinition definition) { + void unregisterGrammarDefinition(final IGrammarDefinition definition) { definitions.remove(definition.getScopeName()); } @@ -63,7 +63,7 @@ Collection getDefinitions() { * @return the grammar definition from the given scopeName and * null otherwise. */ - IGrammarDefinition getDefinition(String scopeName) { + IGrammarDefinition getDefinition(final String scopeName) { return definitions.get(scopeName); } @@ -75,7 +75,7 @@ IGrammarDefinition getDefinition(String scopeName) { * @return list of scope names to inject for the given * scopeName and null otheriwse. */ - Collection getInjections(String scopeName) { + Collection getInjections(final String scopeName) { return injections.get(scopeName); } @@ -86,7 +86,7 @@ Collection getInjections(String scopeName) { * @param scopeName * @param injectTo */ - void registerInjection(String scopeName, String injectTo) { + void registerInjection(final String scopeName, final String injectTo) { Collection injections = getInjections(injectTo); if (injections == null) { injections = new ArrayList<>(); @@ -101,11 +101,11 @@ void registerInjection(String scopeName, String injectTo) { * @param contentType * @return scope name bound with the given content type and null otherwise. */ - String getScopeNameForContentType(IContentType contentType) { + String getScopeNameForContentType(final IContentType contentType) { return scopeNameBindings.get(contentType); } - List getContentTypesForScope(String scopeName) { + List getContentTypesForScope(final String scopeName) { if (scopeName == null) { return List.of(); } @@ -113,7 +113,7 @@ List getContentTypesForScope(String scopeName) { .map(Entry::getKey).collect(Collectors.toList()); } - void registerContentTypeBinding(IContentType contentType, String scopeName) { + void registerContentTypeBinding(final IContentType contentType, final String scopeName) { scopeNameBindings.put(contentType, scopeName); } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java index b5f8f1ec4..ac843804a 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java @@ -45,7 +45,7 @@ private static synchronized GrammarRegistryManager createInstance() { if (INSTANCE != null) { return INSTANCE; } - GrammarRegistryManager manager = new GrammarRegistryManager(); + final GrammarRegistryManager manager = new GrammarRegistryManager(); manager.load(); return manager; } @@ -62,28 +62,28 @@ private void load() { * Load TextMate grammars from extension point. */ private void loadGrammarsFromExtensionPoints() { - IConfigurationElement[] cf = Platform.getExtensionRegistry() + final IConfigurationElement[] cf = Platform.getExtensionRegistry() .getConfigurationElementsFor(TMEclipseRegistryPlugin.PLUGIN_ID, EXTENSION_GRAMMARS); - for (IConfigurationElement ce : cf) { - String extensionName = ce.getName(); + for (final IConfigurationElement ce : cf) { + final String extensionName = ce.getName(); switch (extensionName) { case XMLConstants.GRAMMAR_ELT: super.registerGrammarDefinition(new GrammarDefinition(ce)); break; case XMLConstants.INJECTION_ELT: { - String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); - String injectTo = ce.getAttribute(XMLConstants.INJECT_TO_ATTR); + final String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); + final String injectTo = ce.getAttribute(XMLConstants.INJECT_TO_ATTR); super.registerInjection(scopeName, injectTo); break; } case XMLConstants.SCOPE_NAME_CONTENT_TYPE_BINDING_ELT: { - String contentTypeId = ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR); - IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId); + final String contentTypeId = ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR); + final IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId); if (contentType == null) { Platform.getLog(getClass()) .warn("No content-type found with id='" + contentTypeId + "', ignoring TM4E association."); } else { - String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); + final String scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); super.registerContentTypeBinding(contentType, scopeName); } break; @@ -98,11 +98,11 @@ private void loadGrammarsFromExtensionPoints() { private void loadGrammarsFromPreferences() { // Load grammar definitions from the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); - String json = prefs.get(PreferenceConstants.GRAMMARS, null); + final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); + final String json = prefs.get(PreferenceConstants.GRAMMARS, null); if (json != null) { - IGrammarDefinition[] definitions = PreferenceHelper.loadGrammars(json); - for (IGrammarDefinition definition : definitions) { + final IGrammarDefinition[] definitions = PreferenceHelper.loadGrammars(json); + for (final IGrammarDefinition definition : definitions) { userCache.registerGrammarDefinition(definition); } } @@ -112,8 +112,8 @@ private void loadGrammarsFromPreferences() { public void save() throws BackingStoreException { // Save grammar definitions in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" - String json = PreferenceHelper.toJson(userCache.getDefinitions()); - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); + final String json = PreferenceHelper.toJson(userCache.getDefinitions()); + final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); prefs.put(PreferenceConstants.GRAMMARS, json); prefs.flush(); } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java index 508902973..530efd756 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceConstants.java @@ -13,7 +13,6 @@ /** * Preferences constants for grammar. - * */ public final class PreferenceConstants { diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java index a809f35fa..5e0bb02ef 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java @@ -34,11 +34,11 @@ public final class PreferenceHelper { .create(); } - public static IGrammarDefinition[] loadGrammars(String json) { + public static IGrammarDefinition[] loadGrammars(final String json) { return DEFAULT_GSON.fromJson(json, GrammarDefinition[].class); } - public static String toJson(Collection definitions) { + public static String toJson(final Collection definitions) { return DEFAULT_GSON.toJson(definitions); } From 0d45f59b4303012579d969e391d833020cd18e0e Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 4 May 2022 22:39:05 +0200 Subject: [PATCH 172/202] Enable annotation based null analysis in tm4e.registry plugin --- .../.settings/org.eclipse.jdt.core.prefs | 4 +- org.eclipse.tm4e.registry/build.properties | 7 ++ .../tm4e/registry/GrammarDefinition.java | 9 +- .../registry/IGrammarRegistryManager.java | 46 ++++---- .../eclipse/tm4e/registry/ITMDefinition.java | 5 +- .../eclipse/tm4e/registry/ITMResource.java | 8 +- .../registry/TMEclipseRegistryPlugin.java | 12 ++- .../org/eclipse/tm4e/registry/TMResource.java | 18 +++- .../WorkingCopyGrammarRegistryManager.java | 25 +++-- .../eclipse/tm4e/registry/XMLConstants.java | 10 +- .../AbstractGrammarRegistryManager.java | 100 ++++++++---------- .../tm4e/registry/internal/GrammarCache.java | 48 ++++----- .../internal/GrammarRegistryManager.java | 12 +-- .../tm4e/registry/internal/package-info.java | 4 + .../preferences/PreferenceHelper.java | 17 ++- .../internal/preferences/package-info.java | 4 + .../eclipse/tm4e/registry/package-info.java | 4 + 17 files changed, 180 insertions(+), 153 deletions(-) create mode 100644 org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/package-info.java create mode 100644 org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/package-info.java create mode 100644 org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/package-info.java diff --git a/org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs index f648802b5..6b99f88fc 100644 --- a/org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.tm4e.registry/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullable.secondary= -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 @@ -75,7 +75,7 @@ org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=wa org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=info org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning diff --git a/org.eclipse.tm4e.registry/build.properties b/org.eclipse.tm4e.registry/build.properties index ebceaad62..546508f99 100644 --- a/org.eclipse.tm4e.registry/build.properties +++ b/org.eclipse.tm4e.registry/build.properties @@ -7,3 +7,10 @@ bin.includes = META-INF/,\ .,\ .options,\ about.html + +# https://codeiseasy.wordpress.com/2013/03/08/tycho-and-jdt-null-analysis/ +# JDT Null Analysis for Eclipse +additional.bundles = org.eclipse.jdt.annotation +# JDT Null Analysis types for Tycho +jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation + \ No newline at end of file diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java index 095e126a0..f869fed78 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/GrammarDefinition.java @@ -1,17 +1,18 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jdt.annotation.Nullable; /** * Grammar definition defined by the "org.eclipse.tm4e.registry.grammars" @@ -30,6 +31,7 @@ */ public class GrammarDefinition extends TMResource implements IGrammarDefinition { + @Nullable private String scopeName; /** @@ -55,6 +57,7 @@ public GrammarDefinition(final IConfigurationElement ce) { @Override public String getScopeName() { + assert scopeName != null; return scopeName; } } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java index 0ff301f53..3a91a372c 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/IGrammarRegistryManager.java @@ -15,11 +15,12 @@ import java.util.List; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; import org.osgi.service.prefs.BackingStoreException; /** - * + * * TextMate Grammar registry manager API. * */ @@ -29,32 +30,28 @@ public interface IGrammarRegistryManager { /** * Returns the list of registered TextMate grammar definitions. - * + * * @return the list of registered TextMate grammar definitions. */ IGrammarDefinition[] getDefinitions(); /** * Add grammar definition to the registry. - * + * * NOTE: you must call save() method if you wish to save in the preferences. - * - * @param definition */ void registerGrammarDefinition(IGrammarDefinition definition); /** * Remove grammar definition from the registry. - * + * * NOTE: you must call save() method if you wish to save in the preferences. - * - * @param definition */ void unregisterGrammarDefinition(IGrammarDefinition definition); /** * Save the grammar definitions. - * @throws BackingStoreException + * @throws BackingStoreException */ void save() throws BackingStoreException; @@ -66,35 +63,38 @@ public interface IGrammarRegistryManager { * null if no content-type has a grammar associated. Grammars associated * with parent content-types will be returned if applicable. */ - IGrammar getGrammarFor(IContentType[] contentTypes); + @Nullable + IGrammar getGrammarFor(IContentType @Nullable[] contentTypes); /** * Returns the {@link IGrammar} for the given scope name and null otherwise. - * - * @param contentTypes - * the content type. + * * @return the {@link IGrammar} for the given scope name and null otherwise. */ + @Nullable IGrammar getGrammarForScope(String scopeName); /** * Returns the {@link IGrammar} for the given file type and null otherwise. - * - * @param contentTypes - * the content type. + * * @return the {@link IGrammar} for the file type name and null otherwise. */ + @Nullable IGrammar getGrammarForFileType(String fileType); /** - * Returns the list of content types bound with the given scope name and - * null otherwise. - * - * @param scopeName - * @return the list of content types bound with the given scope name and - * null otherwise. + * Returns the list of content types bound with the given scope name and null otherwise. + * + * @return the list of content types bound with the given scope name and null otherwise. */ + @Nullable List getContentTypesForScope(String scopeName); - + + /** + * Returns list of scope names to inject for the given scopeName and null otherwise. + * + * @return list of scope names to inject for the given scopeName and null otherwise. + */ + @Nullable Collection getInjections(String scopeName); } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java index 52bce04a1..79d35ca87 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMDefinition.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.registry; +import org.eclipse.jdt.annotation.Nullable; + /** * TextMate definition API. * @@ -19,9 +21,10 @@ public interface ITMDefinition { /** * Returns the plugin id which has registered the TextMate resource. - * + * * @return the plugin id which has registered the TextMate resource. */ + @Nullable String getPluginId(); } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java index 7c32e1f07..63bf74d0e 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/ITMResource.java @@ -14,6 +14,8 @@ import java.io.IOException; import java.io.InputStream; +import org.eclipse.jdt.annotation.Nullable; + /** * TextMate resource definition API. * @@ -22,16 +24,18 @@ public interface ITMResource extends ITMDefinition { /** * Returns the TextMate resource path. - * + * * @return the TextMate resource path. */ + @Nullable String getPath(); /** * Returns the stream of the TextMate resource. - * + * * @return the stream of the TextMate resource. * @throws IOException */ + @Nullable InputStream getInputStream() throws IOException; } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java index 06641fe76..fa4a366e7 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMEclipseRegistryPlugin.java @@ -12,37 +12,39 @@ package org.eclipse.tm4e.registry; import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.registry.internal.GrammarRegistryManager; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; /** * OSGi Activator for TextMate Eclipse registry bundle. - * */ public class TMEclipseRegistryPlugin implements BundleActivator { public static final String PLUGIN_ID = "org.eclipse.tm4e.registry"; + @Nullable private static BundleContext context; + @Nullable static BundleContext getContext() { return context; } @Override - public void start(final BundleContext bundleContext) throws Exception { + public void start(@Nullable final BundleContext bundleContext) throws Exception { TMEclipseRegistryPlugin.context = bundleContext; } @Override - public void stop(final BundleContext bundleContext) throws Exception { + public void stop(@Nullable final BundleContext bundleContext) throws Exception { TMEclipseRegistryPlugin.context = null; } /** * Returns the TextMate grammar manager. - * + * * @return the TextMate grammar manager. */ public static IGrammarRegistryManager getGrammarRegistryManager() { @@ -51,7 +53,7 @@ public static IGrammarRegistryManager getGrammarRegistryManager() { /** * Returns true if the debug option is enabled and false otherwise. - * + * * @param option * the option name * @return true if the debug option is enabled and false otherwise. diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index 534137f9b..62985ff21 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry; @@ -19,6 +19,7 @@ import java.util.Scanner; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jdt.annotation.Nullable; /** * TextMate Resource. @@ -27,7 +28,10 @@ public class TMResource implements ITMResource { private static final String PLATFORM_PLUGIN = "platform:/plugin/"; //$NON-NLS-1$ + @Nullable private String path; + + @Nullable private String pluginId; /** @@ -51,24 +55,27 @@ public TMResource(final IConfigurationElement ce) { this.pluginId = ce.getNamespaceIdentifier(); } - public TMResource(final String path, final String pluginId) { + public TMResource(@Nullable final String path, @Nullable final String pluginId) { this.path = path; this.pluginId = pluginId; } + @Nullable @Override public String getPath() { return path; } + @Nullable @Override public String getPluginId() { return pluginId; } + @Nullable @Override public InputStream getInputStream() throws IOException { - if (path == null || path.isEmpty()) { + if (path == null || "".equals(path)) { return null; } if (pluginId != null) { @@ -78,6 +85,7 @@ public InputStream getInputStream() throws IOException { return new FileInputStream(new File(path)); } + @Nullable protected String getResourceContent() { try (InputStream in = this.getInputStream()) { if (in == null) { diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java index 22ca48deb..e55a11127 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/WorkingCopyGrammarRegistryManager.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015, 2021 Angelo ZERR and others. + * Copyright (c) 2015, 2021 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry; @@ -15,19 +15,21 @@ import java.util.Collection; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.registry.internal.AbstractGrammarRegistryManager; import org.osgi.service.prefs.BackingStoreException; /** * Working copy of grammar registry manager. - * */ public class WorkingCopyGrammarRegistryManager extends AbstractGrammarRegistryManager { private final IGrammarRegistryManager manager; + @Nullable private List added; + @Nullable private List removed; public WorkingCopyGrammarRegistryManager(final IGrammarRegistryManager manager) { @@ -40,9 +42,14 @@ private void load() { final IGrammarDefinition[] definitions = manager.getDefinitions(); for (final IGrammarDefinition definition : definitions) { super.registerGrammarDefinition(definition); + // Copy binding scope/content types final String scopeName = definition.getScopeName(); - manager.getContentTypesForScope(scopeName).forEach(contentType -> super.registerContentTypeBinding(contentType, scopeName)); + final var contentTypes = manager.getContentTypesForScope(scopeName); + if (contentTypes != null) { + contentTypes.forEach(contentType -> super.registerContentTypeBinding(contentType, scopeName)); + } + // Copy injection final Collection injections = manager.getInjections(scopeName); if (injections != null) { @@ -56,8 +63,9 @@ private void load() { @Override public void registerGrammarDefinition(final IGrammarDefinition definition) { super.registerGrammarDefinition(definition); + var added = this.added; if (added == null) { - added = new ArrayList<>(); + added = this.added = new ArrayList<>(); } added.add(definition); } @@ -65,11 +73,13 @@ public void registerGrammarDefinition(final IGrammarDefinition definition) { @Override public void unregisterGrammarDefinition(final IGrammarDefinition definition) { super.unregisterGrammarDefinition(definition); + final var added = this.added; if (added != null && added.contains(definition)) { added.remove(definition); } else { + var removed = this.removed; if (removed == null) { - removed = new ArrayList<>(); + removed = this.removed = new ArrayList<>(); } removed.add(definition); } @@ -91,5 +101,4 @@ public void save() throws BackingStoreException { manager.save(); } } - } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java index 80f4482c7..631d4b809 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/XMLConstants.java @@ -1,20 +1,18 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry; /** - * XML constants used with the "org.eclipse.tm4e.registry.grammars" extension - * point. - * + * XML constants used with the "org.eclipse.tm4e.registry.grammars" extension point. */ public class XMLConstants { diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java index 7a8f5ea73..fa3eb692a 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/AbstractGrammarRegistryManager.java @@ -1,14 +1,14 @@ /** - * Copyright (c) 2015-2019 Angelo ZERR. + * Copyright (c) 2015-2019 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes */ package org.eclipse.tm4e.registry.internal; @@ -19,6 +19,7 @@ import java.util.List; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.core.registry.IRegistryOptions; import org.eclipse.tm4e.core.registry.Registry; @@ -32,32 +33,53 @@ public abstract class AbstractGrammarRegistryManager extends Registry implements IGrammarRegistryManager { private final GrammarCache pluginCache; - protected final GrammarCache userCache; + final GrammarCache userCache; private static final class EclipseRegistryOptions implements IRegistryOptions { + @Nullable private AbstractGrammarRegistryManager registry; private void setRegistry(final AbstractGrammarRegistryManager registry) { this.registry = registry; } + @Nullable @Override public Collection getInjections(final String scopeName) { + final var registry = this.registry; + if (registry == null) { + return null; + } return registry.getInjections(scopeName); } + @Nullable @Override public String getFilePath(final String scopeName) { - final IGrammarDefinition info = registry.getDefinition(scopeName); + final IGrammarDefinition info = getDefinition(scopeName); return info != null ? info.getPath() : null; } + @Nullable @Override public InputStream getInputStream(final String scopeName) throws IOException { - final IGrammarDefinition info = registry.getDefinition(scopeName); + final IGrammarDefinition info = getDefinition(scopeName); return info != null ? info.getInputStream() : null; } + + @Nullable + private IGrammarDefinition getDefinition(final String scopeName) { + final var registry = this.registry; + if (registry == null) { + return null; + } + final IGrammarDefinition definition = registry.userCache.getDefinition(scopeName); + if (definition != null) { + return definition; + } + return registry.pluginCache.getDefinition(scopeName); + } } protected AbstractGrammarRegistryManager() { @@ -71,8 +93,9 @@ protected AbstractGrammarRegistryManager(final IRegistryOptions locator) { this.userCache = new GrammarCache(); } + @Nullable @Override - public IGrammar getGrammarFor(final IContentType[] contentTypes) { + public IGrammar getGrammarFor(final IContentType @Nullable [] contentTypes) { if (contentTypes == null) { return null; } @@ -89,18 +112,20 @@ public IGrammar getGrammarFor(final IContentType[] contentTypes) { return null; } + @Nullable @Override public IGrammar getGrammarForScope(final String scopeName) { return getGrammar(scopeName); } + @Nullable @Override public IGrammar getGrammarForFileType(String fileType) { // TODO: cache grammar by file types final IGrammarDefinition[] definitions = getDefinitions(); // #202 - if(fileType.startsWith(".")) { - fileType=fileType.substring(1); + if (fileType.startsWith(".")) { + fileType = fileType.substring(1); } for (final IGrammarDefinition definition : definitions) { // Not very optimized because it forces the load of the whole @@ -118,11 +143,7 @@ public IGrammar getGrammarForFileType(String fileType) { return null; } - /** - * Returns the whole registered grammar definition. - * - * @return - */ + @Nullable @Override public IGrammarDefinition[] getDefinitions() { final Collection pluginDefinitions = pluginCache.getDefinitions(); @@ -133,14 +154,12 @@ public IGrammarDefinition[] getDefinitions() { } /** - * Returns the loaded grammar from the given scopeName and null - * otherwise. + * Returns the loaded grammar from the given scopeName and null otherwise. * - * @param scopeName - * @return the loaded grammar from the given scopeName and null - * otherwise. + * @return the loaded grammar from the given scopeName and null otherwise. */ - private IGrammar getGrammar(final String scopeName) { + @Nullable + private IGrammar getGrammar(@Nullable final String scopeName) { if (scopeName == null) { return null; } @@ -151,52 +170,24 @@ private IGrammar getGrammar(final String scopeName) { return super.loadGrammar(scopeName); } - /** - * Returns the grammar definition from the given scopeName and - * null otherwise. - * - * @param scopeName - * @return the grammar definition from the given scopeName and - * null otherwise. - */ - private IGrammarDefinition getDefinition(final String scopeName) { - final IGrammarDefinition definition = userCache.getDefinition(scopeName); - if (definition != null) { - return definition; - } - return pluginCache.getDefinition(scopeName); - } - - /** - * Returns list of scope names to inject for the given - * scopeName and null otheriwse. - * - * @param scopeName - * @return list of scope names to inject for the given - * scopeName and null otheriwse. - */ + @Nullable @Override public Collection getInjections(final String scopeName) { return pluginCache.getInjections(scopeName); } /** - * Register the given scopeName to inject to the given scope - * name injectTo. - * - * @param scopeName - * @param injectTo + * Register the given scopeName to inject to the given scope name injectTo. */ protected void registerInjection(final String scopeName, final String injectTo) { pluginCache.registerInjection(scopeName, injectTo); } /** - * @param contentType - * @return scope name bound with the given content type (or its base type) and - * null otherwise. + * @return scope name bound with the given content type (or its base type) and null otherwise. */ - private String getScopeNameForContentType(IContentType contentType) { + @Nullable + private String getScopeNameForContentType(@Nullable IContentType contentType) { while (contentType != null) { final String scopeName = pluginCache.getScopeNameForContentType(contentType); if (scopeName != null) { @@ -207,6 +198,7 @@ private String getScopeNameForContentType(IContentType contentType) { return null; } + @Nullable @Override public List getContentTypesForScope(final String scopeName) { return pluginCache.getContentTypesForScope(scopeName); diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java index 19731b672..245c3af27 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java @@ -1,18 +1,19 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry.internal; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,23 +21,22 @@ import java.util.stream.Collectors; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.registry.IGrammarDefinition; /** * Grammar cache. - * */ final class GrammarCache { private final Map definitions = new HashMap<>(); private final Map> injections = new HashMap<>(); - private final Map scopeNameBindings = new HashMap<>(); + private final Map scopeNameBindings = new HashMap<>(); /** * Register a grammar definition. * - * @param definition - * the grammar definition to register. + * @param definition the grammar definition to register. */ void registerGrammarDefinition(final IGrammarDefinition definition) { definitions.put(definition.getScopeName(), definition); @@ -49,45 +49,37 @@ void unregisterGrammarDefinition(final IGrammarDefinition definition) { /** * Returns the whole registered grammar definition. * - * @return + * @return the whole registered grammar definition. */ Collection getDefinitions() { return this.definitions.values(); } /** - * Returns the grammar definition from the given scopeName and - * null otherwise. + * Returns the grammar definition from the given scopeName and null otherwise. * - * @param scopeName - * @return the grammar definition from the given scopeName and - * null otherwise. + * @return the grammar definition from the given scopeName and null otherwise. */ + @Nullable IGrammarDefinition getDefinition(final String scopeName) { return definitions.get(scopeName); } /** - * Returns list of scope names to inject for the given - * scopeName and null otheriwse. + * Returns list of scope names to inject for the given scopeName and null otheriwse. * - * @param scopeName - * @return list of scope names to inject for the given - * scopeName and null otheriwse. + * @return list of scope names to inject for the given scopeName and null otheriwse. */ + @Nullable Collection getInjections(final String scopeName) { return injections.get(scopeName); } /** - * Register the given scopeName to inject to the given scope - * name injectTo. - * - * @param scopeName - * @param injectTo + * Register the given scopeName to inject to the given scope name injectTo. */ void registerInjection(final String scopeName, final String injectTo) { - Collection injections = getInjections(injectTo); + var injections = getInjections(injectTo); if (injections == null) { injections = new ArrayList<>(); this.injections.put(injectTo, injections); @@ -98,17 +90,18 @@ void registerInjection(final String scopeName, final String injectTo) { /** * Returns scope name bound with the given content type and null otherwise. * - * @param contentType * @return scope name bound with the given content type and null otherwise. */ + @Nullable String getScopeNameForContentType(final IContentType contentType) { return scopeNameBindings.get(contentType); } - List getContentTypesForScope(final String scopeName) { + List getContentTypesForScope(@Nullable final String scopeName) { if (scopeName == null) { - return List.of(); + return Collections.emptyList(); } + return scopeNameBindings.entrySet().stream().filter(map -> scopeName.equals(map.getValue())) .map(Entry::getKey).collect(Collectors.toList()); } @@ -116,5 +109,4 @@ List getContentTypesForScope(final String scopeName) { void registerContentTypeBinding(final IContentType contentType, final String scopeName) { scopeNameBindings.put(contentType, scopeName); } - } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java index ac843804a..66c94878a 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarRegistryManager.java @@ -14,8 +14,8 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.registry.GrammarDefinition; import org.eclipse.tm4e.registry.IGrammarDefinition; import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; @@ -31,6 +31,7 @@ public final class GrammarRegistryManager extends AbstractGrammarRegistryManager private static final String EXTENSION_GRAMMARS = "grammars"; + @Nullable private static GrammarRegistryManager INSTANCE; public static GrammarRegistryManager getInstance() { @@ -98,8 +99,8 @@ private void loadGrammarsFromExtensionPoints() { private void loadGrammarsFromPreferences() { // Load grammar definitions from the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" - final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); - final String json = prefs.get(PreferenceConstants.GRAMMARS, null); + final var prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); + final var json = prefs.get(PreferenceConstants.GRAMMARS, null); if (json != null) { final IGrammarDefinition[] definitions = PreferenceHelper.loadGrammars(json); for (final IGrammarDefinition definition : definitions) { @@ -112,10 +113,9 @@ private void loadGrammarsFromPreferences() { public void save() throws BackingStoreException { // Save grammar definitions in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs" - final String json = PreferenceHelper.toJson(userCache.getDefinitions()); - final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); + final var json = PreferenceHelper.toJson(userCache.getDefinitions()); + final var prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID); prefs.put(PreferenceConstants.GRAMMARS, json); prefs.flush(); } - } diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/package-info.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/package-info.java new file mode 100644 index 000000000..fd08b8783 --- /dev/null +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.registry.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java index 5e0bb02ef..d7e6a46d0 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/PreferenceHelper.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry.internal.preferences; @@ -26,13 +26,10 @@ */ public final class PreferenceHelper { - private static final Gson DEFAULT_GSON; - - static { - DEFAULT_GSON = new GsonBuilder() - .registerTypeAdapter(IGrammarDefinition.class, (InstanceCreator) type -> new GrammarDefinition()) - .create(); - } + private static final Gson DEFAULT_GSON = new GsonBuilder() + .registerTypeAdapter(IGrammarDefinition.class, + (InstanceCreator) type -> new GrammarDefinition()) + .create(); public static IGrammarDefinition[] loadGrammars(final String json) { return DEFAULT_GSON.fromJson(json, GrammarDefinition[].class); diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/package-info.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/package-info.java new file mode 100644 index 000000000..78207bf75 --- /dev/null +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/preferences/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.registry.internal.preferences; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/package-info.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/package-info.java new file mode 100644 index 000000000..069f47ac3 --- /dev/null +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.registry; + +import org.eclipse.jdt.annotation.NonNullByDefault; From 306bcb50a5f39cd2ead5b4db5f0ba2cd14c79bbc Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 5 May 2022 15:50:40 +0200 Subject: [PATCH 173/202] Enable annotation based null analysis in tm4e.languageconfiguration --- .../.settings/org.eclipse.jdt.core.prefs | 4 +- .../build.properties | 7 + ...asLanguageConfigurationPropertyTester.java | 46 ++-- .../ILanguageConfiguration.java | 10 +- .../ILanguageConfigurationDefinition.java | 8 +- ...ILanguageConfigurationRegistryManager.java | 2 + ...LanguageConfigurationAutoEditStrategy.java | 197 ++++++++------- ...uageConfigurationCharacterPairMatcher.java | 110 +++++---- .../ToggleLineCommentHandler.java | 230 ++++++++++-------- ...yLanguageConfigurationRegistryManager.java | 33 +-- ...tLanguageConfigurationRegistryManager.java | 12 +- .../internal/LanguageConfiguration.java | 93 ++++--- .../LanguageConfigurationDefinition.java | 55 +++-- .../LanguageConfigurationMessages.java | 3 +- .../internal/LanguageConfigurationPlugin.java | 7 +- .../LanguageConfigurationRegistryManager.java | 141 +++++------ .../internal/package-info.java | 4 + .../LanguageConfigurationContentProvider.java | 10 +- .../LanguageConfigurationLabelProvider.java | 21 +- .../LanguageConfigurationPreferencePage.java | 132 +++++----- .../preferences/PreferenceHelper.java | 10 +- .../internal/preferences/package-info.java | 4 + .../supports/AutoClosingPairConditional.java | 6 +- .../internal/supports/CharacterPair.java | 6 +- .../supports/CharacterPairSupport.java | 25 +- .../internal/supports/CommentSupport.java | 47 ++-- .../internal/supports/Comments.java | 14 +- .../internal/supports/EnterAction.java | 26 +- .../supports/EnterActionAndIndent.java | 2 +- .../internal/supports/Folding.java | 2 +- .../internal/supports/OnEnterRule.java | 13 +- .../internal/supports/OnEnterSupport.java | 45 ++-- .../internal/supports/package-info.java | 4 + .../internal/utils/RegExpUtils.java | 11 +- .../internal/utils/TabSpacesInfo.java | 2 +- .../internal/utils/TextUtils.java | 80 +++--- .../internal/utils/package-info.java | 4 + ...AutoClosingPairConditionalTableWidget.java | 16 +- .../widgets/CharacterPairsTableWidget.java | 42 ++-- .../widgets/ColumnSelectionAdapter.java | 9 +- .../widgets/ColumnViewerComparator.java | 13 +- .../LanguageConfigurationInfoWidget.java | 95 ++++---- ...anguageConfigurationPreferencesWidget.java | 25 +- .../widgets/OnEnterRuleTableWidget.java | 63 +++-- .../internal/widgets/package-info.java | 4 + .../LanguageConfigurationImportWizard.java | 25 +- ...SelectLanguageConfigurationWizardPage.java | 196 ++++++++------- .../internal/wizards/package-info.java | 4 + .../languageconfiguration/package-info.java | 4 + .../internal/supports/OnEnterSupportTest.java | 23 +- .../internal/supports/ParsingTest.java | 6 +- 51 files changed, 1127 insertions(+), 824 deletions(-) create mode 100644 org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/package-info.java create mode 100644 org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/package-info.java create mode 100644 org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/package-info.java create mode 100644 org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/package-info.java create mode 100644 org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/package-info.java create mode 100644 org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/package-info.java create mode 100644 org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/package-info.java diff --git a/org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs index f648802b5..6b99f88fc 100644 --- a/org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.tm4e.languageconfiguration/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullable.secondary= -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 @@ -75,7 +75,7 @@ org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=wa org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=info org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning diff --git a/org.eclipse.tm4e.languageconfiguration/build.properties b/org.eclipse.tm4e.languageconfiguration/build.properties index efe6aaa35..b0eb292de 100644 --- a/org.eclipse.tm4e.languageconfiguration/build.properties +++ b/org.eclipse.tm4e.languageconfiguration/build.properties @@ -7,3 +7,10 @@ bin.includes = META-INF/,\ plugin.properties,\ resources/,\ about.html + +# https://codeiseasy.wordpress.com/2013/03/08/tycho-and-jdt-null-analysis/ +# JDT Null Analysis for Eclipse +additional.bundles = org.eclipse.jdt.annotation +# JDT Null Analysis types for Tycho +jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation + \ No newline at end of file diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java index 259ee0473..342cec892 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/HasLanguageConfigurationPropertyTester.java @@ -1,61 +1,63 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration; import org.eclipse.core.expressions.PropertyTester; import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.text.IDocument; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager; import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; public class HasLanguageConfigurationPropertyTester extends PropertyTester { + @Nullable + private static T adapt(@Nullable Object sourceObject, Class adapter) { + return Adapters.adapt(sourceObject, adapter); + } + @Override - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - ITextEditor editor = Adapters.adapt(receiver, ITextEditor.class); + public boolean test(@Nullable final Object receiver, @Nullable final String property, + final Object @Nullable [] args, @Nullable final Object expectedValue) { + final var editor = adapt(receiver, ITextEditor.class); if (editor == null) { return false; } - IEditorInput input = editor.getEditorInput(); - IDocumentProvider docProvider = editor.getDocumentProvider(); + final var input = editor.getEditorInput(); + final var docProvider = editor.getDocumentProvider(); if (docProvider == null || input == null) { return false; } - IDocument document = docProvider.getDocument(input); + final var document = docProvider.getDocument(input); if (document == null) { return false; } - IContentType[] contentTypes; + final ContentTypeInfo info; try { - ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); - if(info == null) { - return false; - } - contentTypes = info.getContentTypes(); - } catch (CoreException e) { + info = ContentTypeHelper.findContentTypes(document); + } catch (final CoreException e) { return false; } - LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance(); - return registry.getLanguageConfigurationFor(contentTypes) != null; - } + if (info == null) { + return false; + } + final var registry = LanguageConfigurationRegistryManager.getInstance(); + return registry.getLanguageConfigurationFor(info.getContentTypes()) != null; + } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java index 25cfcb37f..067fd3dae 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfiguration.java @@ -13,6 +13,7 @@ import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional; import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments; @@ -27,6 +28,7 @@ public interface ILanguageConfiguration { * * @return the language's comments or null if not set */ + @Nullable Comments getComments(); /** @@ -36,6 +38,7 @@ public interface ILanguageConfiguration { * @return the language's brackets. This configuration implicitly affects * pressing Enter around these brackets. */ + @Nullable List getBrackets(); /** @@ -44,9 +47,10 @@ public interface ILanguageConfiguration { * configured brackets will be used. * * @return the language's auto closing pairs. The 'close' character is - * autautomatically inserted with the 'open' character is typed. If not + * automatically inserted with the 'open' character is typed. If not * set, the configured brackets will be used. */ + @Nullable List getAutoClosingPairs(); /** @@ -54,6 +58,7 @@ public interface ILanguageConfiguration { * * @return the language's rules to be evaluated when pressing Enter. */ + @Nullable List getOnEnterRules(); /** @@ -66,6 +71,7 @@ public interface ILanguageConfiguration { * close characters. If not set, the autoclosing pairs settings will be * used. */ + @Nullable List getSurroundingPairs(); /** @@ -73,6 +79,7 @@ public interface ILanguageConfiguration { * * @return the language's folding or null if not set */ + @Nullable Folding getFolding(); /** @@ -81,5 +88,6 @@ public interface ILanguageConfiguration { * * @return the language's word pattern or null if not set */ + @Nullable String getWordPattern(); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationDefinition.java index 68d759428..e6e1184b1 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationDefinition.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationDefinition.java @@ -12,6 +12,7 @@ package org.eclipse.tm4e.languageconfiguration; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.registry.ITMResource; public interface ILanguageConfigurationDefinition extends ITMResource { @@ -28,6 +29,7 @@ public interface ILanguageConfigurationDefinition extends ITMResource { * * @return the language configuration. */ + @Nullable ILanguageConfiguration getLanguageConfiguration(); /** @@ -37,7 +39,7 @@ public interface ILanguageConfigurationDefinition extends ITMResource { * @return true if on enter is enabled, false * otherwise */ - Boolean isOnEnterEnabled(); + boolean isOnEnterEnabled(); /** * Set whether on-enter actions are enabled for this language configuration @@ -52,7 +54,7 @@ public interface ILanguageConfigurationDefinition extends ITMResource { * @return true if bracket auto closing is enabled, * false otherwise */ - Boolean isBracketAutoClosingEnabled(); + boolean isBracketAutoClosingEnabled(); /** * Set whether the bracket auto closing action is enabled for this language @@ -67,7 +69,7 @@ public interface ILanguageConfigurationDefinition extends ITMResource { * @return true if highlighting of matching pairs is enabled, * false otherwise */ - Boolean isMatchingPairsEnabled(); + boolean isMatchingPairsEnabled(); /** * Set whether the highlighting of matching pairs is enabled for this language diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java index 51d0b7977..3bf2a11f9 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java @@ -12,6 +12,7 @@ package org.eclipse.tm4e.languageconfiguration; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.osgi.service.prefs.BackingStoreException; /** @@ -65,6 +66,7 @@ public interface ILanguageConfigurationRegistryManager { * @return the {@link ILanguageConfiguration} for the given content type and * null otherwise. */ + @Nullable ILanguageConfiguration getLanguageConfigurationFor(IContentType[] contentTypes); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java index bd18fe0df..e3ae6df1a 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration; @@ -15,6 +15,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy; import org.eclipse.jface.text.DocumentCommand; @@ -24,7 +25,6 @@ import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager; import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction; -import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterActionAndIndent; import org.eclipse.tm4e.languageconfiguration.internal.utils.TabSpacesInfo; import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils; import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; @@ -39,15 +39,23 @@ */ public class LanguageConfigurationAutoEditStrategy implements IAutoEditStrategy { + @Nullable private IDocument document; - private IContentType[] contentTypes; + private IContentType @Nullable [] contentTypes; + + @Nullable private TabSpacesInfo tabSpacesInfo; + + @Nullable private ITextViewer viewer; @Override - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { - IContentType[] contentTypes = findContentTypes(document); + public void customizeDocumentCommand(@Nullable final IDocument document, @Nullable final DocumentCommand command) { + if (document == null || command == null) + return; + + final IContentType[] contentTypes = findContentTypes(document); if (contentTypes == null || command.text.isEmpty()) { return; } @@ -60,18 +68,21 @@ public void customizeDocumentCommand(IDocument document, DocumentCommand command } // Auto close pair - LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance(); - for (IContentType contentType : contentTypes) { - CharacterPair autoClosingPair = registry.getAutoClosePair(document.get(), command.offset, command.text, + final LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance(); + for (final IContentType contentType : contentTypes) { + final CharacterPair autoClosingPair = registry.getAutoClosePair(document.get(), command.offset, + command.text, contentType); if (autoClosingPair == null) { continue; } command.caretOffset = command.offset + command.text.length(); command.shiftsCaret = false; - if (command.text.equals(autoClosingPair.getKey()) && isFollowedBy(document, command.offset, autoClosingPair.getKey())) { + if (command.text.equals(autoClosingPair.getKey()) + && isFollowedBy(document, command.offset, autoClosingPair.getKey())) { command.text = ""; - } else if (command.text.equals(autoClosingPair.getValue()) && isFollowedBy(document, command.offset, autoClosingPair.getValue())) { + } else if (command.text.equals(autoClosingPair.getValue()) + && isFollowedBy(document, command.offset, autoClosingPair.getValue())) { command.text = ""; } else { command.text += autoClosingPair.getValue(); @@ -80,16 +91,16 @@ public void customizeDocumentCommand(IDocument document, DocumentCommand command } Arrays.stream(contentTypes) - .flatMap(contentType -> registry.getEnabledAutoClosingPairs(contentType).stream()) - .map(CharacterPair::getValue) - .filter(command.text::equals) - .filter(closing -> isFollowedBy(document, command.offset, closing)) - .findFirst() - .ifPresent(closing -> { - command.caretOffset = command.offset + command.text.length(); - command.shiftsCaret = false; - command.text = ""; - }); + .flatMap(contentType -> registry.getEnabledAutoClosingPairs(contentType).stream()) + .map(CharacterPair::getValue) + .filter(command.text::equals) + .filter(closing -> isFollowedBy(document, command.offset, closing)) + .findFirst() + .ifPresent(closing -> { + command.caretOffset = command.offset + command.text.length(); + command.shiftsCaret = false; + command.text = ""; + }); } @@ -98,12 +109,13 @@ public void customizeDocumentCommand(IDocument document, DocumentCommand command * by the given value and false otherwise. * * @param document the document - * @param offset the offset - * @param value the content value to check + * @param offset the offset + * @param value the content value to check + * * @return true if the content after the given offset is followed * by the given value and false otherwise. */ - private static boolean isFollowedBy(IDocument document, int offset, String value) { + private static boolean isFollowedBy(final IDocument document, int offset, final String value) { for (int i = 0; i < value.length(); i++) { if (document.getLength() <= offset) { return false; @@ -112,7 +124,7 @@ private static boolean isFollowedBy(IDocument document, int offset, String value if (document.getChar(offset) != value.charAt(i)) { return false; } - } catch (BadLocationException e) { + } catch (final BadLocationException e) { return false; } offset++; @@ -120,58 +132,62 @@ private static boolean isFollowedBy(IDocument document, int offset, String value return true; } - private void onEnter(IDocument document, DocumentCommand command) { - LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance(); - for (IContentType contentType : contentTypes) { - if (!registry.shouldEnterAction(document, command.offset, contentType)) { - continue; - } - EnterActionAndIndent r = registry.getEnterAction(document, command.offset, contentType); - if (r != null) { - EnterAction enterAction = r.getEnterAction(); - String indentation = TextUtils.getIndentationFromWhitespace(r.getIndentation(), getTabSpaces()); - String delim = command.text; - switch (enterAction.getIndentAction()) { - case None: { - // Nothing special - String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText()); - String typeText = delim + increasedIndent; - - command.text = typeText; - command.shiftsCaret = false; - command.caretOffset = command.offset + (delim + increasedIndent).length(); - break; - } - case Indent: { - // Indent once - String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText()); - String typeText = delim + increasedIndent; - - command.text = typeText; - command.shiftsCaret = false; - command.caretOffset = command.offset + (delim + increasedIndent).length(); - break; + private void onEnter(final IDocument document, final DocumentCommand command) { + final LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance(); + if (contentTypes != null) { + for (final IContentType contentType : contentTypes) { + if (!registry.shouldEnterAction(document, command.offset, contentType)) { + continue; } - case IndentOutdent: { - // Ultra special - String normalIndent = normalizeIndentation(indentation); - String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText()); - - String typeText = delim + increasedIndent + delim + normalIndent; - command.text = typeText; - command.shiftsCaret = false; - command.caretOffset = command.offset + (delim + increasedIndent).length(); - break; - } - case Outdent: - String outdentedText = outdentString( - normalizeIndentation(indentation + enterAction.getAppendText())); - command.text = delim + outdentedText; - command.shiftsCaret = false; - command.caretOffset = command.offset + (delim + outdentedText).length(); - break; + final var enterIndent = registry.getEnterAction(document, command.offset, contentType); + if (enterIndent != null) { + final EnterAction enterAction = enterIndent.getEnterAction(); + final String indentation = TextUtils.getIndentationFromWhitespace(enterIndent.getIndentation(), + getTabSpaces()); + final String delim = command.text; + switch (enterAction.getIndentAction()) { + case None: { + // Nothing special + final String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText()); + final String typeText = delim + increasedIndent; + + command.text = typeText; + command.shiftsCaret = false; + command.caretOffset = command.offset + (delim + increasedIndent).length(); + break; + } + case Indent: { + // Indent once + final String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText()); + final String typeText = delim + increasedIndent; + + command.text = typeText; + command.shiftsCaret = false; + command.caretOffset = command.offset + (delim + increasedIndent).length(); + break; + } + case IndentOutdent: { + // Ultra special + final String normalIndent = normalizeIndentation(indentation); + final String increasedIndent = normalizeIndentation(indentation + enterAction.getAppendText()); + final String typeText = delim + increasedIndent + delim + normalIndent; + + command.text = typeText; + command.shiftsCaret = false; + command.caretOffset = command.offset + (delim + increasedIndent).length(); + break; + } + case Outdent: + final String outdentedText = outdentString( + normalizeIndentation(indentation + enterAction.getAppendText())); + + command.text = delim + outdentedText; + command.shiftsCaret = false; + command.caretOffset = command.offset + (delim + outdentedText).length(); + break; + } + return; } - return; } } @@ -179,29 +195,29 @@ private void onEnter(IDocument document, DocumentCommand command) { new DefaultIndentLineAutoEditStrategy().customizeDocumentCommand(document, command); } - private IContentType[] findContentTypes(IDocument document) { + private IContentType @Nullable [] findContentTypes(@Nullable final IDocument document) { if (this.document != null && this.document.equals(document)) { return contentTypes; } try { - ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); + final ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); this.contentTypes = info.getContentTypes(); this.document = document; - } catch (CoreException e) { + } catch (final CoreException e) { e.printStackTrace(); } return contentTypes; } - private String outdentString(String str) { + private String outdentString(final String str) { if (str.startsWith("\t")) {//$NON-NLS-1$ return str.substring(1); } - TabSpacesInfo tabSpaces = getTabSpaces(); + final TabSpacesInfo tabSpaces = getTabSpaces(); if (tabSpaces.isInsertSpaces()) { - char[] chars = new char[tabSpaces.getTabSize()]; + final char[] chars = new char[tabSpaces.getTabSize()]; Arrays.fill(chars, ' '); - String spaces = new String(chars); + final String spaces = new String(chars); if (str.startsWith(spaces)) { return str.substring(spaces.length()); } @@ -209,17 +225,15 @@ private String outdentString(String str) { return str; } - private String normalizeIndentation(String str) { - TabSpacesInfo tabSpaces = getTabSpaces(); + private String normalizeIndentation(final String str) { + final TabSpacesInfo tabSpaces = getTabSpaces(); return TextUtils.normalizeIndentation(str, tabSpaces.getTabSize(), tabSpaces.isInsertSpaces()); } private TabSpacesInfo getTabSpaces() { // For performance reason, tab spaces info are cached. - // If user change preferences (tab size, insert spaces), he must close the - // editor - // FIXME : how to detect changes of (tab size, insert spaces) with a generic - // mean? + // If user change preferences (tab size, insert spaces), he must close the editor + // FIXME : how to detect changes of (tab size, insert spaces) with a generic mean? if (tabSpacesInfo != null) { return tabSpacesInfo; } @@ -229,10 +243,9 @@ private TabSpacesInfo getTabSpaces() { private void installViewer() { if (viewer == null) { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IEditorPart editorPart = page.getActiveEditor(); + final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + final IEditorPart editorPart = page.getActiveEditor(); viewer = editorPart.getAdapter(ITextViewer.class); } } - } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java index af2a15538..4f53077db 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationCharacterPairMatcher.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2018 Angelo ZERR. + * Copyright (c) 2018 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration; @@ -15,6 +15,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; @@ -27,25 +28,36 @@ /** * Support of matching bracket with language configuration. - * */ public class LanguageConfigurationCharacterPairMatcher implements ICharacterPairMatcher, ICharacterPairMatcherExtension { + @Nullable private DefaultCharacterPairMatcher matcher; + @Nullable private IDocument document; + @Nullable @Override - public IRegion match(IDocument document, int offset) { - DefaultCharacterPairMatcher matcher = getMatcher(document); - return matcher != null ? matcher.match(document, offset) : null; + public IRegion match(@Nullable final IDocument document, final int offset) { + if (document == null) + return null; + final var matcher = getMatcher(document); + return matcher != null + ? matcher.match(document, offset) + : null; } + @Nullable @Override - public IRegion match(IDocument document, int offset, int length) { - DefaultCharacterPairMatcher matcher = getMatcher(document); - return matcher != null ? matcher.match(document, offset, length) : null; + public IRegion match(@Nullable final IDocument document, final int offset, final int length) { + if (document == null) + return null; + final var matcher = getMatcher(document); + return matcher != null + ? matcher.match(document, offset, length) + : null; } @Override @@ -53,28 +65,44 @@ public int getAnchor() { return matcher != null ? matcher.getAnchor() : -1; } + @Nullable @Override - public IRegion findEnclosingPeerCharacters(IDocument document, int offset, int length) { - DefaultCharacterPairMatcher matcher = getMatcher(document); - return matcher != null ? matcher.findEnclosingPeerCharacters(document, offset, length) : null; + public IRegion findEnclosingPeerCharacters(@Nullable final IDocument document, final int offset, final int length) { + if (document == null) + return null; + final var matcher = getMatcher(document); + return matcher != null + ? matcher.findEnclosingPeerCharacters(document, offset, length) + : null; } @Override - public boolean isMatchedChar(char ch) { - DefaultCharacterPairMatcher matcher = getMatcher(document); - return matcher != null ? matcher.isMatchedChar(ch) : false; + public boolean isMatchedChar(final char ch) { + final var document = this.document; + if (document == null) + return false; + final var matcher = getMatcher(document); + return matcher != null + ? matcher.isMatchedChar(ch) + : false; } @Override - public boolean isMatchedChar(char ch, IDocument document, int offset) { - DefaultCharacterPairMatcher matcher = getMatcher(document); - return matcher != null ? matcher.isMatchedChar(ch, document, offset) : false; + public boolean isMatchedChar(final char ch, @Nullable final IDocument document, final int offset) { + if (document == null) + return false; + final var matcher = getMatcher(document); + return matcher != null + ? matcher.isMatchedChar(ch, document, offset) + : false; } @Override - public boolean isRecomputationOfEnclosingPairRequired(IDocument document, IRegion currentSelection, - IRegion previousSelection) { - DefaultCharacterPairMatcher matcher = getMatcher(document); + public boolean isRecomputationOfEnclosingPairRequired(@Nullable final IDocument document, + @Nullable final IRegion currentSelection, @Nullable final IRegion previousSelection) { + if (document == null) + return false; + final var matcher = getMatcher(document); return matcher != null ? matcher.isRecomputationOfEnclosingPairRequired(document, currentSelection, previousSelection) : false; @@ -97,45 +125,45 @@ public void clear() { /** * Returns the matcher from the document. - * - * @param document - * @return */ - private DefaultCharacterPairMatcher getMatcher(IDocument document) { + @Nullable + private DefaultCharacterPairMatcher getMatcher(final IDocument document) { if (!document.equals(this.document)) { matcher = null; } if (matcher == null) { - // initizalize a DefaultCharacterPairMatcher by using character pairs of the - // language configuration. - final StringBuilder chars = new StringBuilder(); + // initialize a DefaultCharacterPairMatcher by using character pairs of the language configuration. + final var sb = new StringBuilder(); this.document = document; - IContentType[] contentTypes = findContentTypes(document); + final IContentType[] contentTypes = findContentTypes(document); if (contentTypes != null) { - LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance(); - for (IContentType contentType : contentTypes) { + final LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager + .getInstance(); + for (final IContentType contentType : contentTypes) { if (!registry.shouldSurroundingPairs(document, -1, contentType)) { continue; } - List surroundingPairs = registry.getSurroundingPairs(contentType); - for (CharacterPair surroundingPair : surroundingPairs) { - chars.append(surroundingPair.getKey()); - chars.append(surroundingPair.getValue()); + final List surroundingPairs = registry.getSurroundingPairs(contentType); + for (final CharacterPair surroundingPair : surroundingPairs) { + sb.append(surroundingPair.getKey()); + sb.append(surroundingPair.getValue()); } } } - matcher = new DefaultCharacterPairMatcher(chars.toString().toCharArray()); + final var chars = new char[sb.length()]; + sb.getChars(0, sb.length(), chars, 0); + matcher = new DefaultCharacterPairMatcher(chars); } return matcher; } - private IContentType[] findContentTypes(IDocument document) { + private IContentType @Nullable [] findContentTypes(final IDocument document) { try { - ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); - if(info != null) { + final ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); + if (info != null) { return info.getContentTypes(); } - } catch (CoreException e) { + } catch (final CoreException e) { e.printStackTrace(); } return null; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java index 5c1e5569c..e68a4faa3 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration; @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IMultiTextSelection; @@ -29,17 +30,13 @@ import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationRegistryManager; import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; import org.eclipse.tm4e.languageconfiguration.internal.supports.CommentSupport; import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils; import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; public class ToggleLineCommentHandler extends AbstractHandler { @@ -47,25 +44,34 @@ public class ToggleLineCommentHandler extends AbstractHandler { public static final String ADD_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.addblockcommentcommand"; public static final String REMOVE_BLOCK_COMMENT_COMMAND_ID = "org.eclipse.tm4e.languageconfiguration.removeblockcommentcommand"; + @Nullable + private static T adapt(@Nullable Object sourceObject, Class adapter) { + return Adapters.adapt(sourceObject, adapter); + } + + @Nullable @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart part = HandlerUtil.getActiveEditor(event); - ITextEditor editor = Adapters.adapt(part, ITextEditor.class); + public Object execute(@Nullable final ExecutionEvent event) throws ExecutionException { + if (event == null) { + return null; + } + final var part = HandlerUtil.getActiveEditor(event); + final var editor = adapt(part, ITextEditor.class); if (editor == null) { return null; } - ISelection selection = editor.getSelectionProvider().getSelection(); + final var selection = editor.getSelectionProvider().getSelection(); if (!(selection instanceof ITextSelection)) { return null; } - ITextSelection textSelection = (ITextSelection) selection; - IEditorInput input = editor.getEditorInput(); - IDocumentProvider docProvider = editor.getDocumentProvider(); + final var textSelection = (ITextSelection) selection; + final var input = editor.getEditorInput(); + final var docProvider = editor.getDocumentProvider(); if (docProvider == null || input == null) { return null; } - IDocument document = docProvider.getDocument(input); + final var document = docProvider.getDocument(input); if (document == null) { return null; } @@ -73,12 +79,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException { ContentTypeInfo info; try { info = ContentTypeHelper.findContentTypes(document); - } catch (CoreException e) { + } catch (final CoreException e) { return null; } - IContentType[] contentTypes = info.getContentTypes(); - Command command = event.getCommand(); - CommentSupport commentSupport = getCommentSupport(contentTypes); + final var contentTypes = info.getContentTypes(); + final var command = event.getCommand(); + final var commentSupport = getCommentSupport(contentTypes); if (commentSupport == null) { return null; } @@ -87,33 +93,51 @@ public Object execute(ExecutionEvent event) throws ExecutionException { return null; } - IRewriteTarget target = editor.getAdapter(IRewriteTarget.class); + final var target = adapt(editor, IRewriteTarget.class); if (target != null) { target.beginCompoundChange(); } try { - if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId())) { - if (commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty()) { - updateLineComment(document, textSelection, commentSupport.getLineComment(), editor); - } else if (commentSupport.getBlockComment() != null) { - Set lines = computeLines(textSelection, document); - for (int line : lines) { - int lineOffset = document.getLineOffset(line); - int lineLength = document.getLineLength(line); - ITextSelection range = new TextSelection(lineOffset, line == document.getNumberOfLines() - 1 ? lineLength : lineLength - 1); - toggleBlockComment(document, range, commentSupport, editor); + switch (command.getId()) { + case TOGGLE_LINE_COMMENT_COMMAND_ID: { + final var lineComment = commentSupport.getLineComment(); + if (lineComment != null && !lineComment.isEmpty()) { + updateLineComment(document, textSelection, lineComment, editor); + } else { + final var blockComment = commentSupport.getBlockComment(); + if (blockComment != null) { + final Set lines = computeLines(textSelection, document); + for (final int line : lines) { + final int lineOffset = document.getLineOffset(line); + final int lineLength = document.getLineLength(line); + final ITextSelection range = new TextSelection(lineOffset, + line == document.getNumberOfLines() - 1 ? lineLength : lineLength - 1); + toggleBlockComment(document, range, commentSupport, editor); + } } } - } else { - IRegion existingBlock = getBlockComment(document, textSelection, commentSupport); - if (ADD_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock == null) { - addBlockComment(document, textSelection, commentSupport.getBlockComment(), editor); - } else if (REMOVE_BLOCK_COMMENT_COMMAND_ID.equals(command.getId()) && existingBlock != null) { - removeBlockComment(document, textSelection, existingBlock, commentSupport.getBlockComment(), - editor); + break; + } + + case ADD_BLOCK_COMMENT_COMMAND_ID: { + final IRegion existingBlock = getBlockComment(document, textSelection, commentSupport); + final var blockComment = commentSupport.getBlockComment(); + if (existingBlock != null && blockComment != null) { + addBlockComment(document, textSelection, blockComment, editor); + } + break; + } + + case REMOVE_BLOCK_COMMENT_COMMAND_ID: { + final IRegion existingBlock = getBlockComment(document, textSelection, commentSupport); + final var blockComment = commentSupport.getBlockComment(); + if (existingBlock != null && blockComment != null) { + removeBlockComment(document, textSelection, existingBlock, blockComment, editor); } + break; + } } - } catch (BadLocationException e) { + } catch (final BadLocationException e) { // Caught by making no changes } finally { if (target != null) { @@ -123,14 +147,15 @@ public Object execute(ExecutionEvent event) throws ExecutionException { return null; } - private Set computeLines(ITextSelection textSelection, IDocument document) throws BadLocationException { - IRegion[] regions = textSelection instanceof IMultiTextSelection ? - ((IMultiTextSelection)textSelection).getRegions() : - new IRegion[] { new Region(textSelection.getOffset(), textSelection.getLength()) }; - Set lines = new HashSet<>(); - for (IRegion region : regions) { - int lineFrom = document.getLineOfOffset(region.getOffset()); - int lineTo = document.getLineOfOffset(region.getOffset() + region.getLength()); + private Set computeLines(final ITextSelection textSelection, final IDocument document) + throws BadLocationException { + final var regions = textSelection instanceof IMultiTextSelection + ? ((IMultiTextSelection) textSelection).getRegions() + : new IRegion[] { new Region(textSelection.getOffset(), textSelection.getLength()) }; + final var lines = new HashSet(); + for (final var region : regions) { + final int lineFrom = document.getLineOfOffset(region.getOffset()); + final int lineTo = document.getLineOfOffset(region.getOffset() + region.getLength()); for (int line = lineFrom; line <= lineTo; line++) { lines.add(line); } @@ -138,9 +163,10 @@ private Set computeLines(ITextSelection textSelection, IDocument docume return lines; } - private void toggleBlockComment(IDocument document, ITextSelection textSelection, CommentSupport commentSupport, ITextEditor editor) throws BadLocationException { - IRegion existingBlock = getBlockComment(document, textSelection, commentSupport); - CharacterPair blockComment = commentSupport.getBlockComment(); + private void toggleBlockComment(final IDocument document, final ITextSelection textSelection, + final CommentSupport commentSupport, final ITextEditor editor) throws BadLocationException { + final var existingBlock = getBlockComment(document, textSelection, commentSupport); + final var blockComment = commentSupport.getBlockComment(); if (blockComment == null) { return; } @@ -154,37 +180,41 @@ private void toggleBlockComment(IDocument document, ITextSelection textSelection /** * Returns true if comment support is valid according the command to do and * false otherwise. - * + * * @param commentSupport * @param command + * * @return true if comment support is valid according the command to do and * false otherwise. */ - private boolean isValid(CommentSupport commentSupport, Command command) { - if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && commentSupport.getLineComment() != null && !commentSupport.getLineComment().isEmpty()) { + private boolean isValid(final CommentSupport commentSupport, final Command command) { + final var lineComment = commentSupport.getLineComment(); + if (TOGGLE_LINE_COMMENT_COMMAND_ID.equals(command.getId()) && lineComment != null + && !lineComment.isEmpty()) { return true; } // check if block comment is valid - CharacterPair characterPair = commentSupport.getBlockComment(); - return characterPair != null && characterPair.getKey() != null && !characterPair.getKey().isEmpty() - && characterPair.getValue() != null && !characterPair.getValue().isEmpty(); + final var blockComment = commentSupport.getBlockComment(); + return blockComment != null + && !"".equals(blockComment.getKey()) + && !"".equals(blockComment.getValue()); } /** - * Returns the comment support from the given list of content types and null - * otherwise. - * + * Returns the comment support from the given list of content types and null otherwise. + * * @param contentTypes - * @return the comment support from the given list of content types and null - * otherwise. + * + * @return the comment support from the given list of content types and null otherwise. */ - private CommentSupport getCommentSupport(IContentType[] contentTypes) { - LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance(); - for (IContentType contentType : contentTypes) { + @Nullable + private CommentSupport getCommentSupport(final IContentType[] contentTypes) { + final var registry = LanguageConfigurationRegistryManager.getInstance(); + for (final var contentType : contentTypes) { if (!registry.shouldComment(contentType)) { continue; } - CommentSupport commentSupport = registry.getCommentSupport(contentType); + final var commentSupport = registry.getCommentSupport(contentType); if (commentSupport != null) { return commentSupport; } @@ -192,8 +222,8 @@ private CommentSupport getCommentSupport(IContentType[] contentTypes) { return null; } - private void updateLineComment(IDocument document, ITextSelection selection, String comment, ITextEditor editor) - throws BadLocationException { + private void updateLineComment(final IDocument document, final ITextSelection selection, final String comment, + final ITextEditor editor) throws BadLocationException { if (areLinesCommented(document, selection, comment)) { removeLineComments(document, selection, comment, editor); } else { @@ -201,11 +231,11 @@ private void updateLineComment(IDocument document, ITextSelection selection, Str } } - private boolean areLinesCommented(IDocument document, ITextSelection selection, String comment) + private boolean areLinesCommented(final IDocument document, final ITextSelection selection, final String comment) throws BadLocationException { int lineNumber = selection.getStartLine(); while (lineNumber <= selection.getEndLine()) { - IRegion lineRegion = document.getLineInformation(lineNumber); + final var lineRegion = document.getLineInformation(lineNumber); if (!document.get(lineRegion.getOffset(), lineRegion.getLength()).trim().startsWith(comment)) { return false; } @@ -214,16 +244,21 @@ private boolean areLinesCommented(IDocument document, ITextSelection selection, return true; } - private IRegion getBlockComment(IDocument document, ITextSelection selection, CommentSupport commentSupport) - throws BadLocationException { + @Nullable + private IRegion getBlockComment(final IDocument document, final ITextSelection selection, + final CommentSupport commentSupport) throws BadLocationException { if (selection.getText() == null) { return null; } - String text = document.get(); - String open = commentSupport.getBlockComment().getKey(); - String close = commentSupport.getBlockComment().getValue(); - int selectionStart = selection.getOffset(); - int selectionEnd = selectionStart + selection.getLength(); + final var blockComment = commentSupport.getBlockComment(); + if (blockComment == null) { + return null; + } + final String text = document.get(); + final String open = blockComment.getKey(); + final String close = blockComment.getValue(); + final int selectionStart = selection.getOffset(); + final int selectionEnd = selectionStart + selection.getLength(); int openOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionStart, open); if (openOffset == -1) { openOffset = text.lastIndexOf(open, selectionStart); @@ -235,7 +270,7 @@ private IRegion getBlockComment(IDocument document, ITextSelection selection, Co int closeOffset = TextUtils.startIndexOfOffsetTouchingString(text, selectionEnd, close); if (closeOffset == -1 || closeOffset < openOffset + open.length()) { closeOffset = text.indexOf(close, selectionEnd); - IRegion endLineRegion = document.getLineInformation(document.getLineOfOffset(selectionEnd)); + final IRegion endLineRegion = document.getLineInformation(document.getLineOfOffset(selectionEnd)); if (openOffset == -1 || closeOffset < openOffset + open.length() || closeOffset > endLineRegion.getOffset() + endLineRegion.getLength()) { return null; @@ -245,7 +280,7 @@ private IRegion getBlockComment(IDocument document, ITextSelection selection, Co // Make sure there isn't a different block closer before the one we found int othercloseOffset = text.indexOf(close, openOffset + open.length()); while (othercloseOffset != -1 && othercloseOffset < closeOffset) { - int startOfLineOffset = document.getLineOffset(document.getLineOfOffset(othercloseOffset)); + final int startOfLineOffset = document.getLineOffset(document.getLineOfOffset(othercloseOffset)); if (commentSupport.getLineComment() != null && text.substring(startOfLineOffset, othercloseOffset) .indexOf(commentSupport.getLineComment()) != -1) { return null; @@ -255,16 +290,16 @@ private IRegion getBlockComment(IDocument document, ITextSelection selection, Co return new Region(openOffset, closeOffset - openOffset); } - private void removeLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor) - throws BadLocationException { + private void removeLineComments(final IDocument document, final ITextSelection selection, final String comment, + final ITextEditor editor) throws BadLocationException { int lineNumber = selection.getStartLine(); - int endLineNumber = selection.getEndLine(); - String oldText = document.get(); + final int endLineNumber = selection.getEndLine(); + final String oldText = document.get(); int deletedChars = 0; boolean isStartBeforeComment = false; while (lineNumber <= endLineNumber) { - int commentOffset = oldText.indexOf(comment, document.getLineOffset(lineNumber) + deletedChars); + final int commentOffset = oldText.indexOf(comment, document.getLineOffset(lineNumber) + deletedChars); document.replace(commentOffset - deletedChars, comment.length(), ""); if (deletedChars == 0) { isStartBeforeComment = commentOffset > selection.getOffset(); @@ -274,31 +309,32 @@ private void removeLineComments(IDocument document, ITextSelection selection, St } lineNumber++; } - ITextSelection newSelection = new TextSelection( + final var newSelection = new TextSelection( selection.getOffset() - (isStartBeforeComment ? 0 : comment.length()), selection.getLength() - deletedChars); editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength()); } - private void addLineComments(IDocument document, ITextSelection selection, String comment, ITextEditor editor) - throws BadLocationException { + private void addLineComments(final IDocument document, final ITextSelection selection, final String comment, + final ITextEditor editor) throws BadLocationException { int insertedChars = 0; - for (int lineNumber : computeLines(selection, document)) { + for (final int lineNumber : computeLines(selection, document)) { document.replace(document.getLineOffset(lineNumber), 0, comment); insertedChars += comment.length(); } - ITextSelection newSelection = new TextSelection(selection.getOffset() + comment.length(), + final ITextSelection newSelection = new TextSelection(selection.getOffset() + comment.length(), selection.getLength() + insertedChars); editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength()); } - private void removeBlockComment(IDocument document, ITextSelection selection, IRegion existingBlock, - CharacterPair blockComment, ITextEditor editor) throws BadLocationException { - int openOffset = existingBlock.getOffset(); - int openLength = blockComment.getKey().length(); - int closeOffset = existingBlock.getOffset() + existingBlock.getLength(); - int closeLength = blockComment.getValue().length(); + private void removeBlockComment(final IDocument document, final ITextSelection selection, + final IRegion existingBlock, final CharacterPair blockComment, final ITextEditor editor) + throws BadLocationException { + final int openOffset = existingBlock.getOffset(); + final int openLength = blockComment.getKey().length(); + final int closeOffset = existingBlock.getOffset() + existingBlock.getLength(); + final int closeLength = blockComment.getValue().length(); document.replace(openOffset, openLength, ""); document.replace(closeOffset - openLength, closeLength, ""); @@ -311,17 +347,17 @@ private void removeBlockComment(IDocument document, ITextSelection selection, IR if (selection.getOffset() + selection.getLength() > closeOffset) { lengthFix += selection.getOffset() + selection.getLength() - closeOffset; } - ITextSelection newSelection = new TextSelection(selection.getOffset() - offsetFix, + final var newSelection = new TextSelection(selection.getOffset() - offsetFix, selection.getLength() - lengthFix); editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength()); } - private void addBlockComment(IDocument document, ITextSelection selection, CharacterPair blockComment, - ITextEditor editor) throws BadLocationException { + private void addBlockComment(final IDocument document, final ITextSelection selection, + final CharacterPair blockComment, final ITextEditor editor) throws BadLocationException { document.replace(selection.getOffset(), 0, blockComment.getKey()); document.replace(selection.getOffset() + selection.getLength() + blockComment.getKey().length(), 0, blockComment.getValue()); - ITextSelection newSelection = new TextSelection(selection.getOffset() + blockComment.getKey().length(), + final var newSelection = new TextSelection(selection.getOffset() + blockComment.getKey().length(), selection.getLength()); editor.selectAndReveal(newSelection.getOffset(), newSelection.getLength()); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/WorkingCopyLanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/WorkingCopyLanguageConfigurationRegistryManager.java index 05b011ed6..293d46424 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/WorkingCopyLanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/WorkingCopyLanguageConfigurationRegistryManager.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration; import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.internal.AbstractLanguageConfigurationRegistryManager; import org.osgi.service.prefs.BackingStoreException; @@ -21,37 +22,38 @@ public class WorkingCopyLanguageConfigurationRegistryManager extends AbstractLan private final ILanguageConfigurationRegistryManager manager; + @Nullable private List added; + @Nullable private List removed; - public WorkingCopyLanguageConfigurationRegistryManager(ILanguageConfigurationRegistryManager manager) { + public WorkingCopyLanguageConfigurationRegistryManager(final ILanguageConfigurationRegistryManager manager) { this.manager = manager; - load(); - } - private void load() { // Copy definitions - ILanguageConfigurationDefinition[] definitions = manager.getDefinitions(); - for (ILanguageConfigurationDefinition definition : definitions) { + final ILanguageConfigurationDefinition[] definitions = manager.getDefinitions(); + for (final ILanguageConfigurationDefinition definition : definitions) { super.registerLanguageConfigurationDefinition(definition); } } @Override - public void registerLanguageConfigurationDefinition(ILanguageConfigurationDefinition definition) { + public void registerLanguageConfigurationDefinition(final ILanguageConfigurationDefinition definition) { super.registerLanguageConfigurationDefinition(definition); + var added = this.added; if (added == null) { - added = new ArrayList<>(); + added = this.added = new ArrayList<>(); } added.add(definition); } @Override - public void unregisterLanguageConfigurationDefinition(ILanguageConfigurationDefinition definition) { + public void unregisterLanguageConfigurationDefinition(final ILanguageConfigurationDefinition definition) { super.unregisterLanguageConfigurationDefinition(definition); + var removed = this.added; if (removed == null) { - removed = new ArrayList<>(); + removed = this.removed = new ArrayList<>(); } if (added != null) { added.remove(definition); @@ -63,12 +65,12 @@ public void unregisterLanguageConfigurationDefinition(ILanguageConfigurationDefi @Override public void save() throws BackingStoreException { if (removed != null) { - for (ILanguageConfigurationDefinition definition : removed) { + for (final ILanguageConfigurationDefinition definition : removed) { manager.unregisterLanguageConfigurationDefinition(definition); } } if (added != null) { - for (ILanguageConfigurationDefinition definition : added) { + for (final ILanguageConfigurationDefinition definition : added) { manager.registerLanguageConfigurationDefinition(definition); } } @@ -76,5 +78,4 @@ public void save() throws BackingStoreException { manager.save(); } } - } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java index b762408ac..e71047c5f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java @@ -17,6 +17,7 @@ import java.util.Set; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; @@ -28,14 +29,14 @@ public abstract class AbstractLanguageConfigurationRegistryManager implements IL @Override public ILanguageConfigurationDefinition[] getDefinitions() { - Set definitions = new HashSet<>(); + final Set definitions = new HashSet<>(); userDefinitions.values().forEach(definitions::add); pluginDefinitions.values().forEach(definitions::add); return definitions.toArray(ILanguageConfigurationDefinition[]::new); } @Override - public void registerLanguageConfigurationDefinition(ILanguageConfigurationDefinition definition) { + public void registerLanguageConfigurationDefinition(final ILanguageConfigurationDefinition definition) { if (definition.getPluginId() == null) { userDefinitions.put(definition.getContentType(), definition); } else { @@ -44,7 +45,7 @@ public void registerLanguageConfigurationDefinition(ILanguageConfigurationDefini } @Override - public void unregisterLanguageConfigurationDefinition(ILanguageConfigurationDefinition definition) { + public void unregisterLanguageConfigurationDefinition(final ILanguageConfigurationDefinition definition) { if (definition.getPluginId() == null) { userDefinitions.remove(definition.getContentType()); } else { @@ -52,9 +53,10 @@ public void unregisterLanguageConfigurationDefinition(ILanguageConfigurationDefi } } + @Nullable @Override - public ILanguageConfiguration getLanguageConfigurationFor(IContentType[] contentTypes) { - for (IContentType contentType : contentTypes) { + public ILanguageConfiguration getLanguageConfigurationFor(final IContentType[] contentTypes) { + for (final IContentType contentType : contentTypes) { if (userDefinitions.containsKey(contentType)) { return userDefinitions.get(contentType).getLanguageConfiguration(); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java index b4efeac2c..657c4c857 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfiguration.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration; import org.eclipse.tm4e.languageconfiguration.internal.supports.AutoClosingPairConditional; import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPair; @@ -38,6 +39,7 @@ */ public final class LanguageConfiguration implements ILanguageConfiguration { + /** * Returns an instance of {@link LanguageConfiguration} loaded from the VSCode * language-configuration.json file reader. @@ -47,24 +49,25 @@ public final class LanguageConfiguration implements ILanguageConfiguration { * @return an instance of {@link LanguageConfiguration} loaded from the VSCode * language-configuration.json file reader. */ - public static LanguageConfiguration load(Reader reader) { + @Nullable + public static LanguageConfiguration load(final Reader reader) { return new GsonBuilder() - .registerTypeAdapter(OnEnterRule.class, (JsonDeserializer) (json, typeOfT, context) -> { + .registerTypeAdapter(OnEnterRule.class, (JsonDeserializer<@Nullable OnEnterRule>) (json, typeOfT, context) -> { String beforeText = null; String afterText = null; EnterAction action = null; if (json.isJsonObject()) { - JsonObject object = json.getAsJsonObject(); + final JsonObject object = json.getAsJsonObject(); beforeText = getAsString(object.get("beforeText")); //$NON-NLS-1$ afterText = getAsString(object.get("afterText")); //$NON-NLS-1$ - JsonElement actionElement = object.get("action"); //$NON-NLS-1$ + final JsonElement actionElement = object.get("action"); //$NON-NLS-1$ if (actionElement != null && actionElement.isJsonObject()) { - JsonObject actionObject = actionElement.getAsJsonObject(); - String indentActionString = getAsString(actionObject.get("indentAction")); //$NON-NLS-1$ + final JsonObject actionObject = actionElement.getAsJsonObject(); + final String indentActionString = getAsString(actionObject.get("indentAction")); //$NON-NLS-1$ if (indentActionString != null) { - IndentAction indentAction = IndentAction.valueOf(indentActionString); - Integer removeText = getAsInt(actionObject.get("removeText")); //$NON-NLS-1$ - String appendText = getAsString(actionObject.get("appendText")); //$NON-NLS-1$ + final IndentAction indentAction = IndentAction.valueOf(indentActionString); + final Integer removeText = getAsInteger(actionObject.get("removeText")); //$NON-NLS-1$ + final String appendText = getAsString(actionObject.get("appendText")); //$NON-NLS-1$ action = new EnterAction(indentAction); action.setAppendText(appendText); action.setRemoveText(removeText); @@ -75,19 +78,19 @@ public static LanguageConfiguration load(Reader reader) { return null; } return new OnEnterRule(beforeText, afterText, action); - }).registerTypeAdapter(Comments.class, (JsonDeserializer) (json, typeOfT, context) -> { + }).registerTypeAdapter(Comments.class, (JsonDeserializer<@Nullable Comments>) (json, typeOfT, context) -> { // ex: {"lineComment": "//","blockComment": [ "/*", "*/" ]} String lineComment = null; CharacterPair blockComment = null; if (json.isJsonObject()) { - JsonObject object = json.getAsJsonObject(); + final JsonObject object = json.getAsJsonObject(); lineComment = getAsString(object.get("lineComment")); //$NON-NLS-1$ - JsonElement blockCommentElement = object.get("blockComment"); //$NON-NLS-1$ + final JsonElement blockCommentElement = object.get("blockComment"); //$NON-NLS-1$ if (blockCommentElement != null && blockCommentElement.isJsonArray()) { - JsonArray blockCommentArray = blockCommentElement.getAsJsonArray(); + final JsonArray blockCommentArray = blockCommentElement.getAsJsonArray(); if (blockCommentArray.size() == 2) { - String blockCommentStart = getAsString(blockCommentArray.get(0)); - String blockCommentEnd = getAsString(blockCommentArray.get(1)); + final String blockCommentStart = getAsString(blockCommentArray.get(0)); + final String blockCommentEnd = getAsString(blockCommentArray.get(1)); if (blockCommentStart != null && blockCommentEnd != null) { blockComment = new CharacterPair(blockCommentStart, blockCommentEnd); } @@ -99,12 +102,12 @@ public static LanguageConfiguration load(Reader reader) { } return new Comments(lineComment, blockComment); }).registerTypeAdapter(CharacterPair.class, - (JsonDeserializer) (json, typeOfT, context) -> { + (JsonDeserializer<@Nullable CharacterPair>) (json, typeOfT, context) -> { String open = null; String close = null; if (json.isJsonArray()) { // ex: ["{","}"] - JsonArray characterPairs = json.getAsJsonArray(); + final JsonArray characterPairs = json.getAsJsonArray(); if (characterPairs.size() == 2) { open = getAsString(characterPairs.get(0)); close = getAsString(characterPairs.get(1)); @@ -116,27 +119,27 @@ public static LanguageConfiguration load(Reader reader) { return new CharacterPair(open, close); }) .registerTypeAdapter(AutoClosingPairConditional.class, - (JsonDeserializer) (json, typeOfT, context) -> { - List notInList = new ArrayList<>(); + (JsonDeserializer<@Nullable AutoClosingPairConditional>) (json, typeOfT, context) -> { + final List notInList = new ArrayList<>(); String open = null; String close = null; if (json.isJsonArray()) { // ex: ["{","}"] - JsonArray characterPairs = json.getAsJsonArray(); + final JsonArray characterPairs = json.getAsJsonArray(); if (characterPairs.size() == 2) { open = getAsString(characterPairs.get(0)); close = getAsString(characterPairs.get(1)); } } else if (json.isJsonObject()) { // ex: {"open":"'","close":"'", "notIn": ["string", "comment"]} - JsonObject object = json.getAsJsonObject(); + final JsonObject object = json.getAsJsonObject(); open = getAsString(object.get("open")); //$NON-NLS-1$ close = getAsString(object.get("close")); //$NON-NLS-1$ - JsonElement notInElement = object.get("notIn"); //$NON-NLS-1$ + final JsonElement notInElement = object.get("notIn"); //$NON-NLS-1$ if (notInElement != null && notInElement.isJsonArray()) { - JsonArray notInArray = notInElement.getAsJsonArray(); + final JsonArray notInArray = notInElement.getAsJsonArray(); notInArray.forEach(element -> { - String string = getAsString(element); + final String string = getAsString(element); if (string != null) { notInList.add(string); } @@ -148,17 +151,17 @@ public static LanguageConfiguration load(Reader reader) { } return new AutoClosingPairConditional(open, close, notInList); }) - .registerTypeAdapter(Folding.class, (JsonDeserializer) (json, typeOfT, context) -> { + .registerTypeAdapter(Folding.class, (JsonDeserializer<@Nullable Folding>) (json, typeOfT, context) -> { // ex: {"offSide": true, "markers": {"start": "^\\s*/", "end": "^\\s*"}} boolean offSide = false; String startMarker = null; String endMarker = null; if (json.isJsonObject()) { - JsonObject object = json.getAsJsonObject(); + final JsonObject object = json.getAsJsonObject(); offSide = getAsBoolean(object.get("offSide"), offSide); //$NON-NLS-1$ - JsonElement markersElement = object.get("markers"); //$NON-NLS-1$ + final JsonElement markersElement = object.get("markers"); //$NON-NLS-1$ if (markersElement != null && markersElement.isJsonObject()) { - JsonObject markersObject = markersElement.getAsJsonObject(); + final JsonObject markersObject = markersElement.getAsJsonObject(); startMarker = getAsString(markersObject.get("start")); //$NON-NLS-1$ endMarker = getAsString(markersObject.get("end")); //$NON-NLS-1$ } @@ -170,35 +173,37 @@ public static LanguageConfiguration load(Reader reader) { }).create().fromJson(reader, LanguageConfiguration.class); } - private static String getAsString(JsonElement element) { + @Nullable + private static String getAsString(@Nullable final JsonElement element) { if (element == null) { return null; } try { return element.getAsString(); - } catch (Exception e) { + } catch (final Exception e) { return null; } } - private static Boolean getAsBoolean(JsonElement element, Boolean defaultValue) { + private static boolean getAsBoolean(@Nullable final JsonElement element, final boolean defaultValue) { if (element == null) { return defaultValue; } try { return element.getAsBoolean(); - } catch (Exception e) { + } catch (final Exception e) { return defaultValue; } } - private static Integer getAsInt(JsonElement element) { + @Nullable + private static Integer getAsInteger(@Nullable final JsonElement element) { if (element == null) { return null; } try { return element.getAsInt(); - } catch (Exception e) { + } catch (final Exception e) { return null; } } @@ -206,17 +211,19 @@ private static Integer getAsInt(JsonElement element) { /** * Defines the comment symbols */ + @Nullable private Comments comments; /** - * The language's brackets. This configuration implicitly affects pressing Enter - * around these brackets. + * The language's brackets. This configuration implicitly affects pressing Enter around these brackets. */ + @Nullable private List brackets; /** * The language's rules to be evaluated when pressing Enter. */ + @Nullable private List onEnterRules; /** @@ -224,6 +231,7 @@ private static Integer getAsInt(JsonElement element) { * inserted with the 'open' character is typed. If not set, the configured * brackets will be used. */ + @Nullable private List autoClosingPairs; /** @@ -231,49 +239,58 @@ private static Integer getAsInt(JsonElement element) { * selection, the selected string is surrounded by the open and close * characters. If not set, the autoclosing pairs settings will be used. */ + @Nullable private List surroundingPairs; /** * Defines when and how code should be folded in the editor */ + @Nullable private Folding folding; /** - * Regex which defines what is considered to be a word in the programming - * language. + * Regex which defines what is considered to be a word in the programming language. */ + @Nullable private String wordPattern; + @Nullable @Override public Comments getComments() { return comments; } + @Nullable @Override public List getBrackets() { return brackets; } + @Nullable @Override public List getAutoClosingPairs() { return autoClosingPairs; } + @Nullable @Override public List getOnEnterRules() { return onEnterRules; } + @Nullable @Override public List getSurroundingPairs() { return surroundingPairs; } + @Nullable @Override public Folding getFolding() { return folding; } + @Nullable @Override public String getWordPattern() { return wordPattern; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java index 1d779d870..a306a5534 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal; @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.internal.supports.CharacterPairSupport; @@ -39,16 +40,21 @@ public final class LanguageConfigurationDefinition extends TMResource implements private boolean bracketAutoClosingEnabled = true; private boolean matchingPairsEnabled = true; + @Nullable private CharacterPairSupport characterPair; + + @Nullable private OnEnterSupport onEnter; + + @Nullable private CommentSupport comment; - public LanguageConfigurationDefinition(IContentType contentType, String path) { + public LanguageConfigurationDefinition(final IContentType contentType, final String path) { super(path); this.contentType = contentType; } - public LanguageConfigurationDefinition(IConfigurationElement ce) { + public LanguageConfigurationDefinition(final IConfigurationElement ce) { super(ce); this.contentType = ContentTypeHelper.getContentTypeById(ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR)); } @@ -56,8 +62,9 @@ public LanguageConfigurationDefinition(IConfigurationElement ce) { /** * Constructor for user preferences (loaded from Json with Gson). */ - public LanguageConfigurationDefinition(IContentType contentType, String path, String pluginId, - boolean onEnterEnabled, boolean bracketAutoClosingEnabled, boolean matchingPairsEnabled) { + public LanguageConfigurationDefinition(final IContentType contentType, final String path, + @Nullable final String pluginId, + final boolean onEnterEnabled, final boolean bracketAutoClosingEnabled, final boolean matchingPairsEnabled) { super(path, pluginId); this.contentType = contentType; this.onEnterEnabled = onEnterEnabled; @@ -70,9 +77,10 @@ public LanguageConfigurationDefinition(IContentType contentType, String path, St * * @return the "character pair" support and null otherwise. */ + @Nullable CharacterPairSupport getCharacterPair() { if (this.characterPair == null) { - ILanguageConfiguration conf = getLanguageConfiguration(); + final ILanguageConfiguration conf = getLanguageConfiguration(); if (conf != null) { this.characterPair = new CharacterPairSupport(conf.getBrackets(), conf.getAutoClosingPairs(), conf.getSurroundingPairs()); @@ -86,9 +94,10 @@ CharacterPairSupport getCharacterPair() { * * @return the "on enter" support and null otherwise. */ + @Nullable OnEnterSupport getOnEnter() { if (this.onEnter == null) { - ILanguageConfiguration conf = getLanguageConfiguration(); + final ILanguageConfiguration conf = getLanguageConfiguration(); if (conf != null && (conf.getBrackets() != null || conf.getOnEnterRules() != null)) { this.onEnter = new OnEnterSupport(conf.getBrackets(), conf.getOnEnterRules()); } @@ -101,9 +110,10 @@ OnEnterSupport getOnEnter() { * * @return the "commment" support and null otherwise. */ + @Nullable CommentSupport getCommentSupport() { if (this.comment == null) { - ILanguageConfiguration conf = getLanguageConfiguration(); + final ILanguageConfiguration conf = getLanguageConfiguration(); if (conf != null) { this.comment = new CommentSupport(conf.getComments()); } @@ -116,43 +126,48 @@ public IContentType getContentType() { return contentType; } + @Nullable @Override public ILanguageConfiguration getLanguageConfiguration() { - try { - return LanguageConfiguration.load(new InputStreamReader(getInputStream(), Charset.defaultCharset())); - } catch (IOException e) { - LanguageConfigurationPlugin.getInstance().getLog().log(new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, e.getMessage(), e)); + try (var in = getInputStream()) { + return LanguageConfiguration.load(new InputStreamReader(in, Charset.defaultCharset())); + } catch (final IOException e) { + final var plugin = LanguageConfigurationPlugin.getInstance(); + if (plugin != null) { + plugin.getLog().log( + new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, e.getMessage(), e)); + } return null; } } @Override - public Boolean isOnEnterEnabled() { + public boolean isOnEnterEnabled() { return onEnterEnabled; } @Override - public void setOnEnterEnabled(boolean onEnterEnabled) { + public void setOnEnterEnabled(final boolean onEnterEnabled) { this.onEnterEnabled = onEnterEnabled; } @Override - public Boolean isBracketAutoClosingEnabled() { + public boolean isBracketAutoClosingEnabled() { return bracketAutoClosingEnabled; } @Override - public void setBracketAutoClosingEnabled(boolean bracketAutoClosingEnabled) { + public void setBracketAutoClosingEnabled(final boolean bracketAutoClosingEnabled) { this.bracketAutoClosingEnabled = bracketAutoClosingEnabled; } @Override - public Boolean isMatchingPairsEnabled() { + public boolean isMatchingPairsEnabled() { return matchingPairsEnabled; } @Override - public void setMatchingPairsEnabled(boolean matchingPairsEnabled) { + public void setMatchingPairsEnabled(final boolean matchingPairsEnabled) { this.matchingPairsEnabled = matchingPairsEnabled; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java index 23f14c9dc..ff485a828 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java @@ -11,12 +11,13 @@ */ package org.eclipse.tm4e.languageconfiguration.internal; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.osgi.util.NLS; /** * Helper class to get NLSed messages. - * */ +@NonNullByDefault({}) public final class LanguageConfigurationMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages"; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java index c6469b25b..bf4aba97a 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -23,20 +24,22 @@ public final class LanguageConfigurationPlugin extends AbstractUIPlugin { public static final String PLUGIN_ID = "org.eclipse.tm4e.languageconfiguration"; //$NON-NLS-1$ + @Nullable private static LanguageConfigurationPlugin INSTANCE = null; + @Nullable static LanguageConfigurationPlugin getInstance() { return INSTANCE; } @Override - public void start(BundleContext context) throws Exception { + public void start(@Nullable final BundleContext context) throws Exception { super.start(context); INSTANCE = this; } @Override - public void stop(BundleContext context) throws Exception { + public void stop(@Nullable final BundleContext context) throws Exception { INSTANCE = null; super.stop(context); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java index 52ced048c..63d13ab74 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java @@ -1,14 +1,14 @@ /** - * Copyright (c) 2015-2018 Angelo ZERR and others. + * Copyright (c) 2015-2018 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation - * Lucas Bullen (Red Hat Inc.) - language configuration preferences + * Contributors: + * Angelo Zerr - initial API and implementation + * Lucas Bullen (Red Hat Inc.) - language configuration preferences */ package org.eclipse.tm4e.languageconfiguration.internal; @@ -16,11 +16,10 @@ import java.util.Collections; import java.util.List; -import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; @@ -42,6 +41,7 @@ public final class LanguageConfigurationRegistryManager extends AbstractLanguage private static final String EXTENSION_LANGUAGE_CONFIGURATIONS = "languageConfigurations"; //$NON-NLS-1$ private static final String LANGUAGE_CONFIGURATION_ELT = "languageConfiguration"; //$NON-NLS-1$ + @Nullable private static LanguageConfigurationRegistryManager INSTANCE; public static LanguageConfigurationRegistryManager getInstance() { @@ -56,16 +56,17 @@ private static synchronized LanguageConfigurationRegistryManager createInstance( if (INSTANCE != null) { return INSTANCE; } - LanguageConfigurationRegistryManager manager = new LanguageConfigurationRegistryManager(); + final LanguageConfigurationRegistryManager manager = new LanguageConfigurationRegistryManager(); manager.load(); return manager; } - private LanguageConfigurationDefinition getDefinition(IContentType contentType) { + @Nullable + private LanguageConfigurationDefinition getDefinition(final IContentType contentType) { LanguageConfigurationDefinition bestFit = null; - for (ILanguageConfigurationDefinition iDefinition : getDefinitions()) { + for (final var iDefinition : getDefinitions()) { if (iDefinition instanceof LanguageConfigurationDefinition) { - LanguageConfigurationDefinition definition = (LanguageConfigurationDefinition) iDefinition; + final var definition = (LanguageConfigurationDefinition) iDefinition; if (contentType.isKindOf(definition.getContentType()) && (bestFit == null || definition.getContentType().isKindOf(bestFit.getContentType()))) { bestFit = definition; @@ -76,87 +77,89 @@ private LanguageConfigurationDefinition getDefinition(IContentType contentType) return bestFit; } - public CharacterPair getAutoClosePair(String text, Integer offset, String newCharacter, IContentType contentType) { - LanguageConfigurationDefinition definition = getDefinition(contentType); + @Nullable + public CharacterPair getAutoClosePair(final String text, final int offset, final String newCharacter, + final IContentType contentType) { + final var definition = getDefinition(contentType); if (definition == null || !definition.isBracketAutoClosingEnabled()) { return null; } - CharacterPairSupport characterPairSupport = this._getCharacterPairSupport(contentType); + final CharacterPairSupport characterPairSupport = this._getCharacterPairSupport(contentType); return characterPairSupport == null ? null : characterPairSupport.getAutoClosePair(text, offset, newCharacter); } - public boolean shouldSurroundingPairs(IDocument document, int offset, IContentType contentType) { - LanguageConfigurationDefinition definition = getDefinition(contentType); + public boolean shouldSurroundingPairs(final IDocument document, final int offset, final IContentType contentType) { + final var definition = getDefinition(contentType); if (definition == null || !definition.isMatchingPairsEnabled()) { return false; } - CharacterPairSupport characterPairSupport = this._getCharacterPairSupport(contentType); + final var characterPairSupport = this._getCharacterPairSupport(contentType); return characterPairSupport != null; } - public boolean shouldEnterAction(IDocument document, int offset, IContentType contentType) { - LanguageConfigurationDefinition definition = getDefinition(contentType); + public boolean shouldEnterAction(final IDocument document, final int offset, final IContentType contentType) { + final var definition = getDefinition(contentType); if (definition == null || !definition.isOnEnterEnabled()) { return false; } - OnEnterSupport onEnterSupport = this._getOnEnterSupport(contentType); + final var onEnterSupport = this._getOnEnterSupport(contentType); return onEnterSupport != null; } - public boolean shouldComment(IContentType contentType) { - LanguageConfigurationDefinition definition = getDefinition(contentType); + public boolean shouldComment(final IContentType contentType) { + final var definition = getDefinition(contentType); if (definition == null || !definition.isOnEnterEnabled()) { return false; } - CommentSupport commentSupport = this.getCommentSupport(contentType); + final var commentSupport = this.getCommentSupport(contentType); if (commentSupport == null) { return false; } return true; } - public List getEnabledAutoClosingPairs(IContentType contentType) { - LanguageConfigurationDefinition definition = getDefinition(contentType); + public List getEnabledAutoClosingPairs(final IContentType contentType) { + final var definition = getDefinition(contentType); if (definition == null || !definition.isBracketAutoClosingEnabled()) { return Collections.emptyList(); } - CharacterPairSupport characterPairSupport = this._getCharacterPairSupport(contentType); + final var characterPairSupport = this._getCharacterPairSupport(contentType); if (characterPairSupport == null) { return Collections.emptyList(); } return characterPairSupport.getAutoClosingPairs(); } - public List getSurroundingPairs(IContentType contentType) { - CharacterPairSupport characterPairSupport = this._getCharacterPairSupport(contentType); + public List getSurroundingPairs(final IContentType contentType) { + final var characterPairSupport = this._getCharacterPairSupport(contentType); if (characterPairSupport == null) { return Collections.emptyList(); } return characterPairSupport.getSurroundingPairs(); } - public EnterActionAndIndent getEnterAction(IDocument document, int offset, IContentType contentType) { + @Nullable + public EnterActionAndIndent getEnterAction(final IDocument document, final int offset, + final IContentType contentType) { String indentation = TextUtils.getLinePrefixingWhitespaceAtPosition(document, offset); - // let scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, - // range.startColumn); - OnEnterSupport onEnterSupport = this._getOnEnterSupport(contentType /* scopedLineTokens.languageId */); + // let scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, range.startColumn); + final var onEnterSupport = this._getOnEnterSupport(contentType /* scopedLineTokens.languageId */); if (onEnterSupport == null) { return null; } try { - IRegion lineInfo = document.getLineInformationOfOffset(offset); + final IRegion lineInfo = document.getLineInformationOfOffset(offset); - // String scopeLineText = DocumentHelper.getLineTextOfOffset(document, offset, - // false); - String beforeEnterText = document.get(lineInfo.getOffset(), offset - lineInfo.getOffset()); + // String scopeLineText = DocumentHelper.getLineTextOfOffset(document, offset, false); + final String beforeEnterText = document.get(lineInfo.getOffset(), offset - lineInfo.getOffset()); String afterEnterText = null; // selection support // if (range.isEmpty()) { afterEnterText = document.get(offset, lineInfo.getLength() - (offset - lineInfo.getOffset())); // scopedLineText.substr(range.startColumn - // - 1 - - // scopedLineTokens.firstCharOffset); + // - 1 - + // scopedLineTokens.firstCharOffset); // } else { // const endScopedLineTokens = this.getScopedLineTokens(model, // range.endLineNumber, range.endColumn); @@ -164,7 +167,7 @@ public EnterActionAndIndent getEnterAction(IDocument document, int offset, ICont // - 1 - scopedLineTokens.firstCharOffset); // } - String oneLineAboveText = ""; //$NON-NLS-1$ + final String oneLineAboveText = ""; //$NON-NLS-1$ /* * let lineNumber = range.startLineNumber; let oneLineAboveText = ''; * @@ -180,7 +183,7 @@ public EnterActionAndIndent getEnterAction(IDocument document, int offset, ICont EnterAction enterResult = null; try { enterResult = onEnterSupport.onEnter(oneLineAboveText, beforeEnterText, afterEnterText); - } catch (Exception e) { + } catch (final Exception e) { // onUnexpectedError(e); } @@ -199,40 +202,44 @@ public EnterActionAndIndent getEnterAction(IDocument document, int offset, ICont } } - if (enterResult.getRemoveText() != null) { - indentation = indentation.substring(0, indentation.length() - enterResult.getRemoveText()); + final var removeText = enterResult.getRemoveText(); + if (removeText != null) { + indentation = indentation.substring(0, indentation.length() - removeText); } return new EnterActionAndIndent(enterResult, indentation); - } catch (BadLocationException e1) { + } catch (final BadLocationException e1) { } return null; } - public CommentSupport getCommentSupport(IContentType contentType) { - LanguageConfigurationDefinition value = this.getDefinition(contentType); - if (value == null) { + @Nullable + public CommentSupport getCommentSupport(final IContentType contentType) { + final var definition = this.getDefinition(contentType); + if (definition == null) { return null; } - return value.getCommentSupport(); + return definition.getCommentSupport(); } - private OnEnterSupport _getOnEnterSupport(IContentType contentType) { - LanguageConfigurationDefinition value = this.getDefinition(contentType); - if (value == null) { + @Nullable + private OnEnterSupport _getOnEnterSupport(final IContentType contentType) { + final var definition = this.getDefinition(contentType); + if (definition == null) { return null; } - return value.getOnEnter(); + return definition.getOnEnter(); } - private CharacterPairSupport _getCharacterPairSupport(IContentType contentType) { - LanguageConfigurationDefinition value = this.getDefinition(contentType); - if (value == null) { + @Nullable + private CharacterPairSupport _getCharacterPairSupport(final IContentType contentType) { + final var definition = this.getDefinition(contentType); + if (definition == null) { return null; } - return value.getCharacterPair(); + return definition.getCharacterPair(); } private void load() { @@ -241,12 +248,12 @@ private void load() { } private void loadFromExtensionPoints() { - IConfigurationElement[] cf = Platform.getExtensionRegistry() - .getConfigurationElementsFor(LanguageConfigurationPlugin.PLUGIN_ID, EXTENSION_LANGUAGE_CONFIGURATIONS); - for (IConfigurationElement ce : cf) { - String name = ce.getName(); + final var config = Platform.getExtensionRegistry().getConfigurationElementsFor( + LanguageConfigurationPlugin.PLUGIN_ID, EXTENSION_LANGUAGE_CONFIGURATIONS); + for (final var configElem : config) { + final String name = configElem.getName(); if (LANGUAGE_CONFIGURATION_ELT.equals(name)) { - LanguageConfigurationDefinition delegate = new LanguageConfigurationDefinition(ce); + final LanguageConfigurationDefinition delegate = new LanguageConfigurationDefinition(configElem); registerLanguageConfigurationDefinition(delegate); } } @@ -256,12 +263,11 @@ private void loadFromExtensionPoints() { private void loadFromPreferences() { // Load grammar definitions from the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.languageconfiguration.prefs" - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(LanguageConfigurationPlugin.PLUGIN_ID); - String json = prefs.get(PreferenceConstants.LANGUAGE_CONFIGURATIONS, null); + final var prefs = InstanceScope.INSTANCE.getNode(LanguageConfigurationPlugin.PLUGIN_ID); + final String json = prefs.get(PreferenceConstants.LANGUAGE_CONFIGURATIONS, null); if (json != null) { - ILanguageConfigurationDefinition[] definitions = PreferenceHelper - .loadLanguageConfigurationDefinitions(json); - for (ILanguageConfigurationDefinition definition : definitions) { + final var definitions = PreferenceHelper.loadLanguageConfigurationDefinitions(json); + for (final var definition : definitions) { registerLanguageConfigurationDefinition(definition); } } @@ -271,7 +277,7 @@ private void loadFromPreferences() { public void save() throws BackingStoreException { // Save grammar definitions in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.languageconfiguration.prefs" - List definitions = new ArrayList<>(); + final var definitions = new ArrayList(); userDefinitions.values().forEach(definitions::add); pluginDefinitions.values().forEach(definition -> { if (!(definition.isBracketAutoClosingEnabled() && definition.isMatchingPairsEnabled() @@ -279,10 +285,9 @@ public void save() throws BackingStoreException { definitions.add(definition); } }); - String json = PreferenceHelper.toJson(definitions); - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(LanguageConfigurationPlugin.PLUGIN_ID); + final var json = PreferenceHelper.toJson(definitions); + final var prefs = InstanceScope.INSTANCE.getNode(LanguageConfigurationPlugin.PLUGIN_ID); prefs.put(PreferenceConstants.LANGUAGE_CONFIGURATIONS, json); prefs.flush(); } - } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/package-info.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/package-info.java new file mode 100644 index 000000000..13c21ce9c --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.languageconfiguration.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java index 1941fecef..30f65e07a 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationContentProvider.java @@ -11,21 +11,25 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.preferences; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; final class LanguageConfigurationContentProvider implements IStructuredContentProvider { + private static final Object[] EMPTY = {}; + + @Nullable private ILanguageConfigurationRegistryManager registry; @Override - public Object[] getElements(Object input) { - return registry.getDefinitions(); + public Object[] getElements(@Nullable final Object input) { + return registry != null ? registry.getDefinitions() : EMPTY; } @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + public void inputChanged(@Nullable final Viewer viewer, @Nullable final Object oldInput, @Nullable final Object newInput) { registry = (ILanguageConfigurationRegistryManager) newInput; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java index 6f3f575b4..a020d5382 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationLabelProvider.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.preferences; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; @@ -18,19 +19,25 @@ final class LanguageConfigurationLabelProvider extends LabelProvider implements ITableLabelProvider { + @Nullable @Override - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(@Nullable final Object element, final int columnIndex) { return null; } + @Nullable @Override - public String getText(Object element) { + public String getText(@Nullable final Object element) { return getColumnText(element, 0); } + @Nullable @Override - public String getColumnText(Object element, int columnIndex) { - ILanguageConfigurationDefinition definition = (ILanguageConfigurationDefinition) element; + public String getColumnText(@Nullable final Object element, final int columnIndex) { + if (element == null) + return null; + + final ILanguageConfigurationDefinition definition = (ILanguageConfigurationDefinition) element; switch (columnIndex) { case 0: diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java index fb0301934..1c45d640e 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java @@ -16,6 +16,7 @@ import java.util.Collections; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.preference.PreferencePage; @@ -23,7 +24,6 @@ import org.eclipse.jface.util.BidiUtils; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; @@ -61,15 +61,15 @@ */ public final class LanguageConfigurationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - final static String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$ + static final String PAGE_ID = "org.eclipse.tm4e.languageconfiguration.preferences.LanguageConfigurationPreferencePage"; //$NON-NLS-1$ private final ILanguageConfigurationRegistryManager manager = new WorkingCopyLanguageConfigurationRegistryManager( LanguageConfigurationRegistryManager.getInstance()); + @Nullable private TableViewer definitionViewer; - private Button definitionNewButton; - private Button definitionRemoveButton; + @Nullable private LanguageConfigurationPreferencesWidget infoWidget; public LanguageConfigurationPreferencePage() { @@ -77,30 +77,33 @@ public LanguageConfigurationPreferencePage() { } @Override - protected Control createContents(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(); + protected Control createContents(@Nullable final Composite ancestor) { + final var parent = new Composite(ancestor, SWT.NONE); + final var layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); - Composite innerParent = new Composite(parent, SWT.NONE); - GridLayout innerLayout = new GridLayout(); + final var innerParent = new Composite(parent, SWT.NONE); + final var innerLayout = new GridLayout(); innerLayout.numColumns = 2; innerLayout.marginHeight = 0; innerLayout.marginWidth = 0; innerParent.setLayout(innerLayout); - GridData gd = new GridData(GridData.FILL_BOTH); + final var gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; innerParent.setLayoutData(gd); createDefinitionsListContent(parent); + assert definitionViewer != null; definitionViewer.setInput(manager); - infoWidget = new LanguageConfigurationPreferencesWidget(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + final var infoWidget = new LanguageConfigurationPreferencesWidget(parent, SWT.NONE); + this.infoWidget = infoWidget; + + final var data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; infoWidget.setLayoutData(data); @@ -116,46 +119,47 @@ protected Control createContents(Composite ancestor) { * * @param parent */ - private void createDefinitionsListContent(Composite parent) { - Label description = new Label(parent, SWT.NONE); + private void createDefinitionsListContent(final Composite parent) { + final var description = new Label(parent, SWT.NONE); description.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_description2); description.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); - Composite tableComposite = new Composite(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_BOTH); + final var tableComposite = new Composite(parent, SWT.NONE); + final var data = new GridData(GridData.FILL_BOTH); data.widthHint = 360; data.heightHint = convertHeightInCharsToPixels(10); tableComposite.setLayoutData(data); - TableColumnLayout columnLayout = new TableColumnLayout(); + final var columnLayout = new TableColumnLayout(); tableComposite.setLayout(columnLayout); - Table table = new Table(tableComposite, + final var table = new Table(tableComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); table.setHeaderVisible(true); table.setLinesVisible(true); - GC gc = new GC(getShell()); + final GC gc = new GC(getShell()); gc.setFont(JFaceResources.getDialogFont()); - ColumnViewerComparator viewerComparator = new ColumnViewerComparator(); + final var viewerComparator = new ColumnViewerComparator(); - definitionViewer = new TableViewer(table); + final var definitionViewer = new TableViewer(table); + this.definitionViewer = definitionViewer; - TableColumn column1 = new TableColumn(table, SWT.NONE); + final var column1 = new TableColumn(table, SWT.NONE); column1.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_contentType); int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.LanguageConfigurationPreferencePage_contentType); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); column1.addSelectionListener(new ColumnSelectionAdapter(column1, definitionViewer, 0, viewerComparator)); - TableColumn column2 = new TableColumn(table, SWT.NONE); + final var column2 = new TableColumn(table, SWT.NONE); column2.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_path); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.LanguageConfigurationPreferencePage_path); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); column2.addSelectionListener(new ColumnSelectionAdapter(column2, definitionViewer, 1, viewerComparator)); - TableColumn column3 = new TableColumn(table, SWT.NONE); + final var column3 = new TableColumn(table, SWT.NONE); column3.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_pluginId); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.LanguageConfigurationPreferencePage_pluginId); @@ -168,86 +172,85 @@ private void createDefinitionsListContent(Composite parent) { definitionViewer.setContentProvider(new LanguageConfigurationContentProvider()); definitionViewer.setComparator(viewerComparator); - definitionViewer.addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent e) { - IStructuredSelection selection = definitionViewer.getStructuredSelection(); - infoWidget.refresh(null, manager); - if (selection.isEmpty()) { - return; - } - ILanguageConfigurationDefinition definition = (ILanguageConfigurationDefinition) (selection) - .getFirstElement(); - // Update button - definitionRemoveButton.setEnabled(definition.getPluginId() == null); - selectDefinition(definition); - } - - private void selectDefinition(ILanguageConfigurationDefinition definition) { - infoWidget.refresh(definition, manager); - } - }); - // Specify default sorting table.setSortColumn(column1); table.setSortDirection(viewerComparator.getDirection()); BidiUtils.applyTextDirection(definitionViewer.getControl(), BidiUtils.BTD_DEFAULT); - Composite buttons = new Composite(parent, SWT.NONE); + final var buttons = new Composite(parent, SWT.NONE); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - GridLayout layout = new GridLayout(); + final var layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); - definitionNewButton = new Button(buttons, SWT.PUSH); + final var definitionNewButton = new Button(buttons, SWT.PUSH); definitionNewButton.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_new); definitionNewButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); definitionNewButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { + public void handleEvent(@Nullable final Event e) { add(); } private void add() { // Open import wizard for language configurations. - LanguageConfigurationImportWizard wizard = new LanguageConfigurationImportWizard(false); + final var wizard = new LanguageConfigurationImportWizard(false); wizard.setRegistryManager(manager); - WizardDialog dialog = new WizardDialog(getShell(), wizard); + final var dialog = new WizardDialog(getShell(), wizard); if (dialog.open() == Window.OK) { - ILanguageConfigurationDefinition created = wizard.getCreatedDefinition(); + final var created = wizard.getCreatedDefinition(); definitionViewer.refresh(); definitionViewer.setSelection(new StructuredSelection(created)); } } }); - definitionRemoveButton = new Button(buttons, SWT.PUSH); + final var definitionRemoveButton = new Button(buttons, SWT.PUSH); definitionRemoveButton.setText(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_remove); definitionRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); definitionRemoveButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { + public void handleEvent(@Nullable final Event e) { remove(); } private void remove() { - Collection definitions = getSelectedUserDefinitions(); + final var definitions = getSelectedUserDefinitions(definitionViewer); if (!definitions.isEmpty()) { - for (ILanguageConfigurationDefinition definition : definitions) { + for (final var definition : definitions) { manager.unregisterLanguageConfigurationDefinition(definition); } definitionViewer.refresh(); } } }); + + definitionViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(@Nullable final SelectionChangedEvent e) { + final var selection = definitionViewer.getStructuredSelection(); + assert infoWidget != null; + infoWidget.refresh(null, manager); + if (selection.isEmpty()) { + return; + } + final var definition = (ILanguageConfigurationDefinition) (selection).getFirstElement(); + // Update button + assert definitionRemoveButton != null; + definitionRemoveButton.setEnabled(definition.getPluginId() == null); + selectDefinition(definition); + } + + private void selectDefinition(final ILanguageConfigurationDefinition definition) { + assert infoWidget != null; + infoWidget.refresh(definition, manager); + } + }); } - private int computeMinimumColumnWidth(GC gc, String string) { + private int computeMinimumColumnWidth(final GC gc, final String string) { return gc.stringExtent(string).x + 10; // pad 10 to accommodate table header trimmings } @@ -256,8 +259,9 @@ private int computeMinimumColumnWidth(GC gc, String string) { * * @return list of selected definitions which was created by the user. */ - private Collection getSelectedUserDefinitions() { - IStructuredSelection selection = definitionViewer.getStructuredSelection(); + private Collection getSelectedUserDefinitions( + final TableViewer definitionViewer) { + final var selection = definitionViewer.getStructuredSelection(); if (selection.isEmpty()) { return Collections.emptyList(); } @@ -266,7 +270,7 @@ private Collection getSelectedUserDefinitions( } @Override - public void setVisible(boolean visible) { + public void setVisible(final boolean visible) { super.setVisible(visible); if (visible) { setTitle(LanguageConfigurationMessages.LanguageConfigurationPreferencePage_title); @@ -277,14 +281,14 @@ public void setVisible(boolean visible) { public boolean performOk() { try { manager.save(); - } catch (BackingStoreException e) { + } catch (final BackingStoreException e) { // TODO: Log } return super.performOk(); } @Override - public void init(IWorkbench workbench) { + public void init(@Nullable final IWorkbench workbench) { } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java index cf18be1b6..0aa404a00 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java @@ -35,8 +35,8 @@ public final class PreferenceHelper { static { DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(LanguageConfigurationDefinition.class, (JsonDeserializer) (json, typeOfT, context) -> { - JsonObject object = json.getAsJsonObject(); - JsonElement pluginId = object.get("pluginId"); + final JsonObject object = json.getAsJsonObject(); + final JsonElement pluginId = object.get("pluginId"); return new LanguageConfigurationDefinition( ContentTypeHelper.getContentTypeById(object.get("contentTypeId").getAsString()), //$NON-NLS-1$ object.get("path").getAsString(), //$NON-NLS-1$ @@ -46,7 +46,7 @@ public final class PreferenceHelper { object.get("matchingPairsEnabled").getAsBoolean()); //$NON-NLS-1$ }).registerTypeAdapter(LanguageConfigurationDefinition.class, (JsonSerializer) (definition, typeOfT, context) -> { - JsonObject object = new JsonObject(); + final JsonObject object = new JsonObject(); object.addProperty("path", definition.getPath()); //$NON-NLS-1$ object.addProperty("pluginId", definition.getPluginId()); //$NON-NLS-1$ object.addProperty("contentTypeId", definition.getContentType().getId()); //$NON-NLS-1$ @@ -58,11 +58,11 @@ public final class PreferenceHelper { .create(); } - public static ILanguageConfigurationDefinition[] loadLanguageConfigurationDefinitions(String json) { + public static ILanguageConfigurationDefinition[] loadLanguageConfigurationDefinitions(final String json) { return DEFAULT_GSON.fromJson(json, LanguageConfigurationDefinition[].class); } - public static String toJson(Collection definitions) { + public static String toJson(final Collection definitions) { return DEFAULT_GSON.toJson(definitions); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/package-info.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/package-info.java new file mode 100644 index 000000000..eaea04298 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.languageconfiguration.internal.preferences; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java index 2caea279e..eeb849d9d 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/AutoClosingPairConditional.java @@ -13,16 +13,20 @@ import java.util.List; +import org.eclipse.jdt.annotation.Nullable; + @SuppressWarnings("serial") public final class AutoClosingPairConditional extends CharacterPair { + @Nullable private final List notIn; - public AutoClosingPairConditional(String open, String close, List notIn) { + public AutoClosingPairConditional(final String open, final String close, @Nullable final List notIn) { super(open, close); this.notIn = notIn; } + @Nullable public List getNotIn() { return notIn; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java index 286cc5179..d29f623f9 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPair.java @@ -16,11 +16,11 @@ /** * A tuple of two characters, like a pair of opening and closing brackets. */ -@SuppressWarnings("serial") public class CharacterPair extends SimpleEntry { - public CharacterPair(String key, String value) { + private static final long serialVersionUID = 1L; + + public CharacterPair(final String key, final String value) { super(key, value); } - } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java index b119b99fd..c2f9c3cf5 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CharacterPairSupport.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.supports; @@ -16,17 +16,19 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; + /** * The "character pair" support. - * */ public final class CharacterPairSupport { private List autoClosingPairs; private final List surroundingPairs; - public CharacterPairSupport(List brackets, List autoClosingPairs, - List surroundingPairs) { + public CharacterPairSupport(@Nullable final List brackets, + @Nullable final List autoClosingPairs, + @Nullable final List surroundingPairs) { if (autoClosingPairs != null) { this.autoClosingPairs = autoClosingPairs.stream().filter(Objects::nonNull) .map(el -> new AutoClosingPairConditional(el.getKey(), el.getValue(), el.getNotIn())) @@ -44,18 +46,19 @@ public CharacterPairSupport(List brackets, List 1) { - String offsetPrefix = text.substring(0, offset); + final String offsetPrefix = text.substring(0, offset); if (!offsetPrefix.endsWith(opening.substring(0, opening.length() - 1))) { continue; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java index db7ff8b72..bfce90cb9 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/CommentSupport.java @@ -1,58 +1,75 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.supports; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; public final class CommentSupport { + @Nullable private final Comments comments; - public CommentSupport(Comments comments) { + public CommentSupport(@Nullable final Comments comments) { this.comments = comments; } - private boolean isInComment(IDocument document, int offset) { + private boolean isInComment(final IDocument document, final int offset) { try { if (isInBlockComment(document.get(0, offset))) { return true; } - int line = document.getLineOfOffset(offset); - int lineOffset = document.getLineOffset(line); + final int line = document.getLineOfOffset(offset); + final int lineOffset = document.getLineOffset(line); return isInLineComment(document.get(lineOffset, offset - lineOffset)); - } catch (BadLocationException e) { + } catch (final BadLocationException e) { return false; } } + @Nullable public String getLineComment() { - return comments.getLineComment(); + final var comments = this.comments; + return comments == null ? null : comments.getLineComment(); } + @Nullable public CharacterPair getBlockComment() { - return comments.getBlockComment(); + final var comments = this.comments; + return comments == null ? null : comments.getBlockComment(); } - private boolean isInLineComment(String indexLinePrefix) { + private boolean isInLineComment(final String indexLinePrefix) { + final var comments = this.comments; + if (comments == null) + return false; return indexLinePrefix.indexOf(comments.getLineComment()) != -1; } - private boolean isInBlockComment(String indexPrefix) { - String commentOpen = comments.getBlockComment().getKey(); - String commentClose = comments.getBlockComment().getValue(); + private boolean isInBlockComment(final String indexPrefix) { + final var comments = this.comments; + if (comments == null) + return false; + + final var blockComment = comments.getBlockComment(); + if (blockComment == null) + return false; + + final String commentOpen = blockComment.getKey(); + final String commentClose = blockComment.getValue(); int index = indexPrefix.indexOf(commentOpen); while (index != -1 && index < indexPrefix.length()) { - int closeIndex = indexPrefix.indexOf(commentClose, index + commentOpen.length()); + final int closeIndex = indexPrefix.indexOf(commentClose, index + commentOpen.length()); if (closeIndex == -1) { return true; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java index 4559412a5..05dd96e42 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Comments.java @@ -1,31 +1,37 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.supports; +import org.eclipse.jdt.annotation.Nullable; + public final class Comments { + @Nullable private final String lineComment; + @Nullable private final CharacterPair blockComment; - public Comments(String lineComment, CharacterPair blockComment) { + public Comments(@Nullable final String lineComment, @Nullable final CharacterPair blockComment) { this.lineComment = lineComment; this.blockComment = blockComment; } + @Nullable public String getLineComment() { return lineComment; } + @Nullable public CharacterPair getBlockComment() { return blockComment; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java index 6755d6dd9..fdcd4962b 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterAction.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.supports; +import org.eclipse.jdt.annotation.Nullable; + /** * Describes what to do when pressing Enter. */ @@ -46,17 +48,22 @@ public enum IndentAction { /** * Describe whether to outdent current line. */ + @Nullable private Boolean outdentCurrentLine; + /** * Describes text to be appended after the new line and after the indentation. */ + @Nullable private String appendText; + /** * Describes the number of characters to remove from the new line's indentation. */ + @Nullable private Integer removeText; - public EnterAction(IndentAction indentAction) { + public EnterAction(final IndentAction indentAction) { this.indentAction = indentAction; } @@ -67,6 +74,7 @@ public IndentAction getIndentAction() { /** * @return the outdentCurrentLine */ + @Nullable private Boolean getOutdentCurrentLine() { return outdentCurrentLine; } @@ -76,7 +84,7 @@ private Boolean getOutdentCurrentLine() { * the outdentCurrentLine to set * @return */ - private EnterAction setOutdentCurrentLine(Boolean outdentCurrentLine) { + private EnterAction setOutdentCurrentLine(final Boolean outdentCurrentLine) { this.outdentCurrentLine = outdentCurrentLine; return this; } @@ -84,16 +92,15 @@ private EnterAction setOutdentCurrentLine(Boolean outdentCurrentLine) { /** * @return the appendText */ + @Nullable public String getAppendText() { return appendText; } /** - * @param appendText - * the appendText to set - * @return + * @param appendText the appendText to set */ - public EnterAction setAppendText(String appendText) { + public EnterAction setAppendText(@Nullable final String appendText) { this.appendText = appendText; return this; } @@ -101,16 +108,15 @@ public EnterAction setAppendText(String appendText) { /** * @return the removeText */ + @Nullable public Integer getRemoveText() { return removeText; } /** - * @param removeText - * the removeText to set - * @return + * @param removeText the removeText to set */ - public EnterAction setRemoveText(Integer removeText) { + public EnterAction setRemoveText(@Nullable final Integer removeText) { this.removeText = removeText; return this; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java index beaf26c7d..bf749358f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/EnterActionAndIndent.java @@ -21,7 +21,7 @@ public final class EnterActionAndIndent { * @param enterAction * @param indentation */ - public EnterActionAndIndent(EnterAction enterAction, String indentation) { + public EnterActionAndIndent(final EnterAction enterAction, final String indentation) { this.enterAction = enterAction; this.indentation = indentation; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java index ab6813371..ebd34b5bf 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/Folding.java @@ -19,7 +19,7 @@ public final class Folding { private final String markersEnd; - public Folding(Boolean offSide, String markersStart, String markersEnd) { + public Folding(final Boolean offSide, final String markersStart, final String markersEnd) { this.offSide = offSide; this.markersStart = markersStart; this.markersEnd = markersEnd; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java index 8a8754fc3..3cd183579 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterRule.java @@ -13,6 +13,7 @@ import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.internal.utils.RegExpUtils; /** @@ -21,15 +22,15 @@ public final class OnEnterRule { /** - * This rule will only execute if the text before the cursor matches this - * regular expression. + * This rule will only execute if the text before the cursor matches this regular expression. */ + @Nullable private final Pattern beforeText; /** - * This rule will only execute if the text after the cursor matches this regular - * expression. + * This rule will only execute if the text after the cursor matches this regular expression. */ + @Nullable private final Pattern afterText; /** @@ -37,16 +38,18 @@ public final class OnEnterRule { */ private final EnterAction action; - public OnEnterRule(String beforeText, String afterText, EnterAction action) { + public OnEnterRule(final String beforeText, @Nullable final String afterText, final EnterAction action) { this.beforeText = RegExpUtils.create(beforeText); this.afterText = afterText != null ? RegExpUtils.create(afterText) : null; this.action = action; } + @Nullable public Pattern getBeforeText() { return beforeText; } + @Nullable public Pattern getAfterText() { return afterText; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java index eedf7e708..1c792971f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java @@ -18,6 +18,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction; import org.eclipse.tm4e.languageconfiguration.internal.utils.RegExpUtils; @@ -27,26 +28,32 @@ */ public class OnEnterSupport { - private static final List DEFAULT_BRACKETS = Arrays.asList(new CharacterPair("(", ")"), //$NON-NLS-1$ //$NON-NLS-2$ - new CharacterPair("{", "}"), new CharacterPair("[", "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + private static final List DEFAULT_BRACKETS = Arrays.asList( + new CharacterPair("(", ")"), //$NON-NLS-1$ //$NON-NLS-2$ + new CharacterPair("{", "}"), //$NON-NLS-1$ //$NON-NLS-2$ + new CharacterPair("[", "]")); //$NON-NLS-1$ //$NON-NLS-2$ private final List brackets; private final List regExpRules; - public OnEnterSupport(List brackets, List regExpRules) { + public OnEnterSupport(@Nullable final List brackets, @Nullable final List regExpRules) { this.brackets = (brackets != null ? brackets : DEFAULT_BRACKETS).stream().filter(Objects::nonNull) .map(ProcessedBracketPair::new).collect(Collectors.toList()); this.regExpRules = regExpRules != null ? regExpRules : Collections.emptyList(); } - public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, String afterEnterText) { + @Nullable + public EnterAction onEnter(final String oneLineAboveText, final String beforeEnterText, + final String afterEnterText) { // (1): `regExpRules` - for (OnEnterRule rule : regExpRules) { - if (rule.getBeforeText().matcher(beforeEnterText).find()) { - if (rule.getAfterText() != null) { - if (rule.getAfterText().matcher(afterEnterText).find()) { + for (final OnEnterRule rule : regExpRules) { + final var beforeText = rule.getBeforeText(); + if (beforeText != null && beforeText.matcher(beforeEnterText).find()) { + final var afterText = rule.getAfterText(); + if (afterText != null) { + if (afterText.matcher(afterEnterText).find()) { return rule.getAction(); } } else { @@ -57,7 +64,7 @@ public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, Stri // (2): Special indent-outdent if (!beforeEnterText.isEmpty() && !afterEnterText.isEmpty()) { - for (ProcessedBracketPair bracket : brackets) { + for (final ProcessedBracketPair bracket : brackets) { if (bracket.matchOpen(beforeEnterText) && bracket.matchClose(afterEnterText)) { return new EnterAction(IndentAction.IndentOutdent); } @@ -66,7 +73,7 @@ public EnterAction onEnter(String oneLineAboveText, String beforeEnterText, Stri // (3): Open bracket based logic if (!beforeEnterText.isEmpty()) { - for (ProcessedBracketPair bracket : brackets) { + for (final ProcessedBracketPair bracket : brackets) { if (bracket.matchOpen(beforeEnterText)) { return new EnterAction(IndentAction.Indent); } @@ -79,7 +86,10 @@ private static final class ProcessedBracketPair { private static final Pattern B_REGEXP = Pattern.compile("\\B"); //$NON-NLS-1$ + @Nullable private final Pattern openRegExp; + + @Nullable private final Pattern closeRegExp; private ProcessedBracketPair(final CharacterPair charPair) { @@ -87,17 +97,18 @@ private ProcessedBracketPair(final CharacterPair charPair) { closeRegExp = createCloseBracketRegExp(charPair.getValue()); } - private boolean matchOpen(String beforeEnterText) { + private boolean matchOpen(final String beforeEnterText) { return openRegExp != null && openRegExp.matcher(beforeEnterText).find(); } - private boolean matchClose(String afterEnterText) { + private boolean matchClose(final String afterEnterText) { return closeRegExp != null && closeRegExp.matcher(afterEnterText).find(); } - private static Pattern createOpenBracketRegExp(String bracket) { + @Nullable + private static Pattern createOpenBracketRegExp(final String bracket) { final StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); - String c = String.valueOf(str.charAt(0)); + final String c = String.valueOf(str.charAt(0)); if (!B_REGEXP.matcher(c).find()) { str.insert(0, "\\b"); //$NON-NLS-1$ } @@ -105,15 +116,15 @@ private static Pattern createOpenBracketRegExp(String bracket) { return RegExpUtils.create(str.toString()); } - private static Pattern createCloseBracketRegExp(String bracket) { + @Nullable + private static Pattern createCloseBracketRegExp(final String bracket) { final StringBuilder str = new StringBuilder(RegExpUtils.escapeRegExpCharacters(bracket)); - String c = String.valueOf(str.charAt(str.length() - 1)); + final String c = String.valueOf(str.charAt(str.length() - 1)); if (!B_REGEXP.matcher(c).find()) { str.append("\\b"); //$NON-NLS-1$ } str.insert(0, "^\\s*"); //$NON-NLS-1$ return RegExpUtils.create(str.toString()); } - } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/package-info.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/package-info.java new file mode 100644 index 000000000..f327f6bb4 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.languageconfiguration.internal.supports; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java index 284ff8fac..82d4e9823 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/RegExpUtils.java @@ -13,29 +13,30 @@ import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.Nullable; + /** * Regex utilities. - * */ public final class RegExpUtils { /** * Escapes regular expression characters in a given string */ - public static String escapeRegExpCharacters(String value) { + public static String escapeRegExpCharacters(final String value) { return value.replaceAll("[\\-\\\\\\{\\}\\*\\+\\?\\|\\^\\$\\.\\[\\]\\(\\)\\#]", "\\\\$0"); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Create Java Regexp and null otherwise. * - * @param regex * @return Java Regexp and null otherwise. */ - public static Pattern create(String regex) { + @Nullable + public static Pattern create(final String regex) { try { return Pattern.compile(regex); - } catch (Exception e) { + } catch (final Exception e) { return null; } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java index d0df375f0..6870f1fde 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TabSpacesInfo.java @@ -16,7 +16,7 @@ public final class TabSpacesInfo { private final int tabSize; private final boolean insertSpaces; - TabSpacesInfo(int tabSize, boolean insertSpaces) { + TabSpacesInfo(final int tabSize, final boolean insertSpaces) { this.tabSize = tabSize; this.insertSpaces = insertSpaces; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java index 702cf4a92..c67c44f2d 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java @@ -1,18 +1,17 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.utils; -import java.util.Arrays; - +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.IDocument; @@ -30,13 +29,14 @@ public final class TextUtils { * * @param d * @param c + * * @return true if text of the command is an enter and false otherwise. */ - public static boolean isEnter(IDocument d, DocumentCommand c) { + public static boolean isEnter(final IDocument d, final DocumentCommand c) { return (c.length == 0 && c.text != null && TextUtilities.equals(d.getLegalLineDelimiters(), c.text) != -1); } - public static String normalizeIndentation(String str, int tabSize, boolean insertSpaces) { + public static String normalizeIndentation(final String str, final int tabSize, final boolean insertSpaces) { int firstNonWhitespaceIndex = TextUtils.firstNonWhitespaceIndex(str); if (firstNonWhitespaceIndex == -1) { firstNonWhitespaceIndex = str.length(); @@ -45,7 +45,8 @@ public static String normalizeIndentation(String str, int tabSize, boolean inser insertSpaces) + str.substring(firstNonWhitespaceIndex); } - private static String normalizeIndentationFromWhitespace(String str, int tabSize, boolean insertSpaces) { + private static String normalizeIndentationFromWhitespace(final String str, final int tabSize, + final boolean insertSpaces) { int spacesCnt = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == '\t') { @@ -57,7 +58,7 @@ private static String normalizeIndentationFromWhitespace(String str, int tabSize final StringBuilder result = new StringBuilder(); if (!insertSpaces) { - long tabsCnt = Math.round(Math.floor(spacesCnt / tabSize)); + final long tabsCnt = Math.round(Math.floor(spacesCnt / tabSize)); spacesCnt = spacesCnt % tabSize; for (int i = 0; i < tabsCnt; i++) { result.append('\t'); @@ -77,15 +78,15 @@ private static String normalizeIndentationFromWhitespace(String str, int tabSize * Ex:
    * text = "apple banana", offset=8, string="banana" returns=6 */ - public static int startIndexOfOffsetTouchingString(String text, int offset, String string) { + public static int startIndexOfOffsetTouchingString(final String text, final int offset, final String string) { int start = offset - string.length(); start = start < 0 ? 0 : start; int end = offset + string.length(); end = end >= text.length() ? text.length() : end; try { - int indexInSubtext = text.substring(start, end).indexOf(string); + final int indexInSubtext = text.substring(start, end).indexOf(string); return indexInSubtext == -1 ? -1 : start + indexInSubtext; - } catch (IndexOutOfBoundsException e) { + } catch (final IndexOutOfBoundsException e) { return -1; } } @@ -94,9 +95,9 @@ public static int startIndexOfOffsetTouchingString(String text, int offset, Stri * Returns first index of the string that is not whitespace. If string is empty * or contains only whitespaces, returns -1 */ - private static int firstNonWhitespaceIndex(String str) { + private static int firstNonWhitespaceIndex(final String str) { for (int i = 0, len = str.length(); i < len; i++) { - char c = str.charAt(i); + final char c = str.charAt(i); if (c != ' ' && c != '\t') { return i; } @@ -104,17 +105,14 @@ private static int firstNonWhitespaceIndex(String str) { return -1; } - public static String getIndentationFromWhitespace(String whitespace, TabSpacesInfo tabSpaces) { - String tab = "\t"; //$NON-NLS-1$ - String spaces = null; + public static String getIndentationFromWhitespace(final String whitespace, final TabSpacesInfo tabSpaces) { + final String tab = "\t"; //$NON-NLS-1$ int indentOffset = 0; boolean startsWithTab = true; boolean startsWithSpaces = true; - if (tabSpaces.isInsertSpaces()) { - char[] chars = new char[tabSpaces.getTabSize()]; - Arrays.fill(chars, ' '); - spaces = new String(chars); - } + final String spaces = tabSpaces.isInsertSpaces() + ? " ".repeat(tabSpaces.getTabSize()) + : ""; while (startsWithTab || startsWithSpaces) { startsWithTab = whitespace.startsWith(tab, indentOffset); startsWithSpaces = tabSpaces.isInsertSpaces() && whitespace.startsWith(spaces, indentOffset); @@ -128,18 +126,18 @@ public static String getIndentationFromWhitespace(String whitespace, TabSpacesIn return whitespace.substring(0, indentOffset); } - public static String getLinePrefixingWhitespaceAtPosition(IDocument d, int offset) { + public static String getLinePrefixingWhitespaceAtPosition(final IDocument d, final int offset) { try { // find start of line - int p = offset; - IRegion info = d.getLineInformationOfOffset(p); - int start = info.getOffset(); + final int p = offset; + final IRegion info = d.getLineInformationOfOffset(p); + final int start = info.getOffset(); // find white spaces - int end = findEndOfWhiteSpace(d, start, offset); + final int end = findEndOfWhiteSpace(d, start, offset); return d.get(start, end - start); - } catch (BadLocationException excp) { + } catch (final BadLocationException excp) { // stop work } return ""; //$NON-NLS-1$ @@ -151,16 +149,19 @@ public static String getLinePrefixingWhitespaceAtPosition(IDocument d, int offse * offset is found, end is returned. * * @param document the document to search in - * @param offset the offset at which searching start - * @param end the offset at which searching stops + * @param offset the offset at which searching start + * @param end the offset at which searching stops + * * @return the offset in the specified range whose character is not a space or * tab + * * @exception BadLocationException if position is an invalid range in the given - * document + * document */ - private static int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException { + private static int findEndOfWhiteSpace(final IDocument document, int offset, final int end) + throws BadLocationException { while (offset < end) { - char c = document.getChar(offset); + final char c = document.getChar(offset); if (c != ' ' && c != '\t') { return offset; } @@ -169,11 +170,14 @@ private static int findEndOfWhiteSpace(IDocument document, int offset, int end) return end; } - public static TabSpacesInfo getTabSpaces(ITextViewer viewer) { - TabsToSpacesConverter converter = ClassHelper.getFieldValue(viewer, "fTabsToSpacesConverter", TextViewer.class); //$NON-NLS-1$ - if (converter != null) { - int tabSize = ClassHelper.getFieldValue(converter, "fTabRatio", TabsToSpacesConverter.class); //$NON-NLS-1$ - return new TabSpacesInfo(tabSize, true); + public static TabSpacesInfo getTabSpaces(@Nullable final ITextViewer viewer) { + if (viewer != null) { + final TabsToSpacesConverter converter = ClassHelper.getFieldValue(viewer, "fTabsToSpacesConverter", //$NON-NLS-1$ + TextViewer.class); + if (converter != null) { + final int tabSize = ClassHelper.getFieldValue(converter, "fTabRatio", TabsToSpacesConverter.class); //$NON-NLS-1$ + return new TabSpacesInfo(tabSize, true); + } } return new TabSpacesInfo(-1, false); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/package-info.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/package-info.java new file mode 100644 index 000000000..859e73ca3 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.languageconfiguration.internal.utils; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java index 4f723d651..0744e3ee9 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/AutoClosingPairConditionalTableWidget.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnWeightData; @@ -23,17 +24,17 @@ final class AutoClosingPairConditionalTableWidget extends CharacterPairsTableWidget { - AutoClosingPairConditionalTableWidget(Table table) { + AutoClosingPairConditionalTableWidget(final Table table) { super(table); setLabelProvider(new AutoClosingPairConditionalLabelProvider()); - GC gc = new GC(table.getShell()); + final GC gc = new GC(table.getShell()); gc.setFont(JFaceResources.getDialogFont()); - TableColumnLayout columnLayout = new TableColumnLayout(); + final TableColumnLayout columnLayout = new TableColumnLayout(); - TableColumn column2 = new TableColumn(table, SWT.NONE); + final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(LanguageConfigurationMessages.AutoClosingPairConditionalTableWidget_notIn); - int minWidth = computeMinimumColumnWidth(gc, + final int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.AutoClosingPairConditionalTableWidget_notIn); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); @@ -42,11 +43,12 @@ final class AutoClosingPairConditionalTableWidget extends CharacterPairsTableWid private static final class AutoClosingPairConditionalLabelProvider extends CharacterPairLabelProvider { + @Nullable @Override - public String getColumnText(Object element, int columnIndex) { + public String getColumnText(@Nullable final Object element, final int columnIndex) { if (columnIndex == 2) { if ((element instanceof AutoClosingPairConditional)) { - AutoClosingPairConditional conditionalPair = (AutoClosingPairConditional) element; + final AutoClosingPairConditional conditionalPair = (AutoClosingPairConditional) element; return String.join(", ", conditionalPair.getNotIn()); //$NON-NLS-1$ } return ""; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java index 63d3221bd..b510e9915 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/CharacterPairsTableWidget.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.widgets; import java.util.Collections; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnWeightData; @@ -32,21 +33,21 @@ class CharacterPairsTableWidget extends TableViewer { - CharacterPairsTableWidget(Table table) { + CharacterPairsTableWidget(final Table table) { super(table); setContentProvider(new CharacterPairContentProvider()); setLabelProvider(new CharacterPairLabelProvider()); - GC gc = new GC(table.getShell()); + final GC gc = new GC(table.getShell()); gc.setFont(JFaceResources.getDialogFont()); - TableColumnLayout columnLayout = new TableColumnLayout(); + final TableColumnLayout columnLayout = new TableColumnLayout(); - TableColumn column1 = new TableColumn(table, SWT.NONE); + final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_start); int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_start); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); - TableColumn column2 = new TableColumn(table, SWT.NONE); + final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(LanguageConfigurationMessages.CharacterPairsTableWidget_end); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.CharacterPairsTableWidget_end); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); @@ -54,22 +55,23 @@ class CharacterPairsTableWidget extends TableViewer { gc.dispose(); } - protected int computeMinimumColumnWidth(GC gc, String string) { + protected int computeMinimumColumnWidth(final GC gc, final String string) { return gc.stringExtent(string).x + 10; } private static final class CharacterPairContentProvider implements IStructuredContentProvider { - private List characterPairList; + private List characterPairList = Collections.emptyList(); @Override - public Object[] getElements(Object input) { + public Object[] getElements(@Nullable final Object input) { return characterPairList.toArray(CharacterPair[]::new); } @SuppressWarnings("unchecked") @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + public void inputChanged(@Nullable final Viewer viewer, @Nullable final Object oldInput, + @Nullable final Object newInput) { if (newInput == null) { characterPairList = Collections.emptyList(); } else { @@ -79,25 +81,31 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @Override public void dispose() { - characterPairList = null; + characterPairList = Collections.emptyList(); } } protected static class CharacterPairLabelProvider extends LabelProvider implements ITableLabelProvider { + @Nullable @Override - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(@Nullable final Object element, final int columnIndex) { return null; } + @Nullable @Override - public String getText(Object element) { + public String getText(@Nullable final Object element) { return getColumnText(element, 0); } + @Nullable @Override - public String getColumnText(Object element, int columnIndex) { - CharacterPair pair = (CharacterPair) element; + public String getColumnText(@Nullable final Object element, final int columnIndex) { + if (element == null) + return null; + + final CharacterPair pair = (CharacterPair) element; switch (columnIndex) { case 0: diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java index 76270d462..ac9729d35 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -28,7 +29,7 @@ public final class ColumnSelectionAdapter extends SelectionAdapter { private final int fColumnIndex; private final ColumnViewerComparator viewerComparator; - public ColumnSelectionAdapter(TableColumn column, TableViewer tableViewer, int index, ColumnViewerComparator vc) { + public ColumnSelectionAdapter(final TableColumn column, final TableViewer tableViewer, final int index, final ColumnViewerComparator vc) { fTableColumn = column; this.tableViewer = tableViewer; fColumnIndex = index; @@ -36,10 +37,10 @@ public ColumnSelectionAdapter(TableColumn column, TableViewer tableViewer, int i } @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(@Nullable final SelectionEvent e) { viewerComparator.setColumn(fColumnIndex); - int dir = viewerComparator.getDirection(); - Table table = tableViewer.getTable(); + final int dir = viewerComparator.getDirection(); + final Table table = tableViewer.getTable(); table.setSortDirection(dir); table.setSortColumn(fTableColumn); tableViewer.refresh(); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java index 43e8c0a7b..7aa5622f6 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.TableViewer; @@ -42,7 +43,7 @@ public int getDirection() { * * @param column New sort column */ - public void setColumn(int column) { + public void setColumn(final int column) { if (column == fSortColumn) { fSortOrder *= -1; } else { @@ -52,14 +53,14 @@ public void setColumn(int column) { } @Override - public int compare(Viewer viewer, Object e1, Object e2) { + public int compare(@Nullable final Viewer viewer, @Nullable final Object e1, @Nullable final Object e2) { if (viewer instanceof TableViewer) { - IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider(); + final IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider(); - String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); - String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); - int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : ""); //$NON-NLS-1$ //$NON-NLS-2$ + final String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); + final String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); + final int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : ""); //$NON-NLS-1$ //$NON-NLS-2$ return sortResult * fSortOrder; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java index 4eb1f48c3..892a642af 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationInfoWidget.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.widgets; @@ -15,6 +15,8 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -31,20 +33,9 @@ import org.eclipse.tm4e.languageconfiguration.internal.supports.Comments; import org.eclipse.tm4e.languageconfiguration.internal.supports.Folding; +@NonNullByDefault({}) public class LanguageConfigurationInfoWidget extends Composite { - public LanguageConfigurationInfoWidget(Composite parent, int style) { - super(parent, style); - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginLeft = 0; - layout.marginRight = 0; - super.setLayout(layout); - super.setLayoutData(new GridData(GridData.FILL_BOTH)); - createUI(this); - } - private TabItem commentsTab; private Text lineCommentText; private Text blockCommentStartText; @@ -65,15 +56,28 @@ public LanguageConfigurationInfoWidget(Composite parent, int style) { private Text markersEndText; private TabItem wordPatternTab; + private Text wordPatternText; protected TabItem onEnterRulesTab; private OnEnterRuleTableWidget onEnterRuleTable; - private void createUI(Composite ancestor) { - TabFolder folder = new TabFolder(ancestor, SWT.NONE); + public LanguageConfigurationInfoWidget(final Composite parent, final int style) { + super(parent, style); + final GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginLeft = 0; + layout.marginRight = 0; + super.setLayout(layout); + super.setLayoutData(new GridData(GridData.FILL_BOTH)); + createUI(this); + } + + private void createUI(final Composite ancestor) { + final TabFolder folder = new TabFolder(ancestor, SWT.NONE); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); + final GridData gd = new GridData(GridData.FILL_HORIZONTAL); folder.setLayoutData(gd); createCommentsTab(folder); @@ -85,7 +89,7 @@ private void createUI(Composite ancestor) { createOnEnterRulesTab(folder); } - public void refresh(ILanguageConfiguration configuration) { + public void refresh(@Nullable final ILanguageConfiguration configuration) { lineCommentText.setText(""); //$NON-NLS-1$ blockCommentStartText.setText(""); //$NON-NLS-1$ blockCommentEndText.setText(""); //$NON-NLS-1$ @@ -102,13 +106,13 @@ public void refresh(ILanguageConfiguration configuration) { return; } - Comments comments = configuration.getComments(); + final Comments comments = configuration.getComments(); if (comments != null) { lineCommentText.setText(comments.getLineComment() == null ? "" : comments.getLineComment()); - CharacterPair blockComment = comments.getBlockComment(); + final CharacterPair blockComment = comments.getBlockComment(); if (blockComment != null) { - blockCommentStartText.setText(comments.getBlockComment().getKey()); - blockCommentEndText.setText(comments.getBlockComment().getValue()); + blockCommentStartText.setText(blockComment.getKey()); + blockCommentEndText.setText(blockComment.getValue()); } } @@ -116,14 +120,14 @@ public void refresh(ILanguageConfiguration configuration) { autoClosingPairsTable.setInput(removeNullElements(configuration.getAutoClosingPairs())); surroundingPairsTable.setInput(removeNullElements(configuration.getSurroundingPairs())); - Folding folding = configuration.getFolding(); + final Folding folding = configuration.getFolding(); if (folding != null) { offsideText.setText(folding.getOffSide().toString()); markersStartText.setText(folding.getMarkersStart()); markersEndText.setText(folding.getMarkersEnd()); } - String wordPattern = configuration.getWordPattern(); + final String wordPattern = configuration.getWordPattern(); if (wordPattern != null) { wordPatternText.setText(wordPattern); } @@ -131,16 +135,17 @@ public void refresh(ILanguageConfiguration configuration) { onEnterRuleTable.setInput(removeNullElements(configuration.getOnEnterRules())); } - private List removeNullElements(List list) { + @Nullable + private List removeNullElements(@Nullable final List list) { if (list == null) { return null; } return list.stream().filter(Objects::nonNull).collect(Collectors.toList()); } - private void createCommentsTab(TabFolder folder) { + private void createCommentsTab(final TabFolder folder) { commentsTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_comments); - Composite parent = (Composite) commentsTab.getControl(); + final Composite parent = (Composite) commentsTab.getControl(); lineCommentText = createText(parent, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_lineComments); @@ -150,28 +155,28 @@ private void createCommentsTab(TabFolder folder) { LanguageConfigurationMessages.LanguageConfigurationInfoWidget_blockCommentsEnd); } - private void createBracketsTab(TabFolder folder) { + private void createBracketsTab(final TabFolder folder) { bracketsTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_brackets); bracketsTable = new CharacterPairsTableWidget(createTable((Composite) bracketsTab.getControl())); } - protected void createAutoClosingPairsTab(TabFolder folder) { + protected void createAutoClosingPairsTab(final TabFolder folder) { autoClosingPairsTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_autoClosingPairs); autoClosingPairsTable = new AutoClosingPairConditionalTableWidget( createTable((Composite) autoClosingPairsTab.getControl())); } - protected void createSurroundingPairsTab(TabFolder folder) { + protected void createSurroundingPairsTab(final TabFolder folder) { surroundingPairsTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_surroundingPairs); surroundingPairsTable = new CharacterPairsTableWidget( createTable((Composite) surroundingPairsTab.getControl())); } - private void createFoldingTab(TabFolder folder) { + private void createFoldingTab(final TabFolder folder) { foldingTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_folding_title); - Composite parent = (Composite) foldingTab.getControl(); + final Composite parent = (Composite) foldingTab.getControl(); offsideText = createText(parent, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_offSide); offsideText.setToolTipText(LanguageConfigurationMessages.LanguageConfigurationInfoWidget_offSide_tooltip); @@ -180,36 +185,36 @@ private void createFoldingTab(TabFolder folder) { markersEndText = createText(parent, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_end); } - private void createWordPatternTab(TabFolder folder) { + private void createWordPatternTab(final TabFolder folder) { wordPatternTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_wordPattern_title); - Composite parent = (Composite) wordPatternTab.getControl(); + final Composite parent = (Composite) wordPatternTab.getControl(); wordPatternText = createText(parent, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_wordPattern_message); } - protected void createOnEnterRulesTab(TabFolder folder) { + protected void createOnEnterRulesTab(final TabFolder folder) { onEnterRulesTab = createTab(folder, LanguageConfigurationMessages.LanguageConfigurationInfoWidget_onEnterRules); onEnterRuleTable = new OnEnterRuleTableWidget(createTable((Composite) onEnterRulesTab.getControl())); } - private Table createTable(Composite parent) { - Composite tableComposite = new Composite(parent, SWT.NONE); + private Table createTable(final Composite parent) { + final Composite tableComposite = new Composite(parent, SWT.NONE); tableComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); tableComposite.setLayout(new TableColumnLayout()); - Table table = new Table(tableComposite, + final Table table = new Table(tableComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); table.setHeaderVisible(true); table.setLinesVisible(true); return table; } - private TabItem createTab(TabFolder folder, String title) { - TabItem tab = new TabItem(folder, SWT.NONE); + private TabItem createTab(final TabFolder folder, final String title) { + final TabItem tab = new TabItem(folder, SWT.NONE); tab.setText(title); - Composite parent = new Composite(folder, SWT.NONE); + final Composite parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_BOTH)); tab.setControl(parent); @@ -217,11 +222,11 @@ private TabItem createTab(TabFolder folder, String title) { return tab; } - private Text createText(Composite parent, String s) { - Label label = new Label(parent, SWT.NONE); + private Text createText(final Composite parent, final String s) { + final Label label = new Label(parent, SWT.NONE); label.setText(s); - Text text = new Text(parent, SWT.BORDER); + final Text text = new Text(parent, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.setEditable(false); return text; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java index 4162558e4..af00617d8 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/LanguageConfigurationPreferencesWidget.java @@ -13,6 +13,8 @@ import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; @@ -21,6 +23,7 @@ import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; +@NonNullByDefault({}) public final class LanguageConfigurationPreferencesWidget extends LanguageConfigurationInfoWidget { private Button toggleOnEnterButton; @@ -30,11 +33,11 @@ public final class LanguageConfigurationPreferencesWidget extends LanguageConfig private ILanguageConfigurationDefinition definition; private ILanguageConfigurationRegistryManager manager; - public LanguageConfigurationPreferencesWidget(Composite parent, int style) { + public LanguageConfigurationPreferencesWidget(final Composite parent, final int style) { super(parent, style); } - public void refresh(ILanguageConfigurationDefinition definition, ILanguageConfigurationRegistryManager manager) { + public void refresh(@Nullable final ILanguageConfigurationDefinition definition, final ILanguageConfigurationRegistryManager manager) { super.refresh(definition == null ? null : definition.getLanguageConfiguration()); if (definition == null) { toggleOnEnterButton.setEnabled(false); @@ -56,9 +59,9 @@ public void refresh(ILanguageConfigurationDefinition definition, ILanguageConfig } @Override - protected void createOnEnterRulesTab(TabFolder folder) { + protected void createOnEnterRulesTab(final TabFolder folder) { super.createOnEnterRulesTab(folder); - Composite parent = (Composite) onEnterRulesTab.getControl(); + final Composite parent = (Composite) onEnterRulesTab.getControl(); toggleOnEnterButton = new Button(parent, SWT.CHECK); toggleOnEnterButton.setText("Enable on enter actions"); toggleOnEnterButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -74,14 +77,14 @@ private boolean getToggleOnEnter() { return toggleOnEnterButton.getSelection(); } - private void setToggleOnEnter(Boolean selection) { + private void setToggleOnEnter(final Boolean selection) { toggleOnEnterButton.setSelection(selection); } @Override - protected void createAutoClosingPairsTab(TabFolder folder) { + protected void createAutoClosingPairsTab(final TabFolder folder) { super.createAutoClosingPairsTab(folder); - Composite parent = (Composite) autoClosingPairsTab.getControl(); + final Composite parent = (Composite) autoClosingPairsTab.getControl(); toggleBracketAutoClosingButton = new Button(parent, SWT.CHECK); toggleBracketAutoClosingButton.setText("Enable auto closing brackets"); toggleBracketAutoClosingButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -97,14 +100,14 @@ private boolean getBracketAutoClosing() { return toggleBracketAutoClosingButton.getSelection(); } - private void setBracketAutoClosing(Boolean selection) { + private void setBracketAutoClosing(final Boolean selection) { toggleBracketAutoClosingButton.setSelection(selection); } @Override - protected void createSurroundingPairsTab(TabFolder folder) { + protected void createSurroundingPairsTab(final TabFolder folder) { super.createSurroundingPairsTab(folder); - Composite parent = (Composite) surroundingPairsTab.getControl(); + final Composite parent = (Composite) surroundingPairsTab.getControl(); toggleMatchingPairsButton = new Button(parent, SWT.CHECK); toggleMatchingPairsButton.setText("Enable matching brackets"); toggleMatchingPairsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -120,7 +123,7 @@ private boolean getMatchingPairs() { return toggleMatchingPairsButton.getSelection(); } - private void setMatchingPairs(Boolean selection) { + private void setMatchingPairs(final Boolean selection) { toggleMatchingPairsButton.setSelection(selection); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java index 5fda3298d..5516c514b 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/OnEnterRuleTableWidget.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.widgets; import java.util.Collections; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnWeightData; @@ -33,36 +34,36 @@ final class OnEnterRuleTableWidget extends TableViewer { - OnEnterRuleTableWidget(Table table) { + OnEnterRuleTableWidget(final Table table) { super(table); setContentProvider(new OnEnterRuleContentProvider()); setLabelProvider(new OnEnterRuleLabelProvider()); - GC gc = new GC(table.getShell()); + final GC gc = new GC(table.getShell()); gc.setFont(JFaceResources.getDialogFont()); - TableColumnLayout columnLayout = new TableColumnLayout(); + final TableColumnLayout columnLayout = new TableColumnLayout(); - TableColumn column1 = new TableColumn(table, SWT.NONE); + final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText); int minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_beforeText); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); - TableColumn column2 = new TableColumn(table, SWT.NONE); + final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_afterText); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); - TableColumn column3 = new TableColumn(table, SWT.NONE); + final TableColumn column3 = new TableColumn(table, SWT.NONE); column3.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_indentAction); columnLayout.setColumnData(column3, new ColumnWeightData(1, minWidth, true)); - TableColumn column4 = new TableColumn(table, SWT.NONE); + final TableColumn column4 = new TableColumn(table, SWT.NONE); column4.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_appendText); columnLayout.setColumnData(column4, new ColumnWeightData(1, minWidth, true)); - TableColumn column5 = new TableColumn(table, SWT.NONE); + final TableColumn column5 = new TableColumn(table, SWT.NONE); column5.setText(LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); minWidth = computeMinimumColumnWidth(gc, LanguageConfigurationMessages.OnEnterRuleTableWidget_removeText); columnLayout.setColumnData(column5, new ColumnWeightData(1, minWidth, true)); @@ -70,22 +71,24 @@ final class OnEnterRuleTableWidget extends TableViewer { gc.dispose(); } - private int computeMinimumColumnWidth(GC gc, String string) { + private int computeMinimumColumnWidth(final GC gc, final String string) { return gc.stringExtent(string).x + 10; } private static final class OnEnterRuleContentProvider implements IStructuredContentProvider { - private List onEnterRulesList; + private List onEnterRulesList = Collections.emptyList(); @Override - public Object[] getElements(Object input) { + public Object[] getElements(@Nullable final Object input) { + assert onEnterRulesList != null; return onEnterRulesList.toArray(OnEnterRule[]::new); } @SuppressWarnings("unchecked") @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + public void inputChanged(@Nullable final Viewer viewer, @Nullable final Object oldInput, + @Nullable final Object newInput) { if (newInput == null) { onEnterRulesList = Collections.emptyList(); } else { @@ -95,38 +98,48 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @Override public void dispose() { - onEnterRulesList = null; + onEnterRulesList = Collections.emptyList(); } } private static final class OnEnterRuleLabelProvider extends LabelProvider implements ITableLabelProvider { + @Nullable @Override - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(@Nullable final Object element, final int columnIndex) { return null; } + @Nullable @Override - public String getText(Object element) { + public String getText(@Nullable final Object element) { return getColumnText(element, 0); } + @Nullable @Override - public String getColumnText(Object element, int columnIndex) { - OnEnterRule rule = (OnEnterRule) element; - EnterAction action = rule.getAction(); + public String getColumnText(@Nullable final Object element, final int columnIndex) { + if (element == null) + return ""; + + final OnEnterRule rule = (OnEnterRule) element; + final EnterAction action = rule.getAction(); switch (columnIndex) { case 0: - return rule.getBeforeText().pattern(); + final var beforeText = rule.getBeforeText(); + return beforeText == null ? "" : beforeText.pattern(); case 1: - return rule.getAfterText() == null ? "" : rule.getAfterText().pattern(); //$NON-NLS-1$ + final var afterText = rule.getAfterText(); + return afterText == null ? "" : afterText.pattern(); //$NON-NLS-1$ case 2: return action.getIndentAction().toString(); case 3: - return action.getAppendText() == null ? "" : action.getAppendText(); //$NON-NLS-1$ + final var appendText = action.getAppendText(); + return appendText == null ? "" : appendText; //$NON-NLS-1$ case 4: - return action.getRemoveText() == null ? "" : action.getRemoveText().toString(); //$NON-NLS-1$ + final var removeText = action.getRemoveText(); + return removeText == null ? "" : removeText.toString(); //$NON-NLS-1$ default: return ""; //$NON-NLS-1$ } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/package-info.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/package-info.java new file mode 100644 index 000000000..8242416ce --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.languageconfiguration.internal.widgets; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java index d24354e20..5e0986f2c 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/LanguageConfigurationImportWizard.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.wizards; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; @@ -26,25 +27,25 @@ */ public final class LanguageConfigurationImportWizard extends Wizard implements IImportWizard { + @Nullable private SelectLanguageConfigurationWizardPage mainPage; + @Nullable private ILanguageConfigurationDefinition createdDefinition; private ILanguageConfigurationRegistryManager registryManager; private final boolean save; - public LanguageConfigurationImportWizard(boolean save) { + public LanguageConfigurationImportWizard(final boolean save) { this.save = save; - setRegistryManager(LanguageConfigurationRegistryManager.getInstance()); + this.registryManager = LanguageConfigurationRegistryManager.getInstance(); } /** * Set registry to use to add the created grammar definitions. - * - * @param registryManager */ - public void setRegistryManager(ILanguageConfigurationRegistryManager registryManager) { + public void setRegistryManager(final ILanguageConfigurationRegistryManager registryManager) { this.registryManager = registryManager; } @@ -56,12 +57,13 @@ public void addPages() { @Override public boolean performFinish() { - ILanguageConfigurationDefinition definition = mainPage.getDefinition(); + assert mainPage != null; + final ILanguageConfigurationDefinition definition = mainPage.getDefinition(); registryManager.registerLanguageConfigurationDefinition(definition); if (save) { try { registryManager.save(); - } catch (BackingStoreException e) { + } catch (final BackingStoreException e) { e.printStackTrace(); return false; } @@ -71,10 +73,11 @@ public boolean performFinish() { } @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { + public void init(@Nullable final IWorkbench workbench, @Nullable final IStructuredSelection selection) { } + @Nullable public ILanguageConfigurationDefinition getCreatedDefinition() { return createdDefinition; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java index 17b433056..b07d0e6c7 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.wizards; +import static org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages.*; + import java.io.FileReader; import java.util.ArrayList; -import java.util.List; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; @@ -24,6 +25,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -44,12 +46,10 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Text; -import org.eclipse.tm4e.languageconfiguration.ILanguageConfiguration; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationRegistryManager; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfiguration; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition; -import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationMessages; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationPlugin; import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationInfoWidget; import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; @@ -60,25 +60,29 @@ final class SelectLanguageConfigurationWizardPage extends WizardPage implements private static final String[] TEXTMATE_EXTENSIONS = { "*language-configuration.json" }; //$NON-NLS-1$ - private Button browseFileSystemButton; - private Button browseWorkspaceButton; + @Nullable private Text fileText; + + @Nullable private Text contentTypeText; + + @Nullable private LanguageConfigurationInfoWidget infoWidget; private final ILanguageConfigurationRegistryManager registryManager; - SelectLanguageConfigurationWizardPage(ILanguageConfigurationRegistryManager registryManager) { + SelectLanguageConfigurationWizardPage(final ILanguageConfigurationRegistryManager registryManager) { super(PAGE_NAME); this.registryManager = registryManager; - super.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_title); - super.setDescription(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_page_description); + super.setTitle(SelectLanguageConfigurationWizardPage_page_title); + super.setDescription(SelectLanguageConfigurationWizardPage_page_description); } @Override - public final void createControl(Composite parent) { + public final void createControl(@Nullable final Composite parent) { + assert parent != null; initializeDialogUnits(parent); - Composite topLevel = new Composite(parent, SWT.NONE); + final var topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout()); topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); topLevel.setFont(parent.getFont()); @@ -89,22 +93,22 @@ public final void createControl(Composite parent) { } @Override - public void handleEvent(Event event) { + public void handleEvent(@Nullable final Event event) { validateAndUpdateStatus(event); } - private void validateAndUpdateStatus(Event event) { - IStatus status = validatePage(event); + private void validateAndUpdateStatus(@Nullable final Event event) { + final IStatus status = validatePage(event); statusChanged(status == null ? Status.OK_STATUS : status); } - private void statusChanged(IStatus status) { + private void statusChanged(final IStatus status) { setPageComplete(!status.matches(IStatus.ERROR)); applyToStatusLine(this, status); } - private static void applyToStatusLine(DialogPage page, IStatus status) { - String message = Status.OK_STATUS.equals(status) ? null : status.getMessage(); + private static void applyToStatusLine(final DialogPage page, final IStatus status) { + final var message = Status.OK_STATUS.equals(status) ? null : status.getMessage(); switch (status.getSeverity()) { case IStatus.OK: page.setMessage(message, IMessageProvider.NONE); @@ -119,95 +123,98 @@ private static void applyToStatusLine(DialogPage page, IStatus status) { page.setErrorMessage(null); break; default: - if (message != null && message.isEmpty()) { - message = null; - } page.setMessage(null); - page.setErrorMessage(message); + page.setErrorMessage(message != null && message.isEmpty() ? null : message); break; } } - private void createBody(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); + private void createBody(final Composite ancestor) { + final var parent = new Composite(ancestor, SWT.NONE); parent.setFont(parent.getFont()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); parent.setLayout(new GridLayout(2, false)); - fileText = createText(parent, LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_file); + final var fileText = createText(parent, SelectLanguageConfigurationWizardPage_file); + this.fileText = fileText; fileText.addListener(SWT.Modify, this); - Composite buttons = new Composite(parent, SWT.NONE); + final var buttons = new Composite(parent, SWT.NONE); buttons.setLayout(new GridLayout(2, false)); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); + final var gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; gd.horizontalAlignment = SWT.RIGHT; buttons.setLayoutData(gd); - infoWidget = new LanguageConfigurationInfoWidget(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + final var infoWidget = new LanguageConfigurationInfoWidget(parent, SWT.NONE); + this.infoWidget = infoWidget; + final var data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; infoWidget.setLayoutData(data); - browseFileSystemButton = new Button(buttons, SWT.NONE); - browseFileSystemButton - .setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_fileSystem); + final var browseFileSystemButton = new Button(buttons, SWT.NONE); + browseFileSystemButton.setText(SelectLanguageConfigurationWizardPage_browse_fileSystem); browseFileSystemButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(parent.getShell()); + public void widgetSelected(@Nullable final SelectionEvent e) { + final var dialog = new FileDialog(parent.getShell()); dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); dialog.setFilterPath(fileText.getText()); - String result = dialog.open(); + final String result = dialog.open(); if (result != null && !result.isEmpty()) { fileText.setText(result); } } }); - browseWorkspaceButton = new Button(buttons, SWT.NONE); - browseWorkspaceButton - .setText(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_browse_workspace); + final var browseWorkspaceButton = new Button(buttons, SWT.NONE); + browseWorkspaceButton.setText(SelectLanguageConfigurationWizardPage_browse_workspace); browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { - ResourceSelectionDialog dialog = new ResourceSelectionDialog(browseWorkspaceButton.getShell(), + public void widgetSelected(@Nullable final SelectionEvent e) { + final var dialog = new ResourceSelectionDialog(browseWorkspaceButton.getShell(), ResourcesPlugin.getWorkspace().getRoot(), - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_description); - dialog.setTitle(LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_workspace_title); - int returnCode = dialog.open(); - Object[] results = dialog.getResult(); + SelectLanguageConfigurationWizardPage_workspace_description); + dialog.setTitle(SelectLanguageConfigurationWizardPage_workspace_title); + final int returnCode = dialog.open(); + final Object[] results = dialog.getResult(); if (returnCode == 0 && results.length > 0) { fileText.setText(((IResource) results[0]).getFullPath().makeRelative().toString()); } } }); contentTypeText = createText(parent, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentType); + SelectLanguageConfigurationWizardPage_contentType); contentTypeText.addListener(SWT.Modify, this); createContentTypeTreeViewer(parent); } - private void createContentTypeTreeViewer(Composite composite) { - TreeViewer contentTypesViewer = new TreeViewer(composite, + private void createContentTypeTreeViewer(final Composite composite) { + final var contentTypesViewer = new TreeViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); contentTypesViewer.getControl().setFont(composite.getFont()); contentTypesViewer.setContentProvider(new ContentTypesContentProvider()); contentTypesViewer.setLabelProvider(new ContentTypesLabelProvider()); contentTypesViewer.setComparator(new ViewerComparator()); contentTypesViewer.setInput(Platform.getContentTypeManager()); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + final var data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; contentTypesViewer.getControl().setLayoutData(data); - contentTypesViewer.addSelectionChangedListener(event -> contentTypeText - .setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString())); + contentTypesViewer.addSelectionChangedListener(event -> { + final var contentTypeText = this.contentTypeText; + if (contentTypeText != null) { + contentTypeText.setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString()); + } + }); } private static final class ContentTypesLabelProvider extends LabelProvider { @Override - public String getText(Object element) { - IContentType contentType = (IContentType) element; + public String getText(@Nullable final Object element) { + if (element == null) + return ""; + final IContentType contentType = (IContentType) element; return contentType.getName(); } } @@ -217,96 +224,113 @@ private static final class ContentTypesContentProvider implements ITreeContentPr private IContentTypeManager manager = Platform.getContentTypeManager(); @Override - public Object[] getChildren(Object parentElement) { - List elements = new ArrayList<>(); - IContentType baseType = (IContentType) parentElement; - for (IContentType contentType : manager.getAllContentTypes()) { + public Object[] getChildren(@Nullable final Object parentElement) { + final var elements = new ArrayList<>(); + final var baseType = (IContentType) parentElement; + for (final var contentType : manager.getAllContentTypes()) { if ((contentType.getBaseType() == null && baseType == null) - || ((contentType.getBaseType() != null && contentType.getBaseType().equals(baseType)))) { + || (contentType.getBaseType() != null && contentType.getBaseType().equals(baseType))) { elements.add(contentType); } } return elements.toArray(); } + @Nullable @Override - public Object getParent(Object element) { - IContentType contentType = (IContentType) element; + public Object getParent(@Nullable final Object element) { + if (element == null) + return null; + final IContentType contentType = (IContentType) element; return contentType.getBaseType(); } @Override - public boolean hasChildren(Object element) { + public boolean hasChildren(@Nullable final Object element) { return getChildren(element).length > 0; } @Override - public Object[] getElements(Object inputElement) { + public Object[] getElements(@Nullable final Object inputElement) { return getChildren(null); } @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - manager = (IContentTypeManager) newInput; + public void inputChanged(@Nullable final Viewer viewer, @Nullable final Object oldInput, + @Nullable final Object newInput) { + manager = newInput == null ? Platform.getContentTypeManager() : (IContentTypeManager) newInput; } } - private Text createText(Composite parent, String s) { - Label label = new Label(parent, SWT.NONE); + private Text createText(final Composite parent, final String s) { + final var label = new Label(parent, SWT.NONE); label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); label.setText(s); - Text text = new Text(parent, SWT.BORDER); + final var text = new Text(parent, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return text; } - private IStatus validatePage(Event event) { + @Nullable + private IStatus validatePage(@Nullable final Event event) { + final var infoWidget = this.infoWidget; + assert infoWidget != null; infoWidget.refresh(null); - String path = fileText.getText(); + + final var fileText = this.fileText; + assert fileText != null; + final String path = fileText.getText(); if (path.length() == 0) { return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_noSelection); + SelectLanguageConfigurationWizardPage_fileError_noSelection); } IPath p = new Path(path); if (!p.isAbsolute()) { p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation(); } - try { - ILanguageConfiguration configuration = LanguageConfiguration.load(new FileReader(p.toFile())); + try (var file = new FileReader(p.toFile())) { + final var configuration = LanguageConfiguration.load(file); if (configuration == null) { return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_invalid); + SelectLanguageConfigurationWizardPage_fileError_invalid); } infoWidget.refresh(configuration); - } catch (Exception e) { + } catch (final Exception e) { return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_fileError_error - + e.getLocalizedMessage()); + SelectLanguageConfigurationWizardPage_fileError_error + e.getLocalizedMessage()); } + + final var contentTypeText = this.contentTypeText; + assert contentTypeText != null; if (contentTypeText.getText().isEmpty()) { return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_noSelection); + SelectLanguageConfigurationWizardPage_contentTypeError_noSelection); } - IContentType contentType = ContentTypeHelper.getContentTypeById(contentTypeText.getText()); + final var contentType = ContentTypeHelper.getContentTypeById(contentTypeText.getText()); if (contentType == null) { return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeError_invalid); + SelectLanguageConfigurationWizardPage_contentTypeError_invalid); } if (registryManager.getLanguageConfigurationFor(new IContentType[] { contentType }) != null) { return new Status(IStatus.WARNING, LanguageConfigurationPlugin.PLUGIN_ID, - LanguageConfigurationMessages.SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate); + SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate); } return null; } ILanguageConfigurationDefinition getDefinition() { - IPath p = new Path(fileText.getText()); - if (!p.isAbsolute()) { - p = ResourcesPlugin.getWorkspace().getRoot().getFile(p).getLocation(); + final var fileText = this.fileText; + assert fileText != null; + IPath path = new Path(fileText.getText()); + if (!path.isAbsolute()) { + path = ResourcesPlugin.getWorkspace().getRoot().getFile(path).getLocation(); } - return new LanguageConfigurationDefinition(ContentTypeHelper.getContentTypeById(contentTypeText.getText()), - p.toString()); - } + final var contentTypeText = this.contentTypeText; + assert contentTypeText != null; + return new LanguageConfigurationDefinition( + ContentTypeHelper.getContentTypeById(contentTypeText.getText()), + path.toString()); + } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/package-info.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/package-info.java new file mode 100644 index 000000000..f75b58cd3 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.languageconfiguration.internal.wizards; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/package-info.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/package-info.java new file mode 100644 index 000000000..6ff0e49e9 --- /dev/null +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.languageconfiguration; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java index 9a808bfdd..bcff89389 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java @@ -1,22 +1,22 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.supports; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; +import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.internal.supports.EnterAction.IndentAction; import org.junit.jupiter.api.Test; @@ -61,6 +61,7 @@ public void testIndentAction(String beforeText, String afterText, IndentAction e if (expected == IndentAction.None) { assertNull(actual); } else { + assertNotNull(actual); assertEquals(expected, actual.getIndentAction()); } } @@ -113,7 +114,7 @@ private class RegExpRulesTest extends OnEnterSupport { public RegExpRulesTest() { super(null, - Arrays.asList( + List.of( new OnEnterRule("^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", "^\\s*\\*\\/$", new EnterAction(IndentAction.IndentOutdent).setAppendText(" * ")), new OnEnterRule("^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$", null, @@ -126,13 +127,13 @@ public RegExpRulesTest() { new EnterAction(IndentAction.None).setRemoveText(1)))); } - public void testIndentAction(String beforeText, String afterText, IndentAction expectedIndentAction, - String expectedAppendText) { + public void testIndentAction(String beforeText, String afterText, @Nullable IndentAction expectedIndentAction, + @Nullable String expectedAppendText) { testIndentAction(beforeText, afterText, expectedIndentAction, expectedAppendText, 0); } - public void testIndentAction(String beforeText, String afterText, IndentAction expectedIndentAction, - String expectedAppendText, int removeText) { + public void testIndentAction(String beforeText, String afterText, @Nullable IndentAction expectedIndentAction, + @Nullable String expectedAppendText, int removeText) { EnterAction actual = super.onEnter("", beforeText, afterText); if (expectedIndentAction == null) { assertNull(actual, "isNull:" + beforeText); diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java index b0bfb2e6a..9344b40db 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/ParsingTest.java @@ -15,11 +15,13 @@ import java.io.InputStream; import java.io.InputStreamReader; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfiguration; import org.junit.jupiter.api.Test; public class ParsingTest { + @Nullable private LanguageConfiguration loadLanguageConfiguration(String path) throws IOException { try (InputStream is = getClass().getResourceAsStream(path)) { assertNotNull(is); @@ -29,13 +31,13 @@ private LanguageConfiguration loadLanguageConfiguration(String path) throws IOEx @Test public void testCanLoadPhpLanguageConfig() throws Exception { - LanguageConfiguration languageConfiguration = loadLanguageConfiguration("/php-language-configuration.json"); + final var languageConfiguration = loadLanguageConfiguration("/php-language-configuration.json"); assertNotNull(languageConfiguration); } @Test public void testCanLoadRustLanguageConfig() throws Exception { - LanguageConfiguration languageConfiguration = loadLanguageConfiguration("/rust-language-configuration.json"); + final var languageConfiguration = loadLanguageConfiguration("/rust-language-configuration.json"); assertNotNull(languageConfiguration); } } From 4fb7cfa94e88702acb14208b9e5e49bcbac6bf31 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 5 May 2022 15:56:28 +0200 Subject: [PATCH 174/202] Enable eclipse maven builder --- org.eclipse.tm4e.languageconfiguration.tests/.project | 8 +++++++- org.eclipse.tm4e.languageconfiguration/.project | 8 +++++++- org.eclipse.tm4e.registry/.project | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration.tests/.project b/org.eclipse.tm4e.languageconfiguration.tests/.project index 107994bc0..ea80c854b 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/.project +++ b/org.eclipse.tm4e.languageconfiguration.tests/.project @@ -20,9 +20,15 @@ + + org.eclipse.m2e.core.maven2Builder + + + - org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature diff --git a/org.eclipse.tm4e.languageconfiguration/.project b/org.eclipse.tm4e.languageconfiguration/.project index d56cfc773..cb625c415 100644 --- a/org.eclipse.tm4e.languageconfiguration/.project +++ b/org.eclipse.tm4e.languageconfiguration/.project @@ -20,9 +20,15 @@ + + org.eclipse.m2e.core.maven2Builder + + + - org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature diff --git a/org.eclipse.tm4e.registry/.project b/org.eclipse.tm4e.registry/.project index a34f25782..09f9e611f 100644 --- a/org.eclipse.tm4e.registry/.project +++ b/org.eclipse.tm4e.registry/.project @@ -20,9 +20,15 @@ + + org.eclipse.m2e.core.maven2Builder + + + - org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature From 481d574889a644200840026f577fc117169b0b37 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 5 May 2022 18:41:21 +0200 Subject: [PATCH 175/202] Align project configurations and adjust folder layout in test projects --- org.eclipse.tm4e.core.tests/.classpath | 15 +- org.eclipse.tm4e.core.tests/pom.xml | 38 +- .../tm4e/core/grammar/GrammarSuiteTest.java | 2 +- .../resources/matcher-tests.json | 0 .../resources/test-cases/first-mate/README.md | 0 .../fixtures/apply-end-pattern-last.json | 0 .../first-mate/fixtures/c-plus-plus.json | 0 .../test-cases/first-mate/fixtures/c.json | 0 .../first-mate/fixtures/coffee-script.json | 0 .../first-mate/fixtures/content-name.json | 0 .../test-cases/first-mate/fixtures/css.json | 0 .../first-mate/fixtures/forever.json | 0 .../first-mate/fixtures/git-commit.json | 0 .../test-cases/first-mate/fixtures/hello.json | 0 .../first-mate/fixtures/html-erb.json | 0 .../first-mate/fixtures/html-rails.json | 0 .../test-cases/first-mate/fixtures/html.json | 0 .../first-mate/fixtures/hyperlink.json | 0 .../first-mate/fixtures/imaginary.json | 0 .../include-external-repository-rule.json | 0 .../first-mate/fixtures/infinite-loop.json | 0 .../test-cases/first-mate/fixtures/java.json | 0 .../first-mate/fixtures/javascript-regex.json | 0 .../first-mate/fixtures/javascript.json | 0 .../test-cases/first-mate/fixtures/json.json | 0 .../test-cases/first-mate/fixtures/latex.json | 0 .../test-cases/first-mate/fixtures/loops.json | 0 .../first-mate/fixtures/makefile.json | 0 .../first-mate/fixtures/multiline.json | 0 .../first-mate/fixtures/nested-captures.json | 0 .../fixtures/objective-c-plus-plus.json | 0 .../first-mate/fixtures/objective-c.json | 0 .../test-cases/first-mate/fixtures/php.json | 0 .../first-mate/fixtures/python-regex.json | 0 .../first-mate/fixtures/python.json | 0 .../first-mate/fixtures/ruby-on-rails.json | 0 .../test-cases/first-mate/fixtures/ruby.json | 0 .../test-cases/first-mate/fixtures/scss.json | 0 .../test-cases/first-mate/fixtures/sql.json | 0 .../test-cases/first-mate/fixtures/text.json | 0 .../first-mate/fixtures/thrift.json | 0 .../test-cases/first-mate/fixtures/todo.json | 0 .../test-cases/first-mate/tests.json | 0 .../suite1/fixtures/105.grammarA.json | 0 .../suite1/fixtures/105.grammarB.json | 0 .../suite1/fixtures/147.grammar.json | 0 .../test-cases/suite1/fixtures/66.plist | 0 .../test-cases/suite1/fixtures/Jade.json | 0 .../suite1/fixtures/Jade.tmLanguage | 0 .../test-cases/suite1/fixtures/Jade22.json | 0 .../test-cases/suite1/fixtures/Makefile.plist | 0 .../suite1/fixtures/Markdown.tmLanguage | 0 .../test-cases/suite1/fixtures/Perl.plist | 7378 ++++++++--------- .../test-cases/suite1/fixtures/Pug.tmLanguage | 0 .../test-cases/suite1/fixtures/Ruby.plist | 0 .../suite1/fixtures/YAML.tmLanguage | 0 .../test-cases/suite1/fixtures/aspvbnet.plist | 0 .../test-cases/suite1/fixtures/groovy.json | 0 .../test-cases/suite1/fixtures/html.json | 0 .../test-cases/suite1/fixtures/html2.json | 0 .../suite1/fixtures/infinite-loop.json | 0 .../suite1/fixtures/javascript.json | 0 .../test-cases/suite1/fixtures/markdown.plist | 0 .../test-cases/suite1/fixtures/php.plist | 0 .../suite1/fixtures/testlang12.plist | 0 .../suite1/fixtures/whileLang.plist | 0 .../resources/test-cases/suite1/tests.json | 0 .../test-cases/suite1/whileTests.json | 0 .../resources/test-cases/themes/.gitignore | 0 .../resources/test-cases/themes/Abyss.tmTheme | 0 .../test-cases/themes/Kimbie_dark.tmTheme | 0 .../test-cases/themes/Monokai.tmTheme | 0 .../test-cases/themes/QuietLight.tmTheme | 0 .../test-cases/themes/Solarized-dark.tmTheme | 0 .../test-cases/themes/Solarized-light.tmTheme | 0 .../themes/Tomorrow-Night-Blue.tmTheme | 0 .../test-cases/themes/dark_plus.json | 0 .../resources/test-cases/themes/dark_vs.json | 0 .../resources/test-cases/themes/diff.css | 0 .../resources/test-cases/themes/diff.js | 0 .../resources/test-cases/themes/diff.ts | 0 .../test-cases/themes/dimmed-monokai.tmTheme | 0 .../themes/go/colorize-fixtures/test-13777.go | 0 .../themes/go/colorize-fixtures/test.go | 0 .../go/colorize-results/test-13777_go.json | 0 .../themes/go/colorize-results/test_go.json | 0 .../resources/test-cases/themes/go/go.json | 0 .../resources/test-cases/themes/grammars.json | 0 .../resources/test-cases/themes/hc_black.json | 0 .../test-cases/themes/languages.json | 0 .../test-cases/themes/light_plus.json | 0 .../resources/test-cases/themes/light_vs.json | 0 .../resources/test-cases/themes/red.tmTheme | 0 .../test-cases/themes/syntaxes/ASPVBnet.plist | 0 .../themes/syntaxes/Batch File.tmLanguage | 0 .../themes/syntaxes/Clojure.tmLanguage | 0 .../themes/syntaxes/Dockerfile.tmLanguage | 0 .../themes/syntaxes/Groovy.tmLanguage | 0 .../themes/syntaxes/Handlebars.json | 0 .../themes/syntaxes/JSON.tmLanguage | 0 .../test-cases/themes/syntaxes/Jade.json | 0 .../syntaxes/JavaScript.tmLanguage.json | 0 .../syntaxes/MagicPython.tmLanguage.json | 0 .../syntaxes/MagicRegExp.tmLanguage.json | 0 .../test-cases/themes/syntaxes/Makefile.json | 0 .../themes/syntaxes/Objective-C.tmLanguage | 0 .../themes/syntaxes/Perl 6.tmLanguage | 0 .../test-cases/themes/syntaxes/Perl.plist | 0 .../themes/syntaxes/Platform.tmLanguage | 0 .../syntaxes/PowershellSyntax.tmLanguage | 0 .../test-cases/themes/syntaxes/R.plist | 0 ...egular Expressions (JavaScript).tmLanguage | 0 .../test-cases/themes/syntaxes/Ruby.plist | 0 .../test-cases/themes/syntaxes/SQL.plist | 0 .../syntaxes/Shell-Unix-Bash.tmLanguage.json | 0 .../syntaxes/TypeScript.tmLanguage.json | 0 .../syntaxes/TypeScriptReact.tmLanguage.json | 0 .../test-cases/themes/syntaxes/c++.json | 0 .../test-cases/themes/syntaxes/c.json | 0 .../themes/syntaxes/coffeescript.json | 0 .../test-cases/themes/syntaxes/cshtml.json | 0 .../test-cases/themes/syntaxes/css.plist | 0 .../themes/syntaxes/diff.tmLanguage | 0 .../test-cases/themes/syntaxes/fsharp.json | 0 .../themes/syntaxes/git-commit.tmLanguage | 0 .../themes/syntaxes/git-rebase.tmLanguage | 0 .../test-cases/themes/syntaxes/go.json | 0 .../test-cases/themes/syntaxes/html.json | 0 .../test-cases/themes/syntaxes/java.json | 0 .../themes/syntaxes/less.tmLanguage.json | 0 .../test-cases/themes/syntaxes/lua.json | 0 .../themes/syntaxes/markdown.tmLanguage | 0 .../test-cases/themes/syntaxes/php.json | 0 .../themes/syntaxes/properties.plist | 0 .../test-cases/themes/syntaxes/rust.json | 0 .../test-cases/themes/syntaxes/scss.json | 0 .../test-cases/themes/syntaxes/shaderlab.json | 0 .../test-cases/themes/syntaxes/swift.json | 0 .../test-cases/themes/syntaxes/xml.json | 0 .../test-cases/themes/syntaxes/xsl.json | 0 .../test-cases/themes/syntaxes/yaml.json | 0 .../test-cases/themes/tests/12750.html | 0 .../test-cases/themes/tests/12750.html.result | 0 .../themes/tests/12750.html.result.patch | 0 .../test-cases/themes/tests/13448.html | 0 .../test-cases/themes/tests/13448.html.result | 0 .../themes/tests/13448.html.result.patch | 0 .../test-cases/themes/tests/14119.less | 0 .../test-cases/themes/tests/14119.less.result | 0 .../themes/tests/14119.less.result.patch | 0 .../test-cases/themes/tests/COMMIT_EDITMSG | 0 .../themes/tests/COMMIT_EDITMSG.result | 0 .../test-cases/themes/tests/Dockerfile | 0 .../test-cases/themes/tests/Dockerfile.result | 0 .../test-cases/themes/tests/basic.java | 0 .../test-cases/themes/tests/basic.java.result | 0 .../themes/tests/basic.java.result.patch | 0 .../test-cases/themes/tests/git-rebase-todo | 0 .../themes/tests/git-rebase-todo.result | 0 .../test-cases/themes/tests/issue-1550.yaml | 0 .../themes/tests/issue-1550.yaml.result | 0 .../themes/tests/issue-1550.yaml.result.patch | 0 .../test-cases/themes/tests/issue-4008.yaml | 0 .../themes/tests/issue-4008.yaml.result | 0 .../themes/tests/issue-4008.yaml.result.patch | 0 .../test-cases/themes/tests/issue-6303.yaml | 0 .../themes/tests/issue-6303.yaml.result | 0 .../themes/tests/issue-6303.yaml.result.patch | 0 .../test-cases/themes/tests/makefile | 0 .../test-cases/themes/tests/makefile.result | 0 .../themes/tests/makefile.result.patch | 0 .../test-cases/themes/tests/test-13777.go | 0 .../themes/tests/test-13777.go.result | 0 .../test-cases/themes/tests/test-4287.jade | 0 .../themes/tests/test-4287.jade.result | 0 .../test-cases/themes/tests/test-6611.rs | 0 .../themes/tests/test-6611.rs.result | 0 .../themes/tests/test-6611.rs.result.patch | 0 .../test-cases/themes/tests/test-7115.xml | 0 .../themes/tests/test-7115.xml.result | 0 .../themes/tests/test-7115.xml.result.patch | 0 .../test-cases/themes/tests/test-brackets.tsx | 0 .../themes/tests/test-brackets.tsx.result | 0 .../tests/test-brackets.tsx.result.patch | 0 .../themes/tests/test-cssvariables.less | 0 .../tests/test-cssvariables.less.result | 0 .../tests/test-cssvariables.less.result.patch | 0 .../themes/tests/test-cssvariables.scss | 0 .../tests/test-cssvariables.scss.result | 0 .../tests/test-cssvariables.scss.result.patch | 0 .../themes/tests/test-function-inv.ts | 0 .../themes/tests/test-function-inv.ts.result | 0 .../tests/test-function-inv.ts.result.patch | 0 .../test-cases/themes/tests/test-issue11.ts | 0 .../themes/tests/test-issue11.ts.result | 0 .../themes/tests/test-issue11.ts.result.patch | 0 .../test-cases/themes/tests/test-issue5431.ts | 0 .../themes/tests/test-issue5431.ts.result | 0 .../tests/test-issue5431.ts.result.patch | 0 .../test-cases/themes/tests/test-issue5465.ts | 0 .../themes/tests/test-issue5465.ts.result | 0 .../test-cases/themes/tests/test-issue5566.ts | 0 .../themes/tests/test-issue5566.ts.result | 0 .../tests/test-issue5566.ts.result.patch | 0 .../test-cases/themes/tests/test-keywords.ts | 0 .../themes/tests/test-keywords.ts.result | 0 .../tests/test-keywords.ts.result.patch | 0 .../test-cases/themes/tests/test-members.ts | 0 .../themes/tests/test-members.ts.result | 0 .../themes/tests/test-members.ts.result.patch | 0 .../themes/tests/test-object-literals.ts | 0 .../tests/test-object-literals.ts.result | 0 .../test-object-literals.ts.result.patch | 0 .../test-cases/themes/tests/test-regex.coffee | 0 .../themes/tests/test-regex.coffee.result | 0 .../tests/test-regex.coffee.result.patch | 0 .../test-cases/themes/tests/test-strings.ts | 0 .../themes/tests/test-strings.ts.result | 0 .../themes/tests/test-strings.ts.result.patch | 0 .../test-cases/themes/tests/test-this.ts | 0 .../themes/tests/test-this.ts.result | 0 .../themes/tests/test-variables.css | 0 .../themes/tests/test-variables.css.result | 0 .../tests/test-variables.css.result.patch | 0 .../test-cases/themes/tests/test.bat | 0 .../test-cases/themes/tests/test.bat.result | 0 .../resources/test-cases/themes/tests/test.c | 0 .../test-cases/themes/tests/test.c.result | 0 .../themes/tests/test.c.result.patch | 0 .../resources/test-cases/themes/tests/test.cc | 0 .../test-cases/themes/tests/test.cc.result | 0 .../themes/tests/test.cc.result.patch | 0 .../test-cases/themes/tests/test.clj | 0 .../test-cases/themes/tests/test.clj.result | 0 .../themes/tests/test.clj.result.patch | 0 .../test-cases/themes/tests/test.coffee | 0 .../themes/tests/test.coffee.result | 0 .../themes/tests/test.coffee.result.patch | 0 .../test-cases/themes/tests/test.cpp | 0 .../test-cases/themes/tests/test.cpp.result | 0 .../themes/tests/test.cpp.result.patch | 0 .../test-cases/themes/tests/test.cshtml | 0 .../themes/tests/test.cshtml.result | 0 .../themes/tests/test.cshtml.result.patch | 0 .../test-cases/themes/tests/test.css | 0 .../test-cases/themes/tests/test.css.result | 0 .../themes/tests/test.css.result.patch | 0 .../test-cases/themes/tests/test.diff | 0 .../test-cases/themes/tests/test.diff.result | 0 .../themes/tests/test.diff.result.patch | 0 .../resources/test-cases/themes/tests/test.fs | 0 .../test-cases/themes/tests/test.fs.result | 0 .../themes/tests/test.fs.result.patch | 0 .../resources/test-cases/themes/tests/test.go | 0 .../test-cases/themes/tests/test.go.result | 0 .../themes/tests/test.go.result.patch | 0 .../test-cases/themes/tests/test.groovy | 0 .../themes/tests/test.groovy.result | 0 .../themes/tests/test.groovy.result.patch | 0 .../test-cases/themes/tests/test.handlebars | 0 .../themes/tests/test.handlebars.result | 0 .../themes/tests/test.handlebars.result.patch | 0 .../test-cases/themes/tests/test.hbs | 0 .../test-cases/themes/tests/test.hbs.result | 0 .../themes/tests/test.hbs.result.patch | 0 .../test-cases/themes/tests/test.html | 0 .../test-cases/themes/tests/test.html.result | 0 .../themes/tests/test.html.result.patch | 0 .../test-cases/themes/tests/test.ini | 0 .../test-cases/themes/tests/test.ini.result | 0 .../test-cases/themes/tests/test.jade | 0 .../test-cases/themes/tests/test.jade.result | 0 .../themes/tests/test.jade.result.patch | 0 .../resources/test-cases/themes/tests/test.js | 0 .../test-cases/themes/tests/test.js.result | 0 .../themes/tests/test.js.result.patch | 0 .../test-cases/themes/tests/test.json | 0 .../test-cases/themes/tests/test.json.result | 0 .../themes/tests/test.json.result.patch | 0 .../test-cases/themes/tests/test.jsx | 0 .../test-cases/themes/tests/test.jsx.result | 0 .../themes/tests/test.jsx.result.patch | 0 .../test-cases/themes/tests/test.less | 0 .../test-cases/themes/tests/test.less.result | 0 .../themes/tests/test.less.result.patch | 0 .../test-cases/themes/tests/test.lua | 0 .../test-cases/themes/tests/test.lua.result | 0 .../resources/test-cases/themes/tests/test.m | 0 .../test-cases/themes/tests/test.m.result | 0 .../themes/tests/test.m.result.patch | 0 .../resources/test-cases/themes/tests/test.md | 0 .../test-cases/themes/tests/test.md.result | 0 .../themes/tests/test.md.result.patch | 0 .../test-cases/themes/tests/test.php | 0 .../test-cases/themes/tests/test.php.result | 0 .../themes/tests/test.php.result.patch | 0 .../resources/test-cases/themes/tests/test.pl | 0 .../test-cases/themes/tests/test.pl.result | 0 .../themes/tests/test.pl.result.patch | 0 .../test-cases/themes/tests/test.ps1 | 0 .../test-cases/themes/tests/test.ps1.result | 0 .../themes/tests/test.ps1.result.patch | 0 .../resources/test-cases/themes/tests/test.py | 0 .../test-cases/themes/tests/test.py.result | 0 .../themes/tests/test.py.result.patch | 0 .../resources/test-cases/themes/tests/test.r | 0 .../test-cases/themes/tests/test.r.result | 0 .../resources/test-cases/themes/tests/test.rb | 0 .../test-cases/themes/tests/test.rb.result | 0 .../themes/tests/test.rb.result.patch | 0 .../resources/test-cases/themes/tests/test.rs | 0 .../test-cases/themes/tests/test.rs.result | 0 .../test-cases/themes/tests/test.scss | 0 .../test-cases/themes/tests/test.scss.result | 0 .../themes/tests/test.scss.result.patch | 0 .../resources/test-cases/themes/tests/test.sh | 0 .../test-cases/themes/tests/test.sh.result | 0 .../themes/tests/test.sh.result.patch | 0 .../test-cases/themes/tests/test.shader | 0 .../themes/tests/test.shader.result | 0 .../themes/tests/test.shader.result.patch | 0 .../test-cases/themes/tests/test.sql | 0 .../test-cases/themes/tests/test.sql.result | 0 .../test-cases/themes/tests/test.swift | 0 .../test-cases/themes/tests/test.swift.result | 0 .../themes/tests/test.swift.result.patch | 0 .../resources/test-cases/themes/tests/test.ts | 0 .../test-cases/themes/tests/test.ts.result | 0 .../themes/tests/test.ts.result.patch | 0 .../resources/test-cases/themes/tests/test.vb | 0 .../test-cases/themes/tests/test.vb.result | 0 .../themes/tests/test.vb.result.patch | 0 .../test-cases/themes/tests/test.xml | 0 .../test-cases/themes/tests/test.xml.result | 0 .../themes/tests/test.xml.result.patch | 0 .../test-cases/themes/tests/test.yaml | 0 .../test-cases/themes/tests/test.yaml.result | 0 .../themes/tests/test.yaml.result.patch | 0 .../test-cases/themes/tests/test2.pl | 0 .../test-cases/themes/tests/test2.pl.result | 0 .../themes/tests/test2.pl.result.patch | 0 .../test-cases/themes/tests/test6916.js | 0 .../themes/tests/test6916.js.result | 0 .../test-cases/themes/tests/tsconfig.json | 0 .../themes/tests/tsconfig.json.result | 0 .../themes/tests/tsconfig.json.result.patch | 0 .../resources/test-cases/themes/tsconfig.json | 0 org.eclipse.tm4e.core/.classpath | 26 +- .../.classpath | 29 +- .../build.properties | 4 +- .../tests/TestAutoClosing.java | 0 .../tests/TestComment.java | 0 .../tests/TestIndent.java | 0 .../src/main/resources/.gitkeep | 0 .../.classpath | 32 +- .../build.properties | 1 - .../src/main/resources/.gitkeep | 0 org.eclipse.tm4e.markdown/.classpath | 19 +- org.eclipse.tm4e.markdown/.gitignore | 2 - org.eclipse.tm4e.registry/.classpath | 26 +- org.eclipse.tm4e.registry/build.properties | 5 +- .../src/main}/resources/.gitkeep | 0 org.eclipse.tm4e.ui.tests/.classpath | 14 +- org.eclipse.tm4e.ui.tests/build.properties | 6 +- .../org/eclipse/tm4e/ui/RegistryTest.java | 0 .../tm4e/ui/TMinGenericEditorTest.java | 0 .../internal/model/DocumentTMModelTest.java | 0 .../tm4e/ui/internal/text/Command.java | 0 .../internal/text/DocumentReplaceCommand.java | 0 .../ui/internal/text/DocumentSetCommand.java | 0 .../internal/text/StyleRangesCollector.java | 0 ...ewerInvalidateTextPresentationCommand.java | 0 .../org/eclipse/tm4e/ui/text/ICommand.java | 0 .../org/eclipse/tm4e/ui/text/TMEditor.java | 0 ...MPresentationReconcilerTypeScriptTest.java | 0 .../tm4e/ui/themes/MockThemeManager.java | 0 .../tm4e/ui/themes/TMEditorColorTest.java | 0 .../tm4e/ui/themes/ThemeManagerTest.java | 0 .../textmate4e/ui/text/Solarized-light.css | 0 org.eclipse.tm4e.ui/.classpath | 33 +- 380 files changed, 3882 insertions(+), 3748 deletions(-) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/matcher-tests.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/README.md (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/apply-end-pattern-last.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/c-plus-plus.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/c.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/coffee-script.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/content-name.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/css.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/forever.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/git-commit.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/hello.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/html-erb.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/html-rails.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/html.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/hyperlink.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/imaginary.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/include-external-repository-rule.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/infinite-loop.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/java.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/javascript-regex.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/javascript.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/json.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/latex.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/loops.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/makefile.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/multiline.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/nested-captures.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/objective-c-plus-plus.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/objective-c.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/php.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/python-regex.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/python.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/ruby-on-rails.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/ruby.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/scss.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/sql.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/text.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/thrift.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/fixtures/todo.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/first-mate/tests.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/105.grammarA.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/105.grammarB.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/147.grammar.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/66.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Jade.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Jade.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Jade22.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Makefile.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Markdown.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Perl.plist (95%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Pug.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/Ruby.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/YAML.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/aspvbnet.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/groovy.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/html.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/html2.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/infinite-loop.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/javascript.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/markdown.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/php.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/testlang12.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/fixtures/whileLang.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/tests.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/suite1/whileTests.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/.gitignore (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/Abyss.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/Kimbie_dark.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/Monokai.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/QuietLight.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/Solarized-dark.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/Solarized-light.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/Tomorrow-Night-Blue.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/dark_plus.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/dark_vs.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/diff.css (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/diff.js (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/diff.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/dimmed-monokai.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/go/colorize-fixtures/test-13777.go (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/go/colorize-fixtures/test.go (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/go/colorize-results/test-13777_go.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/go/colorize-results/test_go.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/go/go.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/grammars.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/hc_black.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/languages.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/light_plus.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/light_vs.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/red.tmTheme (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/ASPVBnet.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Batch File.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Clojure.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Dockerfile.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Groovy.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Handlebars.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/JSON.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Jade.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/JavaScript.tmLanguage.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/MagicPython.tmLanguage.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/MagicRegExp.tmLanguage.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Makefile.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Objective-C.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Perl 6.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Perl.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Platform.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/PowershellSyntax.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/R.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Regular Expressions (JavaScript).tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Ruby.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/SQL.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/Shell-Unix-Bash.tmLanguage.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/TypeScript.tmLanguage.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/TypeScriptReact.tmLanguage.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/c++.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/c.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/coffeescript.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/cshtml.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/css.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/diff.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/fsharp.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/git-commit.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/git-rebase.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/go.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/html.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/java.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/less.tmLanguage.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/lua.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/markdown.tmLanguage (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/php.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/properties.plist (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/rust.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/scss.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/shaderlab.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/swift.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/xml.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/xsl.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/syntaxes/yaml.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/12750.html (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/12750.html.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/12750.html.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/13448.html (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/13448.html.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/13448.html.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/14119.less (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/14119.less.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/14119.less.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/COMMIT_EDITMSG (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/COMMIT_EDITMSG.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/Dockerfile (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/Dockerfile.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/basic.java (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/basic.java.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/basic.java.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/git-rebase-todo (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/git-rebase-todo.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-1550.yaml (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-1550.yaml.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-1550.yaml.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-4008.yaml (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-4008.yaml.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-4008.yaml.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-6303.yaml (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-6303.yaml.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/issue-6303.yaml.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/makefile (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/makefile.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/makefile.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-13777.go (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-13777.go.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-4287.jade (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-4287.jade.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-6611.rs (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-6611.rs.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-6611.rs.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-7115.xml (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-7115.xml.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-7115.xml.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-brackets.tsx (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-brackets.tsx.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-brackets.tsx.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-cssvariables.less (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-cssvariables.less.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-cssvariables.less.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-cssvariables.scss (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-cssvariables.scss.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-cssvariables.scss.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-function-inv.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-function-inv.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-function-inv.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue11.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue11.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue11.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5431.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5431.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5431.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5465.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5465.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5566.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5566.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-issue5566.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-keywords.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-keywords.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-keywords.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-members.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-members.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-members.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-object-literals.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-object-literals.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-object-literals.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-regex.coffee (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-regex.coffee.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-regex.coffee.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-strings.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-strings.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-strings.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-this.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-this.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-variables.css (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-variables.css.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test-variables.css.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.bat (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.bat.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.c (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.c.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.c.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cc (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cc.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cc.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.clj (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.clj.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.clj.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.coffee (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.coffee.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.coffee.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cpp (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cpp.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cpp.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cshtml (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cshtml.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.cshtml.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.css (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.css.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.css.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.diff (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.diff.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.diff.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.fs (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.fs.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.fs.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.go (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.go.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.go.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.groovy (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.groovy.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.groovy.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.handlebars (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.handlebars.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.handlebars.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.hbs (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.hbs.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.hbs.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.html (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.html.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.html.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ini (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ini.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.jade (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.jade.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.jade.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.js (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.js.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.js.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.json.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.json.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.jsx (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.jsx.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.jsx.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.less (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.less.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.less.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.lua (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.lua.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.m (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.m.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.m.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.md (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.md.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.md.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.php (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.php.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.php.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.pl (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.pl.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.pl.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ps1 (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ps1.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ps1.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.py (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.py.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.py.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.r (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.r.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.rb (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.rb.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.rb.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.rs (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.rs.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.scss (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.scss.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.scss.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.sh (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.sh.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.sh.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.shader (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.shader.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.shader.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.sql (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.sql.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.swift (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.swift.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.swift.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ts (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ts.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.ts.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.vb (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.vb.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.vb.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.xml (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.xml.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.xml.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.yaml (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.yaml.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test.yaml.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test2.pl (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test2.pl.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test2.pl.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test6916.js (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/test6916.js.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/tsconfig.json (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/tsconfig.json.result (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tests/tsconfig.json.result.patch (100%) rename org.eclipse.tm4e.core.tests/src/{test => main}/resources/test-cases/themes/tsconfig.json (100%) rename org.eclipse.tm4e.languageconfiguration.tests/src/{ => main/java}/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java (100%) rename org.eclipse.tm4e.languageconfiguration.tests/src/{ => main/java}/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java (100%) rename org.eclipse.tm4e.languageconfiguration.tests/src/{ => main/java}/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java (100%) rename {org.eclipse.tm4e.core.tests => org.eclipse.tm4e.languageconfiguration.tests}/src/main/resources/.gitkeep (100%) rename {org.eclipse.tm4e.ui.tests => org.eclipse.tm4e.languageconfiguration}/src/main/resources/.gitkeep (100%) delete mode 100644 org.eclipse.tm4e.markdown/.gitignore rename {org.eclipse.tm4e.ui.tests/src/test => org.eclipse.tm4e.registry/src/main}/resources/.gitkeep (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/RegistryTest.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/internal/text/Command.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/text/ICommand.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/text/TMEditor.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java (100%) rename org.eclipse.tm4e.ui.tests/src/{test => main}/resources/org/eclipse/textmate4e/ui/text/Solarized-light.css (100%) diff --git a/org.eclipse.tm4e.core.tests/.classpath b/org.eclipse.tm4e.core.tests/.classpath index d3fc9157f..71f21812a 100644 --- a/org.eclipse.tm4e.core.tests/.classpath +++ b/org.eclipse.tm4e.core.tests/.classpath @@ -6,14 +6,21 @@ - + - + + + + + + + + - + - + diff --git a/org.eclipse.tm4e.core.tests/pom.xml b/org.eclipse.tm4e.core.tests/pom.xml index 3af55b267..d2ad9fb95 100644 --- a/org.eclipse.tm4e.core.tests/pom.xml +++ b/org.eclipse.tm4e.core.tests/pom.xml @@ -1,11 +1,29 @@ - - 4.0.0 - org.eclipse.tm4e.core.tests - eclipse-test-plugin - 0.4.1-SNAPSHOT - - org.eclipse - org.eclipse.tm4e - 0.3.2-SNAPSHOT - + + 4.0.0 + org.eclipse.tm4e.core.tests + eclipse-test-plugin + 0.4.1-SNAPSHOT + + org.eclipse + org.eclipse.tm4e + 0.3.2-SNAPSHOT + + + + + + + org.eclipse.tycho + tycho-compiler-plugin + + + + test-cases/**/*.java + + + + + + diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java index 677573a77..29ec11aa7 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/GrammarSuiteTest.java @@ -35,7 +35,7 @@ */ public class GrammarSuiteTest { - private static final File REPO_ROOT = new File("src/test/resources"); + private static final File REPO_ROOT = new File("src/main/resources"); // TODO: fix thoses tests: // It seems that problem comes from with encoding. OnigString should support UTF-16 like diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/matcher-tests.json b/org.eclipse.tm4e.core.tests/src/main/resources/matcher-tests.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/matcher-tests.json rename to org.eclipse.tm4e.core.tests/src/main/resources/matcher-tests.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/README.md b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/README.md similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/README.md rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/README.md diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/apply-end-pattern-last.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/apply-end-pattern-last.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/apply-end-pattern-last.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/apply-end-pattern-last.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/c-plus-plus.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/c-plus-plus.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/c-plus-plus.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/c-plus-plus.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/c.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/c.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/c.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/c.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/coffee-script.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/coffee-script.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/coffee-script.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/coffee-script.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/content-name.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/content-name.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/content-name.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/content-name.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/css.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/css.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/css.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/css.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/forever.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/forever.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/forever.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/forever.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/git-commit.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/git-commit.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/git-commit.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/git-commit.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/hello.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/hello.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/hello.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/hello.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/html-erb.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/html-erb.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/html-erb.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/html-erb.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/html-rails.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/html-rails.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/html-rails.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/html-rails.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/html.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/html.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/html.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/html.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/hyperlink.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/hyperlink.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/hyperlink.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/hyperlink.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/imaginary.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/imaginary.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/imaginary.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/imaginary.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/include-external-repository-rule.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/include-external-repository-rule.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/include-external-repository-rule.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/include-external-repository-rule.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/infinite-loop.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/infinite-loop.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/infinite-loop.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/infinite-loop.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/java.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/java.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/java.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/java.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/javascript-regex.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/javascript-regex.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/javascript-regex.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/javascript-regex.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/javascript.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/javascript.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/javascript.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/javascript.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/json.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/json.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/json.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/json.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/latex.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/latex.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/latex.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/latex.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/loops.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/loops.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/loops.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/loops.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/makefile.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/makefile.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/makefile.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/makefile.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/multiline.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/multiline.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/multiline.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/multiline.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/nested-captures.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/nested-captures.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/nested-captures.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/nested-captures.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/objective-c-plus-plus.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/objective-c-plus-plus.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/objective-c-plus-plus.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/objective-c-plus-plus.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/objective-c.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/objective-c.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/objective-c.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/objective-c.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/php.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/php.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/php.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/php.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/python-regex.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/python-regex.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/python-regex.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/python-regex.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/python.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/python.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/python.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/python.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby-on-rails.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/ruby-on-rails.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby-on-rails.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/ruby-on-rails.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/ruby.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/ruby.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/ruby.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/scss.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/scss.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/scss.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/scss.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/sql.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/sql.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/sql.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/sql.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/text.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/text.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/text.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/text.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/thrift.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/thrift.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/thrift.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/thrift.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/todo.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/todo.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/fixtures/todo.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/fixtures/todo.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/tests.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/tests.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/first-mate/tests.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/first-mate/tests.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarA.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/105.grammarA.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarA.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/105.grammarA.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarB.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/105.grammarB.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/105.grammarB.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/105.grammarB.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/147.grammar.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/147.grammar.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/147.grammar.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/147.grammar.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/66.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/66.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/66.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/66.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Jade.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Jade.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Jade.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Jade.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade22.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Jade22.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Jade22.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Jade22.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Makefile.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Makefile.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Makefile.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Makefile.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Markdown.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Markdown.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Markdown.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Markdown.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Perl.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Perl.plist similarity index 95% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Perl.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Perl.plist index d259fcb9c..beab27aad 100644 --- a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Perl.plist +++ b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Perl.plist @@ -1,3690 +1,3690 @@ - - - - - comment - - TODO: Include RegExp syntax - - fileTypes - - pl - pm - pod - t - PL - psgi - - firstLineMatch - ^#!.*\bperl\b - keyEquivalent - ^~P - name - Perl - patterns - - - include - #line_comment - - - begin - ^= - captures - - 0 - - name - punctuation.definition.comment.perl - - - end - ^=cut - name - comment.block.documentation.perl - - - include - #variable - - - applyEndPatternLast - 1 - begin - \b(?=qr\s*[^\s\w]) - comment - string.regexp.compile.perl - end - ((([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)]|$)) - endCaptures - - 1 - - name - string.regexp.compile.perl - - 2 - - name - punctuation.definition.string.perl - - 3 - - name - keyword.control.regexp-option.perl - - - patterns - - - begin - (qr)\s*\{ - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \} - name - string.regexp.compile.nested_braces.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_braces_interpolated - - - - - begin - (qr)\s*\[ - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \] - name - string.regexp.compile.nested_brackets.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_brackets_interpolated - - - - - begin - (qr)\s*< - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - > - name - string.regexp.compile.nested_ltgt.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_ltgt_interpolated - - - - - begin - (qr)\s*\( - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \) - name - string.regexp.compile.nested_parens.perl - patterns - - - comment - This is to prevent thinks like qr/foo$/ to treat $/ as a variable - match - \$(?=[^\s\w\\'\{\[\(\<]) - - - include - #escaped_char - - - include - #variable - - - include - #nested_parens_interpolated - - - - - begin - (qr)\s*' - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - ' - name - string.regexp.compile.single-quote.perl - patterns - - - include - #escaped_char - - - - - begin - (qr)\s*([^\s\w'\{\[\(\<]) - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \2 - name - string.regexp.compile.simple-delimiter.perl - patterns - - - comment - This is to prevent thinks like qr/foo$/ to treat $/ as a variable - match - \$(?=[^\s\w'\{\[\(\<]) - name - keyword.control.anchor.perl - - - include - #escaped_char - - - include - #variable - - - include - #nested_parens_interpolated - - - - - - - applyEndPatternLast - 1 - begin - \b(?=m\s*[^\sa-zA-Z0-9]) - comment - string.regexp.find-m.perl - end - ((([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)]|$)) - endCaptures - - 1 - - name - string.regexp.find-m.perl - - 2 - - name - punctuation.definition.string.perl - - 3 - - name - keyword.control.regexp-option.perl - - - patterns - - - begin - (m)\s*\{ - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \} - name - string.regexp.find-m.nested_braces.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_braces_interpolated - - - - - begin - (m)\s*\[ - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \] - name - string.regexp.find-m.nested_brackets.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_brackets_interpolated - - - - - begin - (m)\s*< - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - > - name - string.regexp.find-m.nested_ltgt.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_ltgt_interpolated - - - - - begin - (m)\s*\( - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \) - name - string.regexp.find-m.nested_parens.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_parens_interpolated - - - - - begin - (m)\s*' - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - ' - name - string.regexp.find-m.single-quote.perl - patterns - - - include - #escaped_char - - - - - begin - (m)\s*([^\sa-zA-Z0-9'\{\[\(\<]) - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \2 - name - string.regexp.find-m.simple-delimiter.perl - patterns - - - comment - This is to prevent thinks like qr/foo$/ to treat $/ as a variable - match - \$(?=[^\sa-zA-Z0-9'\{\[\(\<]) - name - keyword.control.anchor.perl - - - include - #escaped_char - - - include - #variable - - - begin - \[ - beginCaptures - - 1 - - name - punctuation.definition.character-class.begin.perl - - - end - \] - endCaptures - - 1 - - name - punctuation.definition.character-class.end.perl - - - name - constant.other.character-class.set.perl - patterns - - - comment - This is to prevent thinks like qr/foo$/ to treat $/ as a variable - match - \$(?=[^\s\w'\{\[\(\<]) - name - keyword.control.anchor.perl - - - include - #escaped_char - - - - - include - #nested_parens_interpolated - - - - - - - applyEndPatternLast - 1 - begin - \b(?=(?<!\&)(s)(\s+\S|\s*[;\,\#\{\}\(\)\[<]|$)) - comment - string.regexp.replace.perl - end - ((([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)\]>]|$)) - endCaptures - - 1 - - name - string.regexp.replace.perl - - 2 - - name - punctuation.definition.string.perl - - 3 - - name - keyword.control.regexp-option.perl - - - patterns - - - begin - (s)\s*\{ - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \} - name - string.regexp.nested_braces.perl - patterns - - - include - #escaped_char - - - include - #nested_braces - - - - - begin - (s)\s*\[ - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \] - name - string.regexp.nested_brackets.perl - patterns - - - include - #escaped_char - - - include - #nested_brackets - - - - - begin - (s)\s*< - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - > - name - string.regexp.nested_ltgt.perl - patterns - - - include - #escaped_char - - - include - #nested_ltgt - - - - - begin - (s)\s*\( - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - \) - name - string.regexp.nested_parens.perl - patterns - - - include - #escaped_char - - - include - #nested_parens - - - - - begin - \{ - captures - - 0 - - name - punctuation.definition.string.perl - - - end - \} - name - string.regexp.format.nested_braces.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_braces_interpolated - - - - - begin - \[ - captures - - 0 - - name - punctuation.definition.string.perl - - - end - \] - name - string.regexp.format.nested_brackets.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_brackets_interpolated - - - - - begin - < - captures - - 0 - - name - punctuation.definition.string.perl - - - end - > - name - string.regexp.format.nested_ltgt.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_ltgt_interpolated - - - - - begin - \( - captures - - 0 - - name - punctuation.definition.string.perl - - - end - \) - name - string.regexp.format.nested_parens.perl - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_parens_interpolated - - - - - begin - ' - captures - - 0 - - name - punctuation.definition.string.perl - - - end - ' - name - string.regexp.format.single_quote.perl - patterns - - - match - \\['\\] - name - constant.character.escape.perl - - - - - begin - ([^\s\w\[({<;]) - captures - - 0 - - name - punctuation.definition.string.perl - - - end - \1 - name - string.regexp.format.simple_delimiter.perl - patterns - - - include - #escaped_char - - - include - #variable - - - - - match - \s+ - - - - - begin - \b(?=s([^\sa-zA-Z0-9\[({<]).*\1([egimosxradlupc]*)([\}\)\;\,]|\s+)) - comment - string.regexp.replaceXXX - end - ((([egimosxradlupc]*)))(?=([\}\)\;\,]|\s+|$)) - endCaptures - - 1 - - name - string.regexp.replace.perl - - 2 - - name - punctuation.definition.string.perl - - 3 - - name - keyword.control.regexp-option.perl - - - patterns - - - begin - (s\s*)([^\sa-zA-Z0-9\[({<]) - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - (?=\2) - name - string.regexp.replaceXXX.simple_delimiter.perl - patterns - - - include - #escaped_char - - - - - begin - ' - captures - - 0 - - name - punctuation.definition.string.perl - - - end - ' - name - string.regexp.replaceXXX.format.single_quote.perl - patterns - - - match - \\['\\] - name - constant.character.escape.perl.perl - - - - - begin - ([^\sa-zA-Z0-9\[({<]) - captures - - 0 - - name - punctuation.definition.string.perl - - - end - \1 - name - string.regexp.replaceXXX.format.simple_delimiter.perl - patterns - - - include - #escaped_char - - - include - #variable - - - - - - - begin - \b(?=(?<!\\)s\s*([^\s\w\[({<>])) - comment - string.regexp.replace.extended - end - \2((([egimosradlupc]*x[egimosradlupc]*)))\b - endCaptures - - 1 - - name - string.regexp.replace.perl - - 2 - - name - punctuation.definition.string.perl - - 3 - - name - keyword.control.regexp-option.perl - - - patterns - - - begin - (s)\s*(.) - captures - - 0 - - name - punctuation.definition.string.perl - - 1 - - name - support.function.perl - - - end - (?=\2) - name - string.regexp.replace.extended.simple_delimiter.perl - patterns - - - include - #escaped_char - - - - - begin - ' - captures - - 0 - - name - punctuation.definition.string.perl - - - end - '(?=[egimosradlupc]*x[egimosradlupc]*)\b - name - string.regexp.replace.extended.simple_delimiter.perl - patterns - - - include - #escaped_char - - - - - begin - (.) - captures - - 0 - - name - punctuation.definition.string.perl - - - end - \1(?=[egimosradlupc]*x[egimosradlupc]*)\b - name - string.regexp.replace.extended.simple_delimiter.perl - patterns - - - include - #escaped_char - - - include - #variable - - - - - - - begin - (?<=\(|\{|~|&)\s*((\/)) - beginCaptures - - 1 - - name - string.regexp.find.perl - - 2 - - name - punctuation.definition.string.perl - - - contentName - string.regexp.find.perl - end - ((\1([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)]|$)) - endCaptures - - 1 - - name - string.regexp.find.perl - - 2 - - name - punctuation.definition.string.perl - - 3 - - name - keyword.control.regexp-option.perl - - - patterns - - - comment - This is to prevent thinks like /foo$/ to treat $/ as a variable - match - \$(?=\/) - name - keyword.control.anchor.perl - - - include - #escaped_char - - - include - #variable - - - - - captures - - 1 - - name - constant.other.key.perl - - - match - \b(\w+)\s*(?==>) - - - match - (?<={)\s*\w+\s*(?=}) - name - constant.other.bareword.perl - - - captures - - 1 - - name - keyword.control.perl - - 2 - - name - entity.name.type.class.perl - - - match - ^\s*(package)\s+([^\s;]+) - name - meta.class.perl - - - captures - - 1 - - name - storage.type.sub.perl - - 2 - - name - entity.name.function.perl - - 3 - - name - storage.type.method.perl - - - match - \b(sub)(?:\s+([-a-zA-Z0-9_]+))?\s*(?:\([\$\@\*;]*\))?[^\w\{] - name - meta.function.perl - - - captures - - 1 - - name - entity.name.function.perl - - 2 - - name - punctuation.definition.parameters.perl - - 3 - - name - variable.parameter.function.perl - - - match - ^\s*(BEGIN|UNITCHECK|CHECK|INIT|END|DESTROY)\b - name - meta.function.perl - - - begin - ^(?=(\t| {4})) - end - (?=[^\t\s]) - name - meta.leading-tabs - patterns - - - captures - - 1 - - name - meta.odd-tab - - 2 - - name - meta.even-tab - - - match - (\t| {4})(\t| {4})? - - - - - captures - - 1 - - name - support.function.perl - - 2 - - name - punctuation.definition.string.perl - - 5 - - name - punctuation.definition.string.perl - - 8 - - name - punctuation.definition.string.perl - - - match - \b(tr|y)\s*([^A-Za-z0-9\s])(.*?)(?<!\\)(\\{2})*(\2)(.*?)(?<!\\)(\\{2})*(\2) - name - string.regexp.replace.perl - - - match - \b(__FILE__|__LINE__|__PACKAGE__|__SUB__|__DATA__|__END__)\b - name - constant.language.perl - - - match - (?<!->)\b(continue|die|do|else|elsif|exit|for|foreach|goto|if|last|next|redo|return|select|unless|until|wait|while|switch|case|require|use|eval)\b - name - keyword.control.perl - - - match - \b(my|our|local)\b - name - storage.modifier.perl - - - match - (?<!\w)\-[rwx0RWXOezsfdlpSbctugkTBMAC]\b - name - keyword.operator.filetest.perl - - - match - \b(and|or|xor|as|not)\b - name - keyword.operator.logical.perl - - - match - (<=>|=>|->) - name - keyword.operator.comparison.perl - - - begin - (((<<) *"HTML"))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.doublequote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.html.embedded.perl - end - (^HTML$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - text.html.basic - - - - - begin - (((<<) *"XML"))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.doublequote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.xml.embedded.perl - end - (^XML$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - text.xml - - - - - begin - (((<<) *"CSS"))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.doublequote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.css.embedded.perl - end - (^CSS$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - source.css - - - - - begin - (((<<) *"JAVASCRIPT"))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.doublequote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.js.embedded.perl - end - (^JAVASCRIPT$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - source.js - - - - - begin - (((<<) *"SQL"))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.doublequote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - source.sql.embedded.perl - end - (^SQL$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - source.sql - - - - - begin - (((<<) *"POSTSCRIPT"))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.doublequote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.postscript.embedded.perl - end - (^POSTSCRIPT$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - source.postscript - - - - - begin - (((<<) *"([^"]*)"))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.doublequote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - string.unquoted.heredoc.doublequote.perl - end - (^\4$) - patterns - - - include - #escaped_char - - - include - #variable - - - - - begin - (((<<) *'HTML'))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.html.embedded.perl - end - (^HTML$) - patterns - - - include - text.html.basic - - - - - begin - (((<<) *'XML'))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.xml.embedded.perl - end - (^XML$) - patterns - - - include - text.xml - - - - - begin - (((<<) *'CSS'))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.css.embedded.perl - end - (^CSS$) - patterns - - - include - source.css - - - - - begin - (((<<) *'JAVASCRIPT'))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.js.embedded.perl - end - (^JAVASCRIPT$) - patterns - - - include - source.js - - - - - begin - (((<<) *'SQL'))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - source.sql.embedded.perl - end - (^SQL$) - patterns - - - include - source.sql - - - - - begin - (((<<) *'POSTSCRIPT'))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - source.postscript.embedded.perl - end - (^POSTSCRIPT$) - patterns - - - include - source.postscript - - - - - begin - (((<<) *'([^']*)'))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - string.unquoted.heredoc.quote.perl - end - (^\4$) - - - begin - (((<<) *\\((?![=\d\$\( ])[^;,'"`\s\)]*)))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.quote.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - string.unquoted.heredoc.quote.perl - end - (^\4$) - - - begin - (((<<) *`([^`]*)`))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.backtick.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - string.unquoted.heredoc.backtick.perl - end - (^\4$) - patterns - - - include - #escaped_char - - - include - #variable - - - - - begin - (((<<) *HTML\b))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.html.embedded.perl - end - (^HTML$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - text.html.basic - - - - - begin - (((<<) *XML\b))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - text.xml.embedded.perl - end - (^XML$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - text.xml - - - - - begin - (((<<) *JAVASCRIPT\b))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - source.js.embedded.perl - end - (^JAVASCRIPT$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - source.js - - - - - begin - (((<<) *SQL\b))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - source.sql.embedded.perl - end - (^SQL$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - source.sql - - - - - begin - (((<<) *POSTSCRIPT\b))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 4 - - patterns - - - include - $self - - - - - contentName - source.postscript.embedded.perl - end - (^POSTSCRIPT$) - patterns - - - include - #escaped_char - - - include - #variable - - - include - source.postscript - - - - - begin - (((<<) *((?![=\d\$\( ])[^;,'"`\s\)]*)))(.*)\n? - captures - - 1 - - name - punctuation.definition.string.perl - - 2 - - name - string.unquoted.heredoc.perl - - 3 - - name - punctuation.definition.heredoc.perl - - 5 - - patterns - - - include - $self - - - - - contentName - string.unquoted.heredoc.perl - end - (^\4$) - patterns - - - include - #escaped_char - - - include - #variable - - - - - begin - \bqq\s*([^\(\{\[\<\w\s]) - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \1 - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.qq.perl - patterns - - - include - #escaped_char - - - include - #variable - - - - - begin - \bqx\s*([^'\(\{\[\<\w\s]) - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \1 - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.interpolated.qx.perl - patterns - - - include - #escaped_char - - - include - #variable - - - - - begin - \bqx\s*' - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - ' - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.interpolated.qx.single-quote.perl - patterns - - - include - #escaped_char - - - - - begin - " - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - " - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.double.perl - patterns - - - include - #escaped_char - - - include - #variable - - - - - begin - (?<!->)\bqw?\s*([^\(\{\[\<\w\s]) - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \1 - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.q.perl - - - begin - ' - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - ' - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.single.perl - patterns - - - match - \\['\\] - name - constant.character.escape.perl - - - - - begin - ` - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - ` - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.interpolated.perl - patterns - - - include - #escaped_char - - - include - #variable - - - - - begin - (?<!->)\bqq\s*\( - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \) - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.qq-paren.perl - patterns - - - include - #escaped_char - - - include - #nested_parens_interpolated - - - include - #variable - - - - - begin - \bqq\s*\{ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \} - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.qq-brace.perl - patterns - - - include - #escaped_char - - - include - #nested_braces_interpolated - - - include - #variable - - - - - begin - \bqq\s*\[ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \] - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.qq-bracket.perl - patterns - - - include - #escaped_char - - - include - #nested_brackets_interpolated - - - include - #variable - - - - - begin - \bqq\s*\< - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \> - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.qq-ltgt.perl - patterns - - - include - #escaped_char - - - include - #nested_ltgt_interpolated - - - include - #variable - - - - - begin - (?<!->)\bqx\s*\( - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \) - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.interpolated.qx-paren.perl - patterns - - - include - #escaped_char - - - include - #nested_parens_interpolated - - - include - #variable - - - - - begin - \bqx\s*\{ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \} - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.interpolated.qx-brace.perl - patterns - - - include - #escaped_char - - - include - #nested_braces_interpolated - - - include - #variable - - - - - begin - \bqx\s*\[ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \] - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.interpolated.qx-bracket.perl - patterns - - - include - #escaped_char - - - include - #nested_brackets_interpolated - - - include - #variable - - - - - begin - \bqx\s*\< - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \> - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.interpolated.qx-ltgt.perl - patterns - - - include - #escaped_char - - - include - #nested_ltgt_interpolated - - - include - #variable - - - - - begin - (?<!->)\bqw?\s*\( - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \) - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.q-paren.perl - patterns - - - include - #nested_parens - - - - - begin - \bqw?\s*\{ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \} - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.q-brace.perl - patterns - - - include - #nested_braces - - - - - begin - \bqw?\s*\[ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \] - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.q-bracket.perl - patterns - - - include - #nested_brackets - - - - - begin - \bqw?\s*\< - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - \> - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.quoted.other.q-ltgt.perl - patterns - - - include - #nested_ltgt - - - - - begin - ^__\w+__ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.perl - - - end - $ - endCaptures - - 0 - - name - punctuation.definition.string.end.perl - - - name - string.unquoted.program-block.perl - - - begin - \b(format)\s+(\w+)\s*= - beginCaptures - - 1 - - name - support.function.perl - - 2 - - name - entity.name.function.format.perl - - - end - ^\.\s*$ - name - meta.format.perl - patterns - - - include - #line_comment - - - include - #variable - - - - - captures - - 1 - - name - support.function.perl - - 2 - - name - entity.name.function.perl - - - match - \b(x)\s*(\d+)\b - - - match - \b(ARGV|DATA|ENV|SIG|STDERR|STDIN|STDOUT|atan2|bind|binmode|bless|caller|chdir|chmod|chomp|chop|chown|chr|chroot|close|closedir|cmp|connect|cos|crypt|dbmclose|dbmopen|defined|delete|dump|each|endgrent|endhostent|endnetent|endprotoent|endpwent|endservent|eof|eq|eval|exec|exists|exp|fcntl|fileno|flock|fork|formline|ge|getc|getgrent|getgrgid|getgrnam|gethostbyaddr|gethostbyname|gethostent|getlogin|getnetbyaddr|getnetbyname|getnetent|getpeername|getpgrp|getppid|getpriority|getprotobyname|getprotobynumber|getprotoent|getpwent|getpwnam|getpwuid|getservbyname|getservbyport|getservent|getsockname|getsockopt|glob|gmtime|grep|gt|hex|import|index|int|ioctl|join|keys|kill|lc|lcfirst|le|length|link|listen|local|localtime|log|lstat|lt|m|map|mkdir|msgctl|msgget|msgrcv|msgsnd|ne|no|oct|open|opendir|ord|pack|pipe|pop|pos|print|printf|push|quotemeta|rand|read|readdir|readlink|recv|ref|rename|reset|reverse|rewinddir|rindex|rmdir|s|scalar|seek|seekdir|semctl|semget|semop|send|setgrent|sethostent|setnetent|setpgrp|setpriority|setprotoent|setpwent|setservent|setsockopt|shift|shmctl|shmget|shmread|shmwrite|shutdown|sin|sleep|socket|socketpair|sort|splice|split|sprintf|sqrt|srand|stat|study|substr|symlink|syscall|sysopen|sysread|system|syswrite|tell|telldir|tie|tied|time|times|tr|truncate|uc|ucfirst|umask|undef|unlink|unpack|unshift|untie|utime|values|vec|waitpid|wantarray|warn|write|y)\b - name - support.function.perl - - - captures - - 1 - - name - punctuation.section.scope.begin.perl - - 2 - - name - punctuation.section.scope.end.perl - - - comment - Match empty brackets for ↩ snippet - match - (\{)(\}) - - - captures - - 1 - - name - punctuation.section.scope.begin.perl - - 2 - - name - punctuation.section.scope.end.perl - - - comment - Match empty parenthesis for ↩ snippet - match - (\()(\)) - - - repository - - escaped_char - - patterns - - - match - \\\d+ - name - constant.character.escape.perl - - - match - \\c[^\s\\] - name - constant.character.escape.perl - - - match - \\g(?:\{(?:\w*|-\d+)\}|\d+) - name - constant.character.escape.perl - - - match - \\k(?:\{\w*\}|<\w*>|'\w*') - name - constant.character.escape.perl - - - match - \\N\{[^\}]*\} - name - constant.character.escape.perl - - - match - \\o\{\d*\} - name - constant.character.escape.perl - - - match - \\(?:p|P)(?:\{\w*\}|P) - name - constant.character.escape.perl - - - match - \\x(?:[0-9a-zA-Z]{2}|\{\w*\})? - name - constant.character.escape.perl - - - match - \\. - name - constant.character.escape.perl - - - - line_comment - - patterns - - - begin - (^[ \t]+)?(?=#) - beginCaptures - - 1 - - name - punctuation.whitespace.comment.leading.perl - - - end - (?!\G) - patterns - - - begin - # - beginCaptures - - 0 - - name - punctuation.definition.comment.perl - - - end - \n - name - comment.line.number-sign.perl - - - - - - nested_braces - - begin - \{ - captures - - 1 - - name - punctuation.section.scope.perl - - - end - \} - patterns - - - include - #escaped_char - - - include - #nested_braces - - - - nested_braces_interpolated - - begin - \{ - captures - - 1 - - name - punctuation.section.scope.perl - - - end - \} - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_braces_interpolated - - - - nested_brackets - - begin - \[ - captures - - 1 - - name - punctuation.section.scope.perl - - - end - \] - patterns - - - include - #escaped_char - - - include - #nested_brackets - - - - nested_brackets_interpolated - - begin - \[ - captures - - 1 - - name - punctuation.section.scope.perl - - - end - \] - patterns - - - include - #escaped_char - - - include - #variable - - - include - #nested_brackets_interpolated - - - - nested_ltgt - - begin - < - captures - - 1 - - name - punctuation.section.scope.perl - - - end - > - patterns - - - include - #nested_ltgt - - - - nested_ltgt_interpolated - - begin - < - captures - - 1 - - name - punctuation.section.scope.perl - - - end - > - patterns - - - include - #variable - - - include - #nested_ltgt_interpolated - - - - nested_parens - - begin - \( - captures - - 1 - - name - punctuation.section.scope.perl - - - end - \) - patterns - - - include - #escaped_char - - - include - #nested_parens - - - - nested_parens_interpolated - - begin - \( - captures - - 1 - - name - punctuation.section.scope.perl - - - end - \) - patterns - - - comment - This is to prevent thinks like qr/foo$/ to treat $/ as a variable - match - \$(?=[^\s\w'\{\[\(\<]) - name - keyword.control.anchor.perl - - - include - #escaped_char - - - include - #variable - - - include - #nested_parens_interpolated - - - - variable - - patterns - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)&(?![A-Za-z0-9_]) - name - variable.other.regexp.match.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)`(?![A-Za-z0-9_]) - name - variable.other.regexp.pre-match.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)'(?![A-Za-z0-9_]) - name - variable.other.regexp.post-match.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)\+(?![A-Za-z0-9_]) - name - variable.other.regexp.last-paren-match.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)"(?![A-Za-z0-9_]) - name - variable.other.readwrite.list-separator.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)0(?![A-Za-z0-9_]) - name - variable.other.predefined.program-name.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)[_ab\*\.\/\|,\\;#%=\-~^:?!\$<>\(\)\[\]@](?![A-Za-z0-9_]) - name - variable.other.predefined.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - (\$)[0-9]+(?![A-Za-z0-9_]) - name - variable.other.subpattern.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - ([\$\@\%](#)?)([a-zA-Zx7f-xff\$]|::)([a-zA-Z0-9_x7f-xff\$]|::)*\b - name - variable.other.readwrite.global.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - 2 - - name - punctuation.definition.variable.perl - - - match - (\$\{)(?:[a-zA-Zx7f-xff\$]|::)(?:[a-zA-Z0-9_x7f-xff\$]|::)*(\}) - name - variable.other.readwrite.global.perl - - - captures - - 1 - - name - punctuation.definition.variable.perl - - - match - ([\$\@\%](#)?)[0-9_]\b - name - variable.other.readwrite.global.special.perl - - - - - scopeName - source.perl - uuid - EDBFE125-6B1C-11D9-9189-000D93589AF6 - + + + + + comment + + TODO: Include RegExp syntax + + fileTypes + + pl + pm + pod + t + PL + psgi + + firstLineMatch + ^#!.*\bperl\b + keyEquivalent + ^~P + name + Perl + patterns + + + include + #line_comment + + + begin + ^= + captures + + 0 + + name + punctuation.definition.comment.perl + + + end + ^=cut + name + comment.block.documentation.perl + + + include + #variable + + + applyEndPatternLast + 1 + begin + \b(?=qr\s*[^\s\w]) + comment + string.regexp.compile.perl + end + ((([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)]|$)) + endCaptures + + 1 + + name + string.regexp.compile.perl + + 2 + + name + punctuation.definition.string.perl + + 3 + + name + keyword.control.regexp-option.perl + + + patterns + + + begin + (qr)\s*\{ + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \} + name + string.regexp.compile.nested_braces.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_braces_interpolated + + + + + begin + (qr)\s*\[ + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \] + name + string.regexp.compile.nested_brackets.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_brackets_interpolated + + + + + begin + (qr)\s*< + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + > + name + string.regexp.compile.nested_ltgt.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_ltgt_interpolated + + + + + begin + (qr)\s*\( + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \) + name + string.regexp.compile.nested_parens.perl + patterns + + + comment + This is to prevent thinks like qr/foo$/ to treat $/ as a variable + match + \$(?=[^\s\w\\'\{\[\(\<]) + + + include + #escaped_char + + + include + #variable + + + include + #nested_parens_interpolated + + + + + begin + (qr)\s*' + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + ' + name + string.regexp.compile.single-quote.perl + patterns + + + include + #escaped_char + + + + + begin + (qr)\s*([^\s\w'\{\[\(\<]) + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \2 + name + string.regexp.compile.simple-delimiter.perl + patterns + + + comment + This is to prevent thinks like qr/foo$/ to treat $/ as a variable + match + \$(?=[^\s\w'\{\[\(\<]) + name + keyword.control.anchor.perl + + + include + #escaped_char + + + include + #variable + + + include + #nested_parens_interpolated + + + + + + + applyEndPatternLast + 1 + begin + \b(?=m\s*[^\sa-zA-Z0-9]) + comment + string.regexp.find-m.perl + end + ((([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)]|$)) + endCaptures + + 1 + + name + string.regexp.find-m.perl + + 2 + + name + punctuation.definition.string.perl + + 3 + + name + keyword.control.regexp-option.perl + + + patterns + + + begin + (m)\s*\{ + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \} + name + string.regexp.find-m.nested_braces.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_braces_interpolated + + + + + begin + (m)\s*\[ + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \] + name + string.regexp.find-m.nested_brackets.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_brackets_interpolated + + + + + begin + (m)\s*< + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + > + name + string.regexp.find-m.nested_ltgt.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_ltgt_interpolated + + + + + begin + (m)\s*\( + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \) + name + string.regexp.find-m.nested_parens.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_parens_interpolated + + + + + begin + (m)\s*' + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + ' + name + string.regexp.find-m.single-quote.perl + patterns + + + include + #escaped_char + + + + + begin + (m)\s*([^\sa-zA-Z0-9'\{\[\(\<]) + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \2 + name + string.regexp.find-m.simple-delimiter.perl + patterns + + + comment + This is to prevent thinks like qr/foo$/ to treat $/ as a variable + match + \$(?=[^\sa-zA-Z0-9'\{\[\(\<]) + name + keyword.control.anchor.perl + + + include + #escaped_char + + + include + #variable + + + begin + \[ + beginCaptures + + 1 + + name + punctuation.definition.character-class.begin.perl + + + end + \] + endCaptures + + 1 + + name + punctuation.definition.character-class.end.perl + + + name + constant.other.character-class.set.perl + patterns + + + comment + This is to prevent thinks like qr/foo$/ to treat $/ as a variable + match + \$(?=[^\s\w'\{\[\(\<]) + name + keyword.control.anchor.perl + + + include + #escaped_char + + + + + include + #nested_parens_interpolated + + + + + + + applyEndPatternLast + 1 + begin + \b(?=(?<!\&)(s)(\s+\S|\s*[;\,\#\{\}\(\)\[<]|$)) + comment + string.regexp.replace.perl + end + ((([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)\]>]|$)) + endCaptures + + 1 + + name + string.regexp.replace.perl + + 2 + + name + punctuation.definition.string.perl + + 3 + + name + keyword.control.regexp-option.perl + + + patterns + + + begin + (s)\s*\{ + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \} + name + string.regexp.nested_braces.perl + patterns + + + include + #escaped_char + + + include + #nested_braces + + + + + begin + (s)\s*\[ + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \] + name + string.regexp.nested_brackets.perl + patterns + + + include + #escaped_char + + + include + #nested_brackets + + + + + begin + (s)\s*< + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + > + name + string.regexp.nested_ltgt.perl + patterns + + + include + #escaped_char + + + include + #nested_ltgt + + + + + begin + (s)\s*\( + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + \) + name + string.regexp.nested_parens.perl + patterns + + + include + #escaped_char + + + include + #nested_parens + + + + + begin + \{ + captures + + 0 + + name + punctuation.definition.string.perl + + + end + \} + name + string.regexp.format.nested_braces.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_braces_interpolated + + + + + begin + \[ + captures + + 0 + + name + punctuation.definition.string.perl + + + end + \] + name + string.regexp.format.nested_brackets.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_brackets_interpolated + + + + + begin + < + captures + + 0 + + name + punctuation.definition.string.perl + + + end + > + name + string.regexp.format.nested_ltgt.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_ltgt_interpolated + + + + + begin + \( + captures + + 0 + + name + punctuation.definition.string.perl + + + end + \) + name + string.regexp.format.nested_parens.perl + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_parens_interpolated + + + + + begin + ' + captures + + 0 + + name + punctuation.definition.string.perl + + + end + ' + name + string.regexp.format.single_quote.perl + patterns + + + match + \\['\\] + name + constant.character.escape.perl + + + + + begin + ([^\s\w\[({<;]) + captures + + 0 + + name + punctuation.definition.string.perl + + + end + \1 + name + string.regexp.format.simple_delimiter.perl + patterns + + + include + #escaped_char + + + include + #variable + + + + + match + \s+ + + + + + begin + \b(?=s([^\sa-zA-Z0-9\[({<]).*\1([egimosxradlupc]*)([\}\)\;\,]|\s+)) + comment + string.regexp.replaceXXX + end + ((([egimosxradlupc]*)))(?=([\}\)\;\,]|\s+|$)) + endCaptures + + 1 + + name + string.regexp.replace.perl + + 2 + + name + punctuation.definition.string.perl + + 3 + + name + keyword.control.regexp-option.perl + + + patterns + + + begin + (s\s*)([^\sa-zA-Z0-9\[({<]) + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + (?=\2) + name + string.regexp.replaceXXX.simple_delimiter.perl + patterns + + + include + #escaped_char + + + + + begin + ' + captures + + 0 + + name + punctuation.definition.string.perl + + + end + ' + name + string.regexp.replaceXXX.format.single_quote.perl + patterns + + + match + \\['\\] + name + constant.character.escape.perl.perl + + + + + begin + ([^\sa-zA-Z0-9\[({<]) + captures + + 0 + + name + punctuation.definition.string.perl + + + end + \1 + name + string.regexp.replaceXXX.format.simple_delimiter.perl + patterns + + + include + #escaped_char + + + include + #variable + + + + + + + begin + \b(?=(?<!\\)s\s*([^\s\w\[({<>])) + comment + string.regexp.replace.extended + end + \2((([egimosradlupc]*x[egimosradlupc]*)))\b + endCaptures + + 1 + + name + string.regexp.replace.perl + + 2 + + name + punctuation.definition.string.perl + + 3 + + name + keyword.control.regexp-option.perl + + + patterns + + + begin + (s)\s*(.) + captures + + 0 + + name + punctuation.definition.string.perl + + 1 + + name + support.function.perl + + + end + (?=\2) + name + string.regexp.replace.extended.simple_delimiter.perl + patterns + + + include + #escaped_char + + + + + begin + ' + captures + + 0 + + name + punctuation.definition.string.perl + + + end + '(?=[egimosradlupc]*x[egimosradlupc]*)\b + name + string.regexp.replace.extended.simple_delimiter.perl + patterns + + + include + #escaped_char + + + + + begin + (.) + captures + + 0 + + name + punctuation.definition.string.perl + + + end + \1(?=[egimosradlupc]*x[egimosradlupc]*)\b + name + string.regexp.replace.extended.simple_delimiter.perl + patterns + + + include + #escaped_char + + + include + #variable + + + + + + + begin + (?<=\(|\{|~|&)\s*((\/)) + beginCaptures + + 1 + + name + string.regexp.find.perl + + 2 + + name + punctuation.definition.string.perl + + + contentName + string.regexp.find.perl + end + ((\1([egimosxradlupc]*)))(?=(\s+\S|\s*[;\,\#\{\}\)]|$)) + endCaptures + + 1 + + name + string.regexp.find.perl + + 2 + + name + punctuation.definition.string.perl + + 3 + + name + keyword.control.regexp-option.perl + + + patterns + + + comment + This is to prevent thinks like /foo$/ to treat $/ as a variable + match + \$(?=\/) + name + keyword.control.anchor.perl + + + include + #escaped_char + + + include + #variable + + + + + captures + + 1 + + name + constant.other.key.perl + + + match + \b(\w+)\s*(?==>) + + + match + (?<={)\s*\w+\s*(?=}) + name + constant.other.bareword.perl + + + captures + + 1 + + name + keyword.control.perl + + 2 + + name + entity.name.type.class.perl + + + match + ^\s*(package)\s+([^\s;]+) + name + meta.class.perl + + + captures + + 1 + + name + storage.type.sub.perl + + 2 + + name + entity.name.function.perl + + 3 + + name + storage.type.method.perl + + + match + \b(sub)(?:\s+([-a-zA-Z0-9_]+))?\s*(?:\([\$\@\*;]*\))?[^\w\{] + name + meta.function.perl + + + captures + + 1 + + name + entity.name.function.perl + + 2 + + name + punctuation.definition.parameters.perl + + 3 + + name + variable.parameter.function.perl + + + match + ^\s*(BEGIN|UNITCHECK|CHECK|INIT|END|DESTROY)\b + name + meta.function.perl + + + begin + ^(?=(\t| {4})) + end + (?=[^\t\s]) + name + meta.leading-tabs + patterns + + + captures + + 1 + + name + meta.odd-tab + + 2 + + name + meta.even-tab + + + match + (\t| {4})(\t| {4})? + + + + + captures + + 1 + + name + support.function.perl + + 2 + + name + punctuation.definition.string.perl + + 5 + + name + punctuation.definition.string.perl + + 8 + + name + punctuation.definition.string.perl + + + match + \b(tr|y)\s*([^A-Za-z0-9\s])(.*?)(?<!\\)(\\{2})*(\2)(.*?)(?<!\\)(\\{2})*(\2) + name + string.regexp.replace.perl + + + match + \b(__FILE__|__LINE__|__PACKAGE__|__SUB__|__DATA__|__END__)\b + name + constant.language.perl + + + match + (?<!->)\b(continue|die|do|else|elsif|exit|for|foreach|goto|if|last|next|redo|return|select|unless|until|wait|while|switch|case|require|use|eval)\b + name + keyword.control.perl + + + match + \b(my|our|local)\b + name + storage.modifier.perl + + + match + (?<!\w)\-[rwx0RWXOezsfdlpSbctugkTBMAC]\b + name + keyword.operator.filetest.perl + + + match + \b(and|or|xor|as|not)\b + name + keyword.operator.logical.perl + + + match + (<=>|=>|->) + name + keyword.operator.comparison.perl + + + begin + (((<<) *"HTML"))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.doublequote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.html.embedded.perl + end + (^HTML$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + text.html.basic + + + + + begin + (((<<) *"XML"))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.doublequote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.xml.embedded.perl + end + (^XML$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + text.xml + + + + + begin + (((<<) *"CSS"))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.doublequote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.css.embedded.perl + end + (^CSS$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + source.css + + + + + begin + (((<<) *"JAVASCRIPT"))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.doublequote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.js.embedded.perl + end + (^JAVASCRIPT$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + source.js + + + + + begin + (((<<) *"SQL"))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.doublequote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + source.sql.embedded.perl + end + (^SQL$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + source.sql + + + + + begin + (((<<) *"POSTSCRIPT"))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.doublequote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.postscript.embedded.perl + end + (^POSTSCRIPT$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + source.postscript + + + + + begin + (((<<) *"([^"]*)"))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.doublequote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + string.unquoted.heredoc.doublequote.perl + end + (^\4$) + patterns + + + include + #escaped_char + + + include + #variable + + + + + begin + (((<<) *'HTML'))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.html.embedded.perl + end + (^HTML$) + patterns + + + include + text.html.basic + + + + + begin + (((<<) *'XML'))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.xml.embedded.perl + end + (^XML$) + patterns + + + include + text.xml + + + + + begin + (((<<) *'CSS'))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.css.embedded.perl + end + (^CSS$) + patterns + + + include + source.css + + + + + begin + (((<<) *'JAVASCRIPT'))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.js.embedded.perl + end + (^JAVASCRIPT$) + patterns + + + include + source.js + + + + + begin + (((<<) *'SQL'))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + source.sql.embedded.perl + end + (^SQL$) + patterns + + + include + source.sql + + + + + begin + (((<<) *'POSTSCRIPT'))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + source.postscript.embedded.perl + end + (^POSTSCRIPT$) + patterns + + + include + source.postscript + + + + + begin + (((<<) *'([^']*)'))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + string.unquoted.heredoc.quote.perl + end + (^\4$) + + + begin + (((<<) *\\((?![=\d\$\( ])[^;,'"`\s\)]*)))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.quote.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + string.unquoted.heredoc.quote.perl + end + (^\4$) + + + begin + (((<<) *`([^`]*)`))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.backtick.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + string.unquoted.heredoc.backtick.perl + end + (^\4$) + patterns + + + include + #escaped_char + + + include + #variable + + + + + begin + (((<<) *HTML\b))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.html.embedded.perl + end + (^HTML$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + text.html.basic + + + + + begin + (((<<) *XML\b))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + text.xml.embedded.perl + end + (^XML$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + text.xml + + + + + begin + (((<<) *JAVASCRIPT\b))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + source.js.embedded.perl + end + (^JAVASCRIPT$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + source.js + + + + + begin + (((<<) *SQL\b))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + source.sql.embedded.perl + end + (^SQL$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + source.sql + + + + + begin + (((<<) *POSTSCRIPT\b))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 4 + + patterns + + + include + $self + + + + + contentName + source.postscript.embedded.perl + end + (^POSTSCRIPT$) + patterns + + + include + #escaped_char + + + include + #variable + + + include + source.postscript + + + + + begin + (((<<) *((?![=\d\$\( ])[^;,'"`\s\)]*)))(.*)\n? + captures + + 1 + + name + punctuation.definition.string.perl + + 2 + + name + string.unquoted.heredoc.perl + + 3 + + name + punctuation.definition.heredoc.perl + + 5 + + patterns + + + include + $self + + + + + contentName + string.unquoted.heredoc.perl + end + (^\4$) + patterns + + + include + #escaped_char + + + include + #variable + + + + + begin + \bqq\s*([^\(\{\[\<\w\s]) + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \1 + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.qq.perl + patterns + + + include + #escaped_char + + + include + #variable + + + + + begin + \bqx\s*([^'\(\{\[\<\w\s]) + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \1 + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.interpolated.qx.perl + patterns + + + include + #escaped_char + + + include + #variable + + + + + begin + \bqx\s*' + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + ' + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.interpolated.qx.single-quote.perl + patterns + + + include + #escaped_char + + + + + begin + " + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + " + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.double.perl + patterns + + + include + #escaped_char + + + include + #variable + + + + + begin + (?<!->)\bqw?\s*([^\(\{\[\<\w\s]) + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \1 + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.q.perl + + + begin + ' + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + ' + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.single.perl + patterns + + + match + \\['\\] + name + constant.character.escape.perl + + + + + begin + ` + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + ` + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.interpolated.perl + patterns + + + include + #escaped_char + + + include + #variable + + + + + begin + (?<!->)\bqq\s*\( + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \) + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.qq-paren.perl + patterns + + + include + #escaped_char + + + include + #nested_parens_interpolated + + + include + #variable + + + + + begin + \bqq\s*\{ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \} + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.qq-brace.perl + patterns + + + include + #escaped_char + + + include + #nested_braces_interpolated + + + include + #variable + + + + + begin + \bqq\s*\[ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \] + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.qq-bracket.perl + patterns + + + include + #escaped_char + + + include + #nested_brackets_interpolated + + + include + #variable + + + + + begin + \bqq\s*\< + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \> + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.qq-ltgt.perl + patterns + + + include + #escaped_char + + + include + #nested_ltgt_interpolated + + + include + #variable + + + + + begin + (?<!->)\bqx\s*\( + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \) + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.interpolated.qx-paren.perl + patterns + + + include + #escaped_char + + + include + #nested_parens_interpolated + + + include + #variable + + + + + begin + \bqx\s*\{ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \} + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.interpolated.qx-brace.perl + patterns + + + include + #escaped_char + + + include + #nested_braces_interpolated + + + include + #variable + + + + + begin + \bqx\s*\[ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \] + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.interpolated.qx-bracket.perl + patterns + + + include + #escaped_char + + + include + #nested_brackets_interpolated + + + include + #variable + + + + + begin + \bqx\s*\< + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \> + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.interpolated.qx-ltgt.perl + patterns + + + include + #escaped_char + + + include + #nested_ltgt_interpolated + + + include + #variable + + + + + begin + (?<!->)\bqw?\s*\( + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \) + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.q-paren.perl + patterns + + + include + #nested_parens + + + + + begin + \bqw?\s*\{ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \} + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.q-brace.perl + patterns + + + include + #nested_braces + + + + + begin + \bqw?\s*\[ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \] + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.q-bracket.perl + patterns + + + include + #nested_brackets + + + + + begin + \bqw?\s*\< + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + \> + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.quoted.other.q-ltgt.perl + patterns + + + include + #nested_ltgt + + + + + begin + ^__\w+__ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.perl + + + end + $ + endCaptures + + 0 + + name + punctuation.definition.string.end.perl + + + name + string.unquoted.program-block.perl + + + begin + \b(format)\s+(\w+)\s*= + beginCaptures + + 1 + + name + support.function.perl + + 2 + + name + entity.name.function.format.perl + + + end + ^\.\s*$ + name + meta.format.perl + patterns + + + include + #line_comment + + + include + #variable + + + + + captures + + 1 + + name + support.function.perl + + 2 + + name + entity.name.function.perl + + + match + \b(x)\s*(\d+)\b + + + match + \b(ARGV|DATA|ENV|SIG|STDERR|STDIN|STDOUT|atan2|bind|binmode|bless|caller|chdir|chmod|chomp|chop|chown|chr|chroot|close|closedir|cmp|connect|cos|crypt|dbmclose|dbmopen|defined|delete|dump|each|endgrent|endhostent|endnetent|endprotoent|endpwent|endservent|eof|eq|eval|exec|exists|exp|fcntl|fileno|flock|fork|formline|ge|getc|getgrent|getgrgid|getgrnam|gethostbyaddr|gethostbyname|gethostent|getlogin|getnetbyaddr|getnetbyname|getnetent|getpeername|getpgrp|getppid|getpriority|getprotobyname|getprotobynumber|getprotoent|getpwent|getpwnam|getpwuid|getservbyname|getservbyport|getservent|getsockname|getsockopt|glob|gmtime|grep|gt|hex|import|index|int|ioctl|join|keys|kill|lc|lcfirst|le|length|link|listen|local|localtime|log|lstat|lt|m|map|mkdir|msgctl|msgget|msgrcv|msgsnd|ne|no|oct|open|opendir|ord|pack|pipe|pop|pos|print|printf|push|quotemeta|rand|read|readdir|readlink|recv|ref|rename|reset|reverse|rewinddir|rindex|rmdir|s|scalar|seek|seekdir|semctl|semget|semop|send|setgrent|sethostent|setnetent|setpgrp|setpriority|setprotoent|setpwent|setservent|setsockopt|shift|shmctl|shmget|shmread|shmwrite|shutdown|sin|sleep|socket|socketpair|sort|splice|split|sprintf|sqrt|srand|stat|study|substr|symlink|syscall|sysopen|sysread|system|syswrite|tell|telldir|tie|tied|time|times|tr|truncate|uc|ucfirst|umask|undef|unlink|unpack|unshift|untie|utime|values|vec|waitpid|wantarray|warn|write|y)\b + name + support.function.perl + + + captures + + 1 + + name + punctuation.section.scope.begin.perl + + 2 + + name + punctuation.section.scope.end.perl + + + comment + Match empty brackets for ↩ snippet + match + (\{)(\}) + + + captures + + 1 + + name + punctuation.section.scope.begin.perl + + 2 + + name + punctuation.section.scope.end.perl + + + comment + Match empty parenthesis for ↩ snippet + match + (\()(\)) + + + repository + + escaped_char + + patterns + + + match + \\\d+ + name + constant.character.escape.perl + + + match + \\c[^\s\\] + name + constant.character.escape.perl + + + match + \\g(?:\{(?:\w*|-\d+)\}|\d+) + name + constant.character.escape.perl + + + match + \\k(?:\{\w*\}|<\w*>|'\w*') + name + constant.character.escape.perl + + + match + \\N\{[^\}]*\} + name + constant.character.escape.perl + + + match + \\o\{\d*\} + name + constant.character.escape.perl + + + match + \\(?:p|P)(?:\{\w*\}|P) + name + constant.character.escape.perl + + + match + \\x(?:[0-9a-zA-Z]{2}|\{\w*\})? + name + constant.character.escape.perl + + + match + \\. + name + constant.character.escape.perl + + + + line_comment + + patterns + + + begin + (^[ \t]+)?(?=#) + beginCaptures + + 1 + + name + punctuation.whitespace.comment.leading.perl + + + end + (?!\G) + patterns + + + begin + # + beginCaptures + + 0 + + name + punctuation.definition.comment.perl + + + end + \n + name + comment.line.number-sign.perl + + + + + + nested_braces + + begin + \{ + captures + + 1 + + name + punctuation.section.scope.perl + + + end + \} + patterns + + + include + #escaped_char + + + include + #nested_braces + + + + nested_braces_interpolated + + begin + \{ + captures + + 1 + + name + punctuation.section.scope.perl + + + end + \} + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_braces_interpolated + + + + nested_brackets + + begin + \[ + captures + + 1 + + name + punctuation.section.scope.perl + + + end + \] + patterns + + + include + #escaped_char + + + include + #nested_brackets + + + + nested_brackets_interpolated + + begin + \[ + captures + + 1 + + name + punctuation.section.scope.perl + + + end + \] + patterns + + + include + #escaped_char + + + include + #variable + + + include + #nested_brackets_interpolated + + + + nested_ltgt + + begin + < + captures + + 1 + + name + punctuation.section.scope.perl + + + end + > + patterns + + + include + #nested_ltgt + + + + nested_ltgt_interpolated + + begin + < + captures + + 1 + + name + punctuation.section.scope.perl + + + end + > + patterns + + + include + #variable + + + include + #nested_ltgt_interpolated + + + + nested_parens + + begin + \( + captures + + 1 + + name + punctuation.section.scope.perl + + + end + \) + patterns + + + include + #escaped_char + + + include + #nested_parens + + + + nested_parens_interpolated + + begin + \( + captures + + 1 + + name + punctuation.section.scope.perl + + + end + \) + patterns + + + comment + This is to prevent thinks like qr/foo$/ to treat $/ as a variable + match + \$(?=[^\s\w'\{\[\(\<]) + name + keyword.control.anchor.perl + + + include + #escaped_char + + + include + #variable + + + include + #nested_parens_interpolated + + + + variable + + patterns + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)&(?![A-Za-z0-9_]) + name + variable.other.regexp.match.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)`(?![A-Za-z0-9_]) + name + variable.other.regexp.pre-match.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)'(?![A-Za-z0-9_]) + name + variable.other.regexp.post-match.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)\+(?![A-Za-z0-9_]) + name + variable.other.regexp.last-paren-match.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)"(?![A-Za-z0-9_]) + name + variable.other.readwrite.list-separator.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)0(?![A-Za-z0-9_]) + name + variable.other.predefined.program-name.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)[_ab\*\.\/\|,\\;#%=\-~^:?!\$<>\(\)\[\]@](?![A-Za-z0-9_]) + name + variable.other.predefined.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + (\$)[0-9]+(?![A-Za-z0-9_]) + name + variable.other.subpattern.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + ([\$\@\%](#)?)([a-zA-Zx7f-xff\$]|::)([a-zA-Z0-9_x7f-xff\$]|::)*\b + name + variable.other.readwrite.global.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + 2 + + name + punctuation.definition.variable.perl + + + match + (\$\{)(?:[a-zA-Zx7f-xff\$]|::)(?:[a-zA-Z0-9_x7f-xff\$]|::)*(\}) + name + variable.other.readwrite.global.perl + + + captures + + 1 + + name + punctuation.definition.variable.perl + + + match + ([\$\@\%](#)?)[0-9_]\b + name + variable.other.readwrite.global.special.perl + + + + + scopeName + source.perl + uuid + EDBFE125-6B1C-11D9-9189-000D93589AF6 + \ No newline at end of file diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Pug.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Pug.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Pug.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Pug.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Ruby.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Ruby.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/Ruby.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/Ruby.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/YAML.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/YAML.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/YAML.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/YAML.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/aspvbnet.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/aspvbnet.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/aspvbnet.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/aspvbnet.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/groovy.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/groovy.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/groovy.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/groovy.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/html.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/html.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/html.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/html.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/html2.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/html2.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/html2.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/html2.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/infinite-loop.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/infinite-loop.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/infinite-loop.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/infinite-loop.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/javascript.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/javascript.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/javascript.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/javascript.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/markdown.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/markdown.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/markdown.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/markdown.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/php.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/php.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/php.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/php.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/testlang12.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/testlang12.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/testlang12.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/testlang12.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/whileLang.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/whileLang.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/fixtures/whileLang.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/fixtures/whileLang.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/tests.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/tests.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/tests.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/tests.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/whileTests.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/whileTests.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/suite1/whileTests.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/suite1/whileTests.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/.gitignore b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/.gitignore similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/.gitignore rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/.gitignore diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Abyss.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Abyss.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Abyss.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Abyss.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Kimbie_dark.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Kimbie_dark.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Kimbie_dark.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Kimbie_dark.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Monokai.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Monokai.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Monokai.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Monokai.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/QuietLight.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/QuietLight.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/QuietLight.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/QuietLight.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Solarized-dark.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Solarized-dark.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Solarized-dark.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Solarized-dark.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Solarized-light.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Solarized-light.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Solarized-light.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Solarized-light.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Tomorrow-Night-Blue.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Tomorrow-Night-Blue.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/Tomorrow-Night-Blue.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/Tomorrow-Night-Blue.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/dark_plus.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dark_plus.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/dark_plus.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dark_plus.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/dark_vs.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dark_vs.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/dark_vs.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dark_vs.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/diff.css b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/diff.css similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/diff.css rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/diff.css diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/diff.js b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/diff.js similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/diff.js rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/diff.js diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/diff.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/diff.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/diff.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/diff.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/dimmed-monokai.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dimmed-monokai.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/dimmed-monokai.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dimmed-monokai.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-fixtures/test-13777.go b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-fixtures/test-13777.go similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-fixtures/test-13777.go rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-fixtures/test-13777.go diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-fixtures/test.go b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-fixtures/test.go similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-fixtures/test.go rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-fixtures/test.go diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-results/test-13777_go.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-results/test-13777_go.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-results/test-13777_go.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-results/test-13777_go.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-results/test_go.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-results/test_go.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/colorize-results/test_go.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/colorize-results/test_go.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/go.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/go.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/go/go.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/go/go.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/grammars.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/grammars.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/grammars.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/grammars.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/hc_black.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/hc_black.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/hc_black.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/hc_black.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/languages.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/languages.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/languages.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/languages.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/light_plus.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/light_plus.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/light_plus.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/light_plus.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/light_vs.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/light_vs.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/light_vs.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/light_vs.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/red.tmTheme b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/red.tmTheme similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/red.tmTheme rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/red.tmTheme diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/ASPVBnet.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/ASPVBnet.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/ASPVBnet.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/ASPVBnet.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Batch File.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Batch File.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Batch File.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Batch File.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Clojure.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Clojure.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Clojure.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Clojure.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Dockerfile.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Dockerfile.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Dockerfile.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Dockerfile.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Groovy.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Groovy.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Groovy.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Groovy.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Handlebars.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Handlebars.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Handlebars.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Handlebars.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/JSON.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/JSON.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/JSON.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/JSON.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Jade.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Jade.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Jade.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Jade.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/JavaScript.tmLanguage.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/JavaScript.tmLanguage.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/JavaScript.tmLanguage.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/JavaScript.tmLanguage.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/MagicPython.tmLanguage.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/MagicPython.tmLanguage.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/MagicPython.tmLanguage.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/MagicPython.tmLanguage.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/MagicRegExp.tmLanguage.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/MagicRegExp.tmLanguage.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/MagicRegExp.tmLanguage.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/MagicRegExp.tmLanguage.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Makefile.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Makefile.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Makefile.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Makefile.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Objective-C.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Objective-C.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Objective-C.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Objective-C.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Perl 6.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Perl 6.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Perl 6.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Perl 6.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Perl.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Perl.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Perl.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Perl.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Platform.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Platform.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Platform.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Platform.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/PowershellSyntax.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/PowershellSyntax.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/PowershellSyntax.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/PowershellSyntax.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/R.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/R.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/R.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/R.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Regular Expressions (JavaScript).tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Regular Expressions (JavaScript).tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Regular Expressions (JavaScript).tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Regular Expressions (JavaScript).tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Ruby.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Ruby.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Ruby.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Ruby.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/SQL.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/SQL.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/SQL.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/SQL.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Shell-Unix-Bash.tmLanguage.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Shell-Unix-Bash.tmLanguage.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/Shell-Unix-Bash.tmLanguage.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/Shell-Unix-Bash.tmLanguage.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/TypeScript.tmLanguage.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/TypeScript.tmLanguage.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/TypeScript.tmLanguage.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/TypeScript.tmLanguage.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/TypeScriptReact.tmLanguage.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/TypeScriptReact.tmLanguage.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/TypeScriptReact.tmLanguage.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/TypeScriptReact.tmLanguage.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/c++.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/c++.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/c++.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/c++.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/c.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/c.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/c.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/c.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/coffeescript.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/coffeescript.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/coffeescript.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/coffeescript.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/cshtml.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/cshtml.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/cshtml.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/cshtml.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/css.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/css.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/css.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/css.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/diff.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/diff.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/diff.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/diff.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/fsharp.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/fsharp.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/fsharp.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/fsharp.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/git-commit.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/git-commit.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/git-commit.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/git-commit.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/git-rebase.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/git-rebase.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/git-rebase.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/git-rebase.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/go.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/go.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/go.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/go.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/html.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/html.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/html.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/html.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/java.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/java.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/java.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/java.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/less.tmLanguage.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/less.tmLanguage.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/less.tmLanguage.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/less.tmLanguage.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/lua.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/lua.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/lua.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/lua.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/markdown.tmLanguage b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/markdown.tmLanguage similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/markdown.tmLanguage rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/markdown.tmLanguage diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/php.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/php.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/php.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/php.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/properties.plist b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/properties.plist similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/properties.plist rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/properties.plist diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/rust.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/rust.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/rust.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/rust.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/scss.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/scss.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/scss.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/scss.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/shaderlab.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/shaderlab.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/shaderlab.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/shaderlab.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/swift.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/swift.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/swift.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/swift.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/xml.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/xml.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/xml.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/xml.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/xsl.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/xsl.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/xsl.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/xsl.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/yaml.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/yaml.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/syntaxes/yaml.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/syntaxes/yaml.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/12750.html b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/12750.html similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/12750.html rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/12750.html diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/12750.html.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/12750.html.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/12750.html.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/12750.html.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/12750.html.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/12750.html.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/12750.html.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/12750.html.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/13448.html b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/13448.html similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/13448.html rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/13448.html diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/13448.html.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/13448.html.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/13448.html.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/13448.html.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/13448.html.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/13448.html.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/13448.html.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/13448.html.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/14119.less b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/14119.less similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/14119.less rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/14119.less diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/14119.less.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/14119.less.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/14119.less.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/14119.less.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/14119.less.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/14119.less.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/14119.less.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/14119.less.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/COMMIT_EDITMSG b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/COMMIT_EDITMSG similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/COMMIT_EDITMSG rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/COMMIT_EDITMSG diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/COMMIT_EDITMSG.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/COMMIT_EDITMSG.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/COMMIT_EDITMSG.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/COMMIT_EDITMSG.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/Dockerfile b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/Dockerfile similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/Dockerfile rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/Dockerfile diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/Dockerfile.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/Dockerfile.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/Dockerfile.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/Dockerfile.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/basic.java b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/basic.java similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/basic.java rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/basic.java diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/basic.java.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/basic.java.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/basic.java.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/basic.java.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/basic.java.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/basic.java.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/basic.java.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/basic.java.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/git-rebase-todo b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/git-rebase-todo similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/git-rebase-todo rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/git-rebase-todo diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/git-rebase-todo.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/git-rebase-todo.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/git-rebase-todo.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/git-rebase-todo.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-1550.yaml b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-1550.yaml similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-1550.yaml rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-1550.yaml diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-1550.yaml.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-1550.yaml.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-1550.yaml.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-1550.yaml.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-1550.yaml.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-1550.yaml.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-1550.yaml.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-1550.yaml.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-4008.yaml b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-4008.yaml similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-4008.yaml rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-4008.yaml diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-4008.yaml.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-4008.yaml.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-4008.yaml.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-4008.yaml.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-4008.yaml.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-4008.yaml.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-4008.yaml.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-4008.yaml.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-6303.yaml b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-6303.yaml similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-6303.yaml rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-6303.yaml diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-6303.yaml.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-6303.yaml.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-6303.yaml.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-6303.yaml.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-6303.yaml.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-6303.yaml.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/issue-6303.yaml.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/issue-6303.yaml.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/makefile b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/makefile similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/makefile rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/makefile diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/makefile.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/makefile.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/makefile.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/makefile.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/makefile.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/makefile.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/makefile.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/makefile.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-13777.go b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-13777.go similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-13777.go rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-13777.go diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-13777.go.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-13777.go.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-13777.go.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-13777.go.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-4287.jade b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-4287.jade similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-4287.jade rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-4287.jade diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-4287.jade.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-4287.jade.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-4287.jade.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-4287.jade.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-6611.rs b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-6611.rs similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-6611.rs rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-6611.rs diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-6611.rs.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-6611.rs.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-6611.rs.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-6611.rs.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-6611.rs.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-6611.rs.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-6611.rs.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-6611.rs.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-7115.xml b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-7115.xml similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-7115.xml rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-7115.xml diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-7115.xml.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-7115.xml.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-7115.xml.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-7115.xml.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-7115.xml.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-7115.xml.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-7115.xml.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-7115.xml.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-brackets.tsx b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-brackets.tsx similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-brackets.tsx rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-brackets.tsx diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-brackets.tsx.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-brackets.tsx.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-brackets.tsx.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-brackets.tsx.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-brackets.tsx.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-brackets.tsx.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-brackets.tsx.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-brackets.tsx.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.less b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.less similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.less rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.less diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.less.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.less.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.less.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.less.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.less.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.less.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.less.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.less.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.scss b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.scss similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.scss rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.scss diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.scss.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.scss.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.scss.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.scss.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.scss.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.scss.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-cssvariables.scss.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-cssvariables.scss.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-function-inv.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-function-inv.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-function-inv.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-function-inv.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-function-inv.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-function-inv.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-function-inv.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-function-inv.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-function-inv.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-function-inv.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-function-inv.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-function-inv.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue11.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue11.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue11.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue11.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue11.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue11.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue11.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue11.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue11.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue11.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue11.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue11.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5431.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5431.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5431.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5431.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5431.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5431.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5431.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5431.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5431.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5431.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5431.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5431.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5465.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5465.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5465.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5465.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5465.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5465.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5465.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5465.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5566.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5566.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5566.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5566.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5566.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5566.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5566.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5566.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5566.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5566.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-issue5566.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-issue5566.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-keywords.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-keywords.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-keywords.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-keywords.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-keywords.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-keywords.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-keywords.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-keywords.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-keywords.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-keywords.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-keywords.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-keywords.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-members.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-members.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-members.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-members.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-members.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-members.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-members.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-members.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-members.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-members.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-members.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-members.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-object-literals.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-object-literals.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-object-literals.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-object-literals.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-object-literals.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-object-literals.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-object-literals.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-object-literals.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-object-literals.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-object-literals.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-object-literals.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-object-literals.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-regex.coffee b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-regex.coffee similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-regex.coffee rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-regex.coffee diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-regex.coffee.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-regex.coffee.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-regex.coffee.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-regex.coffee.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-regex.coffee.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-regex.coffee.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-regex.coffee.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-regex.coffee.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-strings.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-strings.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-strings.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-strings.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-strings.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-strings.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-strings.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-strings.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-strings.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-strings.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-strings.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-strings.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-this.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-this.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-this.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-this.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-this.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-this.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-this.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-this.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-variables.css b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-variables.css similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-variables.css rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-variables.css diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-variables.css.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-variables.css.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-variables.css.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-variables.css.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-variables.css.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-variables.css.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test-variables.css.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test-variables.css.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.bat b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.bat similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.bat rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.bat diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.bat.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.bat.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.bat.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.bat.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.c b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.c similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.c rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.c diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.c.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.c.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.c.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.c.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.c.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.c.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.c.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.c.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cc b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cc similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cc rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cc diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cc.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cc.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cc.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cc.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cc.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cc.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cc.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cc.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.clj b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.clj similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.clj rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.clj diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.clj.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.clj.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.clj.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.clj.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.clj.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.clj.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.clj.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.clj.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.coffee b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.coffee similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.coffee rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.coffee diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.coffee.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.coffee.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.coffee.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.coffee.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.coffee.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.coffee.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.coffee.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.coffee.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cpp b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cpp similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cpp rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cpp diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cpp.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cpp.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cpp.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cpp.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cpp.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cpp.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cpp.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cpp.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cshtml b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cshtml similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cshtml rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cshtml diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cshtml.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cshtml.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cshtml.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cshtml.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cshtml.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cshtml.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.cshtml.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.cshtml.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.css b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.css similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.css rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.css diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.css.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.css.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.css.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.css.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.css.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.css.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.css.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.css.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.diff b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.diff similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.diff rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.diff diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.diff.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.diff.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.diff.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.diff.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.diff.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.diff.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.diff.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.diff.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.fs b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.fs similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.fs rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.fs diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.fs.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.fs.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.fs.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.fs.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.fs.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.fs.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.fs.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.fs.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.go b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.go similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.go rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.go diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.go.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.go.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.go.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.go.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.go.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.go.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.go.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.go.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.groovy b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.groovy similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.groovy rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.groovy diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.groovy.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.groovy.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.groovy.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.groovy.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.groovy.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.groovy.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.groovy.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.groovy.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.handlebars b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.handlebars similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.handlebars rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.handlebars diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.handlebars.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.handlebars.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.handlebars.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.handlebars.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.handlebars.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.handlebars.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.handlebars.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.handlebars.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.hbs b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.hbs similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.hbs rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.hbs diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.hbs.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.hbs.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.hbs.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.hbs.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.hbs.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.hbs.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.hbs.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.hbs.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.html b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.html similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.html rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.html diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.html.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.html.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.html.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.html.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.html.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.html.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.html.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.html.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ini b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ini similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ini rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ini diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ini.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ini.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ini.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ini.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jade b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jade similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jade rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jade diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jade.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jade.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jade.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jade.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jade.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jade.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jade.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jade.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.js b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.js similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.js rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.js diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.js.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.js.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.js.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.js.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.js.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.js.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.js.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.js.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.json.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.json.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.json.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.json.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.json.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.json.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.json.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.json.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jsx b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jsx similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jsx rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jsx diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jsx.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jsx.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jsx.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jsx.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jsx.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jsx.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.jsx.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.jsx.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.less b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.less similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.less rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.less diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.less.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.less.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.less.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.less.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.less.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.less.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.less.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.less.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.lua b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.lua similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.lua rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.lua diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.lua.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.lua.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.lua.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.lua.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.m b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.m similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.m rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.m diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.m.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.m.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.m.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.m.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.m.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.m.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.m.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.m.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.md b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.md similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.md rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.md diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.md.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.md.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.md.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.md.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.md.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.md.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.md.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.md.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.php b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.php similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.php rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.php diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.php.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.php.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.php.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.php.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.php.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.php.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.php.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.php.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.pl b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.pl similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.pl rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.pl diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.pl.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.pl.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.pl.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.pl.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.pl.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.pl.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.pl.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.pl.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ps1 b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ps1 similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ps1 rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ps1 diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ps1.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ps1.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ps1.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ps1.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ps1.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ps1.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ps1.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ps1.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.py b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.py similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.py rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.py diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.py.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.py.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.py.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.py.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.py.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.py.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.py.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.py.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.r b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.r similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.r rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.r diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.r.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.r.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.r.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.r.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rb b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rb similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rb rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rb diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rb.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rb.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rb.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rb.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rb.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rb.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rb.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rb.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rs b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rs similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rs rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rs diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rs.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rs.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.rs.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.rs.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.scss b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.scss similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.scss rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.scss diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.scss.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.scss.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.scss.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.scss.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.scss.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.scss.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.scss.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.scss.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sh b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sh similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sh rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sh diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sh.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sh.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sh.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sh.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sh.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sh.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sh.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sh.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.shader b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.shader similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.shader rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.shader diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.shader.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.shader.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.shader.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.shader.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.shader.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.shader.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.shader.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.shader.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sql b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sql similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sql rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sql diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sql.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sql.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.sql.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.sql.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.swift b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.swift similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.swift rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.swift diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.swift.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.swift.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.swift.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.swift.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.swift.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.swift.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.swift.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.swift.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ts b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ts similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ts rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ts diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ts.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ts.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ts.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ts.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ts.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ts.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.ts.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.ts.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.vb b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.vb similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.vb rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.vb diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.vb.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.vb.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.vb.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.vb.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.vb.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.vb.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.vb.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.vb.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.xml b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.xml similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.xml rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.xml diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.xml.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.xml.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.xml.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.xml.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.xml.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.xml.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.xml.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.xml.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.yaml b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.yaml similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.yaml rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.yaml diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.yaml.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.yaml.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.yaml.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.yaml.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.yaml.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.yaml.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test.yaml.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test.yaml.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test2.pl b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test2.pl similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test2.pl rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test2.pl diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test2.pl.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test2.pl.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test2.pl.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test2.pl.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test2.pl.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test2.pl.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test2.pl.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test2.pl.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test6916.js b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test6916.js similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test6916.js rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test6916.js diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test6916.js.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test6916.js.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/test6916.js.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/test6916.js.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/tsconfig.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/tsconfig.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/tsconfig.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/tsconfig.json diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/tsconfig.json.result b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/tsconfig.json.result similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/tsconfig.json.result rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/tsconfig.json.result diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/tsconfig.json.result.patch b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/tsconfig.json.result.patch similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tests/tsconfig.json.result.patch rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tests/tsconfig.json.result.patch diff --git a/org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tsconfig.json b/org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tsconfig.json similarity index 100% rename from org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/tsconfig.json rename to org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/tsconfig.json diff --git a/org.eclipse.tm4e.core/.classpath b/org.eclipse.tm4e.core/.classpath index 48fdbaaa9..3aa82bf3a 100644 --- a/org.eclipse.tm4e.core/.classpath +++ b/org.eclipse.tm4e.core/.classpath @@ -1,36 +1,40 @@ - + - - + + - + + - + + + + + - + - + + - + - + - - diff --git a/org.eclipse.tm4e.languageconfiguration.tests/.classpath b/org.eclipse.tm4e.languageconfiguration.tests/.classpath index a42a828e0..4222ea313 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/.classpath +++ b/org.eclipse.tm4e.languageconfiguration.tests/.classpath @@ -1,11 +1,34 @@ - + + + + + - + + + + + + + + + + + + + + + + + + + + - + diff --git a/org.eclipse.tm4e.languageconfiguration.tests/build.properties b/org.eclipse.tm4e.languageconfiguration.tests/build.properties index 2a3d80c33..8316739f4 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/build.properties +++ b/org.eclipse.tm4e.languageconfiguration.tests/build.properties @@ -1,5 +1,5 @@ -source.. = src/ -output.. = bin/ +source.. = src/main/java/,\ + src/main/resources/ bin.includes = META-INF/,\ .,\ plugin.xml,\ diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java similarity index 100% rename from org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java rename to org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java similarity index 100% rename from org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java rename to org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java similarity index 100% rename from org.eclipse.tm4e.languageconfiguration.tests/src/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java rename to org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java diff --git a/org.eclipse.tm4e.core.tests/src/main/resources/.gitkeep b/org.eclipse.tm4e.languageconfiguration.tests/src/main/resources/.gitkeep similarity index 100% rename from org.eclipse.tm4e.core.tests/src/main/resources/.gitkeep rename to org.eclipse.tm4e.languageconfiguration.tests/src/main/resources/.gitkeep diff --git a/org.eclipse.tm4e.languageconfiguration/.classpath b/org.eclipse.tm4e.languageconfiguration/.classpath index 824bce586..3aa82bf3a 100644 --- a/org.eclipse.tm4e.languageconfiguration/.classpath +++ b/org.eclipse.tm4e.languageconfiguration/.classpath @@ -2,13 +2,39 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.tm4e.languageconfiguration/build.properties b/org.eclipse.tm4e.languageconfiguration/build.properties index b0eb292de..c63a44828 100644 --- a/org.eclipse.tm4e.languageconfiguration/build.properties +++ b/org.eclipse.tm4e.languageconfiguration/build.properties @@ -13,4 +13,3 @@ bin.includes = META-INF/,\ additional.bundles = org.eclipse.jdt.annotation # JDT Null Analysis types for Tycho jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation - \ No newline at end of file diff --git a/org.eclipse.tm4e.ui.tests/src/main/resources/.gitkeep b/org.eclipse.tm4e.languageconfiguration/src/main/resources/.gitkeep similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/main/resources/.gitkeep rename to org.eclipse.tm4e.languageconfiguration/src/main/resources/.gitkeep diff --git a/org.eclipse.tm4e.markdown/.classpath b/org.eclipse.tm4e.markdown/.classpath index 0bf6f096c..71f21812a 100644 --- a/org.eclipse.tm4e.markdown/.classpath +++ b/org.eclipse.tm4e.markdown/.classpath @@ -6,7 +6,22 @@ - - + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.tm4e.markdown/.gitignore b/org.eclipse.tm4e.markdown/.gitignore deleted file mode 100644 index 934e0e06f..000000000 --- a/org.eclipse.tm4e.markdown/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/bin -/target diff --git a/org.eclipse.tm4e.registry/.classpath b/org.eclipse.tm4e.registry/.classpath index b931e34ba..71f21812a 100644 --- a/org.eclipse.tm4e.registry/.classpath +++ b/org.eclipse.tm4e.registry/.classpath @@ -1,7 +1,27 @@ - + + + + + - - + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.tm4e.registry/build.properties b/org.eclipse.tm4e.registry/build.properties index 546508f99..d51a4353e 100644 --- a/org.eclipse.tm4e.registry/build.properties +++ b/org.eclipse.tm4e.registry/build.properties @@ -1,5 +1,5 @@ -source.. = src/main/java -output.. = bin/ +source.. = src/main/java/,\ + src/main/resources/ bin.includes = META-INF/,\ schema/,\ plugin.xml,\ @@ -13,4 +13,3 @@ bin.includes = META-INF/,\ additional.bundles = org.eclipse.jdt.annotation # JDT Null Analysis types for Tycho jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation - \ No newline at end of file diff --git a/org.eclipse.tm4e.ui.tests/src/test/resources/.gitkeep b/org.eclipse.tm4e.registry/src/main/resources/.gitkeep similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/resources/.gitkeep rename to org.eclipse.tm4e.registry/src/main/resources/.gitkeep diff --git a/org.eclipse.tm4e.ui.tests/.classpath b/org.eclipse.tm4e.ui.tests/.classpath index 880118339..71f21812a 100644 --- a/org.eclipse.tm4e.ui.tests/.classpath +++ b/org.eclipse.tm4e.ui.tests/.classpath @@ -6,19 +6,21 @@ - + - + - + + - + + - + - + diff --git a/org.eclipse.tm4e.ui.tests/build.properties b/org.eclipse.tm4e.ui.tests/build.properties index 44774ac89..3fd0f106d 100644 --- a/org.eclipse.tm4e.ui.tests/build.properties +++ b/org.eclipse.tm4e.ui.tests/build.properties @@ -1,10 +1,8 @@ -source.. = src/main/resources/,\ - src/test/java/,\ - src/test/resources/ +source.. = src/main/java/,\ + src/main/resources/ bin.includes = META-INF/,\ .,\ plugin.properties,\ grammars/,\ plugin.xml,\ about.html - diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/RegistryTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/RegistryTest.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/RegistryTest.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/RegistryTest.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/TMinGenericEditorTest.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentTMModelTest.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/Command.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/Command.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/Command.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/DocumentReplaceCommand.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/DocumentSetCommand.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/StyleRangesCollector.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/internal/text/TextViewerInvalidateTextPresentationCommand.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/ICommand.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/text/ICommand.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/ICommand.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/text/ICommand.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/text/TMEditor.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/TMEditor.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/text/TMEditor.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/text/typescript/TMPresentationReconcilerTypeScriptTest.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/themes/MockThemeManager.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/themes/TMEditorColorTest.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java rename to org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/themes/ThemeManagerTest.java diff --git a/org.eclipse.tm4e.ui.tests/src/test/resources/org/eclipse/textmate4e/ui/text/Solarized-light.css b/org.eclipse.tm4e.ui.tests/src/main/resources/org/eclipse/textmate4e/ui/text/Solarized-light.css similarity index 100% rename from org.eclipse.tm4e.ui.tests/src/test/resources/org/eclipse/textmate4e/ui/text/Solarized-light.css rename to org.eclipse.tm4e.ui.tests/src/main/resources/org/eclipse/textmate4e/ui/text/Solarized-light.css diff --git a/org.eclipse.tm4e.ui/.classpath b/org.eclipse.tm4e.ui/.classpath index 097e3264d..3aa82bf3a 100644 --- a/org.eclipse.tm4e.ui/.classpath +++ b/org.eclipse.tm4e.ui/.classpath @@ -1,15 +1,40 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 5535f313bdb9580ddd8bf30e767b61d8b7e474db Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 5 May 2022 18:45:47 +0200 Subject: [PATCH 176/202] add final modifier where applicable --- .../eclipse/tm4e/markdown/TMHTMLRenderer.java | 28 ++++++------ .../tm4e/markdown/TMMarkdownPlugin.java | 4 +- .../tm4e/markdown/marked/BlockRules.java | 44 +++++++++---------- .../tm4e/markdown/marked/HTMLRenderer.java | 30 ++++++------- .../eclipse/tm4e/markdown/marked/Helpers.java | 6 +-- .../tm4e/markdown/marked/InlineLexer.java | 4 +- .../tm4e/markdown/marked/InlineRules.java | 38 ++++++++-------- .../eclipse/tm4e/markdown/marked/Lexer.java | 24 +++++----- .../eclipse/tm4e/markdown/marked/Marked.java | 8 ++-- .../eclipse/tm4e/markdown/marked/Options.java | 8 ++-- .../eclipse/tm4e/markdown/marked/Parser.java | 8 ++-- .../eclipse/tm4e/markdown/marked/RegExp.java | 14 +++--- .../eclipse/tm4e/markdown/marked/Token.java | 10 ++--- 13 files changed, 113 insertions(+), 113 deletions(-) diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java index 86c96a18e..b6141b8b3 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java @@ -29,25 +29,25 @@ public class TMHTMLRenderer extends HTMLRenderer { private final String defaultLang; - public TMHTMLRenderer(String defaultLang) { + public TMHTMLRenderer(final String defaultLang) { this.defaultLang = defaultLang; } @Override - public void code(String code, String lang, boolean escaped) { - IGrammar grammar = lang == null ? getDefaultGrammar() : getGrammar(lang); + public void code(final String code, final String lang, final boolean escaped) { + final IGrammar grammar = lang == null ? getDefaultGrammar() : getGrammar(lang); if (grammar == null) { super.code(code, lang, escaped); } else { - ITokenizationSupport tokenizationSupport = new Tokenizer(grammar); + final ITokenizationSupport tokenizationSupport = new Tokenizer(grammar); html.append("
    "); tokenizeLines(code, tokenizationSupport); html.append("
    "); } } - private void tokenizeLines(String text, ITokenizationSupport tokenizationSupport) { - String[] lines = text.split("\r\n|\r|\n"); + private void tokenizeLines(final String text, final ITokenizationSupport tokenizationSupport) { + final String[] lines = text.split("\r\n|\r|\n"); TMState currentState = tokenizationSupport.getInitialState(); for (int i = 0; i < lines.length; i++) { currentState = tokenizeLine(lines[i], tokenizationSupport, currentState); @@ -63,17 +63,17 @@ private void emitNewLine() { html.append("
    "); } - private TMState tokenizeLine(String line, ITokenizationSupport tokenizationSupport, TMState startState) { - LineTokens tokenized = tokenizationSupport.tokenize(line, startState); - TMState endState = tokenized.getEndState(); - List tokens = tokenized.getTokens(); + private TMState tokenizeLine(final String line, final ITokenizationSupport tokenizationSupport, final TMState startState) { + final LineTokens tokenized = tokenizationSupport.tokenize(line, startState); + final TMState endState = tokenized.getEndState(); + final List tokens = tokenized.getTokens(); int offset = 0; String tokenText; // For each token inject spans with proper class names based on token // type for (int j = 0; j < tokens.size(); j++) { - TMToken token = tokens.get(j); + final TMToken token = tokens.get(j); // Tokens only provide a startIndex from where they are valid from. // As such, we need to @@ -88,7 +88,7 @@ private TMState tokenizeLine(String line, ITokenizationSupport tokenizationSuppo } String className = "token"; - String safeType = token.type.replaceAll("[^a-z0-9\\-]", " "); + final String safeType = token.type.replaceAll("[^a-z0-9\\-]", " "); if (!safeType.isEmpty()) { className += ' ' + safeType; } @@ -109,8 +109,8 @@ protected IGrammar getDefaultGrammar() { return getGrammar(defaultLang); } - protected IGrammar getGrammar(String lang) { - IContentType[] contentTypes = Platform.getContentTypeManager().findContentTypesFor("x." + lang); + protected IGrammar getGrammar(final String lang) { + final IContentType[] contentTypes = Platform.getContentTypeManager().findContentTypesFor("x." + lang); return TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java index 7ca4efd63..f162e94aa 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java @@ -29,12 +29,12 @@ static BundleContext getContext() { } @Override - public void start(BundleContext bundleContext) throws Exception { + public void start(final BundleContext bundleContext) throws Exception { TMMarkdownPlugin.context = bundleContext; } @Override - public void stop(BundleContext bundleContext) throws Exception { + public void stop(final BundleContext bundleContext) throws Exception { TMMarkdownPlugin.context = null; } } \ No newline at end of file diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java index c162e6143..6a13bc1b3 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java @@ -43,9 +43,9 @@ public class BlockRules { public final RegExp bullet; public final RegExp item; - public BlockRules(RegExp newline, RegExp code, RegExp fences, RegExp hr, RegExp heading, RegExp nptable, - RegExp lheading, RegExp blockquote, RegExp list, RegExp html, RegExp def, RegExp table, RegExp paragraph, - RegExp text, RegExp bullet, RegExp item) { + public BlockRules(final RegExp newline, final RegExp code, final RegExp fences, final RegExp hr, final RegExp heading, final RegExp nptable, + final RegExp lheading, final RegExp blockquote, final RegExp list, final RegExp html, final RegExp def, final RegExp table, final RegExp paragraph, + final RegExp text, final RegExp bullet, final RegExp item) { this.newline = newline; this.code = code; this.fences = fences; @@ -65,22 +65,22 @@ public BlockRules(RegExp newline, RegExp code, RegExp fences, RegExp hr, RegExp } private static BlockRules block() { - RegExp newline = new RegExp("^\\n+"); - RegExp code = new RegExp("^( {4}[^\\n]+\\n*)+/"); - RegExp fences = new RegExp(""); - RegExp hr = new RegExp("^( *[-*_]){3,} *(?:\\n+|$)"); - RegExp heading = new RegExp("^ *(#{1,6}) *([^\\n]+?) *#* *(?:\\n+|$)"); - RegExp nptable = new RegExp(""); - RegExp lheading = new RegExp("^([^\\n]+)\\n *(=|-){2,} *(?:\\n+|$)"); - RegExp blockquote = new RegExp("^( *>[^\\n]+(\\n(?!def)[^\\n]+)*\\n*)+"); - RegExp list = new RegExp("^( *)(bull) [\\s\\S]+?(?:hr|def|\\n{2,}(?! )(?!\\1bull )\\n*|\\s*$)"); - RegExp html = new RegExp("^ *(?:comment *(?:\\n|\\s*$)|closed *(?:\\n{2,}|\\s*$)|closing *(?:\\n{2,}|\\s*$))"); - RegExp def = new RegExp("^ *\\[([^\\]]+)\\]: *]+)>?(?: +[\"(]([^\\n]+)[\")])? *(?:\\n+|$)"); - RegExp table = RegExp.noop(); - RegExp paragraph = new RegExp("^((?:[^\\n]+\\n?(?!hr|heading|lheading|blockquote|tag|def))+)\\n*"); - RegExp text = new RegExp("^[^\\n]+"); - RegExp bullet = new RegExp("(?:[*+-]|\\d+\\.)"); - RegExp item = new RegExp("^( *)(bull) [^\\n]*(?:\\n(?!\\1bull )[^\\n]*)*"); + final RegExp newline = new RegExp("^\\n+"); + final RegExp code = new RegExp("^( {4}[^\\n]+\\n*)+/"); + final RegExp fences = new RegExp(""); + final RegExp hr = new RegExp("^( *[-*_]){3,} *(?:\\n+|$)"); + final RegExp heading = new RegExp("^ *(#{1,6}) *([^\\n]+?) *#* *(?:\\n+|$)"); + final RegExp nptable = new RegExp(""); + final RegExp lheading = new RegExp("^([^\\n]+)\\n *(=|-){2,} *(?:\\n+|$)"); + final RegExp blockquote = new RegExp("^( *>[^\\n]+(\\n(?!def)[^\\n]+)*\\n*)+"); + final RegExp list = new RegExp("^( *)(bull) [\\s\\S]+?(?:hr|def|\\n{2,}(?! )(?!\\1bull )\\n*|\\s*$)"); + final RegExp html = new RegExp("^ *(?:comment *(?:\\n|\\s*$)|closed *(?:\\n{2,}|\\s*$)|closing *(?:\\n{2,}|\\s*$))"); + final RegExp def = new RegExp("^ *\\[([^\\]]+)\\]: *]+)>?(?: +[\"(]([^\\n]+)[\")])? *(?:\\n+|$)"); + final RegExp table = RegExp.noop(); + final RegExp paragraph = new RegExp("^((?:[^\\n]+\\n?(?!hr|heading|lheading|blockquote|tag|def))+)\\n*"); + final RegExp text = new RegExp("^[^\\n]+"); + final RegExp bullet = new RegExp("(?:[*+-]|\\d+\\.)"); + final RegExp item = new RegExp("^( *)(bull) [^\\n]*(?:\\n(?!\\1bull )[^\\n]*)*"); item.replaceAll("bull", bullet); list.replaceAll("bull", bullet).replace("hr", "\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))").replace("def", @@ -97,11 +97,11 @@ private static BlockRules normal() { } private static BlockRules gfm() { - BlockRules gfm = normal(); + final BlockRules gfm = normal(); gfm.fences.source = "^ *(`{3,}|~{3,})[ \\.]*(\\S+)? *\\n([\\s\\S]*?)\\s*\\1 *(?:\\n+|$)"; // gfm.paragraph.source = "^"; gfm.heading.source = "^ *(#{1,6}) +([^\\n]+?) *#* *(?:\\n+|$)"; - String pattern = "(?!" + gfm.fences.source.replaceFirst("\\\\1", "\\\\2") + "|" + final String pattern = "(?!" + gfm.fences.source.replaceFirst("\\\\1", "\\\\2") + "|" + gfm.list.source.replaceFirst("\\\\1", "\\\\3") + "|"; //pattern = pattern.replaceAll("\\\"", "\\\\\""); //pattern = pattern.replaceAll("[$]", "\\\\\\$"); @@ -110,7 +110,7 @@ private static BlockRules gfm() { } private static BlockRules tables() { - BlockRules tables = gfm(); + final BlockRules tables = gfm(); return tables; } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java index bda7005d8..8b05926e0 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java @@ -26,12 +26,12 @@ public HTMLRenderer() { this(new StringBuilder()); } - public HTMLRenderer(StringBuilder html) { + public HTMLRenderer(final StringBuilder html) { this.html = html; } @Override - public void code(String code, String lang, boolean escaped) { + public void code(final String code, final String lang, final boolean escaped) { if (lang == null) { html.append("
    ");
     			html.append(escaped ? code : escape(code, true));
    @@ -44,19 +44,19 @@ public void code(String code, String lang, boolean escaped) {
     	}
     
     	@Override
    -	public void blockquote(String quote) {
    +	public void blockquote(final String quote) {
     		// TODO Auto-generated method stub
     
     	}
     
     	@Override
    -	public void html(String html) {
    +	public void html(final String html) {
     		// TODO Auto-generated method stub
     
     	}
     
     	@Override
    -	public void heading(String text, int level, String raw) {
    +	public void heading(final String text, final int level, final String raw) {
     		html.append("");
     		html.append(text);
     		html.append("");
    @@ -146,25 +146,25 @@ public void br() {
     	}
     
     	@Override
    -	public void del(String text) {
    +	public void del(final String text) {
     		// TODO Auto-generated method stub
     
     	}
     
     	@Override
    -	public void link(String href, String title, String text) {
    +	public void link(final String href, final String title, final String text) {
     		// TODO Auto-generated method stub
     
     	}
     
     	@Override
    -	public void image(String href, String title, String text) {
    +	public void image(final String href, final String title, final String text) {
     		// TODO Auto-generated method stub
     
     	}
     
     	@Override
    -	public void text(String text) {
    +	public void text(final String text) {
     		html.append(text);
     	}
     
    diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java
    index d9dce131a..03d2a15d9 100644
    --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java
    +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java
    @@ -18,11 +18,11 @@
     
     public class Helpers {
     
    -	public static String escape(String html) {
    +	public static String escape(final String html) {
     		return escape(html, false);
     	}
     
    -	public static String escape(String html, boolean encode) {
    +	public static String escape(final String html, final boolean encode) {
     		return html
     			    .replaceAll(!encode ? "&(?!#?\\w+;)" : "&", "&")
     			    .replace("<", "<")
    @@ -31,7 +31,7 @@ public static String escape(String html, boolean encode) {
     			    .replace("'", "'");
     	}
     
    -	public static boolean isEmpty(String s) {
    +	public static boolean isEmpty(final String s) {
     		return s == null || s.isEmpty();
     	}
     
    diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java
    index 27dac2d50..829a7f8b1 100644
    --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java
    +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java
    @@ -27,7 +27,7 @@ public class InlineLexer {
     	private final InlineRules rules;
     	private final IRenderer renderer;
     
    -	public InlineLexer(Object links, Options options, IRenderer renderer) {
    +	public InlineLexer(final Object links, final Options options, final IRenderer renderer) {
     		this.options = options != null ? options : Options.DEFAULTS;
     		// this.links = links;
     		this.renderer = renderer != null ? renderer : new HTMLRenderer();
    @@ -90,7 +90,7 @@ public void output(String src) {
     		}
     	}
     
    -	private String smartypants(String text) {
    +	private String smartypants(final String text) {
     		return text;
     	}
     
    diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java
    index f11a30588..b9b2e1ea9 100644
    --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java
    +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineRules.java
    @@ -43,8 +43,8 @@ public class InlineRules {
     	public final RegExp del;
     	public final RegExp text;
     
    -	public InlineRules(RegExp escape, RegExp autolink, RegExp url, RegExp tag, RegExp link, RegExp reflink,
    -			RegExp nolink, RegExp strong, RegExp em, RegExp code, RegExp br, RegExp del, RegExp text) {
    +	public InlineRules(final RegExp escape, final RegExp autolink, final RegExp url, final RegExp tag, final RegExp link, final RegExp reflink,
    +			final RegExp nolink, final RegExp strong, final RegExp em, final RegExp code, final RegExp br, final RegExp del, final RegExp text) {
     		this.escape = escape;
     		this.autolink = autolink;
     		this.url = url;
    @@ -61,19 +61,19 @@ public InlineRules(RegExp escape, RegExp autolink, RegExp url, RegExp tag, RegEx
     	}
     
     	private static InlineRules inline() {
    -		RegExp escape = new RegExp("^\\\\([\\\\`*{}\\[\\]()#+\\-.!_>])");
    -		RegExp autolink = new RegExp("^<([^ >]+(@|:\\/)[^ >]+)>");
    -		RegExp url = RegExp.noop();
    -		RegExp tag = new RegExp("^|^<\\/?\\w+(?:\"[^\"]*\"|'[^']*'|[^'\">])*?>");
    -		RegExp link = new RegExp("^!?\\[(inside)\\]\\(href\\)");
    -		RegExp reflink = new RegExp("^!?\\[(inside)\\]\\s*\\[([^\\]]*)\\]");
    -		RegExp nolink = new RegExp("^!?\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\]");
    -		RegExp strong = new RegExp("^__([\\s\\S]+?)__(?!_)|^\\*\\*([\\s\\S]+?)\\*\\*(?!\\*)");
    -		RegExp em = new RegExp("^\\b_((?:[^_]|__)+?)_\\b|^\\*((?:\\*\\*|[\\s\\S])+?)\\*(?!\\*)");
    -		RegExp code = new RegExp("^(`+)\\s*([\\s\\S]*?[^`])\\s*\\1(?!`)");
    -		RegExp br = new RegExp("^ {2,}\\n(?!\\s*$)");
    -		RegExp del = RegExp.noop();
    -		RegExp text = new RegExp("^[\\s\\S]+?(?=[\\\\])");
    +		final RegExp autolink = new RegExp("^<([^ >]+(@|:\\/)[^ >]+)>");
    +		final RegExp url = RegExp.noop();
    +		final RegExp tag = new RegExp("^|^<\\/?\\w+(?:\"[^\"]*\"|'[^']*'|[^'\">])*?>");
    +		final RegExp link = new RegExp("^!?\\[(inside)\\]\\(href\\)");
    +		final RegExp reflink = new RegExp("^!?\\[(inside)\\]\\s*\\[([^\\]]*)\\]");
    +		final RegExp nolink = new RegExp("^!?\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\]");
    +		final RegExp strong = new RegExp("^__([\\s\\S]+?)__(?!_)|^\\*\\*([\\s\\S]+?)\\*\\*(?!\\*)");
    +		final RegExp em = new RegExp("^\\b_((?:[^_]|__)+?)_\\b|^\\*((?:\\*\\*|[\\s\\S])+?)\\*(?!\\*)");
    +		final RegExp code = new RegExp("^(`+)\\s*([\\s\\S]*?[^`])\\s*\\1(?!`)");
    +		final RegExp br = new RegExp("^ {2,}\\n(?!\\s*$)");
    +		final RegExp del = RegExp.noop();
    +		final RegExp text = new RegExp("^[\\s\\S]+?(?=[\\\\
    Date: Thu, 5 May 2022 19:29:38 +0200
    Subject: [PATCH 177/202] Enable annotation based null analysis in
     tm4e.markdown plugin
    
    ---
     .../tm4e/core/model/ITokenizationSupport.java |  8 +--
     .../eclipse/tm4e/core/model/LineTokens.java   |  1 -
     .../eclipse/tm4e/core/model/Tokenizer.java    |  2 +-
     .../.settings/org.eclipse.jdt.core.prefs      |  4 +-
     .../META-INF/MANIFEST.MF                      |  3 +-
     org.eclipse.tm4e.markdown/build.properties    |  6 +++
     .../eclipse/tm4e/markdown/TMHTMLRenderer.java | 19 +++----
     .../tm4e/markdown/TMMarkdownPlugin.java       | 14 ++---
     .../tm4e/markdown/marked/BlockRules.java      | 26 +++++----
     .../tm4e/markdown/marked/HTMLRenderer.java    | 10 ++--
     .../eclipse/tm4e/markdown/marked/Helpers.java | 27 ++++------
     .../tm4e/markdown/marked/IRenderer.java       | 16 +++---
     .../tm4e/markdown/marked/InlineLexer.java     | 18 ++++---
     .../eclipse/tm4e/markdown/marked/Lexer.java   | 15 +++---
     .../eclipse/tm4e/markdown/marked/Marked.java  |  7 +--
     .../eclipse/tm4e/markdown/marked/Parser.java  | 54 ++++++++++---------
     .../eclipse/tm4e/markdown/marked/RegExp.java  | 43 ++++++++++-----
     .../eclipse/tm4e/markdown/marked/Token.java   | 19 ++++---
     .../eclipse/tm4e/markdown/marked/Tokens.java  |  6 +++
     .../tm4e/markdown/marked/package-info.java    |  4 ++
     .../eclipse/tm4e/markdown/package-info.java   |  4 ++
     21 files changed, 184 insertions(+), 122 deletions(-)
     create mode 100644 org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/package-info.java
     create mode 100644 org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/package-info.java
    
    diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java
    index 02cfb236a..6c68e1973 100644
    --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java
    +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ITokenizationSupport.java
    @@ -16,15 +16,17 @@
      */
     package org.eclipse.tm4e.core.model;
     
    +import org.eclipse.jdt.annotation.Nullable;
    +
     public interface ITokenizationSupport {
     
     	TMState getInitialState();
     
    -	LineTokens tokenize(String line, TMState state);
    -	
    +	LineTokens tokenize(String line, @Nullable TMState state);
    +
     	// add offsetDelta to each of the returned indices
     	// stop tokenizing at absolute value stopAtOffset (i.e. stream.pos() +
     	// offsetDelta > stopAtOffset)
    -	LineTokens tokenize(String line, TMState state, Integer offsetDelta, Integer stopAtOffset);
    +	LineTokens tokenize(String line, @Nullable TMState state, Integer offsetDelta, Integer stopAtOffset);
     
     }
    diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java
    index 55ce01896..18c1fd073 100644
    --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java
    +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineTokens.java
    @@ -43,7 +43,6 @@ public void setEndState(@Nullable  final TMState endState) {
     		this.endState = endState;
     	}
     
    -	@Nullable
     	public List getTokens() {
     		return tokens;
     	}
    diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java
    index f11ae8e4e..59c1956a0 100644
    --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java
    +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java
    @@ -38,7 +38,7 @@ public TMState getInitialState() {
     	}
     
     	@Override
    -	public LineTokens tokenize(final String line, final TMState state) {
    +	public LineTokens tokenize(final String line, @Nullable final TMState state) {
     		return tokenize(line, state, null, null);
     	}
     
    diff --git a/org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs
    index f648802b5..6b99f88fc 100644
    --- a/org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs
    +++ b/org.eclipse.tm4e.markdown/.settings/org.eclipse.jdt.core.prefs
    @@ -8,7 +8,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota
     org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
     org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
     org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
    -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
    +org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
     org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
     org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
     org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
    @@ -75,7 +75,7 @@ org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=wa
     org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
     org.eclipse.jdt.core.compiler.problem.nullReference=warning
     org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
    -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
    +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=info
     org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
     org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
     org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
    diff --git a/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF b/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF
    index e669c8696..386c02068 100644
    --- a/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF
    +++ b/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF
    @@ -8,7 +8,8 @@ Bundle-Version: 0.3.6.qualifier
     Require-Bundle: org.eclipse.core.runtime,
      org.eclipse.tm4e.core,
      org.eclipse.tm4e.registry,
    - org.eclipse.tm4e.ui
    + org.eclipse.tm4e.ui,
    + com.google.guava;bundle-version="30.1.0"
     Bundle-RequiredExecutionEnvironment: JavaSE-11
     Export-Package: org.eclipse.tm4e.markdown,
      org.eclipse.tm4e.markdown.marked
    diff --git a/org.eclipse.tm4e.markdown/build.properties b/org.eclipse.tm4e.markdown/build.properties
    index 065c68847..0a9f3a653 100644
    --- a/org.eclipse.tm4e.markdown/build.properties
    +++ b/org.eclipse.tm4e.markdown/build.properties
    @@ -4,3 +4,9 @@ bin.includes = META-INF/,\
                    .,\
                    plugin.properties,\
                    about.html
    +
    +# https://codeiseasy.wordpress.com/2013/03/08/tycho-and-jdt-null-analysis/
    +# JDT Null Analysis for Eclipse
    +additional.bundles = org.eclipse.jdt.annotation
    +# JDT Null Analysis types for Tycho
    +jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
    diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java
    index b6141b8b3..1127bf592 100644
    --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java
    +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMHTMLRenderer.java
    @@ -15,6 +15,7 @@
     
     import org.eclipse.core.runtime.Platform;
     import org.eclipse.core.runtime.content.IContentType;
    +import org.eclipse.jdt.annotation.Nullable;
     import org.eclipse.tm4e.core.grammar.IGrammar;
     import org.eclipse.tm4e.core.model.ITokenizationSupport;
     import org.eclipse.tm4e.core.model.LineTokens;
    @@ -34,7 +35,7 @@ public TMHTMLRenderer(final String defaultLang) {
     	}
     
     	@Override
    -	public void code(final String code, final String lang, final boolean escaped) {
    +	public void code(final String code, @Nullable final String lang, final boolean escaped) {
     		final IGrammar grammar = lang == null ? getDefaultGrammar() : getGrammar(lang);
     		if (grammar == null) {
     			super.code(code, lang, escaped);
    @@ -63,23 +64,21 @@ private void emitNewLine() {
     		html.append("
    "); } - private TMState tokenizeLine(final String line, final ITokenizationSupport tokenizationSupport, final TMState startState) { + @Nullable + private TMState tokenizeLine(final String line, final ITokenizationSupport tokenizationSupport, @Nullable final TMState startState) { final LineTokens tokenized = tokenizationSupport.tokenize(line, startState); final TMState endState = tokenized.getEndState(); final List tokens = tokenized.getTokens(); int offset = 0; String tokenText; - // For each token inject spans with proper class names based on token - // type + // For each token inject spans with proper class names based on token type for (int j = 0; j < tokens.size(); j++) { final TMToken token = tokens.get(j); // Tokens only provide a startIndex from where they are valid from. - // As such, we need to - // look ahead the value of the token by advancing until the next - // tokens start inex or the - // end of the line. + // As such, we need to look ahead the value of the token by advancing until the next + // tokens start inex or the end of the line. if (j < tokens.size() - 1) { tokenText = line.substring(offset, tokens.get(j + 1).startIndex); offset = tokens.get(j + 1).startIndex; @@ -97,7 +96,7 @@ private TMState tokenizeLine(final String line, final ITokenizationSupport token html.append("class=\""); html.append(className); html.append("\">"); - html.append(Helpers.escape(tokenText)); + html.append(Helpers.htmlEscape(tokenText)); html.append(""); // emitToken(className, tokenText); } @@ -105,10 +104,12 @@ private TMState tokenizeLine(final String line, final ITokenizationSupport token return endState; } + @Nullable protected IGrammar getDefaultGrammar() { return getGrammar(defaultLang); } + @Nullable protected IGrammar getGrammar(final String lang) { final IContentType[] contentTypes = Platform.getContentTypeManager().findContentTypesFor("x." + lang); return TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java index f162e94aa..a9398de4c 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java @@ -1,40 +1,42 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.markdown; +import org.eclipse.jdt.annotation.Nullable; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; /** * OSGi Activator for TextMate Markdown bundle. - * */ public class TMMarkdownPlugin implements BundleActivator { public static final String PLUGIN_ID = "org.eclipse.tm4e.markdown"; + @Nullable private static BundleContext context; + @Nullable static BundleContext getContext() { return context; } @Override - public void start(final BundleContext bundleContext) throws Exception { + public void start(@Nullable final BundleContext bundleContext) throws Exception { TMMarkdownPlugin.context = bundleContext; } @Override - public void stop(final BundleContext bundleContext) throws Exception { + public void stop(@Nullable final BundleContext bundleContext) throws Exception { TMMarkdownPlugin.context = null; } } \ No newline at end of file diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java index 6a13bc1b3..96edbefcc 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,8 +11,8 @@ * Initial license: MIT * * Contributors: - * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.markdown.marked; @@ -43,8 +43,10 @@ public class BlockRules { public final RegExp bullet; public final RegExp item; - public BlockRules(final RegExp newline, final RegExp code, final RegExp fences, final RegExp hr, final RegExp heading, final RegExp nptable, - final RegExp lheading, final RegExp blockquote, final RegExp list, final RegExp html, final RegExp def, final RegExp table, final RegExp paragraph, + public BlockRules(final RegExp newline, final RegExp code, final RegExp fences, final RegExp hr, + final RegExp heading, final RegExp nptable, + final RegExp lheading, final RegExp blockquote, final RegExp list, final RegExp html, final RegExp def, + final RegExp table, final RegExp paragraph, final RegExp text, final RegExp bullet, final RegExp item) { this.newline = newline; this.code = code; @@ -98,20 +100,22 @@ private static BlockRules normal() { private static BlockRules gfm() { final BlockRules gfm = normal(); - gfm.fences.source = "^ *(`{3,}|~{3,})[ \\.]*(\\S+)? *\\n([\\s\\S]*?)\\s*\\1 *(?:\\n+|$)"; + final var source = "^ *(`{3,}|~{3,})[ \\.]*(\\S+)? *\\n([\\s\\S]*?)\\s*\\1 *(?:\\n+|$)"; + gfm.fences.source = source; // gfm.paragraph.source = "^"; gfm.heading.source = "^ *(#{1,6}) +([^\\n]+?) *#* *(?:\\n+|$)"; - final String pattern = "(?!" + gfm.fences.source.replaceFirst("\\\\1", "\\\\2") + "|" - + gfm.list.source.replaceFirst("\\\\1", "\\\\3") + "|"; - //pattern = pattern.replaceAll("\\\"", "\\\\\""); - //pattern = pattern.replaceAll("[$]", "\\\\\\$"); + final String pattern = "(?!" + + source.replaceFirst("\\\\1", "\\\\2") + "|" + + source.replaceFirst("\\\\1", "\\\\3") + + "|"; + // pattern = pattern.replaceAll("\\\"", "\\\\\""); + // pattern = pattern.replaceAll("[$]", "\\\\\\$"); gfm.paragraph.replace("\\(\\?\\!", pattern); return gfm; } private static BlockRules tables() { final BlockRules tables = gfm(); - return tables; } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java index 8b05926e0..4e063abc8 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java @@ -16,7 +16,9 @@ */ package org.eclipse.tm4e.markdown.marked; -import static org.eclipse.tm4e.markdown.marked.Helpers.escape; +import static org.eclipse.tm4e.markdown.marked.Helpers.htmlEscape; + +import org.eclipse.jdt.annotation.Nullable; public class HTMLRenderer implements IRenderer { @@ -31,14 +33,14 @@ public HTMLRenderer(final StringBuilder html) { } @Override - public void code(final String code, final String lang, final boolean escaped) { + public void code(final String code, @Nullable final String lang, final boolean escaped) { if (lang == null) { html.append("
    ");
    -			html.append(escaped ? code : escape(code, true));
    +			html.append(escaped ? code : htmlEscape(code, true));
     			html.append("\n
    "); } else { html.append("
    ");
    -			html.append(escaped ? code : escape(code, true));
    +			html.append(escaped ? code : htmlEscape(code, true));
     			html.append("\n
    "); } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java index 03d2a15d9..5c9d48f5b 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Helpers.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,28 +11,23 @@ * Initial license: MIT * * Contributors: - * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.markdown.marked; public class Helpers { - public static String escape(final String html) { - return escape(html, false); + public static String htmlEscape(final String html) { + return htmlEscape(html, false); } - public static String escape(final String html, final boolean encode) { + public static String htmlEscape(final String html, final boolean encode) { return html - .replaceAll(!encode ? "&(?!#?\\w+;)" : "&", "&") - .replace("<", "<") - .replace(">", ">") - .replace("\"", """) - .replace("'", "'"); + .replaceAll(!encode ? "&(?!#?\\w+;)" : "&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("'", "'"); } - - public static boolean isEmpty(final String s) { - return s == null || s.isEmpty(); - } - } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java index 0b51d7092..820d08118 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/IRenderer.java @@ -16,9 +16,11 @@ */ package org.eclipse.tm4e.markdown.marked; +import org.eclipse.jdt.annotation.Nullable; + public interface IRenderer { - void code(String code, String lang, boolean escaped); + void code(String code, @Nullable String lang, boolean escaped); void blockquote(String quote); @@ -33,7 +35,7 @@ public interface IRenderer { void listitem(String text); void startParagraph(); - + void endParagraph(); void table(String header, String body); @@ -43,13 +45,13 @@ public interface IRenderer { void tablecell(String content, String flags); void startEm(); - + void endEm(); - + void startStrong(); - + void endStrong(); - + void codespan(String text); void br(); @@ -62,6 +64,6 @@ public interface IRenderer { void text(String text); - + } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java index 829a7f8b1..cedac1cee 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/InlineLexer.java @@ -16,18 +16,20 @@ */ package org.eclipse.tm4e.markdown.marked; -import static org.eclipse.tm4e.markdown.marked.Helpers.escape; -import static org.eclipse.tm4e.markdown.marked.Helpers.isEmpty; +import static org.eclipse.tm4e.markdown.marked.Helpers.htmlEscape; +import com.google.common.base.Strings; import java.util.regex.Matcher; +import org.eclipse.jdt.annotation.Nullable; + public class InlineLexer { private final Options options; private final InlineRules rules; private final IRenderer renderer; - public InlineLexer(final Object links, final Options options, final IRenderer renderer) { + public InlineLexer(@Nullable final Object links, @Nullable final Options options, @Nullable final IRenderer renderer) { this.options = options != null ? options : Options.DEFAULTS; // this.links = links; this.renderer = renderer != null ? renderer : new HTMLRenderer(); @@ -54,13 +56,13 @@ public InlineLexer(final Object links, final Options options, final IRenderer re public void output(String src) { Matcher cap = null; - while (!isEmpty(src)) { + while (!Strings.isNullOrEmpty(src)) { // strong if ((cap = this.rules.strong.exec(src)) != null) { src = src.substring(cap.group(0).length()); this.renderer.startStrong(); - this.output(!isEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); + this.output(!Strings.isNullOrEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); this.renderer.endStrong(); continue; } @@ -69,7 +71,7 @@ public void output(String src) { if ((cap = this.rules.em.exec(src)) != null) { src = src.substring(cap.group(0).length()); this.renderer.startEm(); - this.output(!isEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); + this.output(!Strings.isNullOrEmpty(cap.group(2)) ? cap.group(2) : cap.group(1)); this.renderer.endEm(); continue; } @@ -77,14 +79,14 @@ public void output(String src) { // code if ((cap = this.rules.code.exec(src)) != null) { src = src.substring(cap.group(0).length()); - this.renderer.codespan(escape(cap.group(2), true)); + this.renderer.codespan(htmlEscape(cap.group(2), true)); continue; } // text if ((cap = this.rules.text.exec(src)) != null) { src = src.substring(cap.group(0).length()); - this.renderer.text(escape(this.smartypants(cap.group(0)))); + this.renderer.text(htmlEscape(this.smartypants(cap.group(0)))); continue; } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java index 2ffb0cef3..5cbdfee62 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Lexer.java @@ -16,17 +16,18 @@ */ package org.eclipse.tm4e.markdown.marked; -import static org.eclipse.tm4e.markdown.marked.Helpers.isEmpty; - import java.util.regex.Matcher; +import com.google.common.base.Strings; +import org.eclipse.jdt.annotation.Nullable; + public class Lexer { private final BlockRules rules; private final Tokens tokens; private final Options options; - public Lexer(final Options options) { + public Lexer(@Nullable final Options options) { this.tokens = new Tokens(); this.options = options != null ? options : Options.DEFAULTS; @@ -41,7 +42,7 @@ public Lexer(final Options options) { } } - public static Tokens lex(final String src, final Options options) { + public static Tokens lex(final String src, @Nullable final Options options) { final Lexer lexer = new Lexer(options); return lexer.lex(src); } @@ -56,10 +57,10 @@ private Tokens token(final String src, final boolean top) { return token(src, top, null); } - private Tokens token(String src, final boolean top, final Object bq) { + private Tokens token(String src, final boolean top, @Nullable final Object bq) { src = src.replaceAll("^ +$", ""); Matcher cap; - while (!isEmpty(src)) { + while (!Strings.isNullOrEmpty(src)) { // newline if ((cap = this.rules.newline.exec(src)) != null) { @@ -84,7 +85,7 @@ private Tokens token(String src, final boolean top, final Object bq) { if ((cap = this.rules.fences.exec(src)) != null) { src = src.substring(cap.group(0).length()); final String lang = cap.group(2); - final String text = !isEmpty(cap.group(3)) ? cap.group(3) : ""; + final String text = !Strings.isNullOrEmpty(cap.group(3)) ? cap.group(3) : ""; this.tokens.add(new Token(TokenType.code, lang, text)); continue; } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java index a6f81495e..283d1a020 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Marked.java @@ -16,6 +16,8 @@ */ package org.eclipse.tm4e.markdown.marked; +import org.eclipse.jdt.annotation.Nullable; + public class Marked { public static IRenderer parse(final String src) { @@ -26,12 +28,11 @@ public static IRenderer parse(final String src, final IRenderer renderer) { return parse(src, null, renderer); } - public static IRenderer parse(final String src, final Options opt) { + public static IRenderer parse(final String src, @Nullable final Options opt) { return parse(src, opt, null); } - public static IRenderer parse(final String src, final Options opt, final IRenderer renderer) { - + public static IRenderer parse(final String src, @Nullable final Options opt, @Nullable final IRenderer renderer) { return Parser.parse(Lexer.lex(src, opt), opt, renderer); } } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java index 8f8f4b8a5..1c9012e46 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Parser.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,39 +11,42 @@ * Initial license: MIT * * Contributors: - * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.markdown.marked; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.common.base.Strings; + public class Parser { - private Tokens tokens; - private Token token; private final Options options; - private InlineLexer inline; private final IRenderer renderer; - public Parser(final Options options, final IRenderer renderer) { - this.tokens = new Tokens(); - this.token = null; + @Nullable + private Token token; + + public Parser(@Nullable final Options options, @Nullable final IRenderer renderer) { this.options = options != null ? options : Options.DEFAULTS; this.renderer = renderer != null ? renderer : new HTMLRenderer(); } - public static IRenderer parse(final Tokens src, final Options options, final IRenderer renderer) { + public static IRenderer parse(final Tokens src, @Nullable final Options options, + @Nullable final IRenderer renderer) { final Parser parser = new Parser(options, renderer); return parser.parse(src); } private IRenderer parse(final Tokens src) { - this.inline = new InlineLexer(src.links, this.options, this.renderer); - this.tokens = src.reverse(); + final var inline = new InlineLexer(src.links, this.options, this.renderer); + final var tokens = src.reverse(); // var out = ''; - while (this.next()) { + while (this.next(tokens)) { // out += this.tok(); - this.tok(); + this.tok(inline); } return renderer; @@ -52,35 +55,36 @@ private IRenderer parse(final Tokens src) { /** * Next Token */ - private boolean next() { - return ((this.token = this.tokens.pop()) != null); + private boolean next(Tokens tokens) { + return ((this.token = tokens.pop()) != null); } /** * Parse Current Token */ - private void tok() { - switch (this.token.type) { + private void tok(InlineLexer inline) { + final var token = this.token; + if (token == null) + return; + + switch (token.type) { case space: break; case hr: this.renderer.hr(); break; case heading: - // this.renderer.heading(this.inline.output(this.token.text), - // this.token.depth, this.token.text); - this.renderer.heading(this.token.text, this.token.depth, this.token.text); + // this.renderer.heading(this.inline.output(token.text), token.depth, token.text); + this.renderer.heading(Strings.nullToEmpty(token.text), token.depth, Strings.nullToEmpty(token.text)); break; case code: - this.renderer.code(this.token.text, this.token.lang, this.token.escaped); + this.renderer.code(Strings.nullToEmpty(token.text), token.lang, token.escaped); break; case paragraph: this.renderer.startParagraph(); - this.inline.output(this.token.text); + inline.output(Strings.nullToEmpty(token.text)); this.renderer.endParagraph(); break; } - } - } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java index bae9680f0..cb15fb366 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/RegExp.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,30 +11,39 @@ * Initial license: MIT * * Contributors: - * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.markdown.marked; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.Nullable; + public class RegExp { + @Nullable protected String source; + + @Nullable private Pattern pattern; - public RegExp(final String source) { + public RegExp(@Nullable final String source) { this.source = source; } + @Nullable public Matcher exec(final String s) { if (source == null) { return null; } + if (pattern == null) { pattern = Pattern.compile(source); } + + assert pattern != null; final Matcher matcher = pattern.matcher(s); if (matcher.find()) { return matcher; @@ -46,11 +55,16 @@ public RegExp replace(final String name, final RegExp val) { return replace(name, val.source); } - public RegExp replace(final String name, String val) { + public RegExp replace(@Nullable final String name, @Nullable String val) { + final var source = this.source; + if (name == null) - return new RegExp(this.source); - val = val.replaceAll("(^|[^\\[])\\^", "$1"); - this.source = this.source.replaceFirst(name, Matcher.quoteReplacement(val)); + return new RegExp(source); + + if (source != null && val != null) { + val = val.replaceAll("(^|[^\\[])\\^", "$1"); + this.source = source.replaceFirst(name, Matcher.quoteReplacement(val)); + } return this; } @@ -58,11 +72,16 @@ public RegExp replaceAll(final String name, final RegExp val) { return replaceAll(name, val.source); } - public RegExp replaceAll(final String name, String val) { + public RegExp replaceAll(@Nullable final String name, @Nullable String val) { + final var source = this.source; + if (name == null) - return new RegExp(this.source); - val = val.replaceAll("(^|[^\\[])\\^", "$1"); - this.source = this.source.replaceAll(name, Matcher.quoteReplacement(val)); + return new RegExp(source); + + if (source != null && val != null) { + val = val.replaceAll("(^|[^\\[])\\^", "$1"); + this.source = source.replaceAll(name, Matcher.quoteReplacement(val)); + } return this; } diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java index c8b3a1db3..8dad861f9 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Token.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,16 +11,22 @@ * Initial license: MIT * * Contributors: - * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license - * - Angelo Zerr - translation and adaptation to Java + * - Christopher Jeffrey and others: Initial code, written in JavaScript, licensed under MIT license + * - Angelo Zerr - translation and adaptation to Java */ package org.eclipse.tm4e.markdown.marked; +import org.eclipse.jdt.annotation.Nullable; + public class Token { public final TokenType type; + + @Nullable public final String text; public final int depth; + + @Nullable public final String lang; public final boolean escaped; @@ -28,11 +34,11 @@ public Token(final TokenType type) { this(type, null); } - public Token(final TokenType type, final String text) { + public Token(final TokenType type, @Nullable final String text) { this(type, text, -1); } - public Token(final TokenType type, final String text, final int depth) { + public Token(final TokenType type, @Nullable final String text, final int depth) { this(type, text, depth, null, false); } @@ -40,7 +46,8 @@ public Token(final TokenType type, final String lang, final String text) { this(type, text, -1, lang, false); } - private Token(final TokenType type, final String text, final int depth, final String lang, final boolean escaped) { + private Token(final TokenType type, @Nullable final String text, final int depth, @Nullable final String lang, + final boolean escaped) { this.type = type; this.text = text; this.depth = depth; diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java index dff707ae3..c416d7363 100644 --- a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/Tokens.java @@ -19,8 +19,13 @@ import java.util.ArrayList; import java.util.Collections; +import org.eclipse.jdt.annotation.Nullable; + public class Tokens extends ArrayList { + private static final long serialVersionUID = 1L; + + @Nullable public Object links; public Tokens reverse() { @@ -28,6 +33,7 @@ public Tokens reverse() { return this; } + @Nullable public Token pop() { if (super.isEmpty()) { return null; diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/package-info.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/package-info.java new file mode 100644 index 000000000..1d8f1dd21 --- /dev/null +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.markdown.marked; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/package-info.java b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/package-info.java new file mode 100644 index 000000000..8a091b0de --- /dev/null +++ b/org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.markdown; + +import org.eclipse.jdt.annotation.NonNullByDefault; From b47ebf524d60f79f89bd2c7491db17bf9e58d947 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 5 May 2022 19:56:46 +0200 Subject: [PATCH 178/202] Add final modifier where applicable --- .../java/org/eclipse/tm4e/ui/TMUIPlugin.java | 14 +- .../tm4e/ui/internal/TMPropertyTester.java | 6 +- .../ui/internal/menus/ThemeContribution.java | 36 +-- .../ui/internal/model/DocumentHelper.java | 22 +- .../internal/model/DocumentInputStream.java | 4 +- .../ui/internal/model/DocumentLineList.java | 24 +- .../ui/internal/model/TMDocumentModel.java | 2 +- .../ui/internal/model/TMModelManager.java | 6 +- .../preferences/GrammarPreferencePage.java | 144 ++++++------ .../preferences/PreferenceHelper.java | 4 +- .../preferences/TextMatePreferencePage.java | 14 +- .../preferences/ThemePreferencePage.java | 92 ++++---- .../tm4e/ui/internal/snippets/Snippet.java | 4 +- .../ui/internal/snippets/SnippetManager.java | 16 +- ...TMPresentationReconcilerTestGenerator.java | 22 +- .../internal/themes/AbstractThemeManager.java | 38 ++-- .../themes/BaseThemeAssociationRegistry.java | 18 +- .../themes/ThemeAssociationRegistry.java | 28 +-- .../tm4e/ui/internal/themes/ThemeManager.java | 30 +-- .../themes/WorkingCopyThemeManager.java | 26 +-- .../tm4e/ui/internal/utils/ClassHelper.java | 16 +- .../ui/internal/utils/ContentTypeHelper.java | 60 ++--- .../ui/internal/utils/ContentTypeInfo.java | 2 +- .../ui/internal/utils/PreferenceUtils.java | 2 +- .../widgets/ColumnSelectionAdapter.java | 8 +- .../widgets/ColumnViewerComparator.java | 12 +- .../widgets/ContentTypeLabelProvider.java | 8 +- .../widgets/ContentTypesBindingWidget.java | 4 +- .../GrammarDefinitionContentProvider.java | 4 +- .../GrammarDefinitionLabelProvider.java | 8 +- .../internal/widgets/GrammarInfoWidget.java | 26 +-- .../tm4e/ui/internal/widgets/TMViewer.java | 18 +- .../widgets/TableAndButtonsWidget.java | 30 +-- .../ThemeAssociationLabelProvider.java | 18 +- .../widgets/ThemeAssociationsWidget.java | 22 +- .../widgets/ThemeContentProvider.java | 4 +- .../internal/widgets/ThemeLabelProvider.java | 10 +- .../internal/wizards/AbstractWizardPage.java | 18 +- .../wizards/CreateThemeAssociationWizard.java | 12 +- .../CreateThemeAssociationWizardPage.java | 20 +- .../wizards/SelectGrammarWizardPage.java | 36 +-- .../wizards/TextMateGrammarImportWizard.java | 10 +- .../ui/text/TMPresentationReconciler.java | 205 +++++++++--------- .../eclipse/tm4e/ui/themes/ColorManager.java | 20 +- .../org/eclipse/tm4e/ui/themes/Theme.java | 34 +-- .../tm4e/ui/themes/ThemeAssociation.java | 8 +- .../tm4e/ui/themes/css/CSSTokenProvider.java | 24 +- 47 files changed, 598 insertions(+), 591 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java index 23bd0f0e1..aadbacfb6 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java @@ -47,23 +47,23 @@ public class TMUIPlugin extends AbstractUIPlugin { public TMUIPlugin() { } - public void trace(String message) { + public void trace(final String message) { if (Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID))) { getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); } } @Override - public void start(BundleContext context) throws Exception { + public void start(final BundleContext context) throws Exception { super.start(context); plugin = this; - boolean isDebugOn = Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID)); + final boolean isDebugOn = Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID)); if (isDebugOn) { - Logger tm4eCoreLogger = Logger.getLogger("org.eclipse.tm4e"); + final Logger tm4eCoreLogger = Logger.getLogger("org.eclipse.tm4e"); tm4eCoreLogger.setLevel(Level.FINEST); tm4eCoreLogger.addHandler(new Handler() { - @Override public void publish(LogRecord record) { + @Override public void publish(final LogRecord record) { TMUIPlugin.getDefault().getLog().log(new Status( toSeverity(record.getLevel()), "org.eclipse.tm4e.core", @@ -71,7 +71,7 @@ public void start(BundleContext context) throws Exception { )); } - private int toSeverity(Level level) { + private int toSeverity(final Level level) { if (level.intValue() >= Level.SEVERE.intValue()) { return IStatus.ERROR; } @@ -93,7 +93,7 @@ private int toSeverity(Level level) { } @Override - public void stop(BundleContext context) throws Exception { + public void stop(final BundleContext context) throws Exception { ColorManager.getInstance().dispose(); plugin = null; super.stop(context); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java index fcc903a4d..928ad3240 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java @@ -25,11 +25,11 @@ public final class TMPropertyTester extends PropertyTester { private static final String CAN_SUPPORT_TEXT_MATE = "canSupportTextMate"; @Override - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { if (CAN_SUPPORT_TEXT_MATE.equals(property)) { if (receiver instanceof IEditorPart) { - IEditorPart editorPart = (IEditorPart) receiver; - TMPresentationReconciler reconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); + final IEditorPart editorPart = (IEditorPart) receiver; + final TMPresentationReconciler reconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); return reconciler != null && reconciler.isEnabled(); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java index 93d59932c..db63b1b6c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java @@ -42,29 +42,29 @@ public final class ThemeContribution extends CompoundContributionItem implements private IHandlerService handlerService; @Override - public void initialize(IServiceLocator serviceLocator) { + public void initialize(final IServiceLocator serviceLocator) { handlerService = serviceLocator.getService(IHandlerService.class); } @Override protected IContributionItem[] getContributionItems() { - List items = new ArrayList<>(); + final List items = new ArrayList<>(); if (handlerService != null) { - IEditorPart editorPart = getActivePart(handlerService.getCurrentState()); + final IEditorPart editorPart = getActivePart(handlerService.getCurrentState()); if (editorPart != null) { - IThemeManager manager = TMUIPlugin.getThemeManager(); - boolean dark = manager.isDarkEclipseTheme(); - ITheme[] themes = manager.getThemes(); - TMPresentationReconciler presentationReconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); + final IThemeManager manager = TMUIPlugin.getThemeManager(); + final boolean dark = manager.isDarkEclipseTheme(); + final ITheme[] themes = manager.getThemes(); + final TMPresentationReconciler presentationReconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); if (themes != null && presentationReconciler != null) { - String scopeName = presentationReconciler.getGrammar().getScopeName(); - ITheme selectedTheme = manager.getThemeForScope(scopeName, dark); - for (ITheme theme : themes) { - IAction action = createAction(scopeName, theme, dark); + final String scopeName = presentationReconciler.getGrammar().getScopeName(); + final ITheme selectedTheme = manager.getThemeForScope(scopeName, dark); + for (final ITheme theme : themes) { + final IAction action = createAction(scopeName, theme, dark); if (theme.equals(selectedTheme)) { action.setChecked(true); } - IContributionItem item = new ActionContributionItem(action); + final IContributionItem item = new ActionContributionItem(action); items.add(item); } } @@ -74,27 +74,27 @@ protected IContributionItem[] getContributionItems() { return items.toArray(IContributionItem[]::new); } - private Action createAction(final String scopeName, final ITheme theme, boolean whenDark) { + private Action createAction(final String scopeName, final ITheme theme, final boolean whenDark) { return new Action(theme.getName()) { @Override public void run() { - IThemeManager manager = TMUIPlugin.getThemeManager(); - IThemeAssociation association = new ThemeAssociation(theme.getId(), scopeName, whenDark); + final IThemeManager manager = TMUIPlugin.getThemeManager(); + final IThemeAssociation association = new ThemeAssociation(theme.getId(), scopeName, whenDark); manager.registerThemeAssociation(association); try { manager.save(); - } catch (BackingStoreException e) { + } catch (final BackingStoreException e) { e.printStackTrace(); } } }; } - private static IEditorPart getActivePart(IEvaluationContext context) { + private static IEditorPart getActivePart(final IEvaluationContext context) { if (context == null) return null; - Object activePart = context.getVariable(ISources.ACTIVE_PART_NAME); + final Object activePart = context.getVariable(ISources.ACTIVE_PART_NAME); if ((activePart instanceof IEditorPart)) return (IEditorPart) activePart; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java index 66c5fd0cf..008e1494e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentHelper.java @@ -23,37 +23,37 @@ */ final class DocumentHelper { - static int getStartLine(DocumentEvent event) throws BadLocationException { + static int getStartLine(final DocumentEvent event) throws BadLocationException { return event.getDocument().getLineOfOffset(event.getOffset()); } - static int getEndLine(DocumentEvent event, boolean documentAboutToBeChanged) throws BadLocationException { - int length = documentAboutToBeChanged ? event.getLength() : event.getText().length(); + static int getEndLine(final DocumentEvent event, final boolean documentAboutToBeChanged) throws BadLocationException { + final int length = documentAboutToBeChanged ? event.getLength() : event.getText().length(); return event.getDocument().getLineOfOffset(event.getOffset() + length); } - static boolean isRemove(DocumentEvent event) { + static boolean isRemove(final DocumentEvent event) { return event.getText() == null || event.getText().isEmpty(); } - static boolean isInsert(DocumentEvent event) { + static boolean isInsert(final DocumentEvent event) { return event.getLength() == 0 && event.getText() != null; } - static String getLineText(IDocument document, int line, boolean withLineDelimiter) + static String getLineText(final IDocument document, final int line, final boolean withLineDelimiter) throws BadLocationException { - int lo = document.getLineOffset(line); + final int lo = document.getLineOffset(line); int ll = document.getLineLength(line); if (!withLineDelimiter) { - String delim = document.getLineDelimiter(line); + final String delim = document.getLineDelimiter(line); ll = ll - (delim != null ? delim.length() : 0); } return document.get(lo, ll); } - private static IRegion getRegion(IDocument document, int fromLine, int toLine) throws BadLocationException { - int startOffset = document.getLineOffset(fromLine); - int endOffset = document.getLineOffset(toLine) + document.getLineLength(toLine); + private static IRegion getRegion(final IDocument document, final int fromLine, final int toLine) throws BadLocationException { + final int startOffset = document.getLineOffset(fromLine); + final int endOffset = document.getLineOffset(toLine) + document.getLineLength(toLine); return new Region(startOffset, endOffset - startOffset); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java index 61aa9053a..924ff8980 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentInputStream.java @@ -24,7 +24,7 @@ public final class DocumentInputStream extends InputStream { private final IDocument fDocument; private int fCurrPos = 0; - public DocumentInputStream(IDocument document) { + public DocumentInputStream(final IDocument document) { fDocument= document; } @@ -38,7 +38,7 @@ public int read() throws IOException { if (fCurrPos < fDocument.getLength()) { return fDocument.getChar(fCurrPos++); } - } catch (BadLocationException e) { + } catch (final BadLocationException e) { // ignore } return -1; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java index 71363ae0c..66d33a71c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java @@ -33,7 +33,7 @@ final class DocumentLineList extends AbstractLineList { private final IDocument document; private final InternalListener listener = new InternalListener(); - DocumentLineList(IDocument document) { + DocumentLineList(final IDocument document) { this.document = document; document.addDocumentListener(listener); for (int i = 0; i < document.getNumberOfLines(); i++) { @@ -44,31 +44,31 @@ final class DocumentLineList extends AbstractLineList { private final class InternalListener implements IDocumentListener { @Override - public void documentAboutToBeChanged(DocumentEvent event) { + public void documentAboutToBeChanged(final DocumentEvent event) { try { if (!DocumentHelper.isInsert(event)) { // Remove or Replace (Remove + Insert) removeLine(event); } - } catch (BadLocationException e) { + } catch (final BadLocationException e) { e.printStackTrace(); } } - private void removeLine(DocumentEvent event) throws BadLocationException { - int startLine = DocumentHelper.getStartLine(event); - int endLine = DocumentHelper.getEndLine(event, true); + private void removeLine(final DocumentEvent event) throws BadLocationException { + final int startLine = DocumentHelper.getStartLine(event); + final int endLine = DocumentHelper.getEndLine(event, true); for (int i = endLine; i > startLine; i--) { DocumentLineList.this.removeLine(i); } } @Override - public void documentChanged(DocumentEvent event) { + public void documentChanged(final DocumentEvent event) { try { - int startLine = DocumentHelper.getStartLine(event); + final int startLine = DocumentHelper.getStartLine(event); if (!DocumentHelper.isRemove(event)) { - int endLine = DocumentHelper.getEndLine(event, false); + final int endLine = DocumentHelper.getEndLine(event, false); // Insert new lines for (int i = startLine; i < endLine; i++) { DocumentLineList.this.addLine(i + 1); @@ -81,7 +81,7 @@ public void documentChanged(DocumentEvent event) { DocumentLineList.this.updateLine(startLine); } invalidateLine(startLine); - } catch (BadLocationException e) { + } catch (final BadLocationException e) { TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } @@ -93,12 +93,12 @@ public int getNumberOfLines() { } @Override - public String getLineText(int line) throws Exception { + public String getLineText(final int line) throws Exception { return DocumentHelper.getLineText(document, line, false); } @Override - public int getLineLength(int line) throws Exception { + public int getLineLength(final int line) throws Exception { return document.getLineLength(line); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java index 1b8e379aa..98efa1abc 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModel.java @@ -18,7 +18,7 @@ public final class TMDocumentModel extends TMModel { private final IDocument document; - public TMDocumentModel(IDocument document) { + public TMDocumentModel(final IDocument document) { super(new DocumentLineList(document)); this.document = document; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java index a8c17ab4f..8c415ab83 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java @@ -36,7 +36,7 @@ private TMModelManager() { } @Override - public ITMModel connect(IDocument document) { + public ITMModel connect(final IDocument document) { ITMModel model = models.get(document); if (model != null) { return model; @@ -47,8 +47,8 @@ public ITMModel connect(IDocument document) { } @Override - public void disconnect(IDocument document) { - ITMModel model = models.remove(document); + public void disconnect(final IDocument document) { + final ITMModel model = models.remove(document); if (model != null) { model.dispose(); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index d65495139..81be60a0b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -116,7 +116,7 @@ IGrammarRegistryManager getGrammarRegistryManager() { * * @param grammarRegistryManager */ - void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { + void setGrammarRegistryManager(final IGrammarRegistryManager grammarRegistryManager) { this.grammarRegistryManager = grammarRegistryManager; } @@ -134,7 +134,7 @@ IThemeManager getThemeManager() { * * @param themeManager */ - void setThemeManager(IThemeManager themeManager) { + void setThemeManager(final IThemeManager themeManager) { this.themeManager = themeManager; } @@ -142,26 +142,26 @@ ISnippetManager getSnippetManager() { return snippetManager; } - void setSnippetManager(ISnippetManager snippetManager) { + void setSnippetManager(final ISnippetManager snippetManager) { this.snippetManager = snippetManager; } @Override - protected Control createContents(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(); + protected Control createContents(final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); + final GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); - Composite innerParent = new Composite(parent, SWT.NONE); - GridLayout innerLayout = new GridLayout(); + final Composite innerParent = new Composite(parent, SWT.NONE); + final GridLayout innerLayout = new GridLayout(); innerLayout.numColumns = 2; innerLayout.marginHeight = 0; innerLayout.marginWidth = 0; innerParent.setLayout(innerLayout); - GridData gd = new GridData(GridData.FILL_BOTH); + final GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; innerParent.setLayoutData(gd); @@ -183,41 +183,41 @@ protected Control createContents(Composite ancestor) { * * @param parent */ - private void createGrammarListContent(Composite parent) { - Composite tableComposite = new Composite(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_BOTH); + private void createGrammarListContent(final Composite parent) { + final Composite tableComposite = new Composite(parent, SWT.NONE); + final GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 360; data.heightHint = convertHeightInCharsToPixels(10); tableComposite.setLayoutData(data); - TableColumnLayout columnLayout = new TableColumnLayout(); + final TableColumnLayout columnLayout = new TableColumnLayout(); tableComposite.setLayout(columnLayout); - Table table = new Table(tableComposite, + final Table table = new Table(tableComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE); table.setHeaderVisible(true); table.setLinesVisible(true); - GC gc = new GC(getShell()); + final GC gc = new GC(getShell()); gc.setFont(JFaceResources.getDialogFont()); - ColumnViewerComparator viewerComparator = new ColumnViewerComparator(); + final ColumnViewerComparator viewerComparator = new ColumnViewerComparator(); grammarViewer = new TableViewer(table); - TableColumn column1 = new TableColumn(table, SWT.NONE); + final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(TMUIMessages.GrammarPreferencePage_column_scopeName); int minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_scopeName); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); column1.addSelectionListener(new ColumnSelectionAdapter(column1, grammarViewer, 0, viewerComparator)); - TableColumn column2 = new TableColumn(table, SWT.NONE); + final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(TMUIMessages.GrammarPreferencePage_column_path); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_path); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); column2.addSelectionListener(new ColumnSelectionAdapter(column2, grammarViewer, 1, viewerComparator)); - TableColumn column3 = new TableColumn(table, SWT.NONE); + final TableColumn column3 = new TableColumn(table, SWT.NONE); column3.setText(TMUIMessages.GrammarPreferencePage_column_pluginId); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_pluginId); columnLayout.setColumnData(column3, new ColumnWeightData(2, minWidth, true)); @@ -232,12 +232,12 @@ private void createGrammarListContent(Composite parent) { grammarViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override - public void selectionChanged(SelectionChangedEvent e) { - IStructuredSelection selection = grammarViewer.getStructuredSelection(); + public void selectionChanged(final SelectionChangedEvent e) { + final IStructuredSelection selection = grammarViewer.getStructuredSelection(); if (selection.isEmpty()) { return; } - IGrammarDefinition definition = (IGrammarDefinition) (selection).getFirstElement(); + final IGrammarDefinition definition = (IGrammarDefinition) (selection).getFirstElement(); // Update button grammarRemoveButton.setEnabled(definition.getPluginId() == null); themeAssociationsWidget.getNewButton().setEnabled(false); @@ -246,33 +246,33 @@ public void selectionChanged(SelectionChangedEvent e) { selectGrammar(definition); } - private void selectGrammar(IGrammarDefinition definition) { - String scopeName = definition.getScopeName(); + private void selectGrammar(final IGrammarDefinition definition) { + final String scopeName = definition.getScopeName(); // Fill "General" tab fillGeneralTab(scopeName); // Fill "Content type" tab fillContentTypeTab(scopeName); // Fill "Theme" tab - IThemeAssociation selectedAssociation = fillThemeTab(definition); + final IThemeAssociation selectedAssociation = fillThemeTab(definition); // Fill preview fillPreview(scopeName, selectedAssociation); } - private void fillGeneralTab(String scopeName) { - IGrammar grammar = grammarRegistryManager.getGrammarForScope(scopeName); + private void fillGeneralTab(final String scopeName) { + final IGrammar grammar = grammarRegistryManager.getGrammarForScope(scopeName); grammarInfoWidget.refresh(grammar); } - private void fillContentTypeTab(String scopeName) { + private void fillContentTypeTab(final String scopeName) { // Load the content type binding for the given grammar contentTypesWidget.setInput(grammarRegistryManager.getContentTypesForScope(scopeName)); } - private IThemeAssociation fillThemeTab(IGrammarDefinition definition) { + private IThemeAssociation fillThemeTab(final IGrammarDefinition definition) { IThemeAssociation selectedAssociation = null; - IStructuredSelection oldSelection = themeAssociationsWidget.getSelection(); + final IStructuredSelection oldSelection = themeAssociationsWidget.getSelection(); // Load the theme associations for the given grammar - IThemeAssociation[] themeAssociations = themeAssociationsWidget.setGrammarDefinition(definition); + final IThemeAssociation[] themeAssociations = themeAssociationsWidget.setGrammarDefinition(definition); // Try to keep selection if (!oldSelection.isEmpty() && Arrays.asList(themeAssociations).contains(oldSelection.getFirstElement())) { @@ -289,16 +289,16 @@ private IThemeAssociation fillThemeTab(IGrammarDefinition definition) { return selectedAssociation; } - private void fillPreview(String scopeName, IThemeAssociation selectedAssociation) { + private void fillPreview(final String scopeName, final IThemeAssociation selectedAssociation) { // Preview the grammar - IGrammar grammar = grammarRegistryManager.getGrammarForScope(scopeName); + final IGrammar grammar = grammarRegistryManager.getGrammarForScope(scopeName); if (selectedAssociation != null) { setPreviewTheme(selectedAssociation.getThemeId()); } previewViewer.setGrammar(grammar); // Snippet - ISnippet[] snippets = snippetManager.getSnippets(scopeName); + final ISnippet[] snippets = snippetManager.getSnippets(scopeName); if (snippets == null || snippets.length == 0) { previewViewer.setText(""); } else { @@ -315,9 +315,9 @@ private void fillPreview(String scopeName, IThemeAssociation selectedAssociation BidiUtils.applyTextDirection(grammarViewer.getControl(), BidiUtils.BTD_DEFAULT); - Composite buttons = new Composite(parent, SWT.NONE); + final Composite buttons = new Composite(parent, SWT.NONE); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - GridLayout layout = new GridLayout(); + final GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); @@ -328,19 +328,19 @@ private void fillPreview(String scopeName, IThemeAssociation selectedAssociation grammarNewButton.addListener(SWT.Selection, new Listener() { @Override - public void handleEvent(Event e) { + public void handleEvent(final Event e) { add(); } private void add() { // Open import wizard for TextMate grammar. - TextMateGrammarImportWizard wizard = new TextMateGrammarImportWizard(false); + final TextMateGrammarImportWizard wizard = new TextMateGrammarImportWizard(false); wizard.setGrammarRegistryManager(grammarRegistryManager); - WizardDialog dialog = new WizardDialog(getShell(), wizard); + final WizardDialog dialog = new WizardDialog(getShell(), wizard); if (dialog.open() == Window.OK) { // User grammar was saved, refresh the list of grammar and // select the created grammar. - IGrammarDefinition created = wizard.getCreatedDefinition(); + final IGrammarDefinition created = wizard.getCreatedDefinition(); grammarViewer.refresh(); grammarViewer.setSelection(new StructuredSelection(created)); } @@ -353,12 +353,12 @@ private void add() { grammarRemoveButton.addListener(SWT.Selection, new Listener() { @Override - public void handleEvent(Event e) { + public void handleEvent(final Event e) { remove(); } private void remove() { - IGrammarDefinition definition = (IGrammarDefinition) ((IStructuredSelection) grammarViewer + final IGrammarDefinition definition = (IGrammarDefinition) ((IStructuredSelection) grammarViewer .getSelection()).getFirstElement(); grammarRegistryManager.unregisterGrammarDefinition(definition); grammarViewer.refresh(); @@ -372,10 +372,10 @@ private void remove() { * * @param parent */ - private void createGrammarDetailContent(Composite parent) { - TabFolder folder = new TabFolder(parent, SWT.NONE); + private void createGrammarDetailContent(final Composite parent) { + final TabFolder folder = new TabFolder(parent, SWT.NONE); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); + final GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; folder.setLayoutData(gd); @@ -390,11 +390,11 @@ private void createGrammarDetailContent(Composite parent) { * * @param folder */ - private void createGeneralTab(TabFolder folder) { - TabItem tab = new TabItem(folder, SWT.NONE); + private void createGeneralTab(final TabFolder folder) { + final TabItem tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_general_text); - Composite parent = new Composite(folder, SWT.NONE); + final Composite parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -410,11 +410,11 @@ private void createGeneralTab(TabFolder folder) { * * @param folder */ - private void createContentTypeTab(TabFolder folder) { - TabItem tab = new TabItem(folder, SWT.NONE); + private void createContentTypeTab(final TabFolder folder) { + final TabItem tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_contentType_text); - Composite parent = new Composite(folder, SWT.NONE); + final Composite parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -429,28 +429,28 @@ private void createContentTypeTab(TabFolder folder) { * * @param folder */ - private void createThemeTab(TabFolder folder) { - TabItem tab = new TabItem(folder, SWT.NONE); + private void createThemeTab(final TabFolder folder) { + final TabItem tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_theme_text); - Composite parent = new Composite(folder, SWT.NONE); + final Composite parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); themeAssociationsWidget = new ThemeAssociationsWidget(themeManager, parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + final GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; themeAssociationsWidget.setLayoutData(data); themeAssociationsWidget.addSelectionChangedListener(new ISelectionChangedListener() { @Override - public void selectionChanged(SelectionChangedEvent e) { - IThemeAssociation association = (IThemeAssociation) ((IStructuredSelection) e.getSelection()) + public void selectionChanged(final SelectionChangedEvent e) { + final IThemeAssociation association = (IThemeAssociation) ((IStructuredSelection) e.getSelection()) .getFirstElement(); selectTheme(association); } - private void selectTheme(IThemeAssociation association) { + private void selectTheme(final IThemeAssociation association) { themeAssociationsWidget.getNewButton() .setEnabled(association != null /* && association.getPluginId() == null */); themeAssociationsWidget.getRemoveButton() @@ -464,8 +464,8 @@ private void selectTheme(IThemeAssociation association) { tab.setControl(parent); } - private void setPreviewTheme(String themeId) { - ITheme theme = themeManager.getThemeById(themeId); + private void setPreviewTheme(final String themeId) { + final ITheme theme = themeManager.getThemeById(themeId); if (theme != null) { previewViewer.setTheme(theme); } @@ -476,11 +476,11 @@ private void setPreviewTheme(String themeId) { * * @param folder */ - private void createInjectionTab(TabFolder folder) { - TabItem tab = new TabItem(folder, SWT.NONE); + private void createInjectionTab(final TabFolder folder) { + final TabItem tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_injection_text); - Composite parent = new Composite(folder, SWT.NONE); + final Composite parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -489,7 +489,7 @@ private void createInjectionTab(TabFolder folder) { tab.setControl(parent); } - private int computeMinimumColumnWidth(GC gc, String string) { + private int computeMinimumColumnWidth(final GC gc, final String string) { return gc.stringExtent(string).x + 10; // pad 10 to accommodate table // header trimmings } @@ -500,31 +500,31 @@ private void updateButtons() { } @Override - public void setVisible(boolean visible) { + public void setVisible(final boolean visible) { super.setVisible(visible); if (visible) setTitle(TMUIMessages.GrammarPreferencePage_title); } @Override - public void init(IWorkbench workbench) { + public void init(final IWorkbench workbench) { } - private TMViewer doCreateViewer(Composite parent) { - Label label = new Label(parent, SWT.NONE); + private TMViewer doCreateViewer(final Composite parent) { + final Label label = new Label(parent, SWT.NONE); label.setText(TMUIMessages.GrammarPreferencePage_preview); GridData data = new GridData(); data.horizontalSpan = 2; label.setLayoutData(data); - TMViewer viewer = createViewer(parent); + final TMViewer viewer = createViewer(parent); // Don't set caret to 'null' as this causes // https://bugs.eclipse.org/293263 // viewer.getTextWidget().setCaret(null); - Control control = viewer.getControl(); + final Control control = viewer.getControl(); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; data.heightHint = convertHeightInCharsToPixels(5); @@ -543,7 +543,7 @@ private TMViewer doCreateViewer(Composite parent) { * * @return a configured source viewer */ - private TMViewer createViewer(Composite parent) { + private TMViewer createViewer(final Composite parent) { return new TMViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); } @@ -553,7 +553,7 @@ public boolean performOk() { // Save the working copy if there are some changed. grammarRegistryManager.save(); themeManager.save(); - } catch (BackingStoreException e) { + } catch (final BackingStoreException e) { e.printStackTrace(); return false; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java index a0249815f..717e7b189 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelper.java @@ -32,11 +32,11 @@ public final class PreferenceHelper { DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(IThemeAssociation.class, (InstanceCreator) type -> new ThemeAssociation()).create(); } - public static IThemeAssociation[] loadThemeAssociations(String json) { + public static IThemeAssociation[] loadThemeAssociations(final String json) { return DEFAULT_GSON.fromJson(json, ThemeAssociation[].class); } - public static String toJsonThemeAssociations(Collection themeAssociations) { + public static String toJsonThemeAssociations(final Collection themeAssociations) { return DEFAULT_GSON.toJson(themeAssociations); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java index 9f7bbe40a..2e2df0c36 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java @@ -30,9 +30,9 @@ public final class TextMatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { @Override - protected Control createContents(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(1, false); + protected Control createContents(final Composite parent) { + final Composite composite = new Composite(parent, SWT.NONE); + final GridLayout layout = new GridLayout(1, false); layout.marginHeight = layout.marginWidth = 0; composite.setLayout(layout); @@ -53,16 +53,16 @@ protected Control createContents(Composite parent) { } - private void addRelatedLink(Composite parent, String pageId, String message) { - PreferenceLinkArea contentTypeArea = new PreferenceLinkArea(parent, SWT.NONE, pageId, message, + private void addRelatedLink(final Composite parent, final String pageId, final String message) { + final PreferenceLinkArea contentTypeArea = new PreferenceLinkArea(parent, SWT.NONE, pageId, message, (IWorkbenchPreferenceContainer) getContainer(), null); - GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); + final GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); contentTypeArea.getControl().setLayoutData(data); } @Override - public void init(IWorkbench workbench) { + public void init(final IWorkbench workbench) { } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index d6e4833b4..acc521665 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -90,21 +90,21 @@ public ThemePreferencePage() { } @Override - protected Control createContents(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(); + protected Control createContents(final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); + final GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); - Composite innerParent = new Composite(parent, SWT.NONE); - GridLayout innerLayout = new GridLayout(); + final Composite innerParent = new Composite(parent, SWT.NONE); + final GridLayout innerLayout = new GridLayout(); innerLayout.numColumns = 2; innerLayout.marginHeight = 0; innerLayout.marginWidth = 0; innerParent.setLayout(innerLayout); - GridData gd = new GridData(GridData.FILL_BOTH); + final GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; innerParent.setLayoutData(gd); @@ -129,42 +129,42 @@ protected Control createContents(Composite ancestor) { * * @param parent */ - private void createThemesContent(Composite parent) { + private void createThemesContent(final Composite parent) { GridLayout layout; - Composite tableComposite = new Composite(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_BOTH); + final Composite tableComposite = new Composite(parent, SWT.NONE); + final GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 360; data.heightHint = convertHeightInCharsToPixels(10); tableComposite.setLayoutData(data); - TableColumnLayout columnLayout = new TableColumnLayout(); + final TableColumnLayout columnLayout = new TableColumnLayout(); tableComposite.setLayout(columnLayout); - Table table = new Table(tableComposite, + final Table table = new Table(tableComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); table.setHeaderVisible(true); table.setLinesVisible(true); - GC gc = new GC(getShell()); + final GC gc = new GC(getShell()); gc.setFont(JFaceResources.getDialogFont()); - ColumnViewerComparator viewerComparator = new ColumnViewerComparator(); + final ColumnViewerComparator viewerComparator = new ColumnViewerComparator(); themeViewer = new TableViewer(table); - TableColumn column1 = new TableColumn(table, SWT.NONE); + final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(TMUIMessages.ThemePreferencePage_column_name); int minWidth = computeMinimumColumnWidth(gc, TMUIMessages.ThemePreferencePage_column_name); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); column1.addSelectionListener(new ColumnSelectionAdapter(column1, themeViewer, 0, viewerComparator)); - TableColumn column2 = new TableColumn(table, SWT.NONE); + final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(TMUIMessages.ThemePreferencePage_column_path); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.ThemePreferencePage_column_path); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); column2.addSelectionListener(new ColumnSelectionAdapter(column2, themeViewer, 1, viewerComparator)); - TableColumn column3 = new TableColumn(table, SWT.NONE); + final TableColumn column3 = new TableColumn(table, SWT.NONE); column3.setText(TMUIMessages.ThemePreferencePage_column_pluginId); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.ThemePreferencePage_column_pluginId); columnLayout.setColumnData(column3, new ColumnWeightData(2, minWidth, true)); @@ -192,20 +192,20 @@ private void createThemesContent(Composite parent) { BidiUtils.applyTextDirection(themeViewer.getControl(), BidiUtils.BTD_DEFAULT); - Composite buttons = new Composite(parent, SWT.NONE); + final Composite buttons = new Composite(parent, SWT.NONE); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); - Button themeNewButton = new Button(buttons, SWT.PUSH); + final Button themeNewButton = new Button(buttons, SWT.PUSH); themeNewButton.setText(TMUIMessages.Button_new); themeNewButton.setLayoutData(getButtonGridData(themeNewButton)); themeNewButton.addListener(SWT.Selection, new Listener() { @Override - public void handleEvent(Event e) { - ITheme newTheme = addTheme(); + public void handleEvent(final Event e) { + final ITheme newTheme = addTheme(); if (newTheme != null) { themeManager.registerTheme(newTheme); selectedTheme = newTheme; @@ -215,15 +215,15 @@ public void handleEvent(Event e) { } private ITheme addTheme() { - FileDialog dialog = new FileDialog(getShell()); + final FileDialog dialog = new FileDialog(getShell()); dialog.setText("Select textmate theme file"); dialog.setFilterExtensions(new String[]{"*.css"}); - String res = dialog.open(); + final String res = dialog.open(); if (res == null) { return null; } - File file = new File(res); - String name = file.getName().substring(0, file.getName().length() - ".css".length()); + final File file = new File(res); + final String name = file.getName().substring(0, file.getName().length() - ".css".length()); return new Theme(name, file.getAbsolutePath(), name, false, false); } }); @@ -242,13 +242,13 @@ private ITheme addTheme() { * * @param parent */ - private void createThemeDetailContent(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + private void createThemeDetailContent(final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); + final GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; parent.setLayoutData(data); - GridLayout layout = new GridLayout(); + final GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; @@ -269,13 +269,13 @@ private void createThemeDetailContent(Composite ancestor) { * * @param parent */ - private void createPreviewContent(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + private void createPreviewContent(final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); + final GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; parent.setLayoutData(data); - GridLayout layout = new GridLayout(2, false); + final GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); @@ -283,7 +283,7 @@ private void createPreviewContent(Composite ancestor) { previewViewer = doCreateViewer(parent); } - private int computeMinimumColumnWidth(GC gc, String string) { + private int computeMinimumColumnWidth(final GC gc, final String string) { return gc.stringExtent(string).x + 10; // pad 10 to accommodate table // header trimmings } @@ -295,8 +295,8 @@ private int computeMinimumColumnWidth(GC gc, String string) { * the button * @return the grid data */ - private static GridData getButtonGridData(Button button) { - GridData data = new GridData(GridData.FILL_HORIZONTAL); + private static GridData getButtonGridData(final Button button) { + final GridData data = new GridData(GridData.FILL_HORIZONTAL); // TODO replace SWTUtil // data.widthHint= SWTUtil.getButtonWidthHint(button); // data.heightHint= SWTUtil.getButtonHeightHint(button); @@ -305,14 +305,14 @@ private static GridData getButtonGridData(Button button) { } @Override - public void setVisible(boolean visible) { + public void setVisible(final boolean visible) { super.setVisible(visible); if (visible) setTitle(TMUIMessages.ThemePreferencePage_title); } @Override - public void init(IWorkbench workbench) { + public void init(final IWorkbench workbench) { } private void preview() { @@ -320,23 +320,23 @@ private void preview() { if (selection.isEmpty()) { return; } - ITheme theme = (ITheme) selection.getFirstElement(); + final ITheme theme = (ITheme) selection.getFirstElement(); selection = (IStructuredSelection) grammarViewer.getSelection(); if (selection.isEmpty()) { return; } - IGrammarDefinition definition = (IGrammarDefinition) selection.getFirstElement(); + final IGrammarDefinition definition = (IGrammarDefinition) selection.getFirstElement(); // Preview the grammar - IGrammar grammar = grammarRegistryManager.getGrammarForScope(definition.getScopeName()); + final IGrammar grammar = grammarRegistryManager.getGrammarForScope(definition.getScopeName()); previewViewer.setTheme(theme); previewViewer.setGrammar(grammar); } - private TMViewer doCreateViewer(Composite parent) { - Label label = new Label(parent, SWT.NONE); + private TMViewer doCreateViewer(final Composite parent) { + final Label label = new Label(parent, SWT.NONE); label.setText(TMUIMessages.ThemePreferencePage_preview); GridData data = new GridData(); label.setLayoutData(data); @@ -347,13 +347,13 @@ private TMViewer doCreateViewer(Composite parent) { grammarViewer.addSelectionChangedListener(e -> preview()); grammarViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - TMViewer viewer = createViewer(parent); + final TMViewer viewer = createViewer(parent); // Don't set caret to 'null' as this causes // https://bugs.eclipse.org/293263 // viewer.getTextWidget().setCaret(null); - Control control = viewer.getControl(); + final Control control = viewer.getControl(); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; data.heightHint = convertHeightInCharsToPixels(5); @@ -371,7 +371,7 @@ private TMViewer doCreateViewer(Composite parent) { * the parent control * @return a configured source viewer */ - private TMViewer createViewer(Composite parent) { + private TMViewer createViewer(final Composite parent) { return new TMViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); } @@ -381,7 +381,7 @@ public boolean performOk() { themeManager.save(); grammarRegistryManager.save(); return true; - } catch (BackingStoreException e) { + } catch (final BackingStoreException e) { TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); return false; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java index 10f92cb1e..cdb98d3c7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java @@ -32,13 +32,13 @@ final class Snippet extends TMResource implements ISnippet { * * @param scopeName */ - Snippet(String scopeName, String path, String name) { + Snippet(final String scopeName, final String path, final String name) { super(path); this.scopeName = scopeName; this.name = name; } - Snippet(IConfigurationElement ce) { + Snippet(final IConfigurationElement ce) { super(ce); this.scopeName = ce.getAttribute(XMLConstants.SCOPE_NAME_ATTR); this.name = ce.getAttribute(XMLConstants.NAME_ATTR); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java index 7c99b1fce..38bbc16cd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java @@ -45,7 +45,7 @@ private static synchronized ISnippetManager createInstance() { if (INSTANCE != null) { return INSTANCE; } - SnippetManager manager = new SnippetManager(); + final SnippetManager manager = new SnippetManager(); manager.load(); return manager; } @@ -63,18 +63,18 @@ private void load() { * Load snippets from extension point. */ private void loadGrammarsFromExtensionPoints() { - IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, + final IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, EXTENSION_SNIPPETS); - for (IConfigurationElement ce : cf) { - String extensionName = ce.getName(); + for (final IConfigurationElement ce : cf) { + final String extensionName = ce.getName(); if (SNIPPET_ELT.equals(extensionName)) { this.registerSnippet(new Snippet(ce)); } } } - private void registerSnippet(Snippet snippet) { - String scopeName = snippet.getScopeName(); + private void registerSnippet(final Snippet snippet) { + final String scopeName = snippet.getScopeName(); Collection snippets = this.snippets.get(scopeName); if (snippets == null) { snippets = new ArrayList<>(); @@ -84,8 +84,8 @@ private void registerSnippet(Snippet snippet) { } @Override - public ISnippet[] getSnippets(String scopeName) { - Collection snippets = this.snippets.get(scopeName); + public ISnippet[] getSnippets(final String scopeName) { + final Collection snippets = this.snippets.get(scopeName); return snippets != null ? snippets.toArray(ISnippet[]::new) : EMPTY_SNIPPETS; } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java index d8ffdd0f1..6a1c5f7f4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java @@ -41,7 +41,7 @@ private static final class Command { }*/ @Override - public void install(ITextViewer viewer, IDocument document) { + public void install(final ITextViewer viewer, final IDocument document) { this.viewer = viewer; this.document = document; document.addDocumentListener(this); @@ -89,10 +89,10 @@ public void install(ITextViewer viewer, IDocument document) { } - private String toText(String text) { + private String toText(final String text) { final StringBuilder newText = new StringBuilder(); for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); + final char c = text.charAt(i); switch (c) { case '\n': newText.append("\\n"); @@ -151,7 +151,7 @@ public void uninstall() { } @Override - public void colorize(TextPresentation presentation, Throwable e) { + public void colorize(final TextPresentation presentation, final Throwable e) { // Command command = commands.get(commands.size() - 1); // if (e != null) { // command.error = e; @@ -160,26 +160,26 @@ public void colorize(TextPresentation presentation, Throwable e) { // } } - private void write(String s, boolean newLine) { + private void write(final String s, final boolean newLine) { code.append(s); if (newLine) { code.append("\n"); } } - private void write(String s) { + private void write(final String s) { write(s, false); } @Override - public void documentAboutToBeChanged(DocumentEvent event) { + public void documentAboutToBeChanged(final DocumentEvent event) { } @Override - public void documentChanged(DocumentEvent event) { + public void documentChanged(final DocumentEvent event) { - String command = "document.replace(" + event.getOffset() + ", " + event.getLength() + ", \"" + final String command = "document.replace(" + event.getOffset() + ", " + event.getLength() + ", \"" + toText(event.getText()) + "\");"; write("\t\t" + command, true); @@ -187,12 +187,12 @@ public void documentChanged(DocumentEvent event) { } @Override - public void textChanged(TextEvent event) { + public void textChanged(final TextEvent event) { if (event.getDocumentEvent() != null) { return; } - String command = "viewer.invalidateTextPresentation(" + event.getOffset() + ", " + event.getLength() + ");"; + final String command = "viewer.invalidateTextPresentation(" + event.getOffset() + ", " + event.getLength() + ");"; write("\t\t" + command, true); //commands.add(new Command(command)); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index 7d84d05d0..f4060e026 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -36,34 +36,34 @@ public abstract class AbstractThemeManager implements IThemeManager { private final ThemeAssociationRegistry themeAssociationRegistry = new ThemeAssociationRegistry(); @Override - public void registerTheme(ITheme theme) { + public void registerTheme(final ITheme theme) { themes.put(theme.getId(), theme); } @Override - public void unregisterTheme(ITheme theme) { + public void unregisterTheme(final ITheme theme) { themes.remove(theme.getId()); } @Override - public ITheme getThemeById(String themeId) { + public ITheme getThemeById(final String themeId) { return themes.get(themeId); } @Override public ITheme[] getThemes() { - Collection themes = this.themes.values(); + final Collection themes = this.themes.values(); return themes.toArray(ITheme[]::new); } @Override public ITheme getDefaultTheme() { - boolean dark = isDarkEclipseTheme(); + final boolean dark = isDarkEclipseTheme(); return getDefaultTheme(dark); } - ITheme getDefaultTheme(boolean dark) { - for (ITheme theme : this.themes.values()) { + ITheme getDefaultTheme(final boolean dark) { + for (final ITheme theme : this.themes.values()) { if (theme.isDark() == dark && theme.isDefault()) { return theme; } @@ -72,7 +72,7 @@ ITheme getDefaultTheme(boolean dark) { } @Override - public ITheme[] getThemes(boolean dark) { + public ITheme[] getThemes(final boolean dark) { return themes.values().stream().filter(theme -> theme.isDark() == dark) .collect(Collectors.toList()).toArray(ITheme[]::new); } @@ -83,28 +83,28 @@ public boolean isDarkEclipseTheme() { } @Override - public boolean isDarkEclipseTheme(String eclipseThemeId) { + public boolean isDarkEclipseTheme(final String eclipseThemeId) { return eclipseThemeId != null && eclipseThemeId.toLowerCase().contains("dark"); } @Override - public ITheme getThemeForScope(String scopeName, boolean dark) { - IThemeAssociation association = themeAssociationRegistry.getThemeAssociationFor(scopeName, dark); + public ITheme getThemeForScope(final String scopeName, final boolean dark) { + final IThemeAssociation association = themeAssociationRegistry.getThemeAssociationFor(scopeName, dark); if (association != null) { - String themeId = association.getThemeId(); + final String themeId = association.getThemeId(); return getThemeById(themeId); } return getDefaultTheme(dark); } @Override - public ITheme getThemeForScope(String scopeName) { + public ITheme getThemeForScope(final String scopeName) { return getThemeForScope(scopeName, isDarkEclipseTheme()); } @Override - public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { - List associations = new ArrayList<>(); + public IThemeAssociation[] getThemeAssociationsForScope(final String scopeName) { + final List associations = new ArrayList<>(); IThemeAssociation light = themeAssociationRegistry.getThemeAssociationFor(scopeName, false); if (light == null) { light = new ThemeAssociation(getDefaultTheme(false).getId(), scopeName, false); @@ -119,23 +119,23 @@ public IThemeAssociation[] getThemeAssociationsForScope(String scopeName) { } @Override - public void registerThemeAssociation(IThemeAssociation association) { + public void registerThemeAssociation(final IThemeAssociation association) { themeAssociationRegistry.register(association); } @Override - public void unregisterThemeAssociation(IThemeAssociation association) { + public void unregisterThemeAssociation(final IThemeAssociation association) { themeAssociationRegistry.unregister(association); } @Override public IThemeAssociation[] getAllThemeAssociations() { - List associations = themeAssociationRegistry.getThemeAssociations(); + final List associations = themeAssociationRegistry.getThemeAssociations(); return associations.toArray(IThemeAssociation[]::new); } @Override - public ITokenProvider getThemeForScope(String scopeName, RGB background) { + public ITokenProvider getThemeForScope(final String scopeName, final RGB background) { return getThemeForScope(scopeName, 0.299 * background.red + 0.587 * background.green + 0.114 * background.blue < 128); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java index 9d6f38ffd..e62dd7cb0 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java @@ -31,7 +31,7 @@ final class BaseThemeAssociationRegistry { private final Map> eclipseThemeIds = new HashMap<>(); private final List allAssociations = new ArrayList<>(); - void register(IThemeAssociation association) { + void register(final IThemeAssociation association) { //String eclipseThemeId = association.getEclipseThemeId(); // when association is marked as default or scope name is defined, // update the default association or association for a given E4 Theme. @@ -47,7 +47,7 @@ void register(IThemeAssociation association) { allAssociations.clear(); } - void unregister(IThemeAssociation association) { + void unregister(final IThemeAssociation association) { //String eclipseThemeId = association.getEclipseThemeId(); /*if (association.isDefault()) { if (eclipseThemeId == null) { @@ -66,8 +66,8 @@ void unregister(IThemeAssociation association) { allAssociations.clear(); } - IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { - List associations = eclipseThemeIds.get(eclipseThemeId); + IThemeAssociation getThemeAssociationFor(final String eclipseThemeId) { + final List associations = eclipseThemeIds.get(eclipseThemeId); if (associations != null) { if (associations.size() == 1) { return associations.get(0); @@ -81,7 +81,7 @@ IThemeAssociation getThemeAssociationFor(String eclipseThemeId) { return null; } - IThemeAssociation[] getThemeAssociations(boolean isDefault) { + IThemeAssociation[] getThemeAssociations(final boolean isDefault) { /*if (isDefault) { return getThemeAssociations().stream().filter(theme -> theme.isDefault()).collect(Collectors.toList()) .toArray(IThemeAssociation[]::new); @@ -93,12 +93,12 @@ IThemeAssociation getDefaultAssociation() { return defaultAssociation; } - IThemeAssociation[] getThemeAssociationsForTheme(String themeId) { + IThemeAssociation[] getThemeAssociationsForTheme(final String themeId) { return getThemeAssociations().stream().filter(themeAssociation -> themeId.equals(themeAssociation.getThemeId())) .collect(Collectors.toList()).toArray(IThemeAssociation[]::new); } - boolean hasThemeAssociationsForTheme(String themeId, String eclipseThemeId) { + boolean hasThemeAssociationsForTheme(final String themeId, final String eclipseThemeId) { // Collection associations = eclipseThemeIds.get(eclipseThemeId); // if (associations != null) { // for (IThemeAssociation themeAssociation : associations) { @@ -125,8 +125,8 @@ List getThemeAssociations() { if (defaultAssociation != null) { allAssociations.add(defaultAssociation); } - Collection> associations = eclipseThemeIds.values(); - for (Collection collection : associations) { + final Collection> associations = eclipseThemeIds.values(); + for (final Collection collection : associations) { allAssociations.addAll(collection); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java index a08a34b4f..9a6d88682 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java @@ -36,7 +36,7 @@ IThemeAssociation getLight() { return light; } - void setLight(IThemeAssociation light) { + void setLight(final IThemeAssociation light) { this.light = light; } @@ -44,17 +44,17 @@ IThemeAssociation getDark() { return dark; } - void setDark(IThemeAssociation dark) { + void setDark(final IThemeAssociation dark) { this.dark = dark; } } - IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) { + IThemeAssociation getThemeAssociationFor(final String scopeName, final boolean dark) { // From theme assiocations IThemeAssociation userAssociation = null; - EclipseThemeAssociation registry = scopes.get(scopeName); + final EclipseThemeAssociation registry = scopes.get(scopeName); if (registry != null) { userAssociation = dark ? registry.getDark() : registry.getLight(); } @@ -64,14 +64,14 @@ IThemeAssociation getThemeAssociationFor(String scopeName, boolean dark) { return null; } - void register(IThemeAssociation association) { - String scopeName = association.getScopeName(); + void register(final IThemeAssociation association) { + final String scopeName = association.getScopeName(); EclipseThemeAssociation registry = scopes.get(scopeName); if (registry == null) { registry = new EclipseThemeAssociation(); scopes.put(scopeName, registry); } - boolean dark = association.isWhenDark(); + final boolean dark = association.isWhenDark(); if (dark) { registry.setDark(association); } else { @@ -79,11 +79,11 @@ void register(IThemeAssociation association) { } } - void unregister(IThemeAssociation association) { - String scopeName = association.getScopeName(); - EclipseThemeAssociation registry = scopes.get(scopeName); + void unregister(final IThemeAssociation association) { + final String scopeName = association.getScopeName(); + final EclipseThemeAssociation registry = scopes.get(scopeName); if (registry != null) { - boolean dark = association.isWhenDark(); + final boolean dark = association.isWhenDark(); if (dark) { registry.setDark(null); } else { @@ -148,9 +148,9 @@ void unregister(IThemeAssociation association) { // // @Override List getThemeAssociations() { - List associations = new ArrayList<>(); - Collection eclipseAssociations = scopes.values(); - for (EclipseThemeAssociation eclipseAssociation : eclipseAssociations) { + final List associations = new ArrayList<>(); + final Collection eclipseAssociations = scopes.values(); + for (final EclipseThemeAssociation eclipseAssociation : eclipseAssociations) { if (eclipseAssociation.getLight() != null) { associations.add(eclipseAssociation.getLight()); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java index 8255533f8..fb30dc00a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java @@ -60,7 +60,7 @@ private static synchronized ThemeManager createInstance() { if (INSTANCE != null) { return INSTANCE; } - ThemeManager manager = new ThemeManager(); + final ThemeManager manager = new ThemeManager(); manager.load(); return manager; } @@ -77,10 +77,10 @@ private void load() { * Load TextMate Themes from extension point. */ private void loadThemesFromExtensionPoints() { - IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, + final IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, EXTENSION_THEMES); - for (IConfigurationElement ce : cf) { - String name = ce.getName(); + for (final IConfigurationElement ce : cf) { + final String name = ce.getName(); switch (name) { case THEME_ELT: super.registerTheme(new Theme(ce)); @@ -98,19 +98,19 @@ private void loadThemesFromExtensionPoints() { private void loadThemesFromPreferences() { // Load Theme definitions from the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); String json = prefs.get(PreferenceConstants.THEMES, null); if (json != null) { - for (JsonObject element : new Gson().fromJson(json, JsonObject[].class)) { - String name = element.get("id").getAsString(); + for (final JsonObject element : new Gson().fromJson(json, JsonObject[].class)) { + final String name = element.get("id").getAsString(); super.registerTheme(new Theme(name, element.get("path").getAsString(), name, element.get("dark").getAsBoolean(), false)); } } json = prefs.get(PreferenceConstants.THEME_ASSOCIATIONS, null); if (json != null) { - IThemeAssociation[] themeAssociations = PreferenceHelper.loadThemeAssociations(json); - for (IThemeAssociation association : themeAssociations) { + final IThemeAssociation[] themeAssociations = PreferenceHelper.loadThemeAssociations(json); + for (final IThemeAssociation association : themeAssociations) { super.registerThemeAssociation(association); } } @@ -118,23 +118,23 @@ private void loadThemesFromPreferences() { @Override public void save() throws BackingStoreException { - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); // Save Themes in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" prefs.put(PreferenceConstants.THEMES, Arrays.stream(getThemes()) // .filter(t -> t.getPluginId() == null) // .map(theme -> { - JsonObject json = new JsonObject(); + final JsonObject json = new JsonObject(); json.addProperty("id", theme.getId()); json.addProperty("path", theme.getPath()); json.addProperty("dark", theme.isDark()); return json; - }).collect(JsonArray::new, (JsonArray array, JsonObject object) -> array.add(object), (r,r1) -> {}) + }).collect(JsonArray::new, (final JsonArray array, final JsonObject object) -> array.add(object), (r,r1) -> {}) .toString()); // Save Theme associations in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" - String json = PreferenceHelper.toJsonThemeAssociations(Arrays.stream(getAllThemeAssociations()) + final String json = PreferenceHelper.toJsonThemeAssociations(Arrays.stream(getAllThemeAssociations()) .filter(t -> t.getPluginId() == null).collect(Collectors.toList())); prefs.put(PreferenceConstants.THEME_ASSOCIATIONS, json); @@ -148,7 +148,7 @@ public void save() throws BackingStoreException { * * @param themeChangeListener */ - public void addPreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { + public void addPreferenceChangeListener(final IPreferenceChangeListener themeChangeListener) { // Observe change of Eclipse E4 Theme IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); if (preferences != null) { @@ -167,7 +167,7 @@ public void addPreferenceChangeListener(IPreferenceChangeListener themeChangeLis * * @param themeChangeListener */ - public void removePreferenceChangeListener(IPreferenceChangeListener themeChangeListener) { + public void removePreferenceChangeListener(final IPreferenceChangeListener themeChangeListener) { // Observe change of Eclipse E4 Theme IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); if (preferences != null) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java index d2f99afc7..15f67f05c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java @@ -33,26 +33,26 @@ public final class WorkingCopyThemeManager extends AbstractThemeManager { private List associationAdded; private List associationRemoved; - public WorkingCopyThemeManager(IThemeManager manager) { + public WorkingCopyThemeManager(final IThemeManager manager) { this.manager = manager; load(); } private void load() { // Copy themes - ITheme[] themes = manager.getThemes(); - for (ITheme theme : themes) { + final ITheme[] themes = manager.getThemes(); + for (final ITheme theme : themes) { super.registerTheme(theme); } // Copy theme associations - IThemeAssociation[] associations = manager.getAllThemeAssociations(); - for (IThemeAssociation association : associations) { + final IThemeAssociation[] associations = manager.getAllThemeAssociations(); + for (final IThemeAssociation association : associations) { super.registerThemeAssociation(association); } } @Override - public void registerTheme(ITheme theme) { + public void registerTheme(final ITheme theme) { super.registerTheme(theme); if (themeAdded == null) { themeAdded = new ArrayList<>(); @@ -61,7 +61,7 @@ public void registerTheme(ITheme theme) { } @Override - public void unregisterTheme(ITheme theme) { + public void unregisterTheme(final ITheme theme) { super.unregisterTheme(theme); if (themeAdded != null && themeAdded.contains(theme)) { themeAdded.remove(theme); @@ -74,7 +74,7 @@ public void unregisterTheme(ITheme theme) { } @Override - public void registerThemeAssociation(IThemeAssociation association) { + public void registerThemeAssociation(final IThemeAssociation association) { super.registerThemeAssociation(association); if (associationAdded == null) { associationAdded = new ArrayList<>(); @@ -83,7 +83,7 @@ public void registerThemeAssociation(IThemeAssociation association) { } @Override - public void unregisterThemeAssociation(IThemeAssociation association) { + public void unregisterThemeAssociation(final IThemeAssociation association) { super.unregisterThemeAssociation(association); if (associationAdded != null && associationAdded.contains(association)) { associationAdded.remove(association); @@ -98,22 +98,22 @@ public void unregisterThemeAssociation(IThemeAssociation association) { @Override public void save() throws BackingStoreException { if (themeAdded != null) { - for (ITheme theme : themeAdded) { + for (final ITheme theme : themeAdded) { manager.registerTheme(theme); } } if (themeRemoved != null) { - for (ITheme theme : themeRemoved) { + for (final ITheme theme : themeRemoved) { manager.unregisterTheme(theme); } } if (associationAdded != null) { - for (IThemeAssociation association : associationAdded) { + for (final IThemeAssociation association : associationAdded) { manager.registerThemeAssociation(association); } } if (associationRemoved != null) { - for (IThemeAssociation association : associationRemoved) { + for (final IThemeAssociation association : associationRemoved) { manager.unregisterThemeAssociation(association); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java index e3c2b2330..322f58426 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java @@ -20,33 +20,33 @@ public final class ClassHelper { @SuppressWarnings("unchecked") - public static T getFieldValue(Object object, String name, Class clazz) { - Field f = getDeclaredField(clazz, name); + public static T getFieldValue(final Object object, final String name, final Class clazz) { + final Field f = getDeclaredField(clazz, name); if (f != null) { try { return (T) f.get(object); - } catch (Exception e) { + } catch (final Exception e) { return null; } } return null; } - public static T getFieldValue(Object object, String name) { + public static T getFieldValue(final Object object, final String name) { return getFieldValue(object, name, object.getClass()); } - public static Field getDeclaredField(Class clazz, String name) { + public static Field getDeclaredField(final Class clazz, final String name) { if (clazz == null) { return null; } try { - Field f = clazz.getDeclaredField(name); + final Field f = clazz.getDeclaredField(name); f.setAccessible(true); return f; - } catch (NoSuchFieldException e) { + } catch (final NoSuchFieldException e) { return getDeclaredField(clazz.getSuperclass(), name); - } catch (SecurityException e) { + } catch (final SecurityException e) { return null; } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java index 4030100d8..0c53398dc 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java @@ -50,9 +50,9 @@ public final class ContentTypeHelper { * otherwise. * @throws CoreException */ - public static ContentTypeInfo findContentTypes(IDocument document) throws CoreException { + public static ContentTypeInfo findContentTypes(final IDocument document) throws CoreException { // Find content types from FileBuffers - ContentTypeInfo contentTypes = findContentTypesFromFileBuffers(document); + final ContentTypeInfo contentTypes = findContentTypesFromFileBuffers(document); if (contentTypes != null) { return contentTypes; } @@ -66,8 +66,8 @@ public static ContentTypeInfo findContentTypes(IDocument document) throws CoreEx * @param contentTypeId * @return matching content type or null */ - public static IContentType getContentTypeById(String contentTypeId) { - IContentTypeManager manager = Platform.getContentTypeManager(); + public static IContentType getContentTypeById(final String contentTypeId) { + final IContentTypeManager manager = Platform.getContentTypeManager(); return manager.getContentType(contentTypeId); } @@ -82,9 +82,9 @@ public static IContentType getContentTypeById(String contentTypeId) { * {@link ITextFileBufferManager} and null otherwise. * @throws CoreException */ - private static ContentTypeInfo findContentTypesFromFileBuffers(IDocument document) throws CoreException { - ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); - ITextFileBuffer buffer = bufferManager.getTextFileBuffer(document); + private static ContentTypeInfo findContentTypesFromFileBuffers(final IDocument document) throws CoreException { + final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); + final ITextFileBuffer buffer = bufferManager.getTextFileBuffer(document); if (buffer != null) { return getContentTypes(buffer); } @@ -98,11 +98,11 @@ private static ContentTypeInfo findContentTypesFromFileBuffers(IDocument documen * @return the content types from the given {@link ITextFileBuffer}. * @throws CoreException */ - private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws CoreException { + private static ContentTypeInfo getContentTypes(final ITextFileBuffer buffer) throws CoreException { try { - String fileName = buffer.getFileStore().getName(); - Collection contentTypes = new LinkedHashSet<>(); - IContentType bufferContentType = buffer.getContentType(); + final String fileName = buffer.getFileStore().getName(); + final Collection contentTypes = new LinkedHashSet<>(); + final IContentType bufferContentType = buffer.getContentType(); if (bufferContentType != null) { contentTypes.add(bufferContentType); } @@ -110,7 +110,7 @@ private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws Co // Buffer is dirty (content of the filesystem is not synch with // the editor content), use IDocument content. try (InputStream input = new DocumentInputStream(buffer.getDocument())) { - IContentType[] contentTypesForInput = Platform.getContentTypeManager().findContentTypesFor(input, fileName); + final IContentType[] contentTypesForInput = Platform.getContentTypeManager().findContentTypesFor(input, fileName); if (contentTypesForInput != null) { contentTypes.addAll(Arrays.asList(contentTypesForInput)); return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new)); @@ -122,10 +122,10 @@ private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws Co try (InputStream contents = getContents(buffer)) { contentTypes.addAll(Arrays.asList(Platform.getContentTypeManager().findContentTypesFor(contents, fileName))); return new ContentTypeInfo(fileName, contentTypes.toArray(IContentType[]::new)); - } catch (Throwable e) { + } catch (final Throwable e) { return null; } - } catch (IOException x) { + } catch (final IOException x) { x.printStackTrace(); return null; } @@ -138,11 +138,11 @@ private static ContentTypeInfo getContentTypes(ITextFileBuffer buffer) throws Co * @return the content of the given buffer. * @throws CoreException */ - private static InputStream getContents(ITextFileBuffer buffer) throws CoreException { - IPath path = buffer.getLocation(); + private static InputStream getContents(final ITextFileBuffer buffer) throws CoreException { + final IPath path = buffer.getLocation(); if (path != null) { - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IFile file = workspaceRoot.getFile(path); + final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + final IFile file = workspaceRoot.getFile(path); if (file.exists() && buffer.isSynchronized()) { return file.getContents(); } @@ -160,18 +160,18 @@ private static InputStream getContents(ITextFileBuffer buffer) throws CoreExcept * @return the content types from the given {@link IDocument} by using * {@link IEditorInput} and null otherwise. */ - private static ContentTypeInfo findContentTypesFromEditorInput(IDocument document) { - IEditorInput editorInput = getEditorInput(document); + private static ContentTypeInfo findContentTypesFromEditorInput(final IDocument document) { + final IEditorInput editorInput = getEditorInput(document); if (editorInput != null) { if (editorInput instanceof IStorageEditorInput) { try { - IStorage storage = ((IStorageEditorInput) editorInput).getStorage(); - String fileName = storage.getName(); + final IStorage storage = ((IStorageEditorInput) editorInput).getStorage(); + final String fileName = storage.getName(); try (InputStream input = storage.getContents()) { return new ContentTypeInfo(fileName, Platform.getContentTypeManager().findContentTypesFor(input, fileName)); } - } catch (Exception e) { + } catch (final Exception e) { return null; } } else { @@ -187,7 +187,7 @@ private static ContentTypeInfo findContentTypesFromEditorInput(IDocument documen * @param document * @return the {@link IEditorInput} from the given document and null otherwise. */ - private static IEditorInput getEditorInput(IDocument document) { + private static IEditorInput getEditorInput(final IDocument document) { try { // This utilities class is very ugly, I have not found a clean mean // to retrieve the IEditorInput linked to a document. @@ -199,24 +199,24 @@ private static IEditorInput getEditorInput(IDocument document) { // ISorageEditorInput, see StorageDocumentProvider) // get list of IDocumentListener - ListenerList listeners = ClassHelper.getFieldValue(document, "fDocumentListeners"); + final ListenerList listeners = ClassHelper.getFieldValue(document, "fDocumentListeners"); if (listeners != null) { // Get AbstractDocumentProvider#ElementInfo - Object[] l = listeners.getListeners(); + final Object[] l = listeners.getListeners(); for (int i = 0; i < l.length; i++) { - Object /* AbstractDocumentProvider#ElementInfo */ info = l[i]; + final Object /* AbstractDocumentProvider#ElementInfo */ info = l[i]; try { /* The element for which the info is stored */ - Object input = ClassHelper.getFieldValue(info, "fElement"); + final Object input = ClassHelper.getFieldValue(info, "fElement"); if (input instanceof IEditorInput) { return (IEditorInput) input; } - } catch (Exception e) { + } catch (final Exception e) { } } } - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } return null; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java index d97a0d3c8..3d9a21db3 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java @@ -23,7 +23,7 @@ public final class ContentTypeInfo { private final String fileName; private final IContentType[] contentTypes; - public ContentTypeInfo(String fileName, IContentType[] contentTypes) { + public ContentTypeInfo(final String fileName, final IContentType[] contentTypes) { this.fileName = fileName; this.contentTypes = contentTypes; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java index 735cb714a..8a1a4477a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java @@ -40,7 +40,7 @@ public static IEclipsePreferences getE4PreferenceStore() { * @return themeIf of the current eclipse theme */ public static String getE4PreferenceCSSThemeId() { - IEclipsePreferences preferences = getE4PreferenceStore(); + final IEclipsePreferences preferences = getE4PreferenceStore(); return preferences != null ? preferences.get(PreferenceConstants.E4_THEME_ID, null) : null; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java index a52a02611..7bb27ba1b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java @@ -28,7 +28,7 @@ public final class ColumnSelectionAdapter extends SelectionAdapter { private final int fColumnIndex; private final ColumnViewerComparator viewerComparator; - public ColumnSelectionAdapter(TableColumn column, TableViewer tableViewer, int index, ColumnViewerComparator vc) { + public ColumnSelectionAdapter(final TableColumn column, final TableViewer tableViewer, final int index, final ColumnViewerComparator vc) { fTableColumn = column; this.tableViewer = tableViewer; fColumnIndex = index; @@ -36,10 +36,10 @@ public ColumnSelectionAdapter(TableColumn column, TableViewer tableViewer, int i } @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(final SelectionEvent e) { viewerComparator.setColumn(fColumnIndex); - int dir = viewerComparator.getDirection(); - Table table = tableViewer.getTable(); + final int dir = viewerComparator.getDirection(); + final Table table = tableViewer.getTable(); table.setSortDirection(dir); table.setSortColumn(fTableColumn); tableViewer.refresh(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java index 1a04a3181..ab5c97d18 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java @@ -43,7 +43,7 @@ public int getDirection() { * @param column * New sort column */ - public void setColumn(int column) { + public void setColumn(final int column) { if (column == fSortColumn) { fSortOrder *= -1; } else { @@ -53,14 +53,14 @@ public void setColumn(int column) { } @Override - public int compare(Viewer viewer, Object e1, Object e2) { + public int compare(final Viewer viewer, final Object e1, final Object e2) { if (viewer instanceof TableViewer) { - IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider(); + final IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider(); - String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); - String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); - int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : ""); + final String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); + final String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); + final int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : ""); return sortResult * fSortOrder; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java index 1a524d58f..96baee69b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java @@ -23,24 +23,24 @@ public final class ContentTypeLabelProvider extends LabelProvider implements ITableLabelProvider { @Override - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(final Object element, final int columnIndex) { return null; } @Override - public String getText(Object element) { + public String getText(final Object element) { return getColumnText(element, 0); } @Override - public String getColumnText(Object element, int columnIndex) { + public String getColumnText(final Object element, final int columnIndex) { switch (columnIndex) { case 0: IContentType contentType = null; if(element instanceof IContentType) { contentType = (IContentType) element; } else if(element instanceof String) { - String contentTypeId = (String) element; + final String contentTypeId = (String) element; contentType = Platform.getContentTypeManager().getContentType(contentTypeId); if (contentType == null) { return contentTypeId; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java index 626908a13..67dd34003 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypesBindingWidget.java @@ -22,13 +22,13 @@ */ public final class ContentTypesBindingWidget extends TableAndButtonsWidget { - public ContentTypesBindingWidget(Composite parent, int style) { + public ContentTypesBindingWidget(final Composite parent, final int style) { super(parent, style, TMUIMessages.ContentTypesBindingWidget_description); super.setContentProvider(ArrayContentProvider.getInstance()); super.setLabelProvider(new ContentTypeLabelProvider()); } @Override - protected void createButtons(Composite parent) { + protected void createButtons(final Composite parent) { } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java index 823427f00..dc1ebe2b4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java @@ -24,12 +24,12 @@ public final class GrammarDefinitionContentProvider implements IStructuredConten private IGrammarRegistryManager registry; @Override - public Object[] getElements(Object input) { + public Object[] getElements(final Object input) { return registry.getDefinitions(); } @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { registry = (IGrammarRegistryManager) newInput; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java index 931739324..86adcaac4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java @@ -22,18 +22,18 @@ public final class GrammarDefinitionLabelProvider extends LabelProvider implements ITableLabelProvider { @Override - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(final Object element, final int columnIndex) { return null; } @Override - public String getText(Object element) { + public String getText(final Object element) { return getColumnText(element, 0); } @Override - public String getColumnText(Object element, int columnIndex) { - IGrammarDefinition definition = (IGrammarDefinition) element; + public String getColumnText(final Object element, final int columnIndex) { + final IGrammarDefinition definition = (IGrammarDefinition) element; switch (columnIndex) { case 0: diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java index 3c90bcf84..7459af7d1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java @@ -34,9 +34,9 @@ public final class GrammarInfoWidget extends Composite { private Text scopeNameText; private Text fileTypesText; - public GrammarInfoWidget(Composite parent, int style) { + public GrammarInfoWidget(final Composite parent, final int style) { super(parent, style); - GridLayout layout = new GridLayout(); + final GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; @@ -46,9 +46,9 @@ public GrammarInfoWidget(Composite parent, int style) { createUI(this); } - private void createUI(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(2, false); + private void createUI(final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); + final GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; @@ -56,34 +56,34 @@ private void createUI(Composite ancestor) { parent.setLayout(layout); parent.setLayoutData(new GridData(GridData.FILL_BOTH)); - Label grammarNameLabel = new Label(parent, SWT.NONE); + final Label grammarNameLabel = new Label(parent, SWT.NONE); grammarNameLabel.setText(TMUIMessages.GrammarInfoWidget_name_text); nameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Label grammarScopeNameLabel = new Label(parent, SWT.NONE); + final Label grammarScopeNameLabel = new Label(parent, SWT.NONE); grammarScopeNameLabel.setText(TMUIMessages.GrammarInfoWidget_scopeName_text); scopeNameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); scopeNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Label grammarFileTypesLabel = new Label(parent, SWT.NONE); + final Label grammarFileTypesLabel = new Label(parent, SWT.NONE); grammarFileTypesLabel.setText(TMUIMessages.GrammarInfoWidget_fileTypes_text); fileTypesText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); fileTypesText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } - public void refresh(IGrammar grammar) { + public void refresh(final IGrammar grammar) { if (grammar == null) { nameText.setText(""); scopeNameText.setText(""); fileTypesText.setText(""); } else { - String name = grammar.getName(); + final String name = grammar.getName(); nameText.setText(name != null ? name : ""); - String scope = grammar.getScopeName(); + final String scope = grammar.getScopeName(); scopeNameText.setText(scope != null ? scope : ""); - Collection fileTypes = grammar.getFileTypes(); - String types = fileTypes.stream().map(Object::toString).collect(Collectors.joining(",")); + final Collection fileTypes = grammar.getFileTypes(); + final String types = fileTypes.stream().map(Object::toString).collect(Collectors.joining(",")); fileTypesText.setText(types); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java index fc92b095a..93785f094 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java @@ -33,49 +33,49 @@ public final class TMViewer extends SourceViewer { private TMPresentationReconciler reconciler; - public TMViewer(Composite parent, IVerticalRuler ruler, int styles) { + public TMViewer(final Composite parent, final IVerticalRuler ruler, final int styles) { super(parent, ruler, styles); init(); } - public TMViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, - boolean showAnnotationsOverview, int styles) { + public TMViewer(final Composite parent, final IVerticalRuler verticalRuler, final IOverviewRuler overviewRuler, + final boolean showAnnotationsOverview, final int styles) { super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); init(); } private void init() { this.reconciler = new TMPresentationReconciler(); - SourceViewerConfiguration configuration = new TMSourceViewerConfiguration(); + final SourceViewerConfiguration configuration = new TMSourceViewerConfiguration(); this.configure(configuration); } private final class TMSourceViewerConfiguration extends SourceViewerConfiguration { @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + public IPresentationReconciler getPresentationReconciler(final ISourceViewer sourceViewer) { return reconciler; } } - public void setGrammar(IGrammar grammar) { + public void setGrammar(final IGrammar grammar) { reconciler.setGrammar(grammar); if (getDocument() == null) { super.setDocument(new Document()); } } - public void setTheme(ITheme theme) { + public void setTheme(final ITheme theme) { reconciler.setTheme(theme); - StyledText styledText = getTextWidget(); + final StyledText styledText = getTextWidget(); styledText.setForeground(null); styledText.setBackground(null); theme.initializeViewerColors(styledText); getTextWidget().setFont(JFaceResources.getTextFont()); } - public void setText(String text) { + public void setText(final String text) { if (getDocument() == null) { super.setDocument(new Document()); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java index e0ef6899b..22fc0eaeb 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java @@ -31,9 +31,9 @@ public abstract class TableAndButtonsWidget extends Composite { private TableViewer viewer; - protected TableAndButtonsWidget(Composite parent, int style, String title) { + protected TableAndButtonsWidget(final Composite parent, final int style, final String title) { super(parent, style); - GridLayout layout = new GridLayout(); + final GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; @@ -42,8 +42,8 @@ protected TableAndButtonsWidget(Composite parent, int style, String title) { createUI(title, this); } - private void createUI(String title, Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); + private void createUI(final String title, final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; @@ -59,7 +59,7 @@ private void createUI(String title, Composite ancestor) { createTable(parent); // Buttons - Composite buttonsComposite = new Composite(parent, SWT.NONE); + final Composite buttonsComposite = new Composite(parent, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; @@ -72,19 +72,19 @@ private void createUI(String title, Composite ancestor) { protected abstract void createButtons(Composite parent); - private void createTitle(String title, Composite ancestor) { + private void createTitle(final String title, final Composite ancestor) { if (title == null) { return; } - Label label = new Label(ancestor, SWT.NONE); + final Label label = new Label(ancestor, SWT.NONE); label.setText(title); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + final GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; label.setLayoutData(data); } - private void createTable(Composite parent) { - Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); + private void createTable(final Composite parent) { + final Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); table.setHeaderVisible(false); table.setLinesVisible(false); @@ -93,7 +93,7 @@ private void createTable(Composite parent) { } - public void setInput(Object input) { + public void setInput(final Object input) { viewer.setInput(input); } @@ -101,19 +101,19 @@ public TableViewer getViewer() { return viewer; } - public void setLabelProvider(IBaseLabelProvider labelProvider) { + public void setLabelProvider(final IBaseLabelProvider labelProvider) { viewer.setLabelProvider(labelProvider); } - public void setContentProvider(IContentProvider provider) { + public void setContentProvider(final IContentProvider provider) { viewer.setContentProvider(provider); } - public void addSelectionChangedListener(ISelectionChangedListener listener) { + public void addSelectionChangedListener(final ISelectionChangedListener listener) { viewer.addSelectionChangedListener(listener); } - public void setSelection(IStructuredSelection selection) { + public void setSelection(final IStructuredSelection selection) { viewer.setSelection(selection); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java index 057456c20..bed97d1cd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java @@ -27,22 +27,22 @@ public final class ThemeAssociationLabelProvider extends LabelProvider implements ITableLabelProvider { @Override - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(final Object element, final int columnIndex) { return null; } @Override - public String getText(Object element) { + public String getText(final Object element) { return getColumnText(element, 0); } @Override - public String getColumnText(Object element, int columnIndex) { - IThemeAssociation association = (IThemeAssociation) element; + public String getColumnText(final Object element, final int columnIndex) { + final IThemeAssociation association = (IThemeAssociation) element; switch (columnIndex) { case 0: - ITheme theme = getTheme(association); - String themeName = theme != null ? theme.getName() : association.getThemeId(); + final ITheme theme = getTheme(association); + final String themeName = theme != null ? theme.getName() : association.getThemeId(); if (association.isWhenDark()) { return NLS.bind(TMUIMessages.ThemeAssociationLabelProvider_dark, themeName); } @@ -52,9 +52,9 @@ public String getColumnText(Object element, int columnIndex) { } } - private ITheme getTheme(IThemeAssociation association) { - String themeId = association.getThemeId(); - IThemeManager themeManager = TMUIPlugin.getThemeManager(); + private ITheme getTheme(final IThemeAssociation association) { + final String themeId = association.getThemeId(); + final IThemeManager themeManager = TMUIPlugin.getThemeManager(); return themeManager.getThemeById(themeId); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java index a887a8466..25b3e68d2 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java @@ -43,7 +43,7 @@ public final class ThemeAssociationsWidget extends TableAndButtonsWidget { private IGrammarDefinition definition; - public ThemeAssociationsWidget(IThemeManager themeManager, Composite parent, int style) { + public ThemeAssociationsWidget(final IThemeManager themeManager, final Composite parent, final int style) { super(parent, style, TMUIMessages.ThemeAssociationsWidget_description); this.themeManager = themeManager; super.setContentProvider(ArrayContentProvider.getInstance()); @@ -51,20 +51,20 @@ public ThemeAssociationsWidget(IThemeManager themeManager, Composite parent, int } @Override - protected void createButtons(Composite parent) { + protected void createButtons(final Composite parent) { editButton = new Button(parent, SWT.PUSH); editButton.setText(TMUIMessages.Button_edit); editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); editButton.addListener(SWT.Selection, e -> { // Open the wizard to create association between theme and grammar. - CreateThemeAssociationWizard wizard = new CreateThemeAssociationWizard(false); + final CreateThemeAssociationWizard wizard = new CreateThemeAssociationWizard(false); wizard.setInitialDefinition(definition); - IStructuredSelection selection = super.getSelection(); + final IStructuredSelection selection = super.getSelection(); wizard.setInitialAssociation(selection.isEmpty() ? null : (IThemeAssociation) selection.getFirstElement()); wizard.setThemeManager(themeManager); - WizardDialog dialog = new WizardDialog(getShell(), wizard); + final WizardDialog dialog = new WizardDialog(getShell(), wizard); if (dialog.open() == Window.OK) { - IThemeAssociation association = wizard.getCreatedThemeAssociation(); + final IThemeAssociation association = wizard.getCreatedThemeAssociation(); refresh(association); } }); @@ -77,10 +77,10 @@ protected void createButtons(Composite parent) { if (MessageDialog.openConfirm(getShell(), TMUIMessages.ThemeAssociationsWidget_remove_dialog_title, TMUIMessages.ThemeAssociationsWidget_remove_dialog_message)) { - IStructuredSelection selection = super.getSelection(); - Iterator it = selection.iterator(); + final IStructuredSelection selection = super.getSelection(); + final Iterator it = selection.iterator(); while (it.hasNext()) { - IThemeAssociation association = it.next(); + final IThemeAssociation association = it.next(); themeManager.unregisterThemeAssociation(association); } refresh(null); @@ -98,13 +98,13 @@ public Button getRemoveButton() { return removeButton; } - public IThemeAssociation[] setGrammarDefinition(IGrammarDefinition definition) { + public IThemeAssociation[] setGrammarDefinition(final IGrammarDefinition definition) { this.definition = definition; return refresh(null); } private IThemeAssociation[] refresh(IThemeAssociation association) { - IThemeAssociation[] themeAssociations = themeManager.getThemeAssociationsForScope(definition.getScopeName()); + final IThemeAssociation[] themeAssociations = themeManager.getThemeAssociationsForScope(definition.getScopeName()); // Refresh the list of associations super.setInput(themeAssociations); // Select the first of given association diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java index 7c70c4595..a84e7ffa3 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java @@ -24,12 +24,12 @@ public final class ThemeContentProvider implements IStructuredContentProvider { private IThemeManager registry; @Override - public Object[] getElements(Object input) { + public Object[] getElements(final Object input) { return registry.getThemes(); } @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { registry = (IThemeManager) newInput; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java index 6a9b38504..4cece1a96 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java @@ -22,19 +22,19 @@ public final class ThemeLabelProvider extends LabelProvider implements ITableLabelProvider { @Override - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(final Object element, final int columnIndex) { return null; } @Override - public String getText(Object element) { - ITheme theme = (ITheme) element; + public String getText(final Object element) { + final ITheme theme = (ITheme) element; return theme.getName(); } @Override - public String getColumnText(Object element, int columnIndex) { - ITheme theme = (ITheme) element; + public String getColumnText(final Object element, final int columnIndex) { + final ITheme theme = (ITheme) element; switch (columnIndex) { case 0: return theme.getName(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java index e3a63159f..2b05f5b0c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java @@ -31,19 +31,19 @@ */ abstract class AbstractWizardPage extends WizardPage implements Listener { - protected AbstractWizardPage(String pageName) { + protected AbstractWizardPage(final String pageName) { super(pageName); } - protected AbstractWizardPage(String pageName, String title, ImageDescriptor titleImage) { + protected AbstractWizardPage(final String pageName, final String title, final ImageDescriptor titleImage) { super(pageName, title, titleImage); } @Override - public final void createControl(Composite parent) { + public final void createControl(final Composite parent) { initializeDialogUnits(parent); // top level group - Composite topLevel = new Composite(parent, SWT.NONE); + final Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout()); topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); topLevel.setFont(parent.getFont()); @@ -58,16 +58,16 @@ public final void createControl(Composite parent) { } @Override - public void handleEvent(Event event) { + public void handleEvent(final Event event) { validateAndUpdateStatus(event); } - private void validateAndUpdateStatus(Event event) { - IStatus status = validatePage(event); + private void validateAndUpdateStatus(final Event event) { + final IStatus status = validatePage(event); statusChanged(status == null ? Status.OK_STATUS : status); } - void statusChanged(IStatus status) { + void statusChanged(final IStatus status) { setPageComplete(!status.matches(IStatus.ERROR)); applyToStatusLine(this, status); } @@ -75,7 +75,7 @@ void statusChanged(IStatus status) { /** * Applies the status to the status line of a dialog page. */ - private static void applyToStatusLine(DialogPage page, IStatus status) { + private static void applyToStatusLine(final DialogPage page, final IStatus status) { String message = Status.OK_STATUS.equals(status) ? null : status.getMessage(); switch (status.getSeverity()) { case IStatus.OK: diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java index ac3622dfb..c66c810b8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java @@ -36,7 +36,7 @@ public final class CreateThemeAssociationWizard extends Wizard { private IThemeAssociation initialAssociation; - public CreateThemeAssociationWizard(boolean save) { + public CreateThemeAssociationWizard(final boolean save) { this.save = save; } @@ -45,7 +45,7 @@ public CreateThemeAssociationWizard(boolean save) { * * @param themeManager */ - public void setThemeManager(IThemeManager themeManager) { + public void setThemeManager(final IThemeManager themeManager) { this.themeManager = themeManager; } @@ -57,12 +57,12 @@ public void addPages() { @Override public boolean performFinish() { - IThemeAssociation association = mainPage.getThemeAssociation(); + final IThemeAssociation association = mainPage.getThemeAssociation(); themeManager.registerThemeAssociation(association); if (save) { try { themeManager.save(); - } catch (BackingStoreException e) { + } catch (final BackingStoreException e) { e.printStackTrace(); return false; } @@ -75,11 +75,11 @@ public IThemeAssociation getCreatedThemeAssociation() { return createdThemeAssociation; } - public void setInitialDefinition(IGrammarDefinition definition) { + public void setInitialDefinition(final IGrammarDefinition definition) { this.initialDefinition = definition; } - public void setInitialAssociation(IThemeAssociation association) { + public void setInitialAssociation(final IThemeAssociation association) { this.initialAssociation = association; } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java index 7e69fe259..bcb8d3024 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java @@ -49,8 +49,8 @@ final class CreateThemeAssociationWizardPage extends AbstractWizardPage { private Button whenDarkButton; - protected CreateThemeAssociationWizardPage(IGrammarDefinition initialDefinition, - IThemeAssociation initialAssociation) { + protected CreateThemeAssociationWizardPage(final IGrammarDefinition initialDefinition, + final IThemeAssociation initialAssociation) { super(PAGE_NAME); super.setTitle(TMUIMessages.CreateThemeAssociationWizardPage_title); super.setDescription(TMUIMessages.CreateThemeAssociationWizardPage_description); @@ -59,8 +59,8 @@ protected CreateThemeAssociationWizardPage(IGrammarDefinition initialDefinition, } @Override - protected void createBody(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); + protected void createBody(final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); parent.setFont(parent.getFont()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); parent.setLayout(new GridLayout(4, false)); @@ -90,11 +90,11 @@ protected void createBody(Composite ancestor) { whenDarkButton = new Button(parent, SWT.CHECK); whenDarkButton.setText(TMUIMessages.CreateThemeAssociationWizardPage_whenDark_text); - GridData data = new GridData(); + final GridData data = new GridData(); data.horizontalSpan = 4; whenDarkButton.setLayoutData(data); if (initialAssociation != null) { - ITheme selectedTheme = TMUIPlugin.getThemeManager().getThemeById(initialAssociation.getThemeId()); + final ITheme selectedTheme = TMUIPlugin.getThemeManager().getThemeById(initialAssociation.getThemeId()); if (selectedTheme != null) { themeViewer.setSelection(new StructuredSelection(selectedTheme)); } @@ -108,7 +108,7 @@ protected void initializeDefaultValues() { } @Override - protected IStatus validatePage(Event event) { + protected IStatus validatePage(final Event event) { if (themeViewer.getSelection().isEmpty()) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.CreateThemeAssociationWizardPage_theme_error_required); @@ -121,10 +121,10 @@ protected IStatus validatePage(Event event) { } IThemeAssociation getThemeAssociation() { - String themeId = ((ITheme) themeViewer.getStructuredSelection().getFirstElement()).getId(); - String scopeName = ((IGrammarDefinition) grammarViewer.getStructuredSelection().getFirstElement()) + final String themeId = ((ITheme) themeViewer.getStructuredSelection().getFirstElement()).getId(); + final String scopeName = ((IGrammarDefinition) grammarViewer.getStructuredSelection().getFirstElement()) .getScopeName(); - boolean whenDark = whenDarkButton.getSelection(); + final boolean whenDark = whenDarkButton.getSelection(); return new ThemeAssociation(themeId, scopeName, whenDark); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java index bc2591ec8..0ba96af39 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java @@ -64,8 +64,8 @@ protected SelectGrammarWizardPage() { } @Override - protected void createBody(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); + protected void createBody(final Composite ancestor) { + final Composite parent = new Composite(ancestor, SWT.NONE); parent.setFont(parent.getFont()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); parent.setLayout(new GridLayout(2, false)); @@ -75,9 +75,9 @@ protected void createBody(Composite ancestor) { grammarFileText.addListener(SWT.Modify, this); // Buttons - Composite buttons = new Composite(parent, SWT.NONE); + final Composite buttons = new Composite(parent, SWT.NONE); buttons.setLayout(new GridLayout(2, false)); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); + final GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; gd.horizontalAlignment = SWT.RIGHT; buttons.setLayoutData(gd); @@ -86,11 +86,11 @@ protected void createBody(Composite ancestor) { browseFileSystemButton.setText(TMUIMessages.Button_browse_FileSystem); browseFileSystemButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(parent.getShell()); + public void widgetSelected(final SelectionEvent e) { + final FileDialog dialog = new FileDialog(parent.getShell()); dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); dialog.setFilterPath(grammarFileText.getText()); - String result = dialog.open(); + final String result = dialog.open(); if (result != null && !result.isEmpty()) { grammarFileText.setText(result); } @@ -101,22 +101,22 @@ public void widgetSelected(SelectionEvent e) { browseWorkspaceButton.setText(TMUIMessages.Button_browse_Workspace); browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(final SelectionEvent e) { // TODO } }); grammarInfoWidget = new GrammarInfoWidget(parent, SWT.NONE); - GridData data = new GridData(GridData.FILL_HORIZONTAL); + final GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; grammarInfoWidget.setLayoutData(data); } - private Text createText(Composite parent, String s) { - Label label = new Label(parent, SWT.NONE); + private Text createText(final Composite parent, final String s) { + final Label label = new Label(parent, SWT.NONE); label.setText(s); - Text text = new Text(parent, SWT.BORDER); + final Text text = new Text(parent, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return text; } @@ -127,23 +127,23 @@ protected void initializeDefaultValues() { } @Override - protected IStatus validatePage(Event event) { + protected IStatus validatePage(final Event event) { grammarInfoWidget.refresh(null); - String path = grammarFileText.getText(); + final String path = grammarFileText.getText(); if (path.isEmpty()) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.SelectGrammarWizardPage_file_error_required); } - File f = new File(path); - Registry registry = new Registry(); + final File f = new File(path); + final Registry registry = new Registry(); try(InputStream is = new FileInputStream(f)) { - IGrammar grammar = registry.loadGrammarFromPathSync(f.getName(), is); + final IGrammar grammar = registry.loadGrammarFromPathSync(f.getName(), is); if (grammar == null || grammar.getScopeName() == null) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.SelectGrammarWizardPage_file_error_invalid); } grammarInfoWidget.refresh(grammar); - } catch (Exception e) { + } catch (final Exception e) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, NLS.bind(TMUIMessages.SelectGrammarWizardPage_file_error_load, e.getMessage()), e); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java index 4be8b371f..8c0cb2df6 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java @@ -34,7 +34,7 @@ public final class TextMateGrammarImportWizard extends Wizard implements IImport private final boolean save; - public TextMateGrammarImportWizard(boolean save) { + public TextMateGrammarImportWizard(final boolean save) { this.save = save; } @@ -43,7 +43,7 @@ public TextMateGrammarImportWizard(boolean save) { * * @param grammarRegistryManager */ - public void setGrammarRegistryManager(IGrammarRegistryManager grammarRegistryManager) { + public void setGrammarRegistryManager(final IGrammarRegistryManager grammarRegistryManager) { this.grammarRegistryManager = grammarRegistryManager; } @@ -55,12 +55,12 @@ public void addPages() { @Override public boolean performFinish() { - IGrammarDefinition definition = mainPage.getGrammarDefinition(); + final IGrammarDefinition definition = mainPage.getGrammarDefinition(); grammarRegistryManager.registerGrammarDefinition(definition); if (save) { try { grammarRegistryManager.save(); - } catch (BackingStoreException e) { + } catch (final BackingStoreException e) { e.printStackTrace(); return false; } @@ -70,7 +70,7 @@ public boolean performFinish() { } @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { + public void init(final IWorkbench workbench, final IStructuredSelection selection) { } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index 21e8430d5..2dd4a1a0e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -147,8 +147,8 @@ public TMPresentationReconciler() { private final class ThemeChangeListener implements IPreferenceChangeListener { @Override - public void preferenceChange(PreferenceChangeEvent event) { - IThemeManager themeManager = TMUIPlugin.getThemeManager(); + public void preferenceChange(final PreferenceChangeEvent event) { + final IThemeManager themeManager = TMUIPlugin.getThemeManager(); switch (event.getKey()) { case PreferenceConstants.E4_THEME_ID: preferenceThemeChange((String) event.getNewValue(), themeManager); @@ -159,8 +159,8 @@ public void preferenceChange(PreferenceChangeEvent event) { } } - private void preferenceThemeChange(String eclipseThemeId, IThemeManager themeManager) { - IDocument document = viewer.getDocument(); + private void preferenceThemeChange(final String eclipseThemeId, final IThemeManager themeManager) { + final IDocument document = viewer.getDocument(); if (document == null) { return; } @@ -168,8 +168,8 @@ private void preferenceThemeChange(String eclipseThemeId, IThemeManager themeMan return; } // Select the well TextMate theme from the given E4 theme id. - boolean dark = themeManager.isDarkEclipseTheme(eclipseThemeId); - ITokenProvider newTheme = themeManager.getThemeForScope(grammar.getScopeName(), dark); + final boolean dark = themeManager.isDarkEclipseTheme(eclipseThemeId); + final ITokenProvider newTheme = themeManager.getThemeForScope(grammar.getScopeName(), dark); setTheme(newTheme); } } @@ -179,9 +179,9 @@ private void preferenceThemeChange(String eclipseThemeId, IThemeManager themeMan */ class InternalListener implements ITextInputListener, IModelTokensChangedListener, ITextListener { - private void fireInstall(ITextViewer viewer, IDocument document) { + private void fireInstall(final ITextViewer viewer, final IDocument document) { synchronized (listeners) { - for (ITMPresentationReconcilerListener listener : listeners) { + for (final ITMPresentationReconcilerListener listener : listeners) { listener.install(viewer, document); } } @@ -189,14 +189,14 @@ private void fireInstall(ITextViewer viewer, IDocument document) { private void fireUninstall() { synchronized (listeners) { - for (ITMPresentationReconcilerListener listener : listeners) { + for (final ITMPresentationReconcilerListener listener : listeners) { listener.uninstall(); } } } @Override - public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDocument) { + public void inputDocumentAboutToBeChanged(final IDocument oldDocument, final IDocument newDocument) { if (oldDocument != null) { viewer.removeTextListener(this); getTMModelManager().disconnect(oldDocument); @@ -205,7 +205,7 @@ public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDo } @Override - public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { + public void inputDocumentChanged(final IDocument oldDocument, final IDocument newDocument) { if (newDocument == null) { return; } @@ -213,7 +213,7 @@ public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { try { viewer.addTextListener(this); // Update the grammar - IGrammar localGrammar = findGrammar(newDocument); + final IGrammar localGrammar = findGrammar(newDocument); if (localGrammar != null) { TMPresentationReconciler.this.grammar = localGrammar; @@ -223,7 +223,7 @@ public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { // Update the theme if (localGrammar != null) { - String scopeName = localGrammar.getScopeName(); + final String scopeName = localGrammar.getScopeName(); if (tokenProvider == null) { tokenProvider = TMUIPlugin.getThemeManager().getThemeForScope(scopeName, viewer.getTextWidget().getBackground().getRGB()); } @@ -234,16 +234,16 @@ public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { } } - boolean enable = TMPresentationReconciler.this.enabled = localGrammar != null && tokenProvider != null; + final boolean enable = TMPresentationReconciler.this.enabled = localGrammar != null && tokenProvider != null; if (enable) { // Connect a TextModel to the new document. - ITMModel model = getTMModelManager().connect(newDocument); + final ITMModel model = getTMModelManager().connect(newDocument); model.setGrammar(localGrammar); // Add model listener model.addModelTokensChangedListener(this); } - } catch (CoreException e) { + } catch (final CoreException e) { Platform.getLog(Platform.getBundle(TMEclipseRegistryPlugin.PLUGIN_ID)).log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, "Error while initializing TextMate model.", e)); } } @@ -254,12 +254,12 @@ public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { * @return * @throws CoreException */ - protected IGrammar findGrammar(@NonNull IDocument newDocument) throws CoreException { - IGrammar localGrammar = forcedGrammar ? TMPresentationReconciler.this.grammar : null; + protected IGrammar findGrammar(final @NonNull IDocument newDocument) throws CoreException { + final IGrammar localGrammar = forcedGrammar ? TMPresentationReconciler.this.grammar : null; if (localGrammar != null) { return localGrammar; } - ContentTypeInfo info = ContentTypeHelper.findContentTypes(newDocument); + final ContentTypeInfo info = ContentTypeHelper.findContentTypes(newDocument); if (info == null) { return null; } @@ -267,18 +267,18 @@ protected IGrammar findGrammar(@NonNull IDocument newDocument) throws CoreExcept } @Override - public void textChanged(TextEvent e) { + public void textChanged(final TextEvent e) { if (!e.getViewerRedrawState()) { return; } // changed text: propagate previous style, which will be overridden // later asynchronously by TM if (e.getDocumentEvent() != null) { - int diff = e.getText().length() - e.getLength(); + final int diff = e.getText().length() - e.getLength(); if (diff == 0 || e.getOffset() <= 0) { return; } - StyleRange range = viewer.getTextWidget().getStyleRangeAtOffset(e.getOffset() - 1); + final StyleRange range = viewer.getTextWidget().getStyleRangeAtOffset(e.getOffset() - 1); if (range == null) { return; } @@ -290,15 +290,15 @@ public void textChanged(TextEvent e) { // TextViewer#invalidateTextPresentation is called (because // of validation, folding, etc) // case 2), do the colorization. - IDocument document = viewer.getDocument(); + final IDocument document = viewer.getDocument(); if (document == null) { return; } - IRegion region = computeRegionToRedraw(e, document); + final IRegion region = computeRegionToRedraw(e, document); if (enabled) { // case where there is grammar & theme -> update text presentation with the // grammar tokens - ITMModel model = getTMModelManager().connect(document); + final ITMModel model = getTMModelManager().connect(document); if (model == null) { return; } @@ -316,20 +316,20 @@ public void textChanged(TextEvent e) { try { TMPresentationReconciler.this.colorize(region, (TMDocumentModel) model); - } catch (BadLocationException e1) { + } catch (final BadLocationException e1) { TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e1.getMessage(), e1)); } } else { // case where there is no grammar & theme -> update text presentation with the // default styles (ex: to support highlighting with GenericEditor) - TextPresentation presentation = new TextPresentation(region, 100); + final TextPresentation presentation = new TextPresentation(region, 100); presentation.setDefaultStyleRange( new StyleRange(region.getOffset(), region.getLength(), null, null)); applyTextRegionCollection(presentation); } } - protected @NonNull IRegion computeRegionToRedraw(@NonNull TextEvent e, @NonNull IDocument document) { + protected @NonNull IRegion computeRegionToRedraw(@NonNull final TextEvent e, @NonNull final IDocument document) { IRegion region = null; if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) { // redraw state change, damage the whole document @@ -353,20 +353,20 @@ public void textChanged(TextEvent e) { * null if none * @since 2.1 */ - private IRegion widgetRegion2ModelRegion(TextEvent e) { - String text = e.getText(); - int length = text == null ? 0 : text.length(); + private IRegion widgetRegion2ModelRegion(final TextEvent e) { + final String text = e.getText(); + final int length = text == null ? 0 : text.length(); if (viewer instanceof ITextViewerExtension5) { - ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; + final ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); } - IRegion visible = viewer.getVisibleRegion(); + final IRegion visible = viewer.getVisibleRegion(); return new Region(e.getOffset() + visible.getOffset(), length); } @Override - public void modelTokensChanged(ModelTokensChangedEvent event) { - Control control = viewer.getTextWidget(); + public void modelTokensChanged(final ModelTokensChangedEvent event) { + final Control control = viewer.getTextWidget(); if (control != null) { control.getDisplay().asyncExec(() -> { if (viewer != null) { @@ -376,39 +376,42 @@ public void modelTokensChanged(ModelTokensChangedEvent event) { } } - private void colorize(ModelTokensChangedEvent event) { - IDocument document = viewer.getDocument(); + private void colorize(final ModelTokensChangedEvent event) { + final IDocument document = viewer.getDocument(); if (document == null) { return; } - ITMModel model = event.model; + final ITMModel model = event.model; if (!(model instanceof TMDocumentModel)) { return; } - TMDocumentModel docModel = (TMDocumentModel) model; - for (Range range : event.ranges) { + final TMDocumentModel docModel = (TMDocumentModel) model; + for (final Range range : event.ranges) { try { - int length = document.getLineOffset(range.toLineNumber - 1) + document.getLineLength(range.toLineNumber - 1) - document.getLineOffset(range.fromLineNumber - 1); - IRegion region = new Region(document.getLineOffset(range.fromLineNumber - 1), length); + final int length = document.getLineOffset(range.toLineNumber - 1) + + document.getLineLength(range.toLineNumber - 1) + - document.getLineOffset(range.fromLineNumber - 1); + final IRegion region = new Region(document.getLineOffset(range.fromLineNumber - 1), length); TMPresentationReconciler.this.colorize(region, docModel); - } catch (BadLocationException ex) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + } catch (final BadLocationException ex) { + TMUIPlugin.getDefault().getLog() + .log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); } } } - private IGrammar findGrammar(ContentTypeInfo info) { + private IGrammar findGrammar(final ContentTypeInfo info) { if (info == null) { return null; } - IContentType[] contentTypes = info.getContentTypes(); + final IContentType[] contentTypes = info.getContentTypes(); // Discover the well grammar from the contentTypes IGrammar res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); if (res == null) { // Discover the well grammar from the filetype - String fileName = info.getFileName(); + final String fileName = info.getFileName(); if (fileName != null) { - String fileType = new Path(fileName).getFileExtension(); + final String fileType = new Path(fileName).getFileExtension(); res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarForFileType(fileType); } } @@ -416,13 +419,13 @@ private IGrammar findGrammar(ContentTypeInfo info) { } } - public void setGrammar(IGrammar grammar) { - boolean changed = (viewer != null && ((this.grammar == null) || !this.grammar.equals(grammar))); + public void setGrammar(final IGrammar grammar) { + final boolean changed = (viewer != null && ((this.grammar == null) || !this.grammar.equals(grammar))); this.grammar = grammar; this.forcedGrammar = true; if (changed) { // Grammar has changed, recreate the TextMate model - IDocument document = viewer.getDocument(); + final IDocument document = viewer.getDocument(); if (document == null) { return; } @@ -444,28 +447,29 @@ public void setTheme(final ITokenProvider newTheme) { if (!Objects.equals(oldTheme, newTheme) && grammar != null) { this.tokenProvider = newTheme; applyThemeEditor(); - IDocument document = viewer.getDocument(); - ITMModel model = getTMModelManager().connect(document); + final IDocument document = viewer.getDocument(); + final ITMModel model = getTMModelManager().connect(document); if (!(model instanceof TMDocumentModel)) { return; } - TMDocumentModel docModel = (TMDocumentModel) model; + final TMDocumentModel docModel = (TMDocumentModel) model; try { colorize(new Region(0, document.getLength()), docModel); - } catch (BadLocationException e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } catch (final BadLocationException e) { + TMUIPlugin.getDefault().getLog() + .log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } } @Override - public void install(ITextViewer viewer) { + public void install(final ITextViewer viewer) { Assert.isNotNull(viewer); this.viewer = viewer; viewer.addTextInputListener(internalListener); - IDocument document = viewer.getDocument(); + final IDocument document = viewer.getDocument(); if (document != null) { internalListener.inputDocumentChanged(null, document); } @@ -485,12 +489,12 @@ public void uninstall() { } @Override - public IPresentationDamager getDamager(String contentType) { + public IPresentationDamager getDamager(final String contentType) { return null; } @Override - public IPresentationRepairer getRepairer(String contentType) { + public IPresentationRepairer getRepairer(final String contentType) { return null; } @@ -498,15 +502,15 @@ private ITMModelManager getTMModelManager() { return TMUIPlugin.getTMModelManager(); } - void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws BadLocationException { - IDocument document = model.getDocument(); + void colorize(@NonNull final IRegion damage, @NonNull final TMDocumentModel model) throws BadLocationException { + final IDocument document = model.getDocument(); final int fromLineNumber = document.getLineOfOffset(damage.getOffset()); final int toLineNumber = document.getLineOfOffset(damage.getOffset() + damage.getLength()); applyThemeEditorIfNeeded(); // Refresh the UI Presentation TMUIPlugin.getDefault().trace("Render from: " + fromLineNumber + " to: " + toLineNumber); TextPresentation presentation = null; - Throwable error = null; + final Throwable error = null; try { presentation = new TextPresentation(damage, 1000); @@ -527,10 +531,10 @@ void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws Ba TMUIPlugin.getDefault().trace("TextMate tokens not available for line " + line); break; } - int startLineOffset = document.getLineOffset(line); + final int startLineOffset = document.getLineOffset(line); for (int i = 0; i < tokens.size(); i++) { - TMToken currentToken = tokens.get(i); - TMToken nextToken = (i + 1 < tokens.size()) ? tokens.get(i + 1) : null; + final TMToken currentToken = tokens.get(i); + final TMToken nextToken = (i + 1 < tokens.size()) ? tokens.get(i + 1) : null; int tokenStartIndex = currentToken.startIndex; if (isBeforeRegion(currentToken, startLineOffset, damage)) { @@ -542,7 +546,7 @@ void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws Ba tokenStartIndex = damage.getOffset() - startLineOffset; } else { tokenStartIndex = damage.getOffset() - startLineOffset; - IToken token = toToken(currentToken); + final IToken token = toToken(currentToken); lastAttribute = getTokenTextAttribute(token); length += getTokenLengh(tokenStartIndex, nextToken, line, document); firstToken = false; @@ -555,8 +559,8 @@ void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws Ba break; } - IToken token = toToken(currentToken); - TextAttribute attribute = getTokenTextAttribute(token); + final IToken token = toToken(currentToken); + final TextAttribute attribute = getTokenTextAttribute(token); if (lastAttribute != null && lastAttribute.equals(attribute)) { length += getTokenLengh(tokenStartIndex, nextToken, line, document); firstToken = false; @@ -576,7 +580,7 @@ void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws Ba length = Math.min(length, damage.getOffset() + damage.getLength() - lastStart); addRange(presentation, lastStart, length, lastAttribute); applyTextRegionCollection(presentation); - } catch (Exception e) { + } catch (final Exception e) { TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } finally { fireColorize(presentation, error); @@ -590,9 +594,10 @@ void colorize(@NonNull IRegion damage, @NonNull TMDocumentModel model) throws Ba * @param token * @param startLineOffset * @param damage + * * @return */ - private boolean isBeforeRegion(TMToken token, int startLineOffset, IRegion damage) { + private boolean isBeforeRegion(final TMToken token, final int startLineOffset, final IRegion damage) { return token.startIndex + startLineOffset < damage.getOffset(); } @@ -602,21 +607,22 @@ private boolean isBeforeRegion(TMToken token, int startLineOffset, IRegion damag * @param t * @param startLineOffset * @param damage + * * @return */ - private boolean isAfterRegion(TMToken t, int startLineOffset, IRegion damage) { + private boolean isAfterRegion(final TMToken t, final int startLineOffset, final IRegion damage) { return t.startIndex + startLineOffset >= damage.getOffset() + damage.getLength(); } - private IToken toToken(TMToken t) { - IToken token = getTokenProvider().getToken(t.type); + private IToken toToken(final TMToken t) { + final IToken token = getTokenProvider().getToken(t.type); if (token != null) { return token; } return defaultToken; } - private int getTokenLengh(int tokenStartIndex, TMToken nextToken, int line, IDocument document) + private int getTokenLengh(final int tokenStartIndex, final TMToken nextToken, final int line, final IDocument document) throws BadLocationException { if (nextToken != null) { return nextToken.startIndex - tokenStartIndex; @@ -632,10 +638,11 @@ private int getTokenLengh(int tokenStartIndex, TMToken nextToken, int line, IDoc * * @param token * the token whose text attribute is to be determined + * * @return the token's text attribute */ - protected TextAttribute getTokenTextAttribute(IToken token) { - Object data = token.getData(); + protected TextAttribute getTokenTextAttribute(final IToken token) { + final Object data = token.getData(); if (data instanceof TextAttribute) { return (TextAttribute) data; } @@ -655,11 +662,11 @@ protected TextAttribute getTokenTextAttribute(IToken token) { * the attribute describing the style of the range to be styled * @param lastLineStyleRanges */ - protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { + protected void addRange(final TextPresentation presentation, final int offset, final int length, @Nullable final TextAttribute attr) { if (attr != null) { - int style = attr.getStyle(); - int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); - StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), + final int style = attr.getStyle(); + final int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); + final StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), fontStyle); styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0; styleRange.underline = (style & TextAttribute.UNDERLINE) != 0; @@ -675,7 +682,7 @@ protected void addRange(TextPresentation presentation, int offset, int length, T * @param presentation * the text presentation to be applied to the text viewer */ - private void applyTextRegionCollection(TextPresentation presentation) { + private void applyTextRegionCollection(final TextPresentation presentation) { viewer.changeTextPresentation(presentation, false); } @@ -685,7 +692,7 @@ private void applyTextRegionCollection(TextPresentation presentation) { * @param listener * the TextMate presentation reconciler listener to add. */ - public void addTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { + public void addTMPresentationReconcilerListener(final ITMPresentationReconcilerListener listener) { synchronized (listeners) { if (!listeners.contains(listener)) { listeners.add(listener); @@ -699,7 +706,7 @@ public void addTMPresentationReconcilerListener(ITMPresentationReconcilerListene * @param listener * the TextMate presentation reconciler listener to remove. */ - public void removeTMPresentationReconcilerListener(ITMPresentationReconcilerListener listener) { + public void removeTMPresentationReconcilerListener(final ITMPresentationReconcilerListener listener) { synchronized (listeners) { listeners.remove(listener); } @@ -711,22 +718,22 @@ public void removeTMPresentationReconcilerListener(ITMPresentationReconcilerList * @param presentation * @param error */ - private void fireColorize(TextPresentation presentation, Throwable error) { + private void fireColorize(final TextPresentation presentation, final Throwable error) { synchronized (listeners) { - for (ITMPresentationReconcilerListener listener : listeners) { + for (final ITMPresentationReconcilerListener listener : listeners) { listener.colorize(presentation, error); } } } - public static TMPresentationReconciler getTMPresentationReconciler(IEditorPart editorPart) { + public static TMPresentationReconciler getTMPresentationReconciler(final IEditorPart editorPart) { if (editorPart == null) { return null; } @Nullable - ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); + final ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); if (target instanceof ITextViewer) { - ITextViewer textViewer = ((ITextViewer) target); + final ITextViewer textViewer = ((ITextViewer) target); return TMPresentationReconciler.getTMPresentationReconciler(textViewer); } return null; @@ -740,12 +747,12 @@ public static TMPresentationReconciler getTMPresentationReconciler(IEditorPart e * @return the {@link TMPresentationReconciler} of the given text viewer and * null otherwise. */ - public static TMPresentationReconciler getTMPresentationReconciler(ITextViewer textViewer) { + public static TMPresentationReconciler getTMPresentationReconciler(final ITextViewer textViewer) { try { - Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); + final Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); if (field != null) { field.setAccessible(true); - Object presentationReconciler = field.get(textViewer); + final Object presentationReconciler = field.get(textViewer); //field is IPresentationRecounciler, looking for TMPresentationReconciler implementation return presentationReconciler instanceof TMPresentationReconciler ? (TMPresentationReconciler) presentationReconciler @@ -782,7 +789,7 @@ private void applyThemeEditor() { */ private void applyThemeEditorIfNeeded() { if (!initializeViewerColors) { - StyledText styledText = viewer.getTextWidget(); + final StyledText styledText = viewer.getTextWidget(); ((ITheme) tokenProvider).initializeViewerColors(styledText); initializeViewerColors = true; } @@ -795,25 +802,25 @@ private void applyThemeEditorIfNeeded() { // - get the list of IPainter of PaintManager with reflection // - loop for IPainter to retrieve CursorLinePainter which manages "current line // highlight". - PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class); + final PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class); if (paintManager == null) { return; } - List painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class); + final List painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class); if (painters == null) { return; } - for (IPainter painter : painters) { + for (final IPainter painter : painters) { if (painter instanceof CursorLinePainter) { // Update current line highlight - Color background = tokenProvider.getEditorCurrentLineHighlight(); + final Color background = tokenProvider.getEditorCurrentLineHighlight(); if (background != null) { ((CursorLinePainter) painter).setHighlightColor(background); } updateTextDecorations = true; } } - } catch (Exception e) { + } catch (final Exception e) { TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } @@ -824,7 +831,7 @@ private void applyThemeEditorIfNeeded() { * * @param throwError */ - public void setThrowError(boolean throwError) { + public void setThrowError(final boolean throwError) { this.throwError = throwError; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java index 992476ccd..a7652e8e3 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java @@ -38,7 +38,7 @@ public static ColorManager getInstance() { private ColorManager() { } - public Color getColor(RGB rgb) { + public Color getColor(final RGB rgb) { Color color = fColorTable.get(rgb); if (color == null) { color = new Color(Display.getCurrent(), rgb.red, rgb.green, rgb.blue); @@ -48,7 +48,7 @@ public Color getColor(RGB rgb) { } public void dispose() { - Iterator e = fColorTable.values().iterator(); + final Iterator e = fColorTable.values().iterator(); while (e.hasNext()) { e.next().dispose(); } @@ -61,7 +61,7 @@ public void dispose() { * name of the token * @return Color matching token */ - public Color getPreferenceEditorColor(String tokenId) { + public Color getPreferenceEditorColor(final String tokenId) { return getColor(stringToRGB(PreferenceUtils.getEditorsPreferenceStore().get(tokenId, ""))); } @@ -72,8 +72,8 @@ public Color getPreferenceEditorColor(String tokenId) { * name of the token * @return color is user defined or not */ - public boolean isColorUserDefined(String tokenId) { - String systemDefaultToken = getSystemDefaultToken(tokenId); + public boolean isColorUserDefined(final String tokenId) { + final String systemDefaultToken = getSystemDefaultToken(tokenId); return "".equals(systemDefaultToken) || // returns true if system default token doesn't exists !PreferenceUtils.getEditorsPreferenceStore().getBoolean(systemDefaultToken, true); @@ -90,8 +90,8 @@ public boolean isColorUserDefined(String tokenId) { * name of the token for preferences store * @return Highest priority color */ - public Color getPriorityColor(Color themeColor, String tokenId) { - Color prefColor = getPreferenceEditorColor(tokenId); + public Color getPriorityColor(final Color themeColor, final String tokenId) { + final Color prefColor = getPreferenceEditorColor(tokenId); if (isColorUserDefined(tokenId)) { return prefColor; @@ -107,7 +107,7 @@ public Color getPriorityColor(Color themeColor, String tokenId) { * name of the token * @return system default token or empty string if doesn't exist */ - private String getSystemDefaultToken(String tokenId) { + private String getSystemDefaultToken(final String tokenId) { switch (tokenId) { case AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND: return AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT; @@ -129,8 +129,8 @@ private String getSystemDefaultToken(String tokenId) { * string value of rgb * @return RGB value */ - private RGB stringToRGB(String value) { - String[] rgbValues = BY_COMMA_SPLITTER.splitToStream(value).toArray(String[]::new); + private RGB stringToRGB(final String value) { + final String[] rgbValues = BY_COMMA_SPLITTER.splitToStream(value).toArray(String[]::new); return rgbValues.length == 3 ? new RGB(Integer.parseInt(rgbValues[0]), Integer.parseInt(rgbValues[1]), Integer.parseInt(rgbValues[2])) : new RGB(255, 255, 255); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java index cb7760aeb..0dbf862f1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java @@ -50,7 +50,7 @@ public Theme() { * * @param id */ - public Theme(String id, String path, String name, boolean dark, boolean isDefault) { + public Theme(final String id, final String path, final String name, final boolean dark, final boolean isDefault) { super(path); this.id = id; this.name = name; @@ -58,7 +58,7 @@ public Theme(String id, String path, String name, boolean dark, boolean isDefaul this.isDefault = isDefault; } - public Theme(IConfigurationElement ce) { + public Theme(final IConfigurationElement ce) { super(ce); id = ce.getAttribute(XMLConstants.ID_ATTR); name = ce.getAttribute(XMLConstants.NAME_ATTR); @@ -77,48 +77,48 @@ public String getName() { } @Override - public IToken getToken(String type) { - ITokenProvider provider = getTokenProvider(); + public IToken getToken(final String type) { + final ITokenProvider provider = getTokenProvider(); return provider != null ? provider.getToken(type) : null; } @Override public Color getEditorForeground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorForeground() : null; + final ITokenProvider provider = getTokenProvider(); + final Color themeColor = provider != null ? provider.getEditorForeground() : null; return ColorManager.getInstance() .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND); } @Override public Color getEditorBackground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorBackground() : null; + final ITokenProvider provider = getTokenProvider(); + final Color themeColor = provider != null ? provider.getEditorBackground() : null; return ColorManager.getInstance() .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); } @Override public Color getEditorSelectionForeground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorSelectionForeground() : null; + final ITokenProvider provider = getTokenProvider(); + final Color themeColor = provider != null ? provider.getEditorSelectionForeground() : null; return ColorManager.getInstance() .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND); } @Override public Color getEditorSelectionBackground() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorSelectionBackground() : null; + final ITokenProvider provider = getTokenProvider(); + final Color themeColor = provider != null ? provider.getEditorSelectionBackground() : null; return ColorManager.getInstance() .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND); } @Override public Color getEditorCurrentLineHighlight() { - ITokenProvider provider = getTokenProvider(); - Color themeColor = provider != null ? provider.getEditorCurrentLineHighlight() : null; - ColorManager manager = ColorManager.getInstance(); + final ITokenProvider provider = getTokenProvider(); + final Color themeColor = provider != null ? provider.getEditorCurrentLineHighlight() : null; + final ColorManager manager = ColorManager.getInstance(); return manager.isColorUserDefined(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND) ? manager.getPreferenceEditorColor(PreferenceConstants.EDITOR_CURRENTLINE_HIGHLIGHT) : themeColor; @@ -131,7 +131,7 @@ private ITokenProvider getTokenProvider() { return null; } tokenProvider = new CSSTokenProvider(in); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } @@ -154,7 +154,7 @@ public boolean isDefault() { } @Override - public void initializeViewerColors(StyledText styledText) { + public void initializeViewerColors(final StyledText styledText) { Color color = getEditorBackground(); if (color != null) { styledText.setBackground(color); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java index fe4c65bf7..b385c8949 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java @@ -63,13 +63,13 @@ public ThemeAssociation() { * @param scopeName * @param whenDark */ - public ThemeAssociation(String themeId, String scopeName, boolean whenDark) { + public ThemeAssociation(final String themeId, final String scopeName, final boolean whenDark) { this.themeId = themeId; this.scopeName = scopeName; this.whenDark = whenDark; } - public ThemeAssociation(IConfigurationElement ce) { + public ThemeAssociation(final IConfigurationElement ce) { this(ce.getAttribute(THEME_ID_ATTR), ce.getAttribute(SCOPE_NAME_ATTR), "true".equals(ce.getAttribute(WHEN_DARK_ATTR))); this.pluginId = ce.getNamespaceIdentifier(); @@ -107,14 +107,14 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; - ThemeAssociation other = (ThemeAssociation) obj; + final ThemeAssociation other = (ThemeAssociation) obj; if (pluginId == null) { if (other.pluginId != null) return false; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java index 3463a01b2..d4b8c3fa7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java @@ -38,11 +38,11 @@ public class CSSTokenProvider extends AbstractTokenProvider { private final Map tokenMaps = new HashMap<>(); private CSSParser parser; - public CSSTokenProvider(InputStream in) { + public CSSTokenProvider(final InputStream in) { try { parser = new CSSParser(in); - for (IStyle style : parser.getStyles()) { - RGB color = style.getColor(); + for (final IStyle style : parser.getStyles()) { + final RGB color = style.getColor(); if (color != null) { int s = SWT.NORMAL; if (style.isBold()) { @@ -61,19 +61,19 @@ public CSSTokenProvider(InputStream in) { new Token(new TextAttribute(ColorManager.getInstance().getColor(color), null, s))); } } - } catch (Exception e) { + } catch (final Exception e) { TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } @Override - public IToken getToken(String type) { + public IToken getToken(final String type) { if (type == null) { return null; } - IStyle style = parser.getBestStyle(BY_DOT_SPLITTER.splitToStream(type).toArray(String[]::new)); + final IStyle style = parser.getBestStyle(BY_DOT_SPLITTER.splitToStream(type).toArray(String[]::new)); if (style != null) { - IToken t = tokenMaps.get(style); + final IToken t = tokenMaps.get(style); if (t != null) { return t; } @@ -83,7 +83,7 @@ public IToken getToken(String type) { @Override public Color getEditorForeground() { - IStyle style = parser.getBestStyle("editor"); + final IStyle style = parser.getBestStyle("editor"); if (style != null && style.getColor() != null) { return ColorManager.getInstance().getColor(style.getColor()); } @@ -92,7 +92,7 @@ public Color getEditorForeground() { @Override public Color getEditorBackground() { - IStyle style = parser.getBestStyle("editor"); + final IStyle style = parser.getBestStyle("editor"); if (style != null && style.getBackgroundColor() != null) { return ColorManager.getInstance().getColor(style.getBackgroundColor()); } @@ -101,7 +101,7 @@ public Color getEditorBackground() { @Override public Color getEditorSelectionForeground() { - IStyle style = parser.getBestStyle("editor", "selection"); + final IStyle style = parser.getBestStyle("editor", "selection"); if (style != null && style.getColor() != null) { return ColorManager.getInstance().getColor(style.getColor()); } @@ -110,7 +110,7 @@ public Color getEditorSelectionForeground() { @Override public Color getEditorSelectionBackground() { - IStyle style = parser.getBestStyle("editor", "selection"); + final IStyle style = parser.getBestStyle("editor", "selection"); if (style != null && style.getBackgroundColor() != null) { return ColorManager.getInstance().getColor(style.getBackgroundColor()); } @@ -119,7 +119,7 @@ public Color getEditorSelectionBackground() { @Override public Color getEditorCurrentLineHighlight() { - IStyle style = parser.getBestStyle("editor", "lineHighlight"); + final IStyle style = parser.getBestStyle("editor", "lineHighlight"); if (style != null && style.getBackgroundColor() != null) { return ColorManager.getInstance().getColor(style.getBackgroundColor()); } From fef197b888af2b8a498b367efc22d52828b50b92 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 13:38:03 +0200 Subject: [PATCH 179/202] Enable annotation based null analysis in tm4e.ui plugin --- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 2 +- .../core/internal/utils/NullSafetyHelper.java | 16 +- ...LanguageConfigurationAutoEditStrategy.java | 4 +- .../org/eclipse/tm4e/registry/TMResource.java | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 4 +- org.eclipse.tm4e.ui/build.properties | 6 +- .../java/org/eclipse/tm4e/ui/TMUIPlugin.java | 49 +-- .../tm4e/ui/internal/TMPropertyTester.java | 17 +- .../tm4e/ui/internal/TMUIMessages.java | 3 +- .../ui/internal/menus/ThemeContribution.java | 38 ++- .../tm4e/ui/internal/menus/package-info.java | 4 + .../ui/internal/model/DocumentLineList.java | 17 +- .../ui/internal/model/TMModelManager.java | 3 +- .../tm4e/ui/internal/model/package-info.java | 4 + .../tm4e/ui/internal/package-info.java | 4 + .../preferences/GrammarPreferencePage.java | 159 ++++----- .../preferences/TextMatePreferencePage.java | 5 +- .../preferences/ThemePreferencePage.java | 77 +++-- .../ui/internal/preferences/package-info.java | 4 + .../tm4e/ui/internal/snippets/Snippet.java | 11 +- .../ui/internal/snippets/SnippetManager.java | 4 +- .../ui/internal/snippets/package-info.java | 4 + ...TMPresentationReconcilerTestGenerator.java | 60 ++-- .../tm4e/ui/internal/text/package-info.java | 4 + .../internal/themes/AbstractThemeManager.java | 24 +- .../themes/BaseThemeAssociationRegistry.java | 11 +- .../themes/ThemeAssociationRegistry.java | 61 ++-- .../tm4e/ui/internal/themes/ThemeManager.java | 27 +- .../themes/WorkingCopyThemeManager.java | 36 ++- .../tm4e/ui/internal/themes/package-info.java | 4 + .../tm4e/ui/internal/utils/ClassHelper.java | 7 +- .../ui/internal/utils/ContentTypeHelper.java | 13 +- .../ui/internal/utils/ContentTypeInfo.java | 2 - .../ui/internal/utils/PreferenceUtils.java | 9 +- .../tm4e/ui/internal/utils/package-info.java | 4 + .../widgets/ColumnSelectionAdapter.java | 3 +- .../widgets/ColumnViewerComparator.java | 3 +- .../widgets/ContentTypeLabelProvider.java | 10 +- .../GrammarDefinitionContentProvider.java | 19 +- .../GrammarDefinitionLabelProvider.java | 20 +- .../internal/widgets/GrammarInfoWidget.java | 45 ++- .../tm4e/ui/internal/widgets/TMViewer.java | 30 +- .../widgets/TableAndButtonsWidget.java | 31 +- .../ThemeAssociationLabelProvider.java | 20 +- .../widgets/ThemeAssociationsWidget.java | 33 +- .../widgets/ThemeContentProvider.java | 18 +- .../internal/widgets/ThemeLabelProvider.java | 22 +- .../ui/internal/widgets/package-info.java | 4 + .../internal/wizards/AbstractWizardPage.java | 19 +- .../wizards/CreateThemeAssociationWizard.java | 22 +- .../CreateThemeAssociationWizardPage.java | 46 ++- .../wizards/SelectGrammarWizardPage.java | 63 ++-- .../wizards/TextMateGrammarImportWizard.java | 16 +- .../ui/internal/wizards/package-info.java | 4 + .../eclipse/tm4e/ui/model/package-info.java | 4 + .../org/eclipse/tm4e/ui/package-info.java | 4 + .../tm4e/ui/snippets/package-info.java | 4 + .../ITMPresentationReconcilerListener.java | 7 +- .../ui/text/TMPresentationReconciler.java | 306 ++++++++++-------- .../eclipse/tm4e/ui/text/package-info.java | 4 + .../eclipse/tm4e/ui/themes/ColorManager.java | 35 +- .../org/eclipse/tm4e/ui/themes/ITheme.java | 19 +- .../tm4e/ui/themes/IThemeAssociation.java | 6 +- .../eclipse/tm4e/ui/themes/IThemeManager.java | 32 +- .../tm4e/ui/themes/ITokenProvider.java | 11 +- .../org/eclipse/tm4e/ui/themes/Theme.java | 20 +- .../tm4e/ui/themes/ThemeAssociation.java | 68 ++-- .../tm4e/ui/themes/css/CSSTokenProvider.java | 83 ++--- .../tm4e/ui/themes/css/package-info.java | 4 + .../eclipse/tm4e/ui/themes/package-info.java | 4 + 70 files changed, 1019 insertions(+), 719 deletions(-) create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/package-info.java create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/package-info.java diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index 11a6480e5..fa81b9d7d 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -21,7 +21,7 @@ Export-Package: org.eclipse.tm4e.core, org.eclipse.tm4e.core.internal.grammar;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.internal.matcher;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.internal.theme.reader;x-friends:="org.eclipse.tm4e.core.tests", - org.eclipse.tm4e.core.internal.utils;x-friends:="org.eclipse.tm4e.core.tests", + org.eclipse.tm4e.core.internal.utils;x-friends:="org.eclipse.tm4e.core.tests,org.eclipse.tm4e.ui", org.eclipse.tm4e.core.model, org.eclipse.tm4e.core.registry, org.eclipse.tm4e.core.theme, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java index 513a5b3ea..200a7dbda 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/NullSafetyHelper.java @@ -12,18 +12,20 @@ */ package org.eclipse.tm4e.core.internal.utils; -import java.util.Iterator; - import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; public final class NullSafetyHelper { - public static Iterator<@NonNull T> castNonNull(@Nullable final Iterator value) { - assert value != null; - return value; - } - + /** + * Casts non-null value marked as {@link Nullable} to {@link NonNull}. + *

    + * Only use if you are sure the value is non-null but annotation-based null analysis was not able to determine it. + *

    + * This method is not meant for non-null input validation. + * + * @throws AssertionError if JVM assertions are enabled and the given value is null + */ @NonNull public static T castNonNull(@Nullable final T value) { assert value != null; diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java index e3ae6df1a..cec43f9eb 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationAutoEditStrategy.java @@ -195,13 +195,13 @@ private void onEnter(final IDocument document, final DocumentCommand command) { new DefaultIndentLineAutoEditStrategy().customizeDocumentCommand(document, command); } - private IContentType @Nullable [] findContentTypes(@Nullable final IDocument document) { + private IContentType @Nullable [] findContentTypes(final IDocument document) { if (this.document != null && this.document.equals(document)) { return contentTypes; } try { final ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); - this.contentTypes = info.getContentTypes(); + this.contentTypes = info == null ? null : info.getContentTypes(); this.document = document; } catch (final CoreException e) { e.printStackTrace(); diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index 62985ff21..82567d1db 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -55,7 +55,7 @@ public TMResource(final IConfigurationElement ce) { this.pluginId = ce.getNamespaceIdentifier(); } - public TMResource(@Nullable final String path, @Nullable final String pluginId) { + public TMResource(final String path, final String pluginId) { this.path = path; this.pluginId = pluginId; } diff --git a/org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs index f648802b5..6b99f88fc 100644 --- a/org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.tm4e.ui/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullable.secondary= -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 @@ -75,7 +75,7 @@ org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=wa org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=info org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning diff --git a/org.eclipse.tm4e.ui/build.properties b/org.eclipse.tm4e.ui/build.properties index e175a5d15..e1332cf9b 100644 --- a/org.eclipse.tm4e.ui/build.properties +++ b/org.eclipse.tm4e.ui/build.properties @@ -8,5 +8,9 @@ bin.includes = META-INF/,\ themes/,\ .options,\ about.html -## JDT Null Analysis + +# https://codeiseasy.wordpress.com/2013/03/08/tycho-and-jdt-null-analysis/ +# JDT Null Analysis for Eclipse additional.bundles = org.eclipse.jdt.annotation +# JDT Null Analysis types for Tycho +jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java index aadbacfb6..204e80793 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui; @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.ui.internal.model.TMModelManager; import org.eclipse.tm4e.ui.internal.snippets.SnippetManager; import org.eclipse.tm4e.ui.internal.themes.ThemeManager; @@ -39,22 +40,24 @@ public class TMUIPlugin extends AbstractUIPlugin { private static final String TRACE_ID = PLUGIN_ID + "/trace"; //$NON-NLS-1$ // The shared instance - private static TMUIPlugin plugin; + @Nullable + private static volatile TMUIPlugin plugin; - /** - * The constructor - */ - public TMUIPlugin() { + public static void log(IStatus status) { + final var plugin = TMUIPlugin.plugin; + if (plugin != null) { + plugin.getLog().log(status); + } } - public void trace(final String message) { + public static void trace(final String message) { if (Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID))) { - getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); + log(new Status(IStatus.INFO, PLUGIN_ID, message)); } } @Override - public void start(final BundleContext context) throws Exception { + public void start(@Nullable final BundleContext context) throws Exception { super.start(context); plugin = this; final boolean isDebugOn = Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID)); @@ -63,12 +66,14 @@ public void start(final BundleContext context) throws Exception { tm4eCoreLogger.setLevel(Level.FINEST); tm4eCoreLogger.addHandler(new Handler() { - @Override public void publish(final LogRecord record) { - TMUIPlugin.getDefault().getLog().log(new Status( - toSeverity(record.getLevel()), - "org.eclipse.tm4e.core", - record.getMessage() - )); + @Override + public void publish(@Nullable final LogRecord record) { + if (record != null) { + log(new Status( + toSeverity(record.getLevel()), + "org.eclipse.tm4e.core", + record.getMessage())); + } } private int toSeverity(final Level level) { @@ -81,11 +86,13 @@ private int toSeverity(final Level level) { return IStatus.INFO; } - @Override public void flush() { + @Override + public void flush() { // nothing to do } - @Override public void close() throws SecurityException { + @Override + public void close() throws SecurityException { // nothing to do } }); @@ -93,7 +100,7 @@ private int toSeverity(final Level level) { } @Override - public void stop(final BundleContext context) throws Exception { + public void stop(@Nullable final BundleContext context) throws Exception { ColorManager.getInstance().dispose(); plugin = null; super.stop(context); @@ -104,6 +111,7 @@ public void stop(final BundleContext context) throws Exception { * * @return the shared instance */ + @Nullable public static TMUIPlugin getDefault() { return plugin; } @@ -134,5 +142,4 @@ public static IThemeManager getThemeManager() { public static ISnippetManager getSnippetManager() { return SnippetManager.getInstance(); } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java index 928ad3240..88c9ceb92 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMPropertyTester.java @@ -1,17 +1,18 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal; import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.ui.text.TMPresentationReconciler; import org.eclipse.ui.IEditorPart; @@ -25,15 +26,15 @@ public final class TMPropertyTester extends PropertyTester { private static final String CAN_SUPPORT_TEXT_MATE = "canSupportTextMate"; @Override - public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { + public boolean test(@Nullable final Object receiver, @Nullable final String property, + final Object @Nullable [] args, @Nullable final Object expectedValue) { if (CAN_SUPPORT_TEXT_MATE.equals(property)) { if (receiver instanceof IEditorPart) { - final IEditorPart editorPart = (IEditorPart) receiver; - final TMPresentationReconciler reconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); - return reconciler != null && reconciler.isEnabled(); + final var editorPart = (IEditorPart) receiver; + final var reconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); + return reconciler != null && reconciler.isEnabled(); } } return false; } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java index be527f177..f45db0e7f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java @@ -11,12 +11,13 @@ */ package org.eclipse.tm4e.ui.internal; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.osgi.util.NLS; /** * Helper class to get NLSed messages. - * */ +@NonNullByDefault({}) public final class TMUIMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.tm4e.ui.internal.TMUIMessages"; //$NON-NLS-1$ diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java index db63b1b6c..4b89e87a6 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/ThemeContribution.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.menus; @@ -15,6 +15,7 @@ import java.util.List; import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; @@ -39,10 +40,12 @@ */ public final class ThemeContribution extends CompoundContributionItem implements IWorkbenchContribution { + @Nullable private IHandlerService handlerService; @Override - public void initialize(final IServiceLocator serviceLocator) { + public void initialize(@Nullable final IServiceLocator serviceLocator) { + assert serviceLocator != null; handlerService = serviceLocator.getService(IHandlerService.class); } @@ -55,17 +58,21 @@ protected IContributionItem[] getContributionItems() { final IThemeManager manager = TMUIPlugin.getThemeManager(); final boolean dark = manager.isDarkEclipseTheme(); final ITheme[] themes = manager.getThemes(); - final TMPresentationReconciler presentationReconciler = TMPresentationReconciler.getTMPresentationReconciler(editorPart); - if (themes != null && presentationReconciler != null) { - final String scopeName = presentationReconciler.getGrammar().getScopeName(); - final ITheme selectedTheme = manager.getThemeForScope(scopeName, dark); - for (final ITheme theme : themes) { - final IAction action = createAction(scopeName, theme, dark); - if (theme.equals(selectedTheme)) { - action.setChecked(true); + final TMPresentationReconciler presentationReconciler = TMPresentationReconciler + .getTMPresentationReconciler(editorPart); + if (presentationReconciler != null) { + final var grammar = presentationReconciler.getGrammar(); + if (grammar != null) { + final String scopeName = grammar.getScopeName(); + final ITheme selectedTheme = manager.getThemeForScope(scopeName, dark); + for (final ITheme theme : themes) { + final IAction action = createAction(scopeName, theme, dark); + if (theme.equals(selectedTheme)) { + action.setChecked(true); + } + final IContributionItem item = new ActionContributionItem(action); + items.add(item); } - final IContributionItem item = new ActionContributionItem(action); - items.add(item); } } @@ -90,7 +97,8 @@ public void run() { }; } - private static IEditorPart getActivePart(final IEvaluationContext context) { + @Nullable + private static IEditorPart getActivePart(@Nullable final IEvaluationContext context) { if (context == null) return null; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/package-info.java new file mode 100644 index 000000000..a875d9ce5 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/menus/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.menus; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java index 66d33a71c..fdc97a3e7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentLineList.java @@ -1,18 +1,19 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.model; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; @@ -44,7 +45,9 @@ final class DocumentLineList extends AbstractLineList { private final class InternalListener implements IDocumentListener { @Override - public void documentAboutToBeChanged(final DocumentEvent event) { + public void documentAboutToBeChanged(@Nullable final DocumentEvent event) { + if (event == null) + return; try { if (!DocumentHelper.isInsert(event)) { // Remove or Replace (Remove + Insert) @@ -64,7 +67,9 @@ private void removeLine(final DocumentEvent event) throws BadLocationException { } @Override - public void documentChanged(final DocumentEvent event) { + public void documentChanged(@Nullable final DocumentEvent event) { + if (event == null) + return; try { final int startLine = DocumentHelper.getStartLine(event); if (!DocumentHelper.isRemove(event)) { @@ -82,7 +87,7 @@ public void documentChanged(final DocumentEvent event) { } invalidateLine(startLine); } catch (final BadLocationException e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java index 8c415ab83..37ab3b321 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/TMModelManager.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.IDocument; import org.eclipse.tm4e.core.model.ITMModel; import org.eclipse.tm4e.ui.model.ITMModelManager; @@ -30,7 +31,7 @@ public static ITMModelManager getInstance() { return INSTANCE; } - private final Map models = new HashMap<>(); + private final Map models = new HashMap<>(); private TMModelManager() { } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/package-info.java new file mode 100644 index 000000000..848fee081 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.model; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/package-info.java new file mode 100644 index 000000000..2e9e022ab --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index 81be60a0b..6750df709 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -14,8 +14,11 @@ *******************************************************************************/ package org.eclipse.tm4e.ui.internal.preferences; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.Arrays; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.preference.PreferencePage; @@ -85,17 +88,23 @@ public final class GrammarPreferencePage extends PreferencePage implements IWork private ISnippetManager snippetManager = TMUIPlugin.getSnippetManager(); // Grammar list + @Nullable private TableViewer grammarViewer; - private Button grammarNewButton; + + @Nullable private Button grammarRemoveButton; // General tab + @Nullable private GrammarInfoWidget grammarInfoWidget; // Content type tab + @Nullable private ContentTypesBindingWidget contentTypesWidget; // Theme associations tab + @Nullable private ThemeAssociationsWidget themeAssociationsWidget; // Preview + @Nullable private TMViewer previewViewer; public GrammarPreferencePage() { @@ -147,21 +156,21 @@ void setSnippetManager(final ISnippetManager snippetManager) { } @Override - protected Control createContents(final Composite ancestor) { - final Composite parent = new Composite(ancestor, SWT.NONE); - final GridLayout layout = new GridLayout(); + protected Control createContents(@Nullable final Composite ancestor) { + final var parent = new Composite(ancestor, SWT.NONE); + final var layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); - final Composite innerParent = new Composite(parent, SWT.NONE); - final GridLayout innerLayout = new GridLayout(); + final var innerParent = new Composite(parent, SWT.NONE); + final var innerLayout = new GridLayout(); innerLayout.numColumns = 2; innerLayout.marginHeight = 0; innerLayout.marginWidth = 0; innerParent.setLayout(innerLayout); - final GridData gd = new GridData(GridData.FILL_BOTH); + final var gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; innerParent.setLayoutData(gd); @@ -169,7 +178,7 @@ protected Control createContents(final Composite ancestor) { createGrammarDetailContent(innerParent); previewViewer = doCreateViewer(innerParent); - grammarViewer.setInput(grammarRegistryManager); + castNonNull(grammarViewer).setInput(grammarRegistryManager); updateButtons(); Dialog.applyDialogFont(parent); @@ -180,19 +189,17 @@ protected Control createContents(final Composite ancestor) { /** * Create grammar list content. - * - * @param parent */ private void createGrammarListContent(final Composite parent) { - final Composite tableComposite = new Composite(parent, SWT.NONE); - final GridData data = new GridData(GridData.FILL_BOTH); + final var tableComposite = new Composite(parent, SWT.NONE); + final var data = new GridData(GridData.FILL_BOTH); data.widthHint = 360; data.heightHint = convertHeightInCharsToPixels(10); tableComposite.setLayoutData(data); - final TableColumnLayout columnLayout = new TableColumnLayout(); + final var columnLayout = new TableColumnLayout(); tableComposite.setLayout(columnLayout); - final Table table = new Table(tableComposite, + final var table = new Table(tableComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE); table.setHeaderVisible(true); @@ -201,23 +208,23 @@ private void createGrammarListContent(final Composite parent) { final GC gc = new GC(getShell()); gc.setFont(JFaceResources.getDialogFont()); - final ColumnViewerComparator viewerComparator = new ColumnViewerComparator(); + final var viewerComparator = new ColumnViewerComparator(); - grammarViewer = new TableViewer(table); + final var grammarViewer = this.grammarViewer = new TableViewer(table); - final TableColumn column1 = new TableColumn(table, SWT.NONE); + final var column1 = new TableColumn(table, SWT.NONE); column1.setText(TMUIMessages.GrammarPreferencePage_column_scopeName); int minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_scopeName); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); column1.addSelectionListener(new ColumnSelectionAdapter(column1, grammarViewer, 0, viewerComparator)); - final TableColumn column2 = new TableColumn(table, SWT.NONE); + final var column2 = new TableColumn(table, SWT.NONE); column2.setText(TMUIMessages.GrammarPreferencePage_column_path); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_path); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); column2.addSelectionListener(new ColumnSelectionAdapter(column2, grammarViewer, 1, viewerComparator)); - final TableColumn column3 = new TableColumn(table, SWT.NONE); + final var column3 = new TableColumn(table, SWT.NONE); column3.setText(TMUIMessages.GrammarPreferencePage_column_pluginId); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_pluginId); columnLayout.setColumnData(column3, new ColumnWeightData(2, minWidth, true)); @@ -228,20 +235,22 @@ private void createGrammarListContent(final Composite parent) { grammarViewer.setLabelProvider(new GrammarDefinitionLabelProvider()); grammarViewer.setContentProvider(new GrammarDefinitionContentProvider()); grammarViewer.setComparator(viewerComparator); - grammarViewer.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(final SelectionChangedEvent e) { + public void selectionChanged(@Nullable final SelectionChangedEvent e) { + if (e == null) + return; final IStructuredSelection selection = grammarViewer.getStructuredSelection(); if (selection.isEmpty()) { return; } final IGrammarDefinition definition = (IGrammarDefinition) (selection).getFirstElement(); + // Update button - grammarRemoveButton.setEnabled(definition.getPluginId() == null); - themeAssociationsWidget.getNewButton().setEnabled(false); - themeAssociationsWidget.getRemoveButton().setEnabled(false); + castNonNull(grammarRemoveButton).setEnabled(definition.getPluginId() == null); + castNonNull(themeAssociationsWidget).getNewButton().setEnabled(false); + castNonNull(themeAssociationsWidget).getRemoveButton().setEnabled(false); + // Select grammar selectGrammar(definition); } @@ -260,16 +269,18 @@ private void selectGrammar(final IGrammarDefinition definition) { private void fillGeneralTab(final String scopeName) { final IGrammar grammar = grammarRegistryManager.getGrammarForScope(scopeName); - grammarInfoWidget.refresh(grammar); + castNonNull(grammarInfoWidget).refresh(grammar); } private void fillContentTypeTab(final String scopeName) { // Load the content type binding for the given grammar - contentTypesWidget.setInput(grammarRegistryManager.getContentTypesForScope(scopeName)); + castNonNull(contentTypesWidget).setInput(grammarRegistryManager.getContentTypesForScope(scopeName)); } + @Nullable private IThemeAssociation fillThemeTab(final IGrammarDefinition definition) { IThemeAssociation selectedAssociation = null; + final var themeAssociationsWidget = castNonNull(GrammarPreferencePage.this.themeAssociationsWidget); final IStructuredSelection oldSelection = themeAssociationsWidget.getSelection(); // Load the theme associations for the given grammar final IThemeAssociation[] themeAssociations = themeAssociationsWidget.setGrammarDefinition(definition); @@ -279,7 +290,7 @@ private IThemeAssociation fillThemeTab(final IGrammarDefinition definition) { selectedAssociation = (IThemeAssociation) oldSelection.getFirstElement(); themeAssociationsWidget.setSelection(oldSelection); } else { - selectedAssociation = themeAssociations != null && themeAssociations.length > 0 + selectedAssociation = themeAssociations.length > 0 ? themeAssociations[0] : null; if (selectedAssociation != null) { @@ -289,21 +300,21 @@ private IThemeAssociation fillThemeTab(final IGrammarDefinition definition) { return selectedAssociation; } - private void fillPreview(final String scopeName, final IThemeAssociation selectedAssociation) { + private void fillPreview(final String scopeName, @Nullable final IThemeAssociation selectedAssociation) { // Preview the grammar final IGrammar grammar = grammarRegistryManager.getGrammarForScope(scopeName); if (selectedAssociation != null) { setPreviewTheme(selectedAssociation.getThemeId()); } - previewViewer.setGrammar(grammar); + castNonNull(previewViewer).setGrammar(grammar); // Snippet final ISnippet[] snippets = snippetManager.getSnippets(scopeName); - if (snippets == null || snippets.length == 0) { + if (snippets.length == 0) { previewViewer.setText(""); } else { // TODO: manage list of snippet for the given scope. - previewViewer.setText(snippets[0].getContent()); + castNonNull(previewViewer).setText(snippets[0].getContent()); } } @@ -315,28 +326,28 @@ private void fillPreview(final String scopeName, final IThemeAssociation selecte BidiUtils.applyTextDirection(grammarViewer.getControl(), BidiUtils.BTD_DEFAULT); - final Composite buttons = new Composite(parent, SWT.NONE); + final var buttons = new Composite(parent, SWT.NONE); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - final GridLayout layout = new GridLayout(); + final var layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); - grammarNewButton = new Button(buttons, SWT.PUSH); + final var grammarNewButton = new Button(buttons, SWT.PUSH); grammarNewButton.setText(TMUIMessages.Button_new); grammarNewButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); grammarNewButton.addListener(SWT.Selection, new Listener() { @Override - public void handleEvent(final Event e) { + public void handleEvent(@Nullable final Event e) { add(); } private void add() { // Open import wizard for TextMate grammar. - final TextMateGrammarImportWizard wizard = new TextMateGrammarImportWizard(false); + final var wizard = new TextMateGrammarImportWizard(false); wizard.setGrammarRegistryManager(grammarRegistryManager); - final WizardDialog dialog = new WizardDialog(getShell(), wizard); + final var dialog = new WizardDialog(getShell(), wizard); if (dialog.open() == Window.OK) { // User grammar was saved, refresh the list of grammar and // select the created grammar. @@ -347,18 +358,18 @@ private void add() { } }); - grammarRemoveButton = new Button(buttons, SWT.PUSH); + final var grammarRemoveButton = this.grammarRemoveButton = new Button(buttons, SWT.PUSH); grammarRemoveButton.setText(TMUIMessages.Button_remove); grammarRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); grammarRemoveButton.addListener(SWT.Selection, new Listener() { @Override - public void handleEvent(final Event e) { + public void handleEvent(@Nullable final Event e) { remove(); } private void remove() { - final IGrammarDefinition definition = (IGrammarDefinition) ((IStructuredSelection) grammarViewer + final var definition = (IGrammarDefinition) ((IStructuredSelection) grammarViewer .getSelection()).getFirstElement(); grammarRegistryManager.unregisterGrammarDefinition(definition); grammarViewer.refresh(); @@ -367,15 +378,12 @@ private void remove() { } /** - * Create detail grammar content which is filled when a grammar is selected in - * the grammar list. - * - * @param parent + * Create detail grammar content which is filled when a grammar is selected in the grammar list. */ private void createGrammarDetailContent(final Composite parent) { - final TabFolder folder = new TabFolder(parent, SWT.NONE); + final var folder = new TabFolder(parent, SWT.NONE); - final GridData gd = new GridData(GridData.FILL_HORIZONTAL); + final var gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; folder.setLayoutData(gd); @@ -387,14 +395,12 @@ private void createGrammarDetailContent(final Composite parent) { /** * Create "General" tab - * - * @param folder */ private void createGeneralTab(final TabFolder folder) { - final TabItem tab = new TabItem(folder, SWT.NONE); + final var tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_general_text); - final Composite parent = new Composite(folder, SWT.NONE); + final var parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -402,19 +408,16 @@ private void createGeneralTab(final TabFolder folder) { grammarInfoWidget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tab.setControl(parent); - } /** * Create "Content type" tab - * - * @param folder */ private void createContentTypeTab(final TabFolder folder) { - final TabItem tab = new TabItem(folder, SWT.NONE); + final var tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_contentType_text); - final Composite parent = new Composite(folder, SWT.NONE); + final var parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -426,31 +429,31 @@ private void createContentTypeTab(final TabFolder folder) { /** * Create "Theme" tab - * - * @param folder */ private void createThemeTab(final TabFolder folder) { - final TabItem tab = new TabItem(folder, SWT.NONE); + final var tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_theme_text); - final Composite parent = new Composite(folder, SWT.NONE); + final var parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - themeAssociationsWidget = new ThemeAssociationsWidget(themeManager, parent, SWT.NONE); - final GridData data = new GridData(GridData.FILL_HORIZONTAL); + final var themeAssociationsWidget = this.themeAssociationsWidget = new ThemeAssociationsWidget(themeManager, + parent, SWT.NONE); + final var data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; themeAssociationsWidget.setLayoutData(data); themeAssociationsWidget.addSelectionChangedListener(new ISelectionChangedListener() { @Override - public void selectionChanged(final SelectionChangedEvent e) { - final IThemeAssociation association = (IThemeAssociation) ((IStructuredSelection) e.getSelection()) - .getFirstElement(); + public void selectionChanged(@Nullable final SelectionChangedEvent e) { + if (e == null) + return; + final var association = (IThemeAssociation) ((IStructuredSelection) e.getSelection()).getFirstElement(); selectTheme(association); } - private void selectTheme(final IThemeAssociation association) { + private void selectTheme(@Nullable final IThemeAssociation association) { themeAssociationsWidget.getNewButton() .setEnabled(association != null /* && association.getPluginId() == null */); themeAssociationsWidget.getRemoveButton() @@ -466,7 +469,7 @@ private void selectTheme(final IThemeAssociation association) { private void setPreviewTheme(final String themeId) { final ITheme theme = themeManager.getThemeById(themeId); - if (theme != null) { + if (theme != null && previewViewer != null) { previewViewer.setTheme(theme); } } @@ -477,10 +480,10 @@ private void setPreviewTheme(final String themeId) { * @param folder */ private void createInjectionTab(final TabFolder folder) { - final TabItem tab = new TabItem(folder, SWT.NONE); + final var tab = new TabItem(folder, SWT.NONE); tab.setText(TMUIMessages.GrammarPreferencePage_tab_injection_text); - final Composite parent = new Composite(folder, SWT.NONE); + final var parent = new Composite(folder, SWT.NONE); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -490,12 +493,12 @@ private void createInjectionTab(final TabFolder folder) { } private int computeMinimumColumnWidth(final GC gc, final String string) { - return gc.stringExtent(string).x + 10; // pad 10 to accommodate table - // header trimmings + return gc.stringExtent(string).x + 10; // pad 10 to accommodate table header trimmings } private void updateButtons() { - grammarRemoveButton.setEnabled(false); + if (grammarRemoveButton != null) + grammarRemoveButton.setEnabled(false); } @@ -507,14 +510,14 @@ public void setVisible(final boolean visible) { } @Override - public void init(final IWorkbench workbench) { + public void init(@Nullable final IWorkbench workbench) { } private TMViewer doCreateViewer(final Composite parent) { - final Label label = new Label(parent, SWT.NONE); + final var label = new Label(parent, SWT.NONE); label.setText(TMUIMessages.GrammarPreferencePage_preview); - GridData data = new GridData(); + var data = new GridData(); data.horizontalSpan = 2; label.setLayoutData(data); @@ -524,7 +527,7 @@ private TMViewer doCreateViewer(final Composite parent) { // https://bugs.eclipse.org/293263 // viewer.getTextWidget().setCaret(null); - final Control control = viewer.getControl(); + final var control = viewer.getControl(); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; data.heightHint = convertHeightInCharsToPixels(5); @@ -553,8 +556,8 @@ public boolean performOk() { // Save the working copy if there are some changed. grammarRegistryManager.save(); themeManager.save(); - } catch (final BackingStoreException e) { - e.printStackTrace(); + } catch (final BackingStoreException ex) { + ex.printStackTrace(); return false; } return super.performOk(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java index 2e2df0c36..b610c565e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TextMatePreferencePage.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.internal.preferences; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -30,7 +31,7 @@ public final class TextMatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { @Override - protected Control createContents(final Composite parent) { + protected Control createContents(@Nullable final Composite parent) { final Composite composite = new Composite(parent, SWT.NONE); final GridLayout layout = new GridLayout(1, false); layout.marginHeight = layout.marginWidth = 0; @@ -62,7 +63,7 @@ private void addRelatedLink(final Composite parent, final String pageId, final S } @Override - public void init(final IWorkbench workbench) { + public void init(@Nullable final IWorkbench workbench) { } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index acc521665..ed08ea885 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -6,16 +6,20 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation - * Nicolaj Hoess - Editor templates pref page: Allow to sort by column - https://bugs.eclipse.org/203722 - * Angelo Zerr - Adapt org.eclipse.ui.texteditor.templates.TemplatePreferencePage for TextMate theme + * IBM Corporation - initial API and implementation + * Nicolaj Hoess - Editor templates pref page: Allow to sort by column - + * https://bugs.eclipse.org/203722 + * Angelo Zerr - Adapt org.eclipse.ui.texteditor.templates.TemplatePreferencePage for TextMate + * theme *******************************************************************************/ package org.eclipse.tm4e.ui.internal.preferences; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; import java.io.File; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.preference.PreferencePage; @@ -60,29 +64,35 @@ import org.osgi.service.prefs.BackingStoreException; /** - * A theme preference page allows configuration of the TextMate themes It - * provides controls for adding, removing and changing theme as well as - * enablement, default management. + * A theme preference page allows configuration of the TextMate themes. + * It provides controls for adding, removing and changing theme as well as enablement, default management. */ public final class ThemePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { static final String PAGE_ID = "org.eclipse.tm4e.ui.preferences.ThemePreferencePage"; // Theme content + @Nullable private TableViewer themeViewer; + @Nullable private Button themeRemoveButton; // Preview content + @Nullable private ComboViewer grammarViewer; + @Nullable private TMViewer previewViewer; private final IGrammarRegistryManager grammarRegistryManager = TMEclipseRegistryPlugin.getGrammarRegistryManager(); private final IThemeManager themeManager = TMUIPlugin.getThemeManager(); + @Nullable private Button darkThemeButton; + @Nullable private Button defaultThemeButton; + @Nullable private ITheme selectedTheme; public ThemePreferencePage() { @@ -90,7 +100,7 @@ public ThemePreferencePage() { } @Override - protected Control createContents(final Composite ancestor) { + protected Control createContents(@Nullable final Composite ancestor) { final Composite parent = new Composite(ancestor, SWT.NONE); final GridLayout layout = new GridLayout(); layout.numColumns = 2; @@ -112,11 +122,13 @@ protected Control createContents(final Composite ancestor) { createThemeDetailContent(innerParent); createPreviewContent(innerParent); + final var grammarViewer = castNonNull(this.grammarViewer); grammarViewer.setInput(grammarRegistryManager); if (grammarViewer.getCombo().getItemCount() > 0) { grammarViewer.getCombo().select(0); } - themeViewer.setInput(themeManager); + + castNonNull(themeViewer).setInput(themeManager); Dialog.applyDialogFont(parent); innerParent.layout(); @@ -150,7 +162,7 @@ private void createThemesContent(final Composite parent) { final ColumnViewerComparator viewerComparator = new ColumnViewerComparator(); - themeViewer = new TableViewer(table); + final var themeViewer = this.themeViewer = new TableViewer(table); final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(TMUIMessages.ThemePreferencePage_column_name); @@ -177,11 +189,12 @@ private void createThemesContent(final Composite parent) { themeViewer.setComparator(viewerComparator); themeViewer.addSelectionChangedListener(e -> { // Fill Theme details - selectedTheme = ((ITheme) ((IStructuredSelection) themeViewer.getSelection()).getFirstElement()); + final var selectedTheme = ThemePreferencePage.this.selectedTheme = ((ITheme) ((IStructuredSelection) themeViewer + .getSelection()).getFirstElement()); if (selectedTheme != null) { - darkThemeButton.setSelection(selectedTheme.isDark()); - defaultThemeButton.setSelection(selectedTheme.isDefault()); - themeRemoveButton.setEnabled(selectedTheme.getPluginId() == null); + castNonNull(darkThemeButton).setSelection(selectedTheme.isDark()); + castNonNull(defaultThemeButton).setSelection(selectedTheme.isDefault()); + castNonNull(themeRemoveButton).setEnabled(selectedTheme.getPluginId() == null); } preview(); }); @@ -204,7 +217,7 @@ private void createThemesContent(final Composite parent) { themeNewButton.setLayoutData(getButtonGridData(themeNewButton)); themeNewButton.addListener(SWT.Selection, new Listener() { @Override - public void handleEvent(final Event e) { + public void handleEvent(@Nullable final Event e) { final ITheme newTheme = addTheme(); if (newTheme != null) { themeManager.registerTheme(newTheme); @@ -214,10 +227,11 @@ public void handleEvent(final Event e) { } } + @Nullable private ITheme addTheme() { final FileDialog dialog = new FileDialog(getShell()); dialog.setText("Select textmate theme file"); - dialog.setFilterExtensions(new String[]{"*.css"}); + dialog.setFilterExtensions(new String[] { "*.css" }); final String res = dialog.open(); if (res == null) { return null; @@ -228,11 +242,13 @@ private ITheme addTheme() { } }); - themeRemoveButton = new Button(buttons, SWT.PUSH); + final var themeRemoveButton = this.themeRemoveButton = new Button(buttons, SWT.PUSH); themeRemoveButton.setText(TMUIMessages.Button_remove); themeRemoveButton.setLayoutData(getButtonGridData(themeRemoveButton)); themeRemoveButton.addListener(SWT.Selection, e -> { - themeManager.unregisterTheme(selectedTheme); + if (selectedTheme != null) { + themeManager.unregisterTheme(selectedTheme); + } themeViewer.refresh(); }); } @@ -255,11 +271,11 @@ private void createThemeDetailContent(final Composite ancestor) { layout.marginRight = 0; parent.setLayout(layout); - darkThemeButton = new Button(parent, SWT.CHECK); + final var darkThemeButton = this.darkThemeButton = new Button(parent, SWT.CHECK); darkThemeButton.setText(TMUIMessages.ThemePreferencePage_darkThemeButton_label); darkThemeButton.setEnabled(false); - defaultThemeButton = new Button(parent, SWT.CHECK); + final var defaultThemeButton = this.defaultThemeButton = new Button(parent, SWT.CHECK); defaultThemeButton.setText(TMUIMessages.ThemePreferencePage_defaultThemeButton_label); defaultThemeButton.setEnabled(false); } @@ -285,15 +301,11 @@ private void createPreviewContent(final Composite ancestor) { private int computeMinimumColumnWidth(final GC gc, final String string) { return gc.stringExtent(string).x + 10; // pad 10 to accommodate table - // header trimmings + // header trimmings } /** - * Return the grid data for the button. - * - * @param button - * the button - * @return the grid data + * @returns the grid data for the button. */ private static GridData getButtonGridData(final Button button) { final GridData data = new GridData(GridData.FILL_HORIZONTAL); @@ -312,17 +324,17 @@ public void setVisible(final boolean visible) { } @Override - public void init(final IWorkbench workbench) { + public void init(@Nullable final IWorkbench workbench) { } private void preview() { - IStructuredSelection selection = (IStructuredSelection) themeViewer.getSelection(); + IStructuredSelection selection = (IStructuredSelection) castNonNull(themeViewer).getSelection(); if (selection.isEmpty()) { return; } final ITheme theme = (ITheme) selection.getFirstElement(); - selection = (IStructuredSelection) grammarViewer.getSelection(); + selection = (IStructuredSelection) castNonNull(grammarViewer).getSelection(); if (selection.isEmpty()) { return; } @@ -331,6 +343,7 @@ private void preview() { // Preview the grammar final IGrammar grammar = grammarRegistryManager.getGrammarForScope(definition.getScopeName()); + final var previewViewer = castNonNull(this.previewViewer); previewViewer.setTheme(theme); previewViewer.setGrammar(grammar); } @@ -341,7 +354,7 @@ private TMViewer doCreateViewer(final Composite parent) { GridData data = new GridData(); label.setLayoutData(data); - grammarViewer = new ComboViewer(parent); + final var grammarViewer = this.grammarViewer = new ComboViewer(parent); grammarViewer.setContentProvider(new GrammarDefinitionContentProvider()); grammarViewer.setLabelProvider(new GrammarDefinitionLabelProvider()); grammarViewer.addSelectionChangedListener(e -> preview()); @@ -368,7 +381,8 @@ private TMViewer doCreateViewer(final Composite parent) { * source viewer featuring e.g. syntax coloring. * * @param parent - * the parent control + * the parent control + * * @return a configured source viewer */ private TMViewer createViewer(final Composite parent) { @@ -382,9 +396,8 @@ public boolean performOk() { grammarRegistryManager.save(); return true; } catch (final BackingStoreException e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); return false; } } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/package-info.java new file mode 100644 index 000000000..ce3d8cb28 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.preferences; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java index cdb98d3c7..de45af9c4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/Snippet.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.snippets; @@ -25,6 +25,8 @@ final class Snippet extends TMResource implements ISnippet { * Constructor for user preferences (loaded from Json with Gson). */ Snippet() { + scopeName = ""; + name = ""; } /** @@ -51,7 +53,8 @@ public String getName() { @Override public String getContent() { - return getResourceContent(); + final var content = getResourceContent(); + return content == null ? "":content; } @Override diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java index 38bbc16cd..bea1f614a 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/SnippetManager.java @@ -18,6 +18,7 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.ui.TMUIPlugin; import org.eclipse.tm4e.ui.snippets.ISnippet; import org.eclipse.tm4e.ui.snippets.ISnippetManager; @@ -31,6 +32,7 @@ public final class SnippetManager implements ISnippetManager { // "snippets" extension point private static final String EXTENSION_SNIPPETS = "snippets"; //$NON-NLS-1$ + @Nullable private static ISnippetManager INSTANCE; public static ISnippetManager getInstance() { @@ -50,7 +52,7 @@ private static synchronized ISnippetManager createInstance() { return manager; } - private final Map> snippets = new HashMap<>(); + private final Map> snippets = new HashMap<>(); private SnippetManager() { } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/package-info.java new file mode 100644 index 000000000..fc0f77865 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/snippets/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.snippets; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java index 6a1c5f7f4..0f233360e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/TMPresentationReconcilerTestGenerator.java @@ -1,16 +1,19 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.text; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentListener; @@ -23,7 +26,10 @@ public final class TMPresentationReconcilerTestGenerator implements ITMPresentationReconcilerListener, IDocumentListener, ITextListener { + @Nullable private ITextViewer viewer; + + @Nullable private IDocument document; private final StringBuilder code = new StringBuilder(); @@ -113,10 +119,10 @@ private String toText(final String text) { @Override public void uninstall() { -// for (Command command : commands) { -// write(toString(command.ranges)); -// } -// + // for (Command command : commands) { + // write(toString(command.ranges)); + // } + // write("", true); write("\t\twhile (!shell.isDisposed()) {", true); write("\t\t}", true); @@ -144,20 +150,19 @@ public void uninstall() { write("}"); System.err.println(code.toString()); - document.removeDocumentListener(this); - viewer.removeTextListener(this); - //commands.clear(); - + castNonNull(document).removeDocumentListener(this); + castNonNull(viewer).removeTextListener(this); + // commands.clear(); } @Override - public void colorize(final TextPresentation presentation, final Throwable e) { -// Command command = commands.get(commands.size() - 1); -// if (e != null) { -// command.error = e; -// } else { -// command.ranges = viewer.getTextWidget().getStyleRanges(); -// } + public void colorize(final TextPresentation presentation, @Nullable final Throwable e) { + // Command command = commands.get(commands.size() - 1); + // if (e != null) { + // command.error = e; + // } else { + // command.ranges = viewer.getTextWidget().getStyleRanges(); + // } } private void write(final String s, final boolean newLine) { @@ -172,30 +177,31 @@ private void write(final String s) { } @Override - public void documentAboutToBeChanged(final DocumentEvent event) { + public void documentAboutToBeChanged(@Nullable final DocumentEvent event) { } @Override - public void documentChanged(final DocumentEvent event) { - + public void documentChanged(@Nullable final DocumentEvent event) { + if (event == null) + return; final String command = "document.replace(" + event.getOffset() + ", " + event.getLength() + ", \"" + toText(event.getText()) + "\");"; write("\t\t" + command, true); - //commands.add(new Command(command)); + // commands.add(new Command(command)); } @Override - public void textChanged(final TextEvent event) { - if (event.getDocumentEvent() != null) { + public void textChanged(@Nullable final TextEvent event) { + if (event == null || event.getDocumentEvent() != null) { return; } - final String command = "viewer.invalidateTextPresentation(" + event.getOffset() + ", " + event.getLength() + ");"; + final String command = "viewer.invalidateTextPresentation(" + event.getOffset() + ", " + event.getLength() + + ");"; write("\t\t" + command, true); - //commands.add(new Command(command)); - + // commands.add(new Command(command)); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/package-info.java new file mode 100644 index 000000000..220ced993 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/text/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.text; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java index f4060e026..9f0d93645 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractThemeManager.java @@ -1,13 +1,13 @@ /** - * Copyright (c) 2015, 2021 Angelo ZERR and others. + * Copyright (c) 2015, 2021 Angelo ZERR and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.themes; @@ -18,6 +18,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.graphics.RGB; import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils; import org.eclipse.tm4e.ui.themes.ITheme; @@ -45,6 +46,7 @@ public void unregisterTheme(final ITheme theme) { themes.remove(theme.getId()); } + @Nullable @Override public ITheme getThemeById(final String themeId) { return themes.get(themeId); @@ -68,13 +70,13 @@ ITheme getDefaultTheme(final boolean dark) { return theme; } } - return null; + throw new IllegalStateException("Should never be reached"); } @Override public ITheme[] getThemes(final boolean dark) { return themes.values().stream().filter(theme -> theme.isDark() == dark) - .collect(Collectors.toList()).toArray(ITheme[]::new); + .collect(Collectors.toList()).toArray(ITheme[]::new); } @Override @@ -83,7 +85,7 @@ public boolean isDarkEclipseTheme() { } @Override - public boolean isDarkEclipseTheme(final String eclipseThemeId) { + public boolean isDarkEclipseTheme(@Nullable final String eclipseThemeId) { return eclipseThemeId != null && eclipseThemeId.toLowerCase().contains("dark"); } @@ -92,7 +94,10 @@ public ITheme getThemeForScope(final String scopeName, final boolean dark) { final IThemeAssociation association = themeAssociationRegistry.getThemeAssociationFor(scopeName, dark); if (association != null) { final String themeId = association.getThemeId(); - return getThemeById(themeId); + final var theme = getThemeById(themeId); + if (theme != null) { + return theme; + } } return getDefaultTheme(dark); } @@ -136,7 +141,8 @@ public IThemeAssociation[] getAllThemeAssociations() { @Override public ITokenProvider getThemeForScope(final String scopeName, final RGB background) { - return getThemeForScope(scopeName, 0.299 * background.red + 0.587 * background.green + 0.114 * background.blue < 128); + return getThemeForScope(scopeName, 0.299 * background.red + + 0.587 * background.green + + 0.114 * background.blue < 128); } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java index e62dd7cb0..7622221bd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/BaseThemeAssociationRegistry.java @@ -12,12 +12,12 @@ package org.eclipse.tm4e.ui.internal.themes; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.ui.themes.IThemeAssociation; /** @@ -27,8 +27,9 @@ */ final class BaseThemeAssociationRegistry { + @Nullable private IThemeAssociation defaultAssociation; - private final Map> eclipseThemeIds = new HashMap<>(); + private final Map> eclipseThemeIds = new HashMap<>(); private final List allAssociations = new ArrayList<>(); void register(final IThemeAssociation association) { @@ -66,6 +67,7 @@ void unregister(final IThemeAssociation association) { allAssociations.clear(); } + @Nullable IThemeAssociation getThemeAssociationFor(final String eclipseThemeId) { final List associations = eclipseThemeIds.get(eclipseThemeId); if (associations != null) { @@ -89,6 +91,7 @@ IThemeAssociation[] getThemeAssociations(final boolean isDefault) { return getThemeAssociations().toArray(IThemeAssociation[]::new); } + @Nullable IThemeAssociation getDefaultAssociation() { return defaultAssociation; } @@ -125,8 +128,8 @@ List getThemeAssociations() { if (defaultAssociation != null) { allAssociations.add(defaultAssociation); } - final Collection> associations = eclipseThemeIds.values(); - for (final Collection collection : associations) { + final var associations = eclipseThemeIds.values(); + for (final var collection : associations) { allAssociations.addAll(collection); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java index 9a6d88682..bb6eda273 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeAssociationRegistry.java @@ -1,62 +1,47 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.themes; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.ui.themes.IThemeAssociation; /** * Theme association registry. - * */ final class ThemeAssociationRegistry { - private final Map scopes = new HashMap<>(); + private final Map<@Nullable String, @Nullable EclipseThemeAssociation> scopes = new HashMap<>(); private static final class EclipseThemeAssociation { - private IThemeAssociation light; - private IThemeAssociation dark; - - IThemeAssociation getLight() { - return light; - } - - void setLight(final IThemeAssociation light) { - this.light = light; - } - - IThemeAssociation getDark() { - return dark; - } - - void setDark(final IThemeAssociation dark) { - this.dark = dark; - } + @Nullable + IThemeAssociation light; + @Nullable + IThemeAssociation dark; } - + @Nullable IThemeAssociation getThemeAssociationFor(final String scopeName, final boolean dark) { - // From theme assiocations + // From theme associations IThemeAssociation userAssociation = null; final EclipseThemeAssociation registry = scopes.get(scopeName); if (registry != null) { - userAssociation = dark ? registry.getDark() : registry.getLight(); + userAssociation = dark ? registry.dark : registry.light; } if (userAssociation != null) { return userAssociation; @@ -73,9 +58,9 @@ void register(final IThemeAssociation association) { } final boolean dark = association.isWhenDark(); if (dark) { - registry.setDark(association); + registry.dark = association; } else { - registry.setLight(association); + registry.light = association; } } @@ -85,9 +70,9 @@ void unregister(final IThemeAssociation association) { if (registry != null) { final boolean dark = association.isWhenDark(); if (dark) { - registry.setDark(null); + registry.dark = null; } else { - registry.setLight(null); + registry.light = null; } } } @@ -148,14 +133,16 @@ void unregister(final IThemeAssociation association) { // // @Override List getThemeAssociations() { - final List associations = new ArrayList<>(); - final Collection eclipseAssociations = scopes.values(); + final var associations = new ArrayList(); + final var eclipseAssociations = scopes.values(); for (final EclipseThemeAssociation eclipseAssociation : eclipseAssociations) { - if (eclipseAssociation.getLight() != null) { - associations.add(eclipseAssociation.getLight()); + if (eclipseAssociation == null) + continue; + if (eclipseAssociation.light != null) { + associations.add(eclipseAssociation.light); } - if (eclipseAssociation.getDark() != null) { - associations.add(eclipseAssociation.getDark()); + if (eclipseAssociation.dark != null) { + associations.add(eclipseAssociation.dark); } } return associations; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java index fb30dc00a..810ee6385 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/ThemeManager.java @@ -14,11 +14,10 @@ import java.util.Arrays; import java.util.stream.Collectors; -import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.ui.TMUIPlugin; import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; import org.eclipse.tm4e.ui.internal.preferences.PreferenceHelper; @@ -46,6 +45,7 @@ public final class ThemeManager extends AbstractThemeManager { // "themeAssociation" declaration private static final String THEME_ASSOCIATION_ELT = "themeAssociation"; //$NON-NLS-1$ + @Nullable private static ThemeManager INSTANCE; public static ThemeManager getInstance() { @@ -77,16 +77,16 @@ private void load() { * Load TextMate Themes from extension point. */ private void loadThemesFromExtensionPoints() { - final IConfigurationElement[] cf = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, + final var config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMUIPlugin.PLUGIN_ID, EXTENSION_THEMES); - for (final IConfigurationElement ce : cf) { - final String name = ce.getName(); + for (final var configElement : config) { + final String name = configElement.getName(); switch (name) { case THEME_ELT: - super.registerTheme(new Theme(ce)); + super.registerTheme(new Theme(configElement)); break; case THEME_ASSOCIATION_ELT: - super.registerThemeAssociation(new ThemeAssociation(ce)); + super.registerThemeAssociation(new ThemeAssociation(configElement)); break; } } @@ -98,10 +98,10 @@ private void loadThemesFromExtensionPoints() { private void loadThemesFromPreferences() { // Load Theme definitions from the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" - final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + final var prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); String json = prefs.get(PreferenceConstants.THEMES, null); if (json != null) { - for (final JsonObject element : new Gson().fromJson(json, JsonObject[].class)) { + for (final var element : new Gson().fromJson(json, JsonObject[].class)) { final String name = element.get("id").getAsString(); super.registerTheme(new Theme(name, element.get("path").getAsString(), name, element.get("dark").getAsBoolean(), false)); } @@ -109,7 +109,7 @@ private void loadThemesFromPreferences() { json = prefs.get(PreferenceConstants.THEME_ASSOCIATIONS, null); if (json != null) { - final IThemeAssociation[] themeAssociations = PreferenceHelper.loadThemeAssociations(json); + final var themeAssociations = PreferenceHelper.loadThemeAssociations(json); for (final IThemeAssociation association : themeAssociations) { super.registerThemeAssociation(association); } @@ -118,7 +118,7 @@ private void loadThemesFromPreferences() { @Override public void save() throws BackingStoreException { - final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); + final var prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID); // Save Themes in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs" prefs.put(PreferenceConstants.THEMES, Arrays.stream(getThemes()) // @@ -150,7 +150,7 @@ public void save() throws BackingStoreException { */ public void addPreferenceChangeListener(final IPreferenceChangeListener themeChangeListener) { // Observe change of Eclipse E4 Theme - IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); + var preferences = PreferenceUtils.getE4PreferenceStore(); if (preferences != null) { preferences.addPreferenceChangeListener(themeChangeListener); } @@ -169,7 +169,7 @@ public void addPreferenceChangeListener(final IPreferenceChangeListener themeCha */ public void removePreferenceChangeListener(final IPreferenceChangeListener themeChangeListener) { // Observe change of Eclipse E4 Theme - IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore(); + var preferences = PreferenceUtils.getE4PreferenceStore(); if (preferences != null) { preferences.removePreferenceChangeListener(themeChangeListener); } @@ -179,5 +179,4 @@ public void removePreferenceChangeListener(final IPreferenceChangeListener theme preferences.removePreferenceChangeListener(themeChangeListener); } } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java index 15f67f05c..7a07e39d1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/WorkingCopyThemeManager.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.themes; import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.ui.themes.ITheme; import org.eclipse.tm4e.ui.themes.IThemeAssociation; import org.eclipse.tm4e.ui.themes.IThemeManager; @@ -27,10 +28,16 @@ public final class WorkingCopyThemeManager extends AbstractThemeManager { private final IThemeManager manager; + @Nullable private List themeAdded; + + @Nullable private List themeRemoved; + @Nullable private List associationAdded; + + @Nullable private List associationRemoved; public WorkingCopyThemeManager(final IThemeManager manager) { @@ -54,8 +61,9 @@ private void load() { @Override public void registerTheme(final ITheme theme) { super.registerTheme(theme); + var themeAdded = this.themeAdded; if (themeAdded == null) { - themeAdded = new ArrayList<>(); + themeAdded = this.themeAdded = new ArrayList<>(); } themeAdded.add(theme); } @@ -63,11 +71,13 @@ public void registerTheme(final ITheme theme) { @Override public void unregisterTheme(final ITheme theme) { super.unregisterTheme(theme); + var themeAdded = this.themeAdded; if (themeAdded != null && themeAdded.contains(theme)) { themeAdded.remove(theme); } else { + var themeRemoved = this.themeRemoved; if (themeRemoved == null) { - themeRemoved = new ArrayList<>(); + themeRemoved = this.themeRemoved = new ArrayList<>(); } themeRemoved.add(theme); } @@ -76,8 +86,9 @@ public void unregisterTheme(final ITheme theme) { @Override public void registerThemeAssociation(final IThemeAssociation association) { super.registerThemeAssociation(association); + var associationAdded = this.associationAdded; if (associationAdded == null) { - associationAdded = new ArrayList<>(); + associationAdded = this.associationAdded = new ArrayList<>(); } associationAdded.add(association); } @@ -85,11 +96,13 @@ public void registerThemeAssociation(final IThemeAssociation association) { @Override public void unregisterThemeAssociation(final IThemeAssociation association) { super.unregisterThemeAssociation(association); + var associationAdded = this.associationAdded; if (associationAdded != null && associationAdded.contains(association)) { associationAdded.remove(association); } else { + var associationRemoved = this.associationRemoved; if (associationRemoved == null) { - associationRemoved = new ArrayList<>(); + associationRemoved = this.associationRemoved = new ArrayList<>(); } associationRemoved.add(association); } @@ -98,22 +111,22 @@ public void unregisterThemeAssociation(final IThemeAssociation association) { @Override public void save() throws BackingStoreException { if (themeAdded != null) { - for (final ITheme theme : themeAdded) { + for (final var theme : themeAdded) { manager.registerTheme(theme); } } if (themeRemoved != null) { - for (final ITheme theme : themeRemoved) { + for (final var theme : themeRemoved) { manager.unregisterTheme(theme); } } if (associationAdded != null) { - for (final IThemeAssociation association : associationAdded) { + for (final var association : associationAdded) { manager.registerThemeAssociation(association); } } if (associationRemoved != null) { - for (final IThemeAssociation association : associationRemoved) { + for (final var association : associationRemoved) { manager.unregisterThemeAssociation(association); } } @@ -121,5 +134,4 @@ public void save() throws BackingStoreException { manager.save(); } } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/package-info.java new file mode 100644 index 000000000..fd0db7b9e --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.themes; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java index 322f58426..ef5f6b5ad 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ClassHelper.java @@ -13,12 +13,15 @@ import java.lang.reflect.Field; +import org.eclipse.jdt.annotation.Nullable; + /** * Class Reflection utilities. * */ public final class ClassHelper { + @Nullable @SuppressWarnings("unchecked") public static T getFieldValue(final Object object, final String name, final Class clazz) { final Field f = getDeclaredField(clazz, name); @@ -32,11 +35,13 @@ public static T getFieldValue(final Object object, final String name, final return null; } + @Nullable public static T getFieldValue(final Object object, final String name) { return getFieldValue(object, name, object.getClass()); } - public static Field getDeclaredField(final Class clazz, final String name) { + @Nullable + public static Field getDeclaredField(@Nullable final Class clazz, final String name) { if (clazz == null) { return null; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java index 0c53398dc..56022dd26 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java @@ -31,6 +31,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.IDocument; import org.eclipse.tm4e.ui.internal.model.DocumentInputStream; import org.eclipse.ui.IEditorInput; @@ -46,10 +47,10 @@ public final class ContentTypeHelper { * Find the content types from the given {@link IDocument} and null otherwise. * * @param document - * @return the content types from the given {@link IDocument} and null - * otherwise. + * @return the content types from the given {@link IDocument} and null otherwise. * @throws CoreException */ + @Nullable public static ContentTypeInfo findContentTypes(final IDocument document) throws CoreException { // Find content types from FileBuffers final ContentTypeInfo contentTypes = findContentTypesFromFileBuffers(document); @@ -82,6 +83,7 @@ public static IContentType getContentTypeById(final String contentTypeId) { * {@link ITextFileBufferManager} and null otherwise. * @throws CoreException */ + @Nullable private static ContentTypeInfo findContentTypesFromFileBuffers(final IDocument document) throws CoreException { final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); final ITextFileBuffer buffer = bufferManager.getTextFileBuffer(document); @@ -98,6 +100,7 @@ private static ContentTypeInfo findContentTypesFromFileBuffers(final IDocument d * @return the content types from the given {@link ITextFileBuffer}. * @throws CoreException */ + @Nullable private static ContentTypeInfo getContentTypes(final ITextFileBuffer buffer) throws CoreException { try { final String fileName = buffer.getFileStore().getName(); @@ -160,6 +163,7 @@ private static InputStream getContents(final ITextFileBuffer buffer) throws Core * @return the content types from the given {@link IDocument} by using * {@link IEditorInput} and null otherwise. */ + @Nullable private static ContentTypeInfo findContentTypesFromEditorInput(final IDocument document) { final IEditorInput editorInput = getEditorInput(document); if (editorInput != null) { @@ -174,9 +178,9 @@ private static ContentTypeInfo findContentTypesFromEditorInput(final IDocument d } catch (final Exception e) { return null; } - } else { + } /*else { // TODO: manage other type of IEditorInput - } + }*/ } return null; } @@ -187,6 +191,7 @@ private static ContentTypeInfo findContentTypesFromEditorInput(final IDocument d * @param document * @return the {@link IEditorInput} from the given document and null otherwise. */ + @Nullable private static IEditorInput getEditorInput(final IDocument document) { try { // This utilities class is very ugly, I have not found a clean mean diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java index 3d9a21db3..7dcc939b6 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeInfo.java @@ -14,9 +14,7 @@ import org.eclipse.core.runtime.content.IContentType; /** - * * @author azerr - * */ public final class ContentTypeInfo { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java index 8a1a4477a..f84e0fa59 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/PreferenceUtils.java @@ -13,6 +13,7 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.tm4e.ui.TMUIPlugin; import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; @@ -30,6 +31,7 @@ private PreferenceUtils() { * * @return preferences store */ + @Nullable public static IEclipsePreferences getE4PreferenceStore() { return InstanceScope.INSTANCE.getNode(E4_CSS_PREFERENCE_NAME); } @@ -39,6 +41,7 @@ public static IEclipsePreferences getE4PreferenceStore() { * * @return themeIf of the current eclipse theme */ + @Nullable public static String getE4PreferenceCSSThemeId() { final IEclipsePreferences preferences = getE4PreferenceStore(); return preferences != null ? preferences.get(PreferenceConstants.E4_THEME_ID, null) : null; @@ -49,6 +52,7 @@ public static String getE4PreferenceCSSThemeId() { * * @return preferences store */ + @Nullable public static IEclipsePreferences getEditorsPreferenceStore() { return InstanceScope.INSTANCE.getNode(EDITORS_PREFERENCE_NAME); } @@ -58,8 +62,9 @@ public static IEclipsePreferences getEditorsPreferenceStore() { * * @return preferences store */ + @Nullable public static IPreferenceStore getTM4EPreferencesStore() { - return TMUIPlugin.getDefault().getPreferenceStore(); - + final var plugin = TMUIPlugin.getDefault(); + return plugin == null ? null : plugin.getPreferenceStore(); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/package-info.java new file mode 100644 index 000000000..e67631051 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.utils; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java index 7bb27ba1b..aeb2e81b5 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -36,7 +37,7 @@ public ColumnSelectionAdapter(final TableColumn column, final TableViewer tableV } @Override - public void widgetSelected(final SelectionEvent e) { + public void widgetSelected(@Nullable final SelectionEvent e) { viewerComparator.setColumn(fColumnIndex); final int dir = viewerComparator.getDirection(); final Table table = tableViewer.getTable(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java index ab5c97d18..856aa7413 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.TableViewer; @@ -53,7 +54,7 @@ public void setColumn(final int column) { } @Override - public int compare(final Viewer viewer, final Object e1, final Object e2) { + public int compare(@Nullable final Viewer viewer, @Nullable final Object e1, @Nullable final Object e2) { if (viewer instanceof TableViewer) { final IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java index 96baee69b..f3268f135 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ContentTypeLabelProvider.java @@ -13,6 +13,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; @@ -22,18 +23,21 @@ */ public final class ContentTypeLabelProvider extends LabelProvider implements ITableLabelProvider { + @Nullable @Override - public Image getColumnImage(final Object element, final int columnIndex) { + public Image getColumnImage(@Nullable final Object element, final int columnIndex) { return null; } + @Nullable @Override - public String getText(final Object element) { + public String getText(@Nullable final Object element) { return getColumnText(element, 0); } + @Nullable @Override - public String getColumnText(final Object element, final int columnIndex) { + public String getColumnText(@Nullable final Object element, final int columnIndex) { switch (columnIndex) { case 0: IContentType contentType = null; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java index dc1ebe2b4..a47245472 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionContentProvider.java @@ -1,35 +1,40 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.tm4e.registry.IGrammarRegistryManager; /** * A content provider for the template grammar page's table viewer. - * + * */ public final class GrammarDefinitionContentProvider implements IStructuredContentProvider { - + @Nullable private IGrammarRegistryManager registry; @Override - public Object[] getElements(final Object input) { + public Object @Nullable [] getElements(@Nullable final Object input) { + final var registry = this.registry; + if (registry == null) + return null; return registry.getDefinitions(); } @Override - public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { + public void inputChanged(@Nullable final Viewer viewer, @Nullable final Object oldInput, + @Nullable final Object newInput) { registry = (IGrammarRegistryManager) newInput; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java index 86adcaac4..d0d314d46 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarDefinitionLabelProvider.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; @@ -20,19 +21,24 @@ * Label provider for grammar definition. */ public final class GrammarDefinitionLabelProvider extends LabelProvider implements ITableLabelProvider { - + @Nullable @Override - public Image getColumnImage(final Object element, final int columnIndex) { + public Image getColumnImage(@Nullable final Object element, final int columnIndex) { return null; } + @Nullable @Override - public String getText(final Object element) { + public String getText(@Nullable final Object element) { return getColumnText(element, 0); } + @Nullable @Override - public String getColumnText(final Object element, final int columnIndex) { + public String getColumnText(@Nullable final Object element, final int columnIndex) { + if (element == null) + return ""; + final IGrammarDefinition definition = (IGrammarDefinition) element; switch (columnIndex) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java index 7459af7d1..7082bb38b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/GrammarInfoWidget.java @@ -1,20 +1,21 @@ /** - * Copyright (c) 2015-2019 Angelo ZERR. + * Copyright (c) 2015-2019 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation - * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes */ package org.eclipse.tm4e.ui.internal.widgets; import java.util.Collection; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -25,7 +26,6 @@ import org.eclipse.tm4e.ui.internal.TMUIMessages; /** - * * Widget which display grammar information like name, scope, and file types. */ public final class GrammarInfoWidget extends Composite { @@ -43,36 +43,33 @@ public GrammarInfoWidget(final Composite parent, final int style) { layout.marginRight = 0; super.setLayout(layout); super.setLayoutData(new GridData(GridData.FILL_BOTH)); - createUI(this); - } - private void createUI(final Composite ancestor) { - final Composite parent = new Composite(ancestor, SWT.NONE); - final GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginLeft = 0; - layout.marginRight = 0; - parent.setLayout(layout); - parent.setLayoutData(new GridData(GridData.FILL_BOTH)); + final Composite container = new Composite(this, SWT.NONE); + final GridLayout containerLayout = new GridLayout(2, false); + containerLayout.marginHeight = 0; + containerLayout.marginWidth = 0; + containerLayout.marginLeft = 0; + containerLayout.marginRight = 0; + container.setLayout(containerLayout); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); - final Label grammarNameLabel = new Label(parent, SWT.NONE); + final Label grammarNameLabel = new Label(container, SWT.NONE); grammarNameLabel.setText(TMUIMessages.GrammarInfoWidget_name_text); - nameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); + nameText = new Text(container, SWT.BORDER | SWT.READ_ONLY); nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - final Label grammarScopeNameLabel = new Label(parent, SWT.NONE); + final Label grammarScopeNameLabel = new Label(container, SWT.NONE); grammarScopeNameLabel.setText(TMUIMessages.GrammarInfoWidget_scopeName_text); - scopeNameText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); + scopeNameText = new Text(container, SWT.BORDER | SWT.READ_ONLY); scopeNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - final Label grammarFileTypesLabel = new Label(parent, SWT.NONE); + final Label grammarFileTypesLabel = new Label(container, SWT.NONE); grammarFileTypesLabel.setText(TMUIMessages.GrammarInfoWidget_fileTypes_text); - fileTypesText = new Text(parent, SWT.BORDER | SWT.READ_ONLY); + fileTypesText = new Text(container, SWT.BORDER | SWT.READ_ONLY); fileTypesText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } - public void refresh(final IGrammar grammar) { + public void refresh(@Nullable final IGrammar grammar) { if (grammar == null) { nameText.setText(""); scopeNameText.setText(""); @@ -81,7 +78,7 @@ public void refresh(final IGrammar grammar) { final String name = grammar.getName(); nameText.setText(name != null ? name : ""); final String scope = grammar.getScopeName(); - scopeNameText.setText(scope != null ? scope : ""); + scopeNameText.setText(scope); final Collection fileTypes = grammar.getFileTypes(); final String types = fileTypes.stream().map(Object::toString).collect(Collectors.joining(",")); fileTypesText.setText(types); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java index 93785f094..dc2453aaf 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.presentation.IPresentationReconciler; @@ -27,39 +28,30 @@ /** * Simple TextMate Viewer. - * */ public final class TMViewer extends SourceViewer { - private TMPresentationReconciler reconciler; + private final TMPresentationReconciler reconciler = new TMPresentationReconciler(); public TMViewer(final Composite parent, final IVerticalRuler ruler, final int styles) { - super(parent, ruler, styles); - init(); + this(parent, ruler, null, false, styles); } - public TMViewer(final Composite parent, final IVerticalRuler verticalRuler, final IOverviewRuler overviewRuler, + public TMViewer(final Composite parent, @Nullable final IVerticalRuler verticalRuler, + @Nullable final IOverviewRuler overviewRuler, final boolean showAnnotationsOverview, final int styles) { super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); - init(); - } - - private void init() { - this.reconciler = new TMPresentationReconciler(); - final SourceViewerConfiguration configuration = new TMSourceViewerConfiguration(); - this.configure(configuration); + configure(new TMSourceViewerConfiguration()); } private final class TMSourceViewerConfiguration extends SourceViewerConfiguration { - @Override - public IPresentationReconciler getPresentationReconciler(final ISourceViewer sourceViewer) { + public IPresentationReconciler getPresentationReconciler(@Nullable final ISourceViewer sourceViewer) { return reconciler; } - } - public void setGrammar(final IGrammar grammar) { + public void setGrammar(@Nullable final IGrammar grammar) { reconciler.setGrammar(grammar); if (getDocument() == null) { super.setDocument(new Document()); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java index 22fc0eaeb..f52c382e7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableAndButtonsWidget.java @@ -1,16 +1,19 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -29,6 +32,7 @@ */ public abstract class TableAndButtonsWidget extends Composite { + @Nullable private TableViewer viewer; protected TableAndButtonsWidget(final Composite parent, final int style, final String title) { @@ -73,9 +77,6 @@ private void createUI(final String title, final Composite ancestor) { protected abstract void createButtons(Composite parent); private void createTitle(final String title, final Composite ancestor) { - if (title == null) { - return; - } final Label label = new Label(ancestor, SWT.NONE); label.setText(title); final GridData data = new GridData(GridData.FILL_HORIZONTAL); @@ -84,7 +85,8 @@ private void createTitle(final String title, final Composite ancestor) { } private void createTable(final Composite parent) { - final Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); + final Table table = new Table(parent, + SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); table.setHeaderVisible(false); table.setLinesVisible(false); @@ -93,31 +95,32 @@ private void createTable(final Composite parent) { } - public void setInput(final Object input) { - viewer.setInput(input); + public void setInput(@Nullable final Object input) { + castNonNull(viewer).setInput(input); } + @Nullable public TableViewer getViewer() { return viewer; } public void setLabelProvider(final IBaseLabelProvider labelProvider) { - viewer.setLabelProvider(labelProvider); + castNonNull(viewer).setLabelProvider(labelProvider); } public void setContentProvider(final IContentProvider provider) { - viewer.setContentProvider(provider); + castNonNull(viewer).setContentProvider(provider); } public void addSelectionChangedListener(final ISelectionChangedListener listener) { - viewer.addSelectionChangedListener(listener); + castNonNull(viewer).addSelectionChangedListener(listener); } public void setSelection(final IStructuredSelection selection) { - viewer.setSelection(selection); + castNonNull(viewer).setSelection(selection); } public IStructuredSelection getSelection() { - return viewer.getStructuredSelection(); + return castNonNull(viewer).getStructuredSelection(); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java index bed97d1cd..95f7ee0da 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationLabelProvider.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; @@ -26,18 +27,24 @@ */ public final class ThemeAssociationLabelProvider extends LabelProvider implements ITableLabelProvider { + @Nullable @Override - public Image getColumnImage(final Object element, final int columnIndex) { + public Image getColumnImage(@Nullable final Object element, final int columnIndex) { return null; } + @Nullable @Override - public String getText(final Object element) { + public String getText(@Nullable final Object element) { return getColumnText(element, 0); } + @Nullable @Override - public String getColumnText(final Object element, final int columnIndex) { + public String getColumnText(@Nullable final Object element, final int columnIndex) { + if (element == null) + return ""; + final IThemeAssociation association = (IThemeAssociation) element; switch (columnIndex) { case 0: @@ -52,6 +59,7 @@ public String getColumnText(final Object element, final int columnIndex) { } } + @Nullable private ITheme getTheme(final IThemeAssociation association) { final String themeId = association.getThemeId(); final IThemeManager themeManager = TMUIPlugin.getThemeManager(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java index 25b3e68d2..9698c74df 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java @@ -1,18 +1,21 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.util.Iterator; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; @@ -38,9 +41,11 @@ public final class ThemeAssociationsWidget extends TableAndButtonsWidget { private final IThemeManager themeManager; + @Nullable private Button editButton; + @Nullable private Button removeButton; - + @Nullable private IGrammarDefinition definition; public ThemeAssociationsWidget(final IThemeManager themeManager, final Composite parent, final int style) { @@ -52,7 +57,7 @@ public ThemeAssociationsWidget(final IThemeManager themeManager, final Composite @Override protected void createButtons(final Composite parent) { - editButton = new Button(parent, SWT.PUSH); + final var editButton = this.editButton = new Button(parent, SWT.PUSH); editButton.setText(TMUIMessages.Button_edit); editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); editButton.addListener(SWT.Selection, e -> { @@ -70,11 +75,10 @@ protected void createButtons(final Composite parent) { }); editButton.setEnabled(false); - removeButton = new Button(parent, SWT.PUSH); + final var removeButton = this.removeButton = new Button(parent, SWT.PUSH); removeButton.setText(TMUIMessages.Button_remove); removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); removeButton.addListener(SWT.Selection, e -> { - if (MessageDialog.openConfirm(getShell(), TMUIMessages.ThemeAssociationsWidget_remove_dialog_title, TMUIMessages.ThemeAssociationsWidget_remove_dialog_message)) { final IStructuredSelection selection = super.getSelection(); @@ -91,11 +95,11 @@ protected void createButtons(final Composite parent) { } public Button getNewButton() { - return editButton; + return castNonNull(editButton); } public Button getRemoveButton() { - return removeButton; + return castNonNull(removeButton); } public IThemeAssociation[] setGrammarDefinition(final IGrammarDefinition definition) { @@ -103,12 +107,17 @@ public IThemeAssociation[] setGrammarDefinition(final IGrammarDefinition definit return refresh(null); } - private IThemeAssociation[] refresh(IThemeAssociation association) { - final IThemeAssociation[] themeAssociations = themeManager.getThemeAssociationsForScope(definition.getScopeName()); + private IThemeAssociation[] refresh(@Nullable IThemeAssociation association) { + final var definition = this.definition; + if (definition == null) { + return new IThemeAssociation[0]; + } + final IThemeAssociation[] themeAssociations = themeManager + .getThemeAssociationsForScope(definition.getScopeName()); // Refresh the list of associations super.setInput(themeAssociations); // Select the first of given association - if (association == null && themeAssociations != null && themeAssociations.length > 0) { + if (association == null && themeAssociations.length > 0) { association = themeAssociations[0]; } if (association != null) { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java index a84e7ffa3..4316c56e8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeContentProvider.java @@ -1,35 +1,41 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.tm4e.ui.themes.IThemeManager; /** * A content provider for the template theme page's table viewer. - * + * */ public final class ThemeContentProvider implements IStructuredContentProvider { + @Nullable private IThemeManager registry; @Override - public Object[] getElements(final Object input) { + public Object @Nullable [] getElements(@Nullable final Object input) { + final var registry = this.registry; + if (registry == null) + return null; return registry.getThemes(); } @Override - public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { + public void inputChanged(@Nullable final Viewer viewer, @Nullable final Object oldInput, + @Nullable final Object newInput) { registry = (IThemeManager) newInput; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java index 4cece1a96..0154c4d1f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeLabelProvider.java @@ -1,16 +1,17 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.widgets; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; @@ -21,19 +22,26 @@ */ public final class ThemeLabelProvider extends LabelProvider implements ITableLabelProvider { + @Nullable @Override - public Image getColumnImage(final Object element, final int columnIndex) { + public Image getColumnImage(@Nullable final Object element, final int columnIndex) { return null; } - + + @Nullable @Override - public String getText(final Object element) { + public String getText(@Nullable final Object element) { + if (element == null) + return ""; final ITheme theme = (ITheme) element; return theme.getName(); } + @Nullable @Override - public String getColumnText(final Object element, final int columnIndex) { + public String getColumnText(@Nullable final Object element, final int columnIndex) { + if (element == null) + return ""; final ITheme theme = (ITheme) element; switch (columnIndex) { case 0: diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/package-info.java new file mode 100644 index 000000000..b08e26c4a --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.widgets; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java index 2b05f5b0c..fbbce6fd8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/AbstractWizardPage.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation * */ package org.eclipse.tm4e.ui.internal.wizards; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.resource.ImageDescriptor; @@ -40,7 +41,9 @@ protected AbstractWizardPage(final String pageName, final String title, final Im } @Override - public final void createControl(final Composite parent) { + public final void createControl(@Nullable final Composite parent) { + assert parent != null; + initializeDialogUnits(parent); // top level group final Composite topLevel = new Composite(parent, SWT.NONE); @@ -53,13 +56,14 @@ public final void createControl(final Composite parent) { // initialize page with default values initializeDefaultValues(); // Validate page fields. -// validateAndUpdateStatus(null); + // validateAndUpdateStatus(null); setControl(topLevel); } @Override - public void handleEvent(final Event event) { - validateAndUpdateStatus(event); + public void handleEvent(@Nullable final Event event) { + if (event != null) + validateAndUpdateStatus(event); } private void validateAndUpdateStatus(final Event event) { @@ -104,6 +108,7 @@ private static void applyToStatusLine(final DialogPage page, final IStatus statu protected abstract void initializeDefaultValues(); + @Nullable protected abstract IStatus validatePage(Event event); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java index c66c810b8..34d5f11ad 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizard.java @@ -1,16 +1,19 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.wizards; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.wizard.Wizard; import org.eclipse.tm4e.registry.IGrammarDefinition; import org.eclipse.tm4e.ui.TMUIPlugin; @@ -24,16 +27,20 @@ */ public final class CreateThemeAssociationWizard extends Wizard { + @Nullable private CreateThemeAssociationWizardPage mainPage; + @Nullable private IThemeAssociation createdThemeAssociation; private IThemeManager themeManager = TMUIPlugin.getThemeManager(); private final boolean save; + @Nullable private IGrammarDefinition initialDefinition; + @Nullable private IThemeAssociation initialAssociation; public CreateThemeAssociationWizard(final boolean save) { @@ -42,8 +49,6 @@ public CreateThemeAssociationWizard(final boolean save) { /** * Set theme manager to use to add the created theme associations. - * - * @param themeManager */ public void setThemeManager(final IThemeManager themeManager) { this.themeManager = themeManager; @@ -57,7 +62,7 @@ public void addPages() { @Override public boolean performFinish() { - final IThemeAssociation association = mainPage.getThemeAssociation(); + final IThemeAssociation association = castNonNull(mainPage).getThemeAssociation(); themeManager.registerThemeAssociation(association); if (save) { try { @@ -71,15 +76,16 @@ public boolean performFinish() { return true; } + @Nullable public IThemeAssociation getCreatedThemeAssociation() { return createdThemeAssociation; } - public void setInitialDefinition(final IGrammarDefinition definition) { + public void setInitialDefinition(@Nullable final IGrammarDefinition definition) { this.initialDefinition = definition; } - public void setInitialAssociation(final IThemeAssociation association) { + public void setInitialAssociation(@Nullable final IThemeAssociation association) { this.initialAssociation = association; } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java index bcb8d3024..da0f35147 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/CreateThemeAssociationWizardPage.java @@ -1,18 +1,21 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.wizards; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; @@ -36,21 +39,28 @@ /** * Wizard page to create association between grammar and theme. - * */ final class CreateThemeAssociationWizardPage extends AbstractWizardPage { private static final String PAGE_NAME = CreateThemeAssociationWizardPage.class.getName(); + @Nullable private ComboViewer themeViewer; + + @Nullable private ComboViewer grammarViewer; + + @Nullable private final IGrammarDefinition initialDefinition; + + @Nullable private final IThemeAssociation initialAssociation; + @Nullable private Button whenDarkButton; - protected CreateThemeAssociationWizardPage(final IGrammarDefinition initialDefinition, - final IThemeAssociation initialAssociation) { + protected CreateThemeAssociationWizardPage(@Nullable final IGrammarDefinition initialDefinition, + @Nullable final IThemeAssociation initialAssociation) { super(PAGE_NAME); super.setTitle(TMUIMessages.CreateThemeAssociationWizardPage_title); super.setDescription(TMUIMessages.CreateThemeAssociationWizardPage_description); @@ -68,7 +78,7 @@ protected void createBody(final Composite ancestor) { // TextMate theme Label label = new Label(parent, SWT.NONE); label.setText(TMUIMessages.CreateThemeAssociationWizardPage_theme_text); - themeViewer = new ComboViewer(parent); + final var themeViewer = this.themeViewer = new ComboViewer(parent); themeViewer.setLabelProvider(new ThemeLabelProvider()); themeViewer.setContentProvider(new ThemeContentProvider()); themeViewer.setInput(TMUIPlugin.getThemeManager()); @@ -77,7 +87,7 @@ protected void createBody(final Composite ancestor) { label = new Label(parent, SWT.NONE); label.setText(TMUIMessages.CreateThemeAssociationWizardPage_grammar_text); - grammarViewer = new ComboViewer(parent); + final var grammarViewer = this.grammarViewer = new ComboViewer(parent); grammarViewer.setLabelProvider(new GrammarDefinitionLabelProvider()); grammarViewer.setContentProvider(new GrammarDefinitionContentProvider()); grammarViewer.setInput(TMEclipseRegistryPlugin.getGrammarRegistryManager()); @@ -88,11 +98,13 @@ protected void createBody(final Composite ancestor) { grammarViewer.setSelection(new StructuredSelection(initialDefinition)); } - whenDarkButton = new Button(parent, SWT.CHECK); + final var whenDarkButton = this.whenDarkButton = new Button(parent, SWT.CHECK); whenDarkButton.setText(TMUIMessages.CreateThemeAssociationWizardPage_whenDark_text); final GridData data = new GridData(); data.horizontalSpan = 4; whenDarkButton.setLayoutData(data); + + final var initialAssociation = this.initialAssociation; if (initialAssociation != null) { final ITheme selectedTheme = TMUIPlugin.getThemeManager().getThemeById(initialAssociation.getThemeId()); if (selectedTheme != null) { @@ -107,13 +119,17 @@ protected void initializeDefaultValues() { setPageComplete(false); } + @Nullable @Override protected IStatus validatePage(final Event event) { - if (themeViewer.getSelection().isEmpty()) { + final var themeViewer = this.themeViewer; + if (themeViewer == null || themeViewer.getSelection().isEmpty()) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.CreateThemeAssociationWizardPage_theme_error_required); } - if (grammarViewer.getSelection().isEmpty()) { + + final var grammarViewer = this.grammarViewer; + if (grammarViewer == null || grammarViewer.getSelection().isEmpty()) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.CreateThemeAssociationWizardPage_grammar_error_required); } @@ -121,10 +137,10 @@ protected IStatus validatePage(final Event event) { } IThemeAssociation getThemeAssociation() { - final String themeId = ((ITheme) themeViewer.getStructuredSelection().getFirstElement()).getId(); - final String scopeName = ((IGrammarDefinition) grammarViewer.getStructuredSelection().getFirstElement()) - .getScopeName(); - final boolean whenDark = whenDarkButton.getSelection(); + final String themeId = ((ITheme) castNonNull(themeViewer).getStructuredSelection().getFirstElement()).getId(); + final String scopeName = ((IGrammarDefinition) castNonNull(grammarViewer).getStructuredSelection() + .getFirstElement()).getScopeName(); + final boolean whenDark = castNonNull(whenDarkButton).getSelection(); return new ThemeAssociation(themeId, scopeName, whenDark); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java index 0ba96af39..ee66bb040 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/SelectGrammarWizardPage.java @@ -1,22 +1,23 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.wizards; -import java.io.File; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.io.FileInputStream; -import java.io.InputStream; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -46,13 +47,17 @@ final class SelectGrammarWizardPage extends AbstractWizardPage { private static final String PAGE_NAME = SelectGrammarWizardPage.class.getName(); - private static final String[] TEXTMATE_EXTENSIONS = {"*.tmLanguage","*.json","*.YAML-tmLanguage","*.yaml","*.yml"}; - - private Button browseFileSystemButton; - private Button browseWorkspaceButton; + private static final String[] TEXTMATE_EXTENSIONS = { + "*.tmLanguage", + "*.json", + "*.YAML-tmLanguage", + "*.yaml", + "*.yml" }; + @Nullable private Text grammarFileText; + @Nullable private GrammarInfoWidget grammarInfoWidget; // private ContentTypesBindingWidget contentTypesWidget; @@ -71,7 +76,8 @@ protected void createBody(final Composite ancestor) { parent.setLayout(new GridLayout(2, false)); // Text Field - grammarFileText = createText(parent, TMUIMessages.SelectGrammarWizardPage_file_label); + final var grammarFileText = this.grammarFileText = createText(parent, + TMUIMessages.SelectGrammarWizardPage_file_label); grammarFileText.addListener(SWT.Modify, this); // Buttons @@ -82,12 +88,12 @@ protected void createBody(final Composite ancestor) { gd.horizontalAlignment = SWT.RIGHT; buttons.setLayoutData(gd); - browseFileSystemButton = new Button(buttons, SWT.NONE); + final var browseFileSystemButton = new Button(buttons, SWT.NONE); browseFileSystemButton.setText(TMUIMessages.Button_browse_FileSystem); browseFileSystemButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(final SelectionEvent e) { - final FileDialog dialog = new FileDialog(parent.getShell()); + public void widgetSelected(@Nullable final SelectionEvent e) { + final var dialog = new FileDialog(parent.getShell()); dialog.setFilterExtensions(TEXTMATE_EXTENSIONS); dialog.setFilterPath(grammarFileText.getText()); final String result = dialog.open(); @@ -97,26 +103,26 @@ public void widgetSelected(final SelectionEvent e) { } }); - browseWorkspaceButton = new Button(buttons, SWT.NONE); + final var browseWorkspaceButton = new Button(buttons, SWT.NONE); browseWorkspaceButton.setText(TMUIMessages.Button_browse_Workspace); browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(final SelectionEvent e) { + public void widgetSelected(@Nullable final SelectionEvent e) { // TODO } }); - grammarInfoWidget = new GrammarInfoWidget(parent, SWT.NONE); final GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; + grammarInfoWidget = new GrammarInfoWidget(parent, SWT.NONE); grammarInfoWidget.setLayoutData(data); } private Text createText(final Composite parent, final String s) { - final Label label = new Label(parent, SWT.NONE); + final var label = new Label(parent, SWT.NONE); label.setText(s); - final Text text = new Text(parent, SWT.BORDER); + final var text = new Text(parent, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return text; } @@ -126,19 +132,25 @@ protected void initializeDefaultValues() { setPageComplete(false); } + @Nullable @Override protected IStatus validatePage(final Event event) { + final var grammarInfoWidget = this.grammarInfoWidget; + final var grammarFileText = this.grammarFileText; + if (grammarInfoWidget == null || grammarFileText == null) + return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, + TMUIMessages.SelectGrammarWizardPage_file_error_required); + grammarInfoWidget.refresh(null); final String path = grammarFileText.getText(); if (path.isEmpty()) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.SelectGrammarWizardPage_file_error_required); } - final File f = new File(path); - final Registry registry = new Registry(); - try(InputStream is = new FileInputStream(f)) { - final IGrammar grammar = registry.loadGrammarFromPathSync(f.getName(), is); - if (grammar == null || grammar.getScopeName() == null) { + final var registry = new Registry(); + try (var is = new FileInputStream(path)) { + final IGrammar grammar = registry.loadGrammarFromPathSync(path, is); + if (grammar == null) { return new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, TMUIMessages.SelectGrammarWizardPage_file_error_invalid); } @@ -151,7 +163,8 @@ protected IStatus validatePage(final Event event) { } IGrammarDefinition getGrammarDefinition() { - return new GrammarDefinition(grammarInfoWidget.getScopeNameText().getText(), grammarFileText.getText()); + return new GrammarDefinition( + castNonNull(grammarInfoWidget).getScopeNameText().getText(), + castNonNull(grammarFileText).getText()); } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java index 8c0cb2df6..4118d81bd 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/TextMateGrammarImportWizard.java @@ -1,16 +1,19 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.internal.wizards; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.tm4e.registry.IGrammarDefinition; @@ -26,8 +29,10 @@ */ public final class TextMateGrammarImportWizard extends Wizard implements IImportWizard { + @Nullable private SelectGrammarWizardPage mainPage; + @Nullable private IGrammarDefinition createdDefinition; private IGrammarRegistryManager grammarRegistryManager = TMEclipseRegistryPlugin.getGrammarRegistryManager(); @@ -55,7 +60,7 @@ public void addPages() { @Override public boolean performFinish() { - final IGrammarDefinition definition = mainPage.getGrammarDefinition(); + final IGrammarDefinition definition = castNonNull(mainPage).getGrammarDefinition(); grammarRegistryManager.registerGrammarDefinition(definition); if (save) { try { @@ -70,10 +75,11 @@ public boolean performFinish() { } @Override - public void init(final IWorkbench workbench, final IStructuredSelection selection) { + public void init(@Nullable final IWorkbench workbench, @Nullable final IStructuredSelection selection) { } + @Nullable public IGrammarDefinition getCreatedDefinition() { return createdDefinition; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/package-info.java new file mode 100644 index 000000000..3e4ce4c34 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/wizards/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.internal.wizards; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/package-info.java new file mode 100644 index 000000000..ab6797c27 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.model; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/package-info.java new file mode 100644 index 000000000..2a2faeef4 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/package-info.java new file mode 100644 index 000000000..627bca121 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/snippets/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.snippets; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java index 9e41d55f3..fd1eab970 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/ITMPresentationReconcilerListener.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.text; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.TextPresentation; @@ -23,7 +24,7 @@ public interface ITMPresentationReconcilerListener { /** * Install the given viewer and document. - * + * * @param viewer * @param document */ @@ -36,11 +37,11 @@ public interface ITMPresentationReconcilerListener { /** * Colorize the StyledText with the given text presentation. - * + * * @param presentation * the text presentation. * @param error * when there are error. */ - void colorize(TextPresentation presentation, Throwable error); + void colorize(TextPresentation presentation, @Nullable Throwable error); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java index 2dd4a1a0e..b6da491f0 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java @@ -13,12 +13,13 @@ */ package org.eclipse.tm4e.ui.text; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; @@ -27,7 +28,6 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.CursorLinePainter; @@ -83,12 +83,9 @@ * TextMate presentation reconciler which must be initialized with: * *

      - *
    • a TextMate grammar {@link IGrammar} used to initialize the TextMate model - * {@link TMDocumentModel}.
    • - *
    • a token provider {@link ITokenProvider} to retrieve the {@link IToken} - * from a TextMate token type .
    • + *
    • a TextMate grammar {@link IGrammar} used to initialize the TextMate model {@link TMDocumentModel}.
    • + *
    • a token provider {@link ITokenProvider} to retrieve the {@link IToken} from a TextMate token type .
    • *
    - * */ public class TMPresentationReconciler implements IPresentationReconciler { @@ -98,17 +95,22 @@ public class TMPresentationReconciler implements IPresentationReconciler { private final Token defaultToken; /** The target viewer. */ + @Nullable private ITextViewer viewer; + /** The internal listener. */ private final InternalListener internalListener; + @Nullable private IGrammar grammar; private boolean forcedGrammar; + @Nullable private ITokenProvider tokenProvider; private final TextAttribute fDefaultTextAttribute; + @Nullable private IPreferenceChangeListener themeChangeListener; private final List listeners = new ArrayList<>(); @@ -118,14 +120,12 @@ public class TMPresentationReconciler implements IPresentationReconciler { private boolean updateTextDecorations; /** - * true if the presentation reconciler is enabled (grammar and theme are - * available) and false otherwise. + * true if the presentation reconciler is enabled (grammar and theme are available) and false otherwise. */ private boolean enabled; /** - * true if a {@link TMException} should be thrown if grammar or theme cannot be - * found and false otherwise. + * true if a {@link TMException} should be thrown if grammar or theme cannot be found and false otherwise. */ private boolean throwError; @@ -142,12 +142,13 @@ public TMPresentationReconciler() { /** * Listener to recolorize editors when E4 Theme from General / Appearance * preferences changed or TextMate theme changed.. - * */ private final class ThemeChangeListener implements IPreferenceChangeListener { @Override - public void preferenceChange(final PreferenceChangeEvent event) { + public void preferenceChange(@Nullable final PreferenceChangeEvent event) { + if(event == null) + return; final IThemeManager themeManager = TMUIPlugin.getThemeManager(); switch (event.getKey()) { case PreferenceConstants.E4_THEME_ID: @@ -159,11 +160,18 @@ public void preferenceChange(final PreferenceChangeEvent event) { } } - private void preferenceThemeChange(final String eclipseThemeId, final IThemeManager themeManager) { - final IDocument document = viewer.getDocument(); + void preferenceThemeChange(@Nullable final String eclipseThemeId, final IThemeManager themeManager) { + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) { + return; + } + + final IDocument document = viewer.getDocument(); if (document == null) { return; } + + final var grammar = TMPresentationReconciler.this.grammar; if (grammar == null) { return; } @@ -177,9 +185,9 @@ private void preferenceThemeChange(final String eclipseThemeId, final IThemeMana /** * Internal listener class. */ - class InternalListener implements ITextInputListener, IModelTokensChangedListener, ITextListener { + private final class InternalListener implements ITextInputListener, IModelTokensChangedListener, ITextListener { - private void fireInstall(final ITextViewer viewer, final IDocument document) { + void fireInstall(final ITextViewer viewer, final IDocument document) { synchronized (listeners) { for (final ITMPresentationReconcilerListener listener : listeners) { listener.install(viewer, document); @@ -187,7 +195,7 @@ private void fireInstall(final ITextViewer viewer, final IDocument document) { } } - private void fireUninstall() { + void fireUninstall() { synchronized (listeners) { for (final ITMPresentationReconcilerListener listener : listeners) { listener.uninstall(); @@ -196,19 +204,29 @@ private void fireUninstall() { } @Override - public void inputDocumentAboutToBeChanged(final IDocument oldDocument, final IDocument newDocument) { - if (oldDocument != null) { + public void inputDocumentAboutToBeChanged(@Nullable final IDocument oldDocument, + @Nullable final IDocument newDocument) { + if (oldDocument == null) + return; + + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer != null) { viewer.removeTextListener(this); - getTMModelManager().disconnect(oldDocument); - fireUninstall(); } + getTMModelManager().disconnect(oldDocument); + fireUninstall(); } @Override - public void inputDocumentChanged(final IDocument oldDocument, final IDocument newDocument) { + public void inputDocumentChanged(@Nullable final IDocument oldDocument, @Nullable final IDocument newDocument) { if (newDocument == null) { return; } + + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) + return; + fireInstall(viewer, newDocument); try { viewer.addTextListener(this); @@ -223,9 +241,10 @@ public void inputDocumentChanged(final IDocument oldDocument, final IDocument ne // Update the theme if (localGrammar != null) { - final String scopeName = localGrammar.getScopeName(); + final String scopeName = localGrammar.getScopeName(); if (tokenProvider == null) { - tokenProvider = TMUIPlugin.getThemeManager().getThemeForScope(scopeName, viewer.getTextWidget().getBackground().getRGB()); + tokenProvider = TMUIPlugin.getThemeManager().getThemeForScope(scopeName, + viewer.getTextWidget().getBackground().getRGB()); } if (tokenProvider != null) { applyThemeEditor(); @@ -234,28 +253,33 @@ public void inputDocumentChanged(final IDocument oldDocument, final IDocument ne } } - final boolean enable = TMPresentationReconciler.this.enabled = localGrammar != null && tokenProvider != null; - if (enable) { - // Connect a TextModel to the new document. - final ITMModel model = getTMModelManager().connect(newDocument); - model.setGrammar(localGrammar); - - // Add model listener - model.addModelTokensChangedListener(this); + if (localGrammar != null) { + final var enable = TMPresentationReconciler.this.enabled = tokenProvider != null; + if (enable) { + // Connect a TextModel to the new document. + final ITMModel model = getTMModelManager().connect(newDocument); + model.setGrammar(localGrammar); + + // Add model listener + model.addModelTokensChangedListener(this); + } + } else { + TMPresentationReconciler.this.enabled = false; } } catch (final CoreException e) { - Platform.getLog(Platform.getBundle(TMEclipseRegistryPlugin.PLUGIN_ID)).log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, "Error while initializing TextMate model.", e)); + Platform.getLog(Platform.getBundle(TMEclipseRegistryPlugin.PLUGIN_ID)).log( + new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, "Error while initializing TextMate model.", e)); } } /** * Finds a grammar for the given document. - * @param newDocument - * @return + * * @throws CoreException */ - protected IGrammar findGrammar(final @NonNull IDocument newDocument) throws CoreException { - final IGrammar localGrammar = forcedGrammar ? TMPresentationReconciler.this.grammar : null; + @Nullable + IGrammar findGrammar(final IDocument newDocument) throws CoreException { + final IGrammar localGrammar = forcedGrammar ? TMPresentationReconciler.this.grammar : null; if (localGrammar != null) { return localGrammar; } @@ -267,14 +291,18 @@ protected IGrammar findGrammar(final @NonNull IDocument newDocument) throws Core } @Override - public void textChanged(final TextEvent e) { - if (!e.getViewerRedrawState()) { + public void textChanged(final @Nullable TextEvent e) { + if (e == null || !e.getViewerRedrawState()) { return; } - // changed text: propagate previous style, which will be overridden - // later asynchronously by TM + + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) + return; + + // changed text: propagate previous style, which will be overridden later asynchronously by TM if (e.getDocumentEvent() != null) { - final int diff = e.getText().length() - e.getLength(); + final int diff = e.getText().length() - e.getLength(); if (diff == 0 || e.getOffset() <= 0) { return; } @@ -287,8 +315,7 @@ public void textChanged(final TextEvent e) { return; } - // TextViewer#invalidateTextPresentation is called (because - // of validation, folding, etc) + // TextViewer#invalidateTextPresentation is called (because of validation, folding, etc) // case 2), do the colorization. final IDocument document = viewer.getDocument(); if (document == null) { @@ -296,40 +323,37 @@ public void textChanged(final TextEvent e) { } final IRegion region = computeRegionToRedraw(e, document); if (enabled) { - // case where there is grammar & theme -> update text presentation with the - // grammar tokens - final ITMModel model = getTMModelManager().connect(document); - if (model == null) { - return; - } + // case where there is grammar & theme -> update text presentation with the grammar tokens + final ITMModel model = getTMModelManager().connect(document); // It's possible that there are two or more SourceViewers opened for the same document, // so when one of them is closed the existing TMModel is also "closed" and its TokenizerThread // is interrupted and terminated. - // In this case, in order to let the others Source Viewers to continue working a new + // In this case, in order to let the others Source Viewers to continue working a new // TMModel object is to be created for the document, so it should be initialized // with the existing grammar as well as new ModelTokenListener is to be added - if (TMPresentationReconciler.this.grammar != null) { - model.setGrammar(TMPresentationReconciler.this.grammar); + final var grammar = TMPresentationReconciler.this.grammar; + if (grammar != null) { + model.setGrammar(grammar); model.addModelTokensChangedListener(this); } try { TMPresentationReconciler.this.colorize(region, (TMDocumentModel) model); } catch (final BadLocationException e1) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e1.getMessage(), e1)); + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e1.getMessage(), e1)); } } else { // case where there is no grammar & theme -> update text presentation with the // default styles (ex: to support highlighting with GenericEditor) - final TextPresentation presentation = new TextPresentation(region, 100); + final TextPresentation presentation = new TextPresentation(region, 100); presentation.setDefaultStyleRange( new StyleRange(region.getOffset(), region.getLength(), null, null)); applyTextRegionCollection(presentation); } } - protected @NonNull IRegion computeRegionToRedraw(@NonNull final TextEvent e, @NonNull final IDocument document) { + IRegion computeRegionToRedraw(final TextEvent e, final IDocument document) { IRegion region = null; if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) { // redraw state change, damage the whole document @@ -344,20 +368,21 @@ public void textChanged(final TextEvent e) { } /** - * Translates the given text event into the corresponding range of the viewer's - * document. + * Translates the given text event into the corresponding range of the viewer's document. * * @param e * the text event - * @return the widget region corresponding the region of the given event or - * null if none + * @return the widget region corresponding the region of the given event or null if none + * * @since 2.1 */ - private IRegion widgetRegion2ModelRegion(final TextEvent e) { - final String text = e.getText(); + @Nullable + IRegion widgetRegion2ModelRegion(final TextEvent e) { + final String text = e.getText(); final int length = text == null ? 0 : text.length(); + final var viewer = castNonNull(TMPresentationReconciler.this.viewer); if (viewer instanceof ITextViewerExtension5) { - final ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; + final ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); } final IRegion visible = viewer.getVisibleRegion(); @@ -366,17 +391,22 @@ private IRegion widgetRegion2ModelRegion(final TextEvent e) { @Override public void modelTokensChanged(final ModelTokensChangedEvent event) { - final Control control = viewer.getTextWidget(); - if (control != null) { - control.getDisplay().asyncExec(() -> { - if (viewer != null) { + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer != null) { + final Control control = viewer.getTextWidget(); + if (control != null) { + control.getDisplay().asyncExec(() -> { colorize(event); - } - }); + }); + } } } - private void colorize(final ModelTokensChangedEvent event) { + void colorize(final ModelTokensChangedEvent event) { + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) + return; + final IDocument document = viewer.getDocument(); if (document == null) { return; @@ -394,13 +424,13 @@ private void colorize(final ModelTokensChangedEvent event) { final IRegion region = new Region(document.getLineOffset(range.fromLineNumber - 1), length); TMPresentationReconciler.this.colorize(region, docModel); } catch (final BadLocationException ex) { - TMUIPlugin.getDefault().getLog() - .log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); } } } - private IGrammar findGrammar(final ContentTypeInfo info) { + @Nullable + IGrammar findGrammar(@Nullable final ContentTypeInfo info) { if (info == null) { return null; } @@ -410,7 +440,7 @@ private IGrammar findGrammar(final ContentTypeInfo info) { if (res == null) { // Discover the well grammar from the filetype final String fileName = info.getFileName(); - if (fileName != null) { + if (fileName.indexOf('.') > -1) { final String fileType = new Path(fileName).getFileExtension(); res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarForFileType(fileType); } @@ -419,12 +449,14 @@ private IGrammar findGrammar(final ContentTypeInfo info) { } } - public void setGrammar(final IGrammar grammar) { - final boolean changed = (viewer != null && ((this.grammar == null) || !this.grammar.equals(grammar))); + public void setGrammar(@Nullable final IGrammar grammar) { + var viewer = this.viewer; + final boolean changed = (viewer != null && ((this.grammar == null) || !Objects.equals(grammar, this.grammar))); this.grammar = grammar; this.forcedGrammar = true; if (changed) { // Grammar has changed, recreate the TextMate model + viewer = castNonNull(viewer); final IDocument document = viewer.getDocument(); if (document == null) { return; @@ -434,10 +466,12 @@ public void setGrammar(final IGrammar grammar) { } } + @Nullable public IGrammar getGrammar() { return grammar; } + @Nullable public ITokenProvider getTokenProvider() { return tokenProvider; } @@ -447,6 +481,9 @@ public void setTheme(final ITokenProvider newTheme) { if (!Objects.equals(oldTheme, newTheme) && grammar != null) { this.tokenProvider = newTheme; applyThemeEditor(); + final var viewer = this.viewer; + if (viewer == null) + return; final IDocument document = viewer.getDocument(); final ITMModel model = getTMModelManager().connect(document); if (!(model instanceof TMDocumentModel)) { @@ -456,45 +493,46 @@ public void setTheme(final ITokenProvider newTheme) { try { colorize(new Region(0, document.getLength()), docModel); } catch (final BadLocationException e) { - TMUIPlugin.getDefault().getLog() - .log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } } @Override - public void install(final ITextViewer viewer) { - Assert.isNotNull(viewer); - - this.viewer = viewer; + public void install(@Nullable ITextViewer viewer) { + viewer = this.viewer = castNonNull(viewer); viewer.addTextInputListener(internalListener); final IDocument document = viewer.getDocument(); if (document != null) { internalListener.inputDocumentChanged(null, document); } - themeChangeListener = new ThemeChangeListener(); + final var themeChangeListener = this.themeChangeListener = new ThemeChangeListener(); ThemeManager.getInstance().addPreferenceChangeListener(themeChangeListener); } @Override public void uninstall() { + final var viewer = castNonNull(this.viewer); viewer.removeTextInputListener(internalListener); // Ensure we uninstall all listeners internalListener.inputDocumentAboutToBeChanged(viewer.getDocument(), null); + final var themeChangeListener = this.themeChangeListener; if (themeChangeListener != null) { ThemeManager.getInstance().removePreferenceChangeListener(themeChangeListener); } - themeChangeListener = null; + this.themeChangeListener = null; } + @Nullable @Override - public IPresentationDamager getDamager(final String contentType) { + public IPresentationDamager getDamager(@Nullable final String contentType) { return null; } + @Nullable @Override - public IPresentationRepairer getRepairer(final String contentType) { + public IPresentationRepairer getRepairer(@Nullable final String contentType) { return null; } @@ -502,18 +540,16 @@ private ITMModelManager getTMModelManager() { return TMUIPlugin.getTMModelManager(); } - void colorize(@NonNull final IRegion damage, @NonNull final TMDocumentModel model) throws BadLocationException { - final IDocument document = model.getDocument(); + void colorize(final IRegion damage, final TMDocumentModel model) throws BadLocationException { + final IDocument document = model.getDocument(); final int fromLineNumber = document.getLineOfOffset(damage.getOffset()); final int toLineNumber = document.getLineOfOffset(damage.getOffset() + damage.getLength()); applyThemeEditorIfNeeded(); // Refresh the UI Presentation - TMUIPlugin.getDefault().trace("Render from: " + fromLineNumber + " to: " + toLineNumber); - TextPresentation presentation = null; - final Throwable error = null; + TMUIPlugin.trace("Render from: " + fromLineNumber + " to: " + toLineNumber); + final var presentation = new TextPresentation(damage, 1000); + Exception error = null; try { - presentation = new TextPresentation(damage, 1000); - int lastStart = presentation.getExtent().getOffset(); int length = 0; boolean firstToken = true; @@ -528,7 +564,7 @@ void colorize(@NonNull final IRegion damage, @NonNull final TMDocumentModel mode // This case comes from when the viewer is invalidated (by // validation for instance) and textChanged is called. // see https://github.com/eclipse/tm4e/issues/78 - TMUIPlugin.getDefault().trace("TextMate tokens not available for line " + line); + TMUIPlugin.trace("TextMate tokens not available for line " + line); break; } final int startLineOffset = document.getLineOffset(line); @@ -554,14 +590,13 @@ void colorize(@NonNull final IRegion damage, @NonNull final TMDocumentModel mode continue; } } else if (isAfterRegion(currentToken, startLineOffset, damage)) { - // The token is after the damage region, stop the - // colorization process + // The token is after the damage region, stop the colorization process break; } final IToken token = toToken(currentToken); final TextAttribute attribute = getTokenTextAttribute(token); - if (lastAttribute != null && lastAttribute.equals(attribute)) { + if (lastAttribute.equals(attribute)) { length += getTokenLengh(tokenStartIndex, nextToken, line, document); firstToken = false; } else { @@ -581,7 +616,8 @@ void colorize(@NonNull final IRegion damage, @NonNull final TMDocumentModel mode addRange(presentation, lastStart, length, lastAttribute); applyTextRegionCollection(presentation); } catch (final Exception e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + error = e; + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } finally { fireColorize(presentation, error); } @@ -615,14 +651,18 @@ private boolean isAfterRegion(final TMToken t, final int startLineOffset, final } private IToken toToken(final TMToken t) { - final IToken token = getTokenProvider().getToken(t.type); - if (token != null) { - return token; + final var tokenProvider = this.tokenProvider; + if (tokenProvider != null) { + final IToken token = tokenProvider.getToken(t.type); + if (token != null) { + return token; + } } return defaultToken; } - private int getTokenLengh(final int tokenStartIndex, final TMToken nextToken, final int line, final IDocument document) + private int getTokenLengh(final int tokenStartIndex, @Nullable final TMToken nextToken, final int line, + final IDocument document) throws BadLocationException { if (nextToken != null) { return nextToken.startIndex - tokenStartIndex; @@ -662,9 +702,10 @@ protected TextAttribute getTokenTextAttribute(final IToken token) { * the attribute describing the style of the range to be styled * @param lastLineStyleRanges */ - protected void addRange(final TextPresentation presentation, final int offset, final int length, @Nullable final TextAttribute attr) { + protected void addRange(final TextPresentation presentation, final int offset, final int length, + @Nullable final TextAttribute attr) { if (attr != null) { - final int style = attr.getStyle(); + final int style = attr.getStyle(); final int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); final StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), fontStyle); @@ -683,7 +724,10 @@ protected void addRange(final TextPresentation presentation, final int offset, f * the text presentation to be applied to the text viewer */ private void applyTextRegionCollection(final TextPresentation presentation) { - viewer.changeTextPresentation(presentation, false); + final var viewer = this.viewer; + if (viewer != null) { + viewer.changeTextPresentation(presentation, false); + } } /** @@ -714,11 +758,8 @@ public void removeTMPresentationReconcilerListener(final ITMPresentationReconcil /** * Fire colorize. - * - * @param presentation - * @param error */ - private void fireColorize(final TextPresentation presentation, final Throwable error) { + private void fireColorize(final TextPresentation presentation, @Nullable final Throwable error) { synchronized (listeners) { for (final ITMPresentationReconcilerListener listener : listeners) { listener.colorize(presentation, error); @@ -726,7 +767,8 @@ private void fireColorize(final TextPresentation presentation, final Throwable e } } - public static TMPresentationReconciler getTMPresentationReconciler(final IEditorPart editorPart) { + @Nullable + public static TMPresentationReconciler getTMPresentationReconciler(@Nullable final IEditorPart editorPart) { if (editorPart == null) { return null; } @@ -740,41 +782,39 @@ public static TMPresentationReconciler getTMPresentationReconciler(final IEditor } /** - * Returns the {@link TMPresentationReconciler} of the given text viewer and - * null otherwise. + * Returns the {@link TMPresentationReconciler} of the given text viewer and null otherwise. * - * @param textViewer - * @return the {@link TMPresentationReconciler} of the given text viewer and - * null otherwise. + * @return the {@link TMPresentationReconciler} of the given text viewer and null otherwise. */ + @Nullable public static TMPresentationReconciler getTMPresentationReconciler(final ITextViewer textViewer) { try { - final Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); + final Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); if (field != null) { - field.setAccessible(true); + field.trySetAccessible(); final Object presentationReconciler = field.get(textViewer); - //field is IPresentationRecounciler, looking for TMPresentationReconciler implementation + // field is IPresentationRecounciler, looking for TMPresentationReconciler implementation return presentationReconciler instanceof TMPresentationReconciler ? (TMPresentationReconciler) presentationReconciler : null; } } catch (SecurityException | NoSuchFieldException e) { // if SourceViewer class no longer has fPresentationReconciler or changes access level - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); - } catch (IllegalArgumentException | IllegalAccessException | NullPointerException | ExceptionInInitializerError iae) { - //This should not be logged as an error. This is an expected possible outcome of field.get(textViewer). - //The method assumes ITextViewer is actually ISourceViewer, and specifically the SourceViewer implementation - // that was available at the current build. This code also works with any implementation that follows the + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } catch (IllegalArgumentException | IllegalAccessException | NullPointerException + | ExceptionInInitializerError iae) { + // This should not be logged as an error. This is an expected possible outcome of field.get(textViewer). + // The method assumes ITextViewer is actually ISourceViewer, and specifically the SourceViewer + // implementation + // that was available at the current build. This code also works with any implementation that follows the // internal structure if also an ITextViewer. - //If these assumptions are false, the method should return null. Logging causes repeat noise. + // If these assumptions are false, the method should return null. Logging causes repeat noise. } return null; } /** - * Initialize foreground, background color, current line highlight from the - * current theme. - * + * Initialize foreground, background color, current line highlight from the current theme. */ private void applyThemeEditor() { this.initializeViewerColors = false; @@ -783,11 +823,12 @@ private void applyThemeEditor() { } /** - * Initialize foreground, background color, current line highlight from the - * current theme if needed. - * + * Initialize foreground, background color, current line highlight from the current theme if needed. */ private void applyThemeEditorIfNeeded() { + final var viewer = castNonNull(this.viewer); + final var tokenProvider = castNonNull(this.tokenProvider); + if (!initializeViewerColors) { final StyledText styledText = viewer.getTextWidget(); ((ITheme) tokenProvider).initializeViewerColors(styledText); @@ -821,7 +862,7 @@ private void applyThemeEditorIfNeeded() { } } } catch (final Exception e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } @@ -857,5 +898,4 @@ public boolean isThrowError() { public boolean isEnabled() { return enabled; } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/package-info.java new file mode 100644 index 000000000..b13c47863 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.text; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java index a7652e8e3..d8ae1a467 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ColorManager.java @@ -12,9 +12,9 @@ package org.eclipse.tm4e.ui.themes; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; import org.eclipse.tm4e.core.theme.RGB; @@ -33,7 +33,7 @@ public static ColorManager getInstance() { return INSTANCE; } - private final Map fColorTable = new HashMap<>(10); + private final Map fColorTable = new HashMap<>(10); private ColorManager() { } @@ -48,9 +48,9 @@ public Color getColor(final RGB rgb) { } public void dispose() { - final Iterator e = fColorTable.values().iterator(); - while (e.hasNext()) { - e.next().dispose(); + for (final var c : fColorTable.values()) { + if (c != null) + c.dispose(); } } @@ -59,10 +59,15 @@ public void dispose() { * * @param tokenId * name of the token + * * @return Color matching token */ + @Nullable public Color getPreferenceEditorColor(final String tokenId) { - return getColor(stringToRGB(PreferenceUtils.getEditorsPreferenceStore().get(tokenId, ""))); + final var prefStore = PreferenceUtils.getEditorsPreferenceStore(); + if(prefStore == null) + return null; + return getColor(stringToRGB(prefStore.get(tokenId, ""))); } /** @@ -70,13 +75,18 @@ public Color getPreferenceEditorColor(final String tokenId) { * * @param tokenId * name of the token + * * @return color is user defined or not */ public boolean isColorUserDefined(final String tokenId) { + final var prefStore = PreferenceUtils.getEditorsPreferenceStore(); + if(prefStore == null) + return false; + final String systemDefaultToken = getSystemDefaultToken(tokenId); return "".equals(systemDefaultToken) || // returns true if system default token doesn't exists - !PreferenceUtils.getEditorsPreferenceStore().getBoolean(systemDefaultToken, true); + !prefStore.getBoolean(systemDefaultToken, true); } /** @@ -88,9 +98,11 @@ public boolean isColorUserDefined(final String tokenId) { * color defined in TM theme * @param tokenId * name of the token for preferences store + * * @return Highest priority color */ - public Color getPriorityColor(final Color themeColor, final String tokenId) { + @Nullable + public Color getPriorityColor(@Nullable final Color themeColor, final String tokenId) { final Color prefColor = getPreferenceEditorColor(tokenId); if (isColorUserDefined(tokenId)) { @@ -105,6 +117,7 @@ public Color getPriorityColor(final Color themeColor, final String tokenId) { * * @param tokenId * name of the token + * * @return system default token or empty string if doesn't exist */ private String getSystemDefaultToken(final String tokenId) { @@ -127,13 +140,13 @@ private String getSystemDefaultToken(final String tokenId) { * * @param value * string value of rgb + * * @return RGB value */ private RGB stringToRGB(final String value) { final String[] rgbValues = BY_COMMA_SPLITTER.splitToStream(value).toArray(String[]::new); return rgbValues.length == 3 - ? new RGB(Integer.parseInt(rgbValues[0]), Integer.parseInt(rgbValues[1]), Integer.parseInt(rgbValues[2])) - : new RGB(255, 255, 255); + ? new RGB(Integer.parseInt(rgbValues[0]), Integer.parseInt(rgbValues[1]), Integer.parseInt(rgbValues[2])) + : new RGB(255, 255, 255); } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java index 2ae20ba5c..9024c1362 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITheme.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.themes; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.custom.StyledText; /** @@ -21,37 +22,40 @@ public interface ITheme extends ITokenProvider { /** * Returns the id of the theme. - * + * * @return the id of the theme. */ String getId(); /** * Returns the name of the theme. - * + * * @return the name of the theme. */ String getName(); /** * Returns the path of the theme. - * + * * @return the path of the theme. */ + @Nullable String getPath(); /** * Returns the plugin id. - * + * * @return the plugin id */ + @Nullable String getPluginId(); /** * Returns the theme content as CSS style sheet. - * + * * @return the theme content as CSS style sheet. */ + @Nullable String toCSSStyleSheet(); boolean isDark(); @@ -59,10 +63,9 @@ public interface ITheme extends ITokenProvider { boolean isDefault(); /** - * Initialize foreground, background color of the given {@link StyledText} with - * theme. + * Initialize foreground, background color of the given {@link StyledText} with theme. * - * @param textWidget + * @param styledText the StyledText to initialize */ void initializeViewerColors(StyledText styledText); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java index 253a798c3..d10f6f3ea 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeAssociation.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.themes; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.registry.ITMDefinition; /** @@ -21,16 +22,17 @@ public interface IThemeAssociation extends ITMDefinition { /** * Returns the TextMate theme id. - * + * * @return the TextMate theme id. */ String getThemeId(); /** * Returns the TextMate grammar scope linked to the theme id and null otherwise. - * + * * @return the TextMate grammar scope to the theme id and null otherwise. */ + @Nullable String getScopeName(); boolean isWhenDark(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java index 6d14d5b1d..b015188a2 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/IThemeManager.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.themes; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.graphics.RGB; import org.osgi.service.prefs.BackingStoreException; @@ -22,7 +23,7 @@ public interface IThemeManager { /** * Register the given theme. - * + * * @param theme * to unregister. */ @@ -30,7 +31,7 @@ public interface IThemeManager { /** * Unregister the given theme. - * + * * @param theme * to unregister. */ @@ -38,30 +39,31 @@ public interface IThemeManager { /** * Returns the {@link ITheme} by the theme id. - * + * * @param themeId * the theme id. * @return the {@link ITheme} by the theme id. */ + @Nullable ITheme getThemeById(String themeId); /** * Returns the list of TextMate themes. - * + * * @return the list of TextMate themes. */ ITheme[] getThemes(); /** * Returns the default theme. - * + * * @return the default theme. */ ITheme getDefaultTheme(); /** * Returns the list of TextMate themes for the given eclipse theme id. - * + * * @return the list of TextMate themes for the given eclipse theme id. */ ITheme[] getThemes(boolean dark); @@ -69,7 +71,7 @@ public interface IThemeManager { /** * Returns the TextMate theme {@link ITheme} for the given TextMate grammar * scopeName and E4 Theme eclipseThemeId. - * + * * @param scopeName * the TextMate grammar * @param eclipseThemeId @@ -82,7 +84,7 @@ public interface IThemeManager { /** * Returns the TextMate theme {@link ITheme} for the given TextMate grammar * scopeName and default E4 Theme. - * + * * @param scopeName * @return the TextMate theme {@link ITheme} for the given TextMate grammar * scopeName and default E4 Theme. @@ -91,7 +93,7 @@ public interface IThemeManager { /** * Register the given theme association. - * + * * @param association * to register. */ @@ -99,7 +101,7 @@ public interface IThemeManager { /** * Unregister the given theme association. - * + * * @param association * to unregister. */ @@ -107,7 +109,7 @@ public interface IThemeManager { /** * Returns list of all theme associations. - * + * * @return list of all theme associations. */ IThemeAssociation[] getAllThemeAssociations(); @@ -115,7 +117,7 @@ public interface IThemeManager { /** * Returns the theme associations for the given TextMate grammar * scopeName. - * + * * @param scopeName * @return the theme associations for the given TextMate grammar * scopeName. @@ -124,17 +126,17 @@ public interface IThemeManager { /** * Save the themes definitions. - * + * * @throws BackingStoreException */ void save() throws BackingStoreException; boolean isDarkEclipseTheme(); - boolean isDarkEclipseTheme(String eclipseThemeId); + boolean isDarkEclipseTheme(@Nullable String eclipseThemeId); /** - * + * * @param scopeName * @param background * @return the theme that will fit best for the defined background color diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java index 1353c36fa..36c519998 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ITokenProvider.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.themes; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.rules.IToken; import org.eclipse.swt.graphics.Color; @@ -22,19 +23,25 @@ public interface ITokenProvider { /** * Returns the Eclipse {@link IToken} from the given type and null otherwise. - * + * * @param type * @return the Eclipse {@link IToken} from the given type and null otherwise. */ + @Nullable IToken getToken(String type); + @Nullable Color getEditorBackground(); + @Nullable Color getEditorForeground(); + @Nullable Color getEditorSelectionBackground(); + @Nullable Color getEditorSelectionForeground(); - + + @Nullable Color getEditorCurrentLineHighlight(); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java index 0dbf862f1..af99ef766 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/Theme.java @@ -1,19 +1,20 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.themes; import java.io.InputStream; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.rules.IToken; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Color; @@ -32,6 +33,7 @@ public class Theme extends TMResource implements ITheme { private static final String DARK_ATTR = "dark"; private static final String DEFAULT_ATTR = "default"; + @Nullable private ITokenProvider tokenProvider; private String id; @@ -43,6 +45,8 @@ public class Theme extends TMResource implements ITheme { * Constructor for user preferences (loaded from Json with Gson). */ public Theme() { + name = ""; + id = ""; } /** @@ -76,12 +80,14 @@ public String getName() { return name; } + @Nullable @Override public IToken getToken(final String type) { final ITokenProvider provider = getTokenProvider(); return provider != null ? provider.getToken(type) : null; } + @Nullable @Override public Color getEditorForeground() { final ITokenProvider provider = getTokenProvider(); @@ -90,6 +96,7 @@ public Color getEditorForeground() { .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND); } + @Nullable @Override public Color getEditorBackground() { final ITokenProvider provider = getTokenProvider(); @@ -98,6 +105,7 @@ public Color getEditorBackground() { .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); } + @Nullable @Override public Color getEditorSelectionForeground() { final ITokenProvider provider = getTokenProvider(); @@ -106,6 +114,7 @@ public Color getEditorSelectionForeground() { .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND); } + @Nullable @Override public Color getEditorSelectionBackground() { final ITokenProvider provider = getTokenProvider(); @@ -114,6 +123,7 @@ public Color getEditorSelectionBackground() { .getPriorityColor(themeColor, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND); } + @Nullable @Override public Color getEditorCurrentLineHighlight() { final ITokenProvider provider = getTokenProvider(); @@ -124,9 +134,10 @@ public Color getEditorCurrentLineHighlight() { : themeColor; } + @Nullable private ITokenProvider getTokenProvider() { if (tokenProvider == null) { - try(InputStream in = super.getInputStream()) { + try (InputStream in = super.getInputStream()) { if (in == null) { return null; } @@ -138,6 +149,7 @@ private ITokenProvider getTokenProvider() { return tokenProvider; } + @Nullable @Override public String toCSSStyleSheet() { return super.getResourceContent(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java index b385c8949..bf5b18224 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/ThemeAssociation.java @@ -1,43 +1,45 @@ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.ui.themes; +import java.util.Objects; + /** - * Copyright (c) 2015-2017 Angelo ZERR. + * Copyright (c) 2015-2017 Angelo ZERR. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Angelo Zerr - initial API and implementation + * Contributors: + * Angelo Zerr - initial API and implementation */ import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jdt.annotation.Nullable; /** * Theme association implementation. - * */ public class ThemeAssociation implements IThemeAssociation { @@ -46,22 +48,24 @@ public class ThemeAssociation implements IThemeAssociation { private static final String WHEN_DARK_ATTR = "whenDark"; //$NON-NLS-1$ private String themeId; + + @Nullable private String scopeName; + private boolean whenDark; + + @Nullable private String pluginId; /** * Constructor for user preferences (loaded from Json with Gson). */ public ThemeAssociation() { + themeId = ""; } /** * Constructor to register theme associations for a given scope name. - * - * @param themeId - * @param scopeName - * @param whenDark */ public ThemeAssociation(final String themeId, final String scopeName, final boolean whenDark) { this.themeId = themeId; @@ -75,6 +79,7 @@ public ThemeAssociation(final IConfigurationElement ce) { this.pluginId = ce.getNamespaceIdentifier(); } + @Nullable @Override public String getPluginId() { return pluginId; @@ -85,6 +90,7 @@ public String getThemeId() { return themeId; } + @Nullable @Override public String getScopeName() { return scopeName; @@ -97,42 +103,22 @@ public boolean isWhenDark() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((pluginId == null) ? 0 : pluginId.hashCode()); - result = prime * result + ((scopeName == null) ? 0 : scopeName.hashCode()); - result = prime * result + ((themeId == null) ? 0 : themeId.hashCode()); - result = prime * result + (whenDark ? 1231 : 1237); - return result; + return Objects.hash(pluginId, scopeName, themeId, whenDark); } @Override - public boolean equals(final Object obj) { + public boolean equals(@Nullable Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; - final ThemeAssociation other = (ThemeAssociation) obj; - if (pluginId == null) { - if (other.pluginId != null) - return false; - } else if (!pluginId.equals(other.pluginId)) - return false; - if (scopeName == null) { - if (other.scopeName != null) - return false; - } else if (!scopeName.equals(other.scopeName)) - return false; - if (themeId == null) { - if (other.themeId != null) - return false; - } else if (!themeId.equals(other.themeId)) - return false; - if (whenDark != other.whenDark) - return false; - return true; + ThemeAssociation other = (ThemeAssociation) obj; + return Objects.equals(pluginId, other.pluginId) + && Objects.equals(scopeName, other.scopeName) + && Objects.equals(themeId, other.themeId) + && whenDark == other.whenDark; } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java index d4b8c3fa7..83d022a1c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.TextAttribute; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.Token; @@ -35,7 +36,9 @@ public class CSSTokenProvider extends AbstractTokenProvider { private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); - private final Map tokenMaps = new HashMap<>(); + private final Map tokenMaps = new HashMap<>(); + + @Nullable private CSSParser parser; public CSSTokenProvider(final InputStream in) { @@ -62,68 +65,72 @@ public CSSTokenProvider(final InputStream in) { } } } catch (final Exception e) { - TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); } } + @Nullable @Override - public IToken getToken(final String type) { - if (type == null) { + public IToken getToken(@Nullable final String type) { + if (type == null) return null; - } + + final var parser = this.parser; + if (parser == null) + return null; + final IStyle style = parser.getBestStyle(BY_DOT_SPLITTER.splitToStream(type).toArray(String[]::new)); - if (style != null) { - final IToken t = tokenMaps.get(style); - if (t != null) { - return t; - } - } - return null; + if (style == null) + return null; + + return tokenMaps.get(style); + } + + @Nullable + private Color getColor(final boolean isForeground, final String... styles) { + final var parser = this.parser; + if (parser == null) + return null; + + final var style = parser.getBestStyle(styles); + if (style == null) + return null; + + final var rgb = isForeground ? style.getColor() : style.getBackgroundColor(); + if (rgb == null) + return null; + + return ColorManager.getInstance().getColor(rgb); } + @Nullable @Override public Color getEditorForeground() { - final IStyle style = parser.getBestStyle("editor"); - if (style != null && style.getColor() != null) { - return ColorManager.getInstance().getColor(style.getColor()); - } - return null; + return getColor(true, "editor"); } + @Nullable @Override public Color getEditorBackground() { - final IStyle style = parser.getBestStyle("editor"); - if (style != null && style.getBackgroundColor() != null) { - return ColorManager.getInstance().getColor(style.getBackgroundColor()); - } - return null; + return getColor(false, "editor"); } + @Nullable @Override public Color getEditorSelectionForeground() { - final IStyle style = parser.getBestStyle("editor", "selection"); - if (style != null && style.getColor() != null) { - return ColorManager.getInstance().getColor(style.getColor()); - } - return null; + return getColor(true, "editor", "selection"); } + @Nullable @Override public Color getEditorSelectionBackground() { - final IStyle style = parser.getBestStyle("editor", "selection"); - if (style != null && style.getBackgroundColor() != null) { - return ColorManager.getInstance().getColor(style.getBackgroundColor()); - } - return null; + return getColor(false, "editor", "selection"); + } + @Nullable @Override public Color getEditorCurrentLineHighlight() { - final IStyle style = parser.getBestStyle("editor", "lineHighlight"); - if (style != null && style.getBackgroundColor() != null) { - return ColorManager.getInstance().getColor(style.getBackgroundColor()); - } - return null; + return getColor(false, "editor", "lineHighlight"); } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/package-info.java new file mode 100644 index 000000000..6a88c3457 --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.themes.css; + +import org.eclipse.jdt.annotation.NonNullByDefault; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/package-info.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/package-info.java new file mode 100644 index 000000000..02ae596cf --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/package-info.java @@ -0,0 +1,4 @@ +@NonNullByDefault +package org.eclipse.tm4e.ui.themes; + +import org.eclipse.jdt.annotation.NonNullByDefault; From b3e6010f12cbcba9d3abc83221ef7a48b8f2f3b9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 14:10:21 +0200 Subject: [PATCH 180/202] Fix null compiler warnings --- .../src/main/java/org/eclipse/tm4e/registry/TMResource.java | 2 +- .../tm4e/ui/internal/preferences/GrammarPreferencePage.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java index 82567d1db..62985ff21 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/TMResource.java @@ -55,7 +55,7 @@ public TMResource(final IConfigurationElement ce) { this.pluginId = ce.getNamespaceIdentifier(); } - public TMResource(final String path, final String pluginId) { + public TMResource(@Nullable final String path, @Nullable final String pluginId) { this.path = path; this.pluginId = pluginId; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index 6750df709..7bde5db46 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -306,7 +306,8 @@ private void fillPreview(final String scopeName, @Nullable final IThemeAssociati if (selectedAssociation != null) { setPreviewTheme(selectedAssociation.getThemeId()); } - castNonNull(previewViewer).setGrammar(grammar); + final var previewViewer = castNonNull(GrammarPreferencePage.this.previewViewer); + previewViewer.setGrammar(grammar); // Snippet final ISnippet[] snippets = snippetManager.getSnippets(scopeName); @@ -314,10 +315,9 @@ private void fillPreview(final String scopeName, @Nullable final IThemeAssociati previewViewer.setText(""); } else { // TODO: manage list of snippet for the given scope. - castNonNull(previewViewer).setText(snippets[0].getContent()); + previewViewer.setText(snippets[0].getContent()); } } - }); // Specify default sorting From 2d03220ff78fd44781924cb96a4608de622264f9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 15:00:08 +0200 Subject: [PATCH 181/202] Use varargs for LanguageConfigurationRegistryManager# getLanguageConfigurationFor() --- .../ILanguageConfigurationRegistryManager.java | 3 +-- .../internal/AbstractLanguageConfigurationRegistryManager.java | 2 +- .../wizards/SelectLanguageConfigurationWizardPage.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java index 3bf2a11f9..d470b3232 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ILanguageConfigurationRegistryManager.java @@ -67,6 +67,5 @@ public interface ILanguageConfigurationRegistryManager { * null otherwise. */ @Nullable - ILanguageConfiguration getLanguageConfigurationFor(IContentType[] contentTypes); - + ILanguageConfiguration getLanguageConfigurationFor(IContentType... contentTypes); } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java index e71047c5f..0ce038703 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/AbstractLanguageConfigurationRegistryManager.java @@ -55,7 +55,7 @@ public void unregisterLanguageConfigurationDefinition(final ILanguageConfigurati @Nullable @Override - public ILanguageConfiguration getLanguageConfigurationFor(final IContentType[] contentTypes) { + public ILanguageConfiguration getLanguageConfigurationFor(final IContentType... contentTypes) { for (final IContentType contentType : contentTypes) { if (userDefinitions.containsKey(contentType)) { return userDefinitions.get(contentType).getLanguageConfiguration(); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java index b07d0e6c7..ffc8e9d44 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java @@ -312,7 +312,7 @@ private IStatus validatePage(@Nullable final Event event) { return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, SelectLanguageConfigurationWizardPage_contentTypeError_invalid); } - if (registryManager.getLanguageConfigurationFor(new IContentType[] { contentType }) != null) { + if (registryManager.getLanguageConfigurationFor(contentType) != null) { return new Status(IStatus.WARNING, LanguageConfigurationPlugin.PLUGIN_ID, SelectLanguageConfigurationWizardPage_contentTypeWarning_duplicate); } From c9afccc831f206a8fb4e34b9cde4943668c472ae Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 15:13:17 +0200 Subject: [PATCH 182/202] Add error handling when loading lang configs for unknown content types --- .../ToggleLineCommentHandler.java | 4 +- .../LanguageConfigurationDefinition.java | 11 ++- .../internal/LanguageConfigurationPlugin.java | 8 ++ .../LanguageConfigurationRegistryManager.java | 14 +++- .../preferences/PreferenceHelper.java | 77 +++++++++++-------- ...SelectLanguageConfigurationWizardPage.java | 11 +-- .../ui/internal/utils/ContentTypeHelper.java | 1 + 7 files changed, 80 insertions(+), 46 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java index e68a4faa3..a225aaa4f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/ToggleLineCommentHandler.java @@ -76,9 +76,11 @@ public Object execute(@Nullable final ExecutionEvent event) throws ExecutionExce return null; } - ContentTypeInfo info; + final ContentTypeInfo info; try { info = ContentTypeHelper.findContentTypes(document); + if (info == null) + return null; } catch (final CoreException e) { return null; } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java index a306a5534..4ec3a531b 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationDefinition.java @@ -15,6 +15,7 @@ import java.io.InputStreamReader; import java.nio.charset.Charset; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -54,9 +55,15 @@ public LanguageConfigurationDefinition(final IContentType contentType, final Str this.contentType = contentType; } - public LanguageConfigurationDefinition(final IConfigurationElement ce) { + public LanguageConfigurationDefinition(final IConfigurationElement ce) throws CoreException { super(ce); - this.contentType = ContentTypeHelper.getContentTypeById(ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR)); + final var contentTypeId = ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR); + final var contentType = ContentTypeHelper.getContentTypeById(contentTypeId); + if (contentType == null) + throw new CoreException( + new Status(IStatus.ERROR, LanguageConfiguration.class, + "Cannot load language configuration with unknown content type ID " + contentTypeId)); + this.contentType = contentType; } /** diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java index bf4aba97a..9b360068f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationPlugin.java @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal; +import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -32,6 +33,13 @@ static LanguageConfigurationPlugin getInstance() { return INSTANCE; } + public static void log(IStatus status) { + final var plugin = LanguageConfigurationPlugin.INSTANCE; + if (plugin != null) { + plugin.getLog().log(status); + } + } + @Override public void start(@Nullable final BundleContext context) throws Exception { super.start(context); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java index 63d13ab74..0dde8b8ec 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationRegistryManager.java @@ -16,6 +16,7 @@ import java.util.Collections; import java.util.List; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.preferences.InstanceScope; @@ -67,8 +68,9 @@ private LanguageConfigurationDefinition getDefinition(final IContentType content for (final var iDefinition : getDefinitions()) { if (iDefinition instanceof LanguageConfigurationDefinition) { final var definition = (LanguageConfigurationDefinition) iDefinition; - if (contentType.isKindOf(definition.getContentType()) - && (bestFit == null || definition.getContentType().isKindOf(bestFit.getContentType()))) { + final var definitionContentType = definition.getContentType(); + if (contentType.isKindOf(definitionContentType) + && (bestFit == null || definitionContentType.isKindOf(bestFit.getContentType()))) { bestFit = definition; } } @@ -253,7 +255,13 @@ private void loadFromExtensionPoints() { for (final var configElem : config) { final String name = configElem.getName(); if (LANGUAGE_CONFIGURATION_ELT.equals(name)) { - final LanguageConfigurationDefinition delegate = new LanguageConfigurationDefinition(configElem); + final LanguageConfigurationDefinition delegate; + try { + delegate = new LanguageConfigurationDefinition(configElem); + } catch (CoreException ex) { + LanguageConfigurationPlugin.log(ex.getStatus()); + continue; + } registerLanguageConfigurationDefinition(delegate); } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java index 0aa404a00..e39b022ab 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java @@ -1,20 +1,26 @@ /** - * Copyright (c) 2018 Red Hat Inc. and others. + * Copyright (c) 2018 Red Hat Inc. and others. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Lucas Bullen (Red Hat Inc.) - initial API and implementation + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial API and implementation */ package org.eclipse.tm4e.languageconfiguration.internal.preferences; +import java.util.Arrays; import java.util.Collection; +import java.util.Objects; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationDefinition; +import org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationPlugin; import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; import com.google.gson.Gson; @@ -26,44 +32,49 @@ /** * Helper class load, save language configuration preferences with Json format. - * */ public final class PreferenceHelper { - private static final Gson DEFAULT_GSON; - - static { - DEFAULT_GSON = new GsonBuilder().registerTypeAdapter(LanguageConfigurationDefinition.class, - (JsonDeserializer) (json, typeOfT, context) -> { - final JsonObject object = json.getAsJsonObject(); - final JsonElement pluginId = object.get("pluginId"); - return new LanguageConfigurationDefinition( - ContentTypeHelper.getContentTypeById(object.get("contentTypeId").getAsString()), //$NON-NLS-1$ - object.get("path").getAsString(), //$NON-NLS-1$ - pluginId == null ? null : pluginId.getAsString(), - object.get("onEnterEnabled").getAsBoolean(), //$NON-NLS-1$ - object.get("bracketAutoClosingEnabled").getAsBoolean(), //$NON-NLS-1$ - object.get("matchingPairsEnabled").getAsBoolean()); //$NON-NLS-1$ - }).registerTypeAdapter(LanguageConfigurationDefinition.class, - (JsonSerializer) (definition, typeOfT, context) -> { - final JsonObject object = new JsonObject(); - object.addProperty("path", definition.getPath()); //$NON-NLS-1$ - object.addProperty("pluginId", definition.getPluginId()); //$NON-NLS-1$ - object.addProperty("contentTypeId", definition.getContentType().getId()); //$NON-NLS-1$ - object.addProperty("onEnterEnabled", definition.isOnEnterEnabled()); //$NON-NLS-1$ - object.addProperty("bracketAutoClosingEnabled", definition.isBracketAutoClosingEnabled()); //$NON-NLS-1$ - object.addProperty("matchingPairsEnabled", definition.isMatchingPairsEnabled()); //$NON-NLS-1$ - return object; - }) - .create(); - } + private static final Gson DEFAULT_GSON = new GsonBuilder() + .registerTypeAdapter(LanguageConfigurationDefinition.class, + (JsonDeserializer<@Nullable LanguageConfigurationDefinition>) (json, typeOfT, context) -> { + final JsonObject object = json.getAsJsonObject(); + final JsonElement pluginId = object.get("pluginId"); + final var contentTypeId = object.get("contentTypeId").getAsString(); + final var contentType = ContentTypeHelper.getContentTypeById(contentTypeId); + if (contentType == null) { + LanguageConfigurationPlugin.log(new Status(IStatus.ERROR, PreferenceHelper.class, + "Cannot load language configuration with unknown content type ID " + + contentTypeId)); + return null; + } + return new LanguageConfigurationDefinition(contentType, // $NON-NLS-1$ + object.get("path").getAsString(), //$NON-NLS-1$ + pluginId == null ? null : pluginId.getAsString(), + object.get("onEnterEnabled").getAsBoolean(), //$NON-NLS-1$ + object.get("bracketAutoClosingEnabled").getAsBoolean(), //$NON-NLS-1$ + object.get("matchingPairsEnabled").getAsBoolean()); //$NON-NLS-1$ + }) + .registerTypeAdapter(LanguageConfigurationDefinition.class, + (JsonSerializer) (definition, typeOfT, context) -> { + final JsonObject object = new JsonObject(); + object.addProperty("path", definition.getPath()); //$NON-NLS-1$ + object.addProperty("pluginId", definition.getPluginId()); //$NON-NLS-1$ + object.addProperty("contentTypeId", definition.getContentType().getId()); //$NON-NLS-1$ + object.addProperty("onEnterEnabled", definition.isOnEnterEnabled()); //$NON-NLS-1$ + object.addProperty("bracketAutoClosingEnabled", definition.isBracketAutoClosingEnabled()); //$NON-NLS-1$ + object.addProperty("matchingPairsEnabled", definition.isMatchingPairsEnabled()); //$NON-NLS-1$ + return object; + }) + .create(); public static ILanguageConfigurationDefinition[] loadLanguageConfigurationDefinitions(final String json) { - return DEFAULT_GSON.fromJson(json, LanguageConfigurationDefinition[].class); + return Arrays.stream(DEFAULT_GSON.fromJson(json, LanguageConfigurationDefinition[].class)) + .filter(Objects::nonNull).toArray( + ILanguageConfigurationDefinition[]::new); } public static String toJson(final Collection definitions) { return DEFAULT_GSON.toJson(definitions); } - } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java index ffc8e9d44..18486e1b9 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/wizards/SelectLanguageConfigurationWizardPage.java @@ -302,8 +302,7 @@ private IStatus validatePage(@Nullable final Event event) { } final var contentTypeText = this.contentTypeText; - assert contentTypeText != null; - if (contentTypeText.getText().isEmpty()) { + if (contentTypeText == null || contentTypeText.getText().isEmpty()) { return new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, SelectLanguageConfigurationWizardPage_contentTypeError_noSelection); } @@ -320,17 +319,15 @@ private IStatus validatePage(@Nullable final Event event) { } ILanguageConfigurationDefinition getDefinition() { - final var fileText = this.fileText; assert fileText != null; IPath path = new Path(fileText.getText()); if (!path.isAbsolute()) { path = ResourcesPlugin.getWorkspace().getRoot().getFile(path).getLocation(); } - final var contentTypeText = this.contentTypeText; assert contentTypeText != null; - return new LanguageConfigurationDefinition( - ContentTypeHelper.getContentTypeById(contentTypeText.getText()), - path.toString()); + final var contentType = ContentTypeHelper.getContentTypeById(contentTypeText.getText()); + assert contentType != null; + return new LanguageConfigurationDefinition(contentType, path.toString()); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java index 56022dd26..9306b907b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java @@ -67,6 +67,7 @@ public static ContentTypeInfo findContentTypes(final IDocument document) throws * @param contentTypeId * @return matching content type or null */ + @Nullable public static IContentType getContentTypeById(final String contentTypeId) { final IContentTypeManager manager = Platform.getContentTypeManager(); return manager.getContentType(contentTypeId); From 0e6a72ddac2c8bb48e4e56a00d786be1ec639280 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 17:13:24 +0200 Subject: [PATCH 183/202] Move CSS SAC parser classes to tm4e.core.internal.theme.css.sac --- .../css/sac/AbstractSACParserFactory.java} | 18 ++++---------- .../theme/css/sac}/ISACParserFactory.java | 2 +- .../theme/css/sac}/SACConstants.java | 2 +- .../SACParserFactory.java} | 8 +++---- .../tm4e/core/theme/css/CSSParser.java | 5 ++-- .../theme/css/ParserNotFoundException.java | 24 ------------------- 6 files changed, 12 insertions(+), 47 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{theme/css/SACParserFactory.java => internal/theme/css/sac/AbstractSACParserFactory.java} (74%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{theme/css => internal/theme/css/sac}/ISACParserFactory.java (97%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{theme/css => internal/theme/css/sac}/SACConstants.java (95%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/{SACParserFactoryImpl.java => sac/SACParserFactory.java} (91%) delete mode 100644 org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/AbstractSACParserFactory.java similarity index 74% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/AbstractSACParserFactory.java index b22b14fa2..0911ab0fa 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/AbstractSACParserFactory.java @@ -8,23 +8,22 @@ * Contributors: * Angelo Zerr - initial API and implementation *******************************************************************************/ -package org.eclipse.tm4e.core.theme.css; +package org.eclipse.tm4e.core.internal.theme.css.sac; import static java.lang.System.Logger.Level.*; import java.lang.System.Logger; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.internal.theme.css.SACParserFactoryImpl; import org.w3c.css.sac.Parser; import org.w3c.css.sac.helpers.ParserFactory; /** * SAC Parser Factory. */ -public abstract class SACParserFactory extends ParserFactory implements ISACParserFactory { +public abstract class AbstractSACParserFactory extends ParserFactory implements ISACParserFactory { - private static final Logger LOGGER = System.getLogger(SACParserFactory.class.getName()); + private static final Logger LOGGER = System.getLogger(AbstractSACParserFactory.class.getName()); @Nullable private String preferredParserName; @@ -32,7 +31,7 @@ public abstract class SACParserFactory extends ParserFactory implements ISACPars /** * Return default instance of SAC Parser. If preferredParserName is filled, * it return the instance of SAC Parser registered with this name, otherwise - * this method search the SAC Parser class name to instanciate into System + * this method search the SAC Parser class name to instantiate into System * property with key org.w3c.css.sac.parser. */ @Override @@ -58,13 +57,4 @@ public String getPreferredParserName() { public void setPreferredParserName(@Nullable final String preferredParserName) { this.preferredParserName = preferredParserName; } - - /** - * @return instance of SACParserFactory - */ - public static ISACParserFactory newInstance() { - // TODO : manage new instance of SAC Parser Factory like - // SAXParserFactory. - return new SACParserFactoryImpl(); - } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/ISACParserFactory.java similarity index 97% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/ISACParserFactory.java index ef0ea88cd..09f056e2d 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ISACParserFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/ISACParserFactory.java @@ -8,7 +8,7 @@ * Contributors: * Angelo Zerr - initial API and implementation *******************************************************************************/ -package org.eclipse.tm4e.core.theme.css; +package org.eclipse.tm4e.core.internal.theme.css.sac; import org.eclipse.jdt.annotation.Nullable; import org.w3c.css.sac.Parser; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACConstants.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACConstants.java similarity index 95% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACConstants.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACConstants.java index 5be9139be..19ba7472b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/SACConstants.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACConstants.java @@ -8,7 +8,7 @@ * Contributors: * Angelo Zerr - initial API and implementation *******************************************************************************/ -package org.eclipse.tm4e.core.theme.css; +package org.eclipse.tm4e.core.internal.theme.css.sac; /** * SAC Constants Parsers. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACParserFactory.java similarity index 91% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACParserFactory.java index ecdf954de..eabb24f6c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/SACParserFactoryImpl.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACParserFactory.java @@ -8,22 +8,20 @@ * Contributors: * Angelo Zerr - initial API and implementation *******************************************************************************/ -package org.eclipse.tm4e.core.internal.theme.css; +package org.eclipse.tm4e.core.internal.theme.css.sac; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.theme.css.SACConstants; -import org.eclipse.tm4e.core.theme.css.SACParserFactory; import org.w3c.css.sac.Parser; /** * SAC Parser factory implementation. By default, this SAC FActory support * Flute, SteadyState and Batik SAC Parser. */ -public final class SACParserFactoryImpl extends SACParserFactory { +public final class SACParserFactory extends AbstractSACParserFactory { private static Map parsers = new HashMap<>(); @@ -38,7 +36,7 @@ public final class SACParserFactoryImpl extends SACParserFactory { registerSACParser(SACConstants.SACPARSER_BATIK); } - public SACParserFactoryImpl() { + public SACParserFactory() { // Flute parser is the default SAC Parser to use. super.setPreferredParserName(SACConstants.SACPARSER_BATIK); } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java index ad2dcaf04..35431168a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java @@ -21,6 +21,7 @@ import org.eclipse.tm4e.core.internal.theme.css.CSSDocumentHandler; import org.eclipse.tm4e.core.internal.theme.css.CSSSelectorFactory; import org.eclipse.tm4e.core.internal.theme.css.ExtendedSelector; +import org.eclipse.tm4e.core.internal.theme.css.sac.SACParserFactory; import org.eclipse.tm4e.core.theme.IStyle; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; @@ -29,7 +30,7 @@ import org.w3c.css.sac.SelectorList; /** - * CSS Parser to parse style for TextMate syntax coloration. + * CSS Parser to parse style for TextMate syntax coloring. * */ public class CSSParser { @@ -47,7 +48,7 @@ private static InputSource toSource(final InputStream source) { } public CSSParser(final InputSource source) throws Exception { - this(source, SACParserFactory.newInstance().makeParser()); + this(source, new SACParserFactory().makeParser()); } public CSSParser(final String source) throws Exception { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java deleted file mode 100644 index f390a0703..000000000 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/ParserNotFoundException.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2013 Angelo Zerr 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: - * Angelo Zerr - initial API and implementation - * IBM Corporation - ongoing development - *******************************************************************************/ -package org.eclipse.tm4e.core.theme.css; - -/** - * Exception used when SAC parser is not retrieved. - */ -public class ParserNotFoundException extends RuntimeException { - - private static final long serialVersionUID = 4339161134287845644L; - - public ParserNotFoundException(final Throwable throwable) { - super(throwable); - } -} From 77e68651924c39ba9b158854696bbb793c8c5a23 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 17:14:26 +0200 Subject: [PATCH 184/202] Move CSSStyle class to tm4e.core.internal.theme.css --- .../tm4e/core/internal/theme/css/CSSDocumentHandler.java | 1 - .../eclipse/tm4e/core/{ => internal}/theme/css/CSSStyle.java | 2 +- .../main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/css/CSSStyle.java (97%) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java index 90f6bc658..11bf0ed8a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSDocumentHandler.java @@ -17,7 +17,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IStyle; import org.eclipse.tm4e.core.theme.RGB; -import org.eclipse.tm4e.core.theme.css.CSSStyle; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.DocumentHandler; import org.w3c.css.sac.InputSource; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSStyle.java similarity index 97% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSStyle.java index 49a3f683e..8a246c3fb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSStyle.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme.css; +package org.eclipse.tm4e.core.internal.theme.css; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.theme.IStyle; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java index 35431168a..88ff3f98c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/css/CSSParser.java @@ -20,6 +20,7 @@ import org.eclipse.tm4e.core.internal.theme.css.CSSConditionFactory; import org.eclipse.tm4e.core.internal.theme.css.CSSDocumentHandler; import org.eclipse.tm4e.core.internal.theme.css.CSSSelectorFactory; +import org.eclipse.tm4e.core.internal.theme.css.CSSStyle; import org.eclipse.tm4e.core.internal.theme.css.ExtendedSelector; import org.eclipse.tm4e.core.internal.theme.css.sac.SACParserFactory; import org.eclipse.tm4e.core.theme.IStyle; From 7d82d732b00c6a4246800768af48ffdc7be7d05e Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 17:27:36 +0200 Subject: [PATCH 185/202] Move internal theme classes to org.eclipse.tm4e.core.internal.theme --- .../tm4e/core/{ => internal}/theme/ThemeMatchingTest.java | 6 +++++- .../tm4e/core/{ => internal}/theme/ThemeParsingTest.java | 5 ++++- .../core/{ => internal}/theme/ThemeResolvingTest.java | 8 +++++++- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 1 + .../org/eclipse/tm4e/core/internal/grammar/Grammar.java | 2 +- .../eclipse/tm4e/core/internal/grammar/LineTokens.java | 2 +- .../tm4e/core/internal/grammar/ScopeListElement.java | 4 ++-- .../eclipse/tm4e/core/internal/grammar/ScopeMetadata.java | 2 +- .../tm4e/core/internal/grammar/ScopeMetadataProvider.java | 4 ++-- .../tm4e/core/internal/grammar/StackElementMetadata.java | 2 +- .../eclipse/tm4e/core/internal/registry/SyncRegistry.java | 6 +++--- .../eclipse/tm4e/core/{ => internal}/theme/ColorMap.java | 2 +- .../eclipse/tm4e/core/{ => internal}/theme/FontStyle.java | 2 +- .../eclipse/tm4e/core/{ => internal}/theme/IRawTheme.java | 2 +- .../tm4e/core/{ => internal}/theme/IRawThemeSetting.java | 2 +- .../tm4e/core/{ => internal}/theme/IThemeProvider.java | 2 +- .../tm4e/core/{ => internal}/theme/IThemeSetting.java | 2 +- .../tm4e/core/{ => internal}/theme/ParsedThemeRule.java | 2 +- .../org/eclipse/tm4e/core/{ => internal}/theme/Theme.java | 2 +- .../org/eclipse/tm4e/core/internal/theme/ThemeRaw.java | 3 --- .../tm4e/core/{ => internal}/theme/ThemeTrieElement.java | 2 +- .../core/{ => internal}/theme/ThemeTrieElementRule.java | 2 +- .../tm4e/core/internal/theme/reader/SyncThemeReader.java | 2 +- .../tm4e/core/internal/theme/reader/ThemeReader.java | 2 +- .../org/eclipse/tm4e/core/registry/IRegistryOptions.java | 2 +- .../java/org/eclipse/tm4e/core/registry/Registry.java | 4 ++-- .../core/internal/grammar/StackElementMetadataTest.java | 2 +- 27 files changed, 44 insertions(+), 33 deletions(-) rename org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/ThemeMatchingTest.java (97%) rename org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/ThemeParsingTest.java (94%) rename org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/ThemeResolvingTest.java (97%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/ColorMap.java (98%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/FontStyle.java (95%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/IRawTheme.java (92%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/IRawThemeSetting.java (94%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/IThemeProvider.java (91%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/IThemeSetting.java (92%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/ParsedThemeRule.java (98%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/Theme.java (99%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/ThemeTrieElement.java (99%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/theme/ThemeTrieElementRule.java (98%) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java similarity index 97% rename from org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java rename to org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java index 9d7d16ce7..251fc5bfe 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeMatchingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -21,6 +21,10 @@ import org.eclipse.tm4e.core.internal.grammar.ScopeListElement; import org.eclipse.tm4e.core.internal.grammar.ScopeMetadata; import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata; +import org.eclipse.tm4e.core.internal.theme.ColorMap; +import org.eclipse.tm4e.core.internal.theme.FontStyle; +import org.eclipse.tm4e.core.internal.theme.Theme; +import org.eclipse.tm4e.core.internal.theme.ThemeTrieElementRule; import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; import org.junit.jupiter.api.Test; diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java similarity index 94% rename from org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java rename to org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java index 0f050ad3f..85f949e21 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeParsingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import static org.junit.jupiter.api.Assertions.assertArrayEquals; @@ -17,6 +17,9 @@ import java.util.Arrays; import java.util.List; +import org.eclipse.tm4e.core.internal.theme.FontStyle; +import org.eclipse.tm4e.core.internal.theme.ParsedThemeRule; +import org.eclipse.tm4e.core.internal.theme.Theme; import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; import org.junit.jupiter.api.Test; diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java similarity index 97% rename from org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java rename to org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java index f32a17bbd..f71ab9291 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/theme/ThemeResolvingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import static org.junit.jupiter.api.Assertions.*; @@ -19,6 +19,12 @@ import java.util.HashMap; import java.util.List; +import org.eclipse.tm4e.core.internal.theme.ColorMap; +import org.eclipse.tm4e.core.internal.theme.FontStyle; +import org.eclipse.tm4e.core.internal.theme.ParsedThemeRule; +import org.eclipse.tm4e.core.internal.theme.Theme; +import org.eclipse.tm4e.core.internal.theme.ThemeTrieElement; +import org.eclipse.tm4e.core.internal.theme.ThemeTrieElementRule; import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; import org.eclipse.tm4e.core.internal.utils.CompareUtils; import org.junit.jupiter.api.Test; diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index fa81b9d7d..4f1295259 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -20,6 +20,7 @@ Export-Package: org.eclipse.tm4e.core, org.eclipse.tm4e.core.grammar, org.eclipse.tm4e.core.internal.grammar;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.internal.matcher;x-friends:="org.eclipse.tm4e.core.tests", + org.eclipse.tm4e.core.internal.theme;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.internal.theme.reader;x-friends:="org.eclipse.tm4e.core.tests", org.eclipse.tm4e.core.internal.utils;x-friends:="org.eclipse.tm4e.core.tests,org.eclipse.tm4e.ui", org.eclipse.tm4e.core.model, diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index c1e6c2c4e..bb351226a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -42,10 +42,10 @@ import org.eclipse.tm4e.core.internal.rule.IRuleFactoryHelper; import org.eclipse.tm4e.core.internal.rule.Rule; import org.eclipse.tm4e.core.internal.rule.RuleFactory; +import org.eclipse.tm4e.core.internal.theme.IThemeProvider; import org.eclipse.tm4e.core.internal.types.IRawGrammar; import org.eclipse.tm4e.core.internal.types.IRawRepository; import org.eclipse.tm4e.core.internal.types.IRawRule; -import org.eclipse.tm4e.core.theme.IThemeProvider; /** * TextMate grammar implementation. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 0a21ff1a6..0243a160a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -27,7 +27,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IToken; -import org.eclipse.tm4e.core.theme.FontStyle; +import org.eclipse.tm4e.core.internal.theme.FontStyle; final class LineTokens { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index 8e48fd1c7..98db0df9c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -17,8 +17,8 @@ import java.util.Objects; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.theme.FontStyle; -import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; +import org.eclipse.tm4e.core.internal.theme.FontStyle; +import org.eclipse.tm4e.core.internal.theme.ThemeTrieElementRule; import com.google.common.base.Splitter; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java index 4af964032..9c66f1652 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadata.java @@ -14,7 +14,7 @@ import java.util.List; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; +import org.eclipse.tm4e.core.internal.theme.ThemeTrieElementRule; public final class ScopeMetadata { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java index 45c0a0ab2..7cb9f736c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeMetadataProvider.java @@ -20,9 +20,9 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.TMException; +import org.eclipse.tm4e.core.internal.theme.IThemeProvider; +import org.eclipse.tm4e.core.internal.theme.ThemeTrieElementRule; import org.eclipse.tm4e.core.internal.utils.RegexSource; -import org.eclipse.tm4e.core.theme.IThemeProvider; -import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; /** * @see - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/FontStyle.java similarity index 95% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/FontStyle.java index cf2001f5a..1bfa7615f 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/FontStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/FontStyle.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; /** * Font style definitions. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IRawTheme.java similarity index 92% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IRawTheme.java index f577ef769..bba1cca52 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawTheme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IRawTheme.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import java.util.Collection; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IRawThemeSetting.java similarity index 94% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IRawThemeSetting.java index 32565430d..8e2089af0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IRawThemeSetting.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IRawThemeSetting.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import org.eclipse.jdt.annotation.Nullable; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IThemeProvider.java similarity index 91% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IThemeProvider.java index b26c341d3..3a2099a9b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeProvider.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IThemeProvider.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import java.util.List; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IThemeSetting.java similarity index 92% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IThemeSetting.java index 0a342fb42..72b4f7aae 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/IThemeSetting.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/IThemeSetting.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import org.eclipse.jdt.annotation.Nullable; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ParsedThemeRule.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ParsedThemeRule.java index 792e2a093..b7e5d5b80 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ParsedThemeRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ParsedThemeRule.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import java.util.List; import java.util.Objects; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/Theme.java similarity index 99% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/Theme.java index 990d75a2d..a0dcf8379 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/Theme.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java index 81ad2cede..f39b0c5db 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeRaw.java @@ -16,9 +16,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.internal.parser.PropertySettable; -import org.eclipse.tm4e.core.theme.IRawTheme; -import org.eclipse.tm4e.core.theme.IRawThemeSetting; -import org.eclipse.tm4e.core.theme.IThemeSetting; public final class ThemeRaw extends HashMap implements IRawTheme, IRawThemeSetting, IThemeSetting, PropertySettable { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeTrieElement.java similarity index 99% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeTrieElement.java index dba44e47e..cf55af5d4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeTrieElement.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import java.util.ArrayList; import java.util.HashMap; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeTrieElementRule.java similarity index 98% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeTrieElementRule.java index 77a333830..88b6c687a 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/theme/ThemeTrieElementRule.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeTrieElementRule.java @@ -9,7 +9,7 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.theme; +package org.eclipse.tm4e.core.internal.theme; import java.util.ArrayList; import java.util.List; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java index 401869fe4..ecd1a1127 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/SyncThemeReader.java @@ -19,7 +19,7 @@ import java.io.InputStream; import org.eclipse.tm4e.core.internal.parser.PListParser; -import org.eclipse.tm4e.core.theme.IRawTheme; +import org.eclipse.tm4e.core.internal.theme.IRawTheme; final class SyncThemeReader { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java index 8d2a15ac7..a86843605 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/reader/ThemeReader.java @@ -24,8 +24,8 @@ import org.eclipse.tm4e.core.internal.parser.PListParserJSON; import org.eclipse.tm4e.core.internal.parser.PListParserXML; import org.eclipse.tm4e.core.internal.parser.PListParserYAML; +import org.eclipse.tm4e.core.internal.theme.IRawTheme; import org.eclipse.tm4e.core.internal.theme.ThemeRaw; -import org.eclipse.tm4e.core.theme.IRawTheme; /** * TextMate Theme reader utilities. diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java index 8d960e202..465ce707c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/registry/IRegistryOptions.java @@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tm4e.core.theme.IRawTheme; +import org.eclipse.tm4e.core.internal.theme.IRawTheme; /** * @see Date: Fri, 6 May 2022 17:38:37 +0200 Subject: [PATCH 186/202] Move model internal classes to org.eclipse.tm4e.core.internal.model --- .../tm4e/core/{ => internal}/model/DecodeMap.java | 6 +++--- .../model/ModelTokensChangedEventBuilder.java | 7 +++++-- .../core/{ => internal}/model/TMTokenDecodeData.java | 4 ++-- .../org/eclipse/tm4e/core/model/AbstractLineList.java | 2 +- .../java/org/eclipse/tm4e/core/model/ModelLine.java | 2 +- .../java/org/eclipse/tm4e/core/model/TMModel.java | 11 ++++------- .../java/org/eclipse/tm4e/core/model/Tokenizer.java | 2 ++ 7 files changed, 18 insertions(+), 16 deletions(-) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/model/DecodeMap.java (93%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/model/ModelTokensChangedEventBuilder.java (85%) rename org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/{ => internal}/model/TMTokenDecodeData.java (84%) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/DecodeMap.java similarity index 93% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/DecodeMap.java index cd865df62..7859336c4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/DecodeMap.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/DecodeMap.java @@ -14,7 +14,7 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.model; +package org.eclipse.tm4e.core.internal.model; import java.util.LinkedHashMap; import java.util.Map; @@ -23,7 +23,7 @@ import com.google.common.base.Splitter; -final class DecodeMap { +public final class DecodeMap { private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final Splitter BY_DOT_SPLITTER = Splitter.on('.'); @@ -32,7 +32,7 @@ final class DecodeMap { private final Map scopeToTokenIds = new LinkedHashMap<>(); private final Map tokenToTokenId = new LinkedHashMap<>(); private final Map tokenIdToToken = new LinkedHashMap<>(); - TMTokenDecodeData prevToken = new TMTokenDecodeData(EMPTY_STRING_ARRAY, + public TMTokenDecodeData prevToken = new TMTokenDecodeData(EMPTY_STRING_ARRAY, new LinkedHashMap<>()); public int[] getTokenIds(final String scope) { diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/ModelTokensChangedEventBuilder.java similarity index 85% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/ModelTokensChangedEventBuilder.java index cb40e9fdd..1e934d3da 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelTokensChangedEventBuilder.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/ModelTokensChangedEventBuilder.java @@ -14,15 +14,18 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.model; +package org.eclipse.tm4e.core.internal.model; import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import java.util.ArrayList; import java.util.List; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tm4e.core.model.ITMModel; +import org.eclipse.tm4e.core.model.ModelTokensChangedEvent; +import org.eclipse.tm4e.core.model.Range; -final class ModelTokensChangedEventBuilder { +public final class ModelTokensChangedEventBuilder { private final ITMModel model; private final List ranges = new ArrayList<>(); diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/TMTokenDecodeData.java similarity index 84% rename from org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java rename to org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/TMTokenDecodeData.java index bbebd480a..3525fbbeb 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMTokenDecodeData.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/model/TMTokenDecodeData.java @@ -14,7 +14,7 @@ * - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license * - Angelo Zerr - translation and adaptation to Java */ -package org.eclipse.tm4e.core.model; +package org.eclipse.tm4e.core.internal.model; import java.util.Map; @@ -23,7 +23,7 @@ public class TMTokenDecodeData { public final String[] scopes; public final Map> scopeTokensMaps; - TMTokenDecodeData(final String[] scopes, final Map> scopeTokensMaps) { + public TMTokenDecodeData(final String[] scopes, final Map> scopeTokensMaps) { this.scopes = scopes; this.scopeTokensMaps = scopeTokensMaps; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java index e6bac6846..b79b4ae70 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java @@ -39,7 +39,7 @@ public abstract class AbstractLineList implements IModelLines { @Nullable private TMModel model; - void setModel(@Nullable final TMModel model) { + protected void setModel(@Nullable final TMModel model) { this.model = model; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java index 02e3852f7..d8ac79f65 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/ModelLine.java @@ -20,7 +20,7 @@ public class ModelLine { boolean isInvalid; @Nullable - private TMState state; + TMState state; @Nullable List tokens; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index e4e020438..903629fdf 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -25,6 +25,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.internal.model.ModelTokensChangedEventBuilder; /** * TextMate model class. @@ -132,7 +133,7 @@ private void revalidateTokensNow(final int startLine, @Nullable final Integer to // - tokenizing the next line would go above MAX_ALLOWED_TIME int lineIndex = startLine; - while (lineIndex <= toLineIndex && lineIndex < model.getLines().getNumberOfLines()) { + while (lineIndex <= toLineIndex && lineIndex < model.lines.getNumberOfLines()) { elapsedTime = System.currentTimeMillis() - startTime; if (elapsedTime > MAX_ALLOWED_TIME) { // Stop if MAX_ALLOWED_TIME is reached @@ -187,7 +188,7 @@ private int updateTokensInRange(final ModelTokensChangedEventBuilder eventBuilde try { text = model.lines.getLineText(lineIndex); // Tokenize only the first X characters - r = castNonNull(model.tokenizer).tokenize(text, modeLine.getState(), 0, stopLineTokenizationAfter); + r = castNonNull(model.tokenizer).tokenize(text, modeLine.state, 0, stopLineTokenizationAfter); } catch (final Exception ex) { LOGGER.log(ERROR, ex.toString()); return nextInvalidLineIndex; @@ -281,7 +282,7 @@ public synchronized void removeModelTokensChangedListener(final IModelTokensChan @Override public void dispose() { stop(); - getLines().dispose(); + lines.dispose(); } /** @@ -342,8 +343,4 @@ void invalidateLine(final int lineIndex) { lines.get(lineIndex).isInvalid = true; invalidLines.add(lineIndex); } - - public IModelLines getLines() { - return lines; - } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java index 59c1956a0..debc99fb5 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/Tokenizer.java @@ -22,6 +22,8 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.internal.model.DecodeMap; +import org.eclipse.tm4e.core.internal.model.TMTokenDecodeData; public class Tokenizer implements ITokenizationSupport { From 0ece04b1ae2d972c9bd7ee2d3cae0a14f52eed6d Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 17:50:54 +0200 Subject: [PATCH 187/202] Move CSSParserTest to org.eclipse.tm4e.core.theme.css --- .../eclipse/tm4e/core/{ => theme}/css/CSSParserTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) rename org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/{ => theme}/css/CSSParserTest.java (89%) diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/css/CSSParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/theme/css/CSSParserTest.java similarity index 89% rename from org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/css/CSSParserTest.java rename to org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/theme/css/CSSParserTest.java index cf25dd4cc..12aef9d24 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/css/CSSParserTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/theme/css/CSSParserTest.java @@ -9,10 +9,9 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.css; +package org.eclipse.tm4e.core.theme.css; import org.eclipse.tm4e.core.theme.IStyle; -import org.eclipse.tm4e.core.theme.css.CSSParser; public class CSSParserTest { @@ -20,10 +19,10 @@ public static void main(String[] args) throws Exception { CSSParser parser = new CSSParser(".comment {color:rgb(0,1,2)} .comment.ts {color:rgb(0,1,2)}"); String[] names = "comment".split("[.]"); parser.getBestStyle(names); - + names = "comment.ts".split("[.]"); IStyle style = parser.getBestStyle(names); - + System.err.println(style.getColor().red); } } From cc038025519bb7059135883f4fec4ca1da79c2fb Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 17:51:50 +0200 Subject: [PATCH 188/202] Move PListParserTest to org.eclipse.tm4e.core.internal.parser --- .../core/internal/{grammar => }/parser/PListParserTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) rename org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/{grammar => }/parser/PListParserTest.java (85%) diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/parser/PListParserTest.java similarity index 85% rename from org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java rename to org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/parser/PListParserTest.java index 71ca823a2..6e337d782 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/grammar/parser/PListParserTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/parser/PListParserTest.java @@ -9,17 +9,13 @@ * Contributors: * Angelo Zerr - initial API and implementation */ -package org.eclipse.tm4e.core.internal.grammar.parser; +package org.eclipse.tm4e.core.internal.parser; import static org.junit.jupiter.api.Assertions.*; import org.eclipse.tm4e.core.Data; import org.eclipse.tm4e.core.internal.grammar.RawGrammar; import org.eclipse.tm4e.core.internal.grammar.reader.GrammarReader; -import org.eclipse.tm4e.core.internal.parser.PListParser; -import org.eclipse.tm4e.core.internal.parser.PListParserJSON; -import org.eclipse.tm4e.core.internal.parser.PListParserXML; -import org.eclipse.tm4e.core.internal.parser.PListParserYAML; import org.junit.jupiter.api.Test; public class PListParserTest { From 0461d7400f193d6c7088864c8560f64ad23478d8 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 May 2022 17:57:44 +0200 Subject: [PATCH 189/202] Remove unused imports --- .../tm4e/core/internal/theme/ThemeMatchingTest.java | 7 +------ .../eclipse/tm4e/core/internal/theme/ThemeParsingTest.java | 5 +---- .../tm4e/core/internal/theme/ThemeResolvingTest.java | 6 ------ 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java index 251fc5bfe..b763b5dbd 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java @@ -11,8 +11,7 @@ */ package org.eclipse.tm4e.core.internal.theme; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.util.Arrays; @@ -21,10 +20,6 @@ import org.eclipse.tm4e.core.internal.grammar.ScopeListElement; import org.eclipse.tm4e.core.internal.grammar.ScopeMetadata; import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata; -import org.eclipse.tm4e.core.internal.theme.ColorMap; -import org.eclipse.tm4e.core.internal.theme.FontStyle; -import org.eclipse.tm4e.core.internal.theme.Theme; -import org.eclipse.tm4e.core.internal.theme.ThemeTrieElementRule; import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; import org.junit.jupiter.api.Test; diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java index 85f949e21..12c364ad3 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java @@ -11,15 +11,12 @@ */ package org.eclipse.tm4e.core.internal.theme; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.util.Arrays; import java.util.List; -import org.eclipse.tm4e.core.internal.theme.FontStyle; -import org.eclipse.tm4e.core.internal.theme.ParsedThemeRule; -import org.eclipse.tm4e.core.internal.theme.Theme; import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; import org.junit.jupiter.api.Test; diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java index f71ab9291..d24d57fb8 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java @@ -19,12 +19,6 @@ import java.util.HashMap; import java.util.List; -import org.eclipse.tm4e.core.internal.theme.ColorMap; -import org.eclipse.tm4e.core.internal.theme.FontStyle; -import org.eclipse.tm4e.core.internal.theme.ParsedThemeRule; -import org.eclipse.tm4e.core.internal.theme.Theme; -import org.eclipse.tm4e.core.internal.theme.ThemeTrieElement; -import org.eclipse.tm4e.core.internal.theme.ThemeTrieElementRule; import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; import org.eclipse.tm4e.core.internal.utils.CompareUtils; import org.junit.jupiter.api.Test; From ab8b7a6f09185ab56b6da27886e91f9f0376dc25 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 13:46:23 +0200 Subject: [PATCH 190/202] Add GrammarBenchmark --- .gitignore | 3 + org.eclipse.tm4e.core/pom.xml | 82 +- .../src/benchmark/BENCHMARK.md | 74 ++ .../src/benchmark/run-grammar-benchmark.cmd | 21 + .../src/benchmark/run-grammar-benchmark.sh | 19 + .../tm4e/core/benchmark/BenchmarkRunner.java | 105 ++ .../tm4e/core/benchmark/GrammarBenchmark.java | 65 ++ .../GrammarBenchmark.Java.tmLanguage.json | 1030 +++++++++++++++++ .../benchmark/GrammarBenchmark.JavaFile.txt | 901 ++++++++++++++ 9 files changed, 2290 insertions(+), 10 deletions(-) create mode 100644 org.eclipse.tm4e.core/src/benchmark/BENCHMARK.md create mode 100644 org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.cmd create mode 100644 org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.sh create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java create mode 100644 org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.java create mode 100644 org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.Java.tmLanguage.json create mode 100644 org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.JavaFile.txt diff --git a/.gitignore b/.gitignore index cca875399..6a06219e1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ !**/.settings/org.eclipse.jdt.core.prefs !**/.settings/org.eclipse.pde.core.prefs +# Eclipse GFM Viewer +*.md.html + # Maven /target /*/target diff --git a/org.eclipse.tm4e.core/pom.xml b/org.eclipse.tm4e.core/pom.xml index f4241abff..47031f2fa 100644 --- a/org.eclipse.tm4e.core/pom.xml +++ b/org.eclipse.tm4e.core/pom.xml @@ -1,11 +1,73 @@ - - 4.0.0 - org.eclipse.tm4e.core - eclipse-plugin - 0.4.4-SNAPSHOT - - org.eclipse - org.eclipse.tm4e - 0.3.2-SNAPSHOT - + + 4.0.0 + org.eclipse.tm4e.core + eclipse-plugin + 0.4.4-SNAPSHOT + + org.eclipse + org.eclipse.tm4e + 0.3.2-SNAPSHOT + + + + + benchmark + + + benchmarkClass + + + + + + + net.officefloor.maven + tycho-shade-maven-plugin + 3.40.0 + + + shade + pre-integration-test + + shade + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + integration-test + + exec + + + java + + + -Xms2048M + -Xmx2048M + -XX:+UseG1GC + + + -Xlog:gc:stderr + + -Dfile.encoding=UTF-8 + + -cp + ${project.build.directory}/${project.artifactId}-${project.version}-tychoshade.jar;${project.build.directory}/test-classes + ${benchmarkClass} + + + + + + + + + diff --git a/org.eclipse.tm4e.core/src/benchmark/BENCHMARK.md b/org.eclipse.tm4e.core/src/benchmark/BENCHMARK.md new file mode 100644 index 000000000..1f5a1d6bc --- /dev/null +++ b/org.eclipse.tm4e.core/src/benchmark/BENCHMARK.md @@ -0,0 +1,74 @@ +# TM4E Core Benchmarks + +## GrammarBenchmark + +The [GrammarBenchmark](../test/java/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.java) measures how long it takes to tokenize a given source file using the +**[Grammar](../org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java)#tokenizeLine()** +method and how much memory is allocated on the JVM heap to do so. As test source file the +[GrammarBenchmark.JavaFile.txt](../test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.JavaFile.txt) is used. + +The benchmark executes multiple rounds. In the beginning warm-up rounds are executed to get the JIT compiler activated. +The results of these rounds should be ignored. + +Each round is executed sequentially in a new thread. This gives the OS the opportunity, that in case for the first round an over-utilized core was chosen, to +select a better core to execute the new thread of the next benchmark round. + +The output will look something like this: +```yaml +[0.047s][info][gc] Using G1 +Source Code chars: 36.385 +Source Code lines: 901 +JVM Vendor: ojdkbuild +JVM Version: 11.0.14 +JVM Inital Heap: 2048.00 MB +JVM Maximum Heap: 2048.00 MB +JVM Args: -Xms2048M -Xmx2048M -XX:+UseG1GC -Xlog:gc:stderr -Dfile.encoding=UTF-8 +-------------------------------- +Warmup Rounds: 3 +Benchmark Rounds: 3 +Operations per Benchmark Round: 50 +-------------------------------- +warm-up 1/3... +#[1.626s][info][gc] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 102M->3M(2048M) 4.692ms +#[6.155s][info][gc] GC(1) Pause Young (Normal) (G1 Evacuation Pause) 690M->3M(2048M) 3.132ms +#[10.557s][info][gc] GC(2) Pause Young (Normal) (G1 Evacuation Pause) 719M->3M(2048M) 2.788ms +#[15.228s][info][gc] GC(3) Pause Young (Normal) (G1 Evacuation Pause) 761M->3M(2048M) 2.957ms +#[20.160s][info][gc] GC(4) Pause Young (Normal) (G1 Evacuation Pause) 804M->3M(2048M) 2.743ms +#[25.590s][info][gc] GC(5) Pause Young (Normal) (G1 Evacuation Pause) 882M->3M(2048M) 2.632ms + -> result: 28307 ms/round | 529.90 ops/s | 113.23 ms/op +warm-up 2/3... +#[31.646s][info][gc] GC(6) Pause Young (Normal) (G1 Evacuation Pause) 987M->3M(2048M) 2.683ms +#[38.579s][info][gc] GC(7) Pause Young (Normal) (G1 Evacuation Pause) 1129M->3M(2048M) 2.927ms +#[46.106s][info][gc] GC(8) Pause Young (Normal) (G1 Evacuation Pause) 1227M->3M(2048M) 2.872ms +#[53.542s][info][gc] GC(9) Pause Young (Normal) (G1 Evacuation Pause) 1227M->3M(2048M) 2.727ms + -> result: 27172 ms/round | 552.04 ops/s | 108.69 ms/op +warm-up 3/3... +#[61.026s][info][gc] GC(10) Pause Young (Normal) (G1 Evacuation Pause) 1227M->3M(2048M) 3.225ms +#[68.556s][info][gc] GC(11) Pause Young (Normal) (G1 Evacuation Pause) 1227M->3M(2048M) 2.938ms +#[76.021s][info][gc] GC(12) Pause Young (Normal) (G1 Evacuation Pause) 1227M->3M(2048M) 2.766ms + -> result: 27129 ms/round | 552.91 ops/s | 108.52 ms/op +-------------------------------- +benchmark 1/3... +#[83.000s][info][gc] GC(13) Pause Full (System.gc()) 1139M->3M(2048M) 9.200ms +#[84.020s][info][gc] GC(14) Pause Full (System.gc()) 3M->3M(2048M) 6.465ms + -> result: 5315 ms/round | 564.44 ops/s | 106.30 ms/op | 17.73 MB/op +benchmark 2/3... +#[90.352s][info][gc] GC(15) Pause Full (System.gc()) 889M->3M(2048M) 8.125ms +#[91.361s][info][gc] GC(16) Pause Full (System.gc()) 3M->3M(2048M) 5.792ms + -> result: 5208 ms/round | 576.04 ops/s | 104.16 ms/op | 17.73 MB/op +benchmark 3/3... +#[97.590s][info][gc] GC(17) Pause Full (System.gc()) 889M->3M(2048M) 7.367ms +#[98.604s][info][gc] GC(18) Pause Full (System.gc()) 3M->3M(2048M) 6.515ms + -> result: 5202 ms/round | 576.70 ops/s | 104.04 ms/op | 17.73 MB/op +DONE. +``` + +The results of the three benchmark rounds show that it was possible to parse the whole source file 564.44 to 576.70 times per second.\ +One time parsing of the source file took 104.04 to 106.30 ms and allocated 17.73MB of temporary objects on the JVM heap. + +### How to run the benchmark +To run the benchmark execute the `run-grammar-benchmark.sh` or `run-grammar-benchmark.cmd` from a command line window. + +You can also run the [GrammarBenchmark](../test/java/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.java) from within Eclipse via +`Run As -> Java Application` for development/debugging/testing purposes. However you need to add these VM arguments to the launch configuration: +`-Xms2048M -Xmx2048M -XX:+UseG1GC -Xlog:gc:stderr -Dfile.encoding=UTF-8`. Don't rely on the results when launched like this. diff --git a/org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.cmd b/org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.cmd new file mode 100644 index 000000000..b4f2ecfb4 --- /dev/null +++ b/org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.cmd @@ -0,0 +1,21 @@ +@echo off +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: Copyright (c) 2022 Sebatian Thomschke 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: +:: Sebatian Thomschke - Initial API and implementation +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +setlocal + +cd /D "%~dp0..\..\.." + +mvn clean verify ^ + -pl target-platform,org.eclipse.tm4e.core ^ + -Djgit.dirtyWorkingTree=warning ^ + -DskipTests ^ + -DbenchmarkClass=org.eclipse.tm4e.core.benchmark.GrammarBenchmark diff --git a/org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.sh b/org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.sh new file mode 100644 index 000000000..01c199ad4 --- /dev/null +++ b/org.eclipse.tm4e.core/src/benchmark/run-grammar-benchmark.sh @@ -0,0 +1,19 @@ +#!/bin/bash +############################################################################### +# Copyright (c) 2022 Sebatian Thomschke 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: +# Sebatian Thomschke - Initial API and implementation +############################################################################### + +cd "$(dirname "$0")/../../.." + +mvn clean verify \ + -pl target-platform,org.eclipse.tm4e.core \ + -Djgit.dirtyWorkingTree=warning \ + -DskipTests \ + -DbenchmarkClass=org.eclipse.tm4e.core.benchmark.GrammarBenchmark diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java new file mode 100644 index 000000000..09bda82d1 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.tm4e.core.benchmark; + +import java.lang.management.ManagementFactory; +import java.util.Locale; + +public final class BenchmarkRunner { + + private static final Runtime RUNTIME = Runtime.getRuntime(); + private static final String SEPARATOR = "--------------------------------"; + + public static void run(final int warmUpRounds, final int benchmarkRounds, final int opsPerBenchmarkRound, + final Runnable benchmark) throws InterruptedException { + Locale.setDefault(Locale.ENGLISH); + System.out.println("JVM Vendor: " + System.getProperty("java.vendor")); + System.out.println("JVM Version: " + System.getProperty("java.version")); + System.out.println(String.format("JVM Inital Heap: %.2f MB", RUNTIME.maxMemory() / (float) 1024 / 1024)); + System.out.println(String.format("JVM Maximum Heap: %.2f MB", RUNTIME.totalMemory() / (float) 1024 / 1024)); + System.out.println("JVM Args: " + String.join(" ", ManagementFactory.getRuntimeMXBean().getInputArguments())); + System.out.println(SEPARATOR); + + System.out.println("Warmup Rounds: " + warmUpRounds); + System.out.println("Benchmark Rounds: " + warmUpRounds); + System.out.println("Operations per Benchmark Round: " + opsPerBenchmarkRound); + System.out.println(SEPARATOR); + + // warmup + for (int r = 1; r <= warmUpRounds; r++) { + runRound("warm-up", r, warmUpRounds, + 5 * opsPerBenchmarkRound, // use more iterations to force JIT to kick in + false, // don't try to measure heap usage as warm-up rounds will trigger gc + benchmark); + } + + System.out.println(SEPARATOR); + + // benchmark + for (int r = 1; r <= benchmarkRounds; r++) { + runRound("benchmark", r, benchmarkRounds, + opsPerBenchmarkRound, + true, + benchmark); + } + System.out.println("DONE."); + } + + private static void runRound(final String label, final int round, final int totalRounds, final int iterations, + final boolean measureHeapUsage, + final Runnable benchmark) throws InterruptedException { + // spinning up a thread so the JVM hopefully runs the benchmark on different cores each round + final var t = new Thread(() -> { + System.out.println(label + " " + round + "/" + totalRounds + "..."); + if (measureHeapUsage) { + try { + System.gc(); + Thread.sleep(1_000); + System.gc(); + Thread.sleep(1_000); + } catch (final InterruptedException ex) { + Thread.interrupted(); + throw new RuntimeException(ex); + } + } + + final var startFreeMem = RUNTIME.freeMemory(); + final var startAt = System.currentTimeMillis(); + + for (int i = 0; i < iterations; i++) { + benchmark.run(); + } + + final var durationMS = System.currentTimeMillis() - startAt; + final var durationMSPerIteration = durationMS / (float) iterations; + final var iterationsPerSecond = 60_000 / durationMSPerIteration; + + if (measureHeapUsage) { + final var heapBytesPerIteration = (startFreeMem - RUNTIME.freeMemory()) + / (float) iterations; + System.out.println(String.format( + " -> result: %5d ms/round | %,7.2f ops/s | %,5.2f ms/op | %,5.2f MB/op", + durationMS, + iterationsPerSecond, + durationMSPerIteration, + heapBytesPerIteration / 1024 / 1024)); + } else { + System.out.println(String.format( + " -> result: %5d ms/round | %,7.2f ops/s | %,5.2f ms/op", + durationMS, + iterationsPerSecond, + durationMSPerIteration)); + } + }); + t.setPriority(Thread.MAX_PRIORITY); + t.run(); + t.join(); + } +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.java new file mode 100644 index 000000000..47d9e5399 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2022 Sebastian Thomschke and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.tm4e.core.benchmark; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.grammar.IStackElement; +import org.eclipse.tm4e.core.registry.Registry; + +public final class GrammarBenchmark implements Runnable { + + private static final int WARMUP_ROUNDS = 3; + private static final int BENCHMARK_ROUNDS = 3; + private static final int OPS_PER_BENCHMARK_ROUND = 50; + + public static void main(final String... args) throws Exception { + BenchmarkRunner.run(WARMUP_ROUNDS, BENCHMARK_ROUNDS, OPS_PER_BENCHMARK_ROUND, new GrammarBenchmark()); + } + + final IGrammar grammar; + final String[] sourceCode; + + GrammarBenchmark() throws Exception { + /* + * load the grammar + */ + try (var grammarFileIS = GrammarBenchmark.class.getResourceAsStream("GrammarBenchmark.Java.tmLanguage.json")) { + grammar = new Registry().loadGrammarFromPathSync("GrammarBenchmark.Java.tmLanguage.json", grammarFileIS); + } + + /* + * load the file to be parsed + */ + try (var sourceFileIS = GrammarBenchmark.class.getResourceAsStream("GrammarBenchmark.JavaFile.txt")) { + sourceCode = new BufferedReader(new InputStreamReader(sourceFileIS, StandardCharsets.UTF_8)) + .lines() + .toArray(String[]::new); + } + System.out.println( + String.format("Source Code chars: %,d", Arrays.stream(sourceCode).mapToInt(String::length).sum())); + System.out.println(String.format("Source Code lines: %,d", sourceCode.length)); + } + + /** + * Tokenize all lines of the pre-loaded source file + */ + @Override + public void run() { + IStackElement state = null; + for (final var line : sourceCode) { + state = grammar.tokenizeLine(line, state).getRuleStack(); + } + } +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.Java.tmLanguage.json b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.Java.tmLanguage.json new file mode 100644 index 000000000..f0fcef2d0 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.Java.tmLanguage.json @@ -0,0 +1,1030 @@ +{ + "fileTypes": [ + "java", + "bsh" + ], + "keyEquivalent": "^~J", + "name": "Java", + "patterns": [ + { + "captures": { + "1": { + "name": "keyword.other.package.java" + }, + "2": { + "name": "storage.modifier.package.java" + }, + "3": { + "name": "punctuation.terminator.java" + } + }, + "match": "^\\s*(package)\\b(?:\\s*([^ ;$]+)\\s*(;)?)?", + "name": "meta.package.java" + }, + { + "begin": "(import static)\\b\\s*", + "beginCaptures": { + "1": { + "name": "keyword.other.import.static.java" + } + }, + "captures": { + "1": { + "name": "keyword.other.import.java" + }, + "2": { + "name": "storage.modifier.import.java" + }, + "3": { + "name": "punctuation.terminator.java" + } + }, + "contentName": "storage.modifier.import.java", + "end": "\\s*(?:$|(;))", + "endCaptures": { + "1": { + "name": "punctuation.terminator.java" + } + }, + "name": "meta.import.java", + "patterns": [ + { + "match": "\\.", + "name": "punctuation.separator.java" + }, + { + "match": "\\s", + "name": "invalid.illegal.character_not_allowed_here.java" + } + ] + }, + { + "begin": "(import)\\b\\s*", + "beginCaptures": { + "1": { + "name": "keyword.other.import.java" + } + }, + "captures": { + "1": { + "name": "keyword.other.import.java" + }, + "2": { + "name": "storage.modifier.import.java" + }, + "3": { + "name": "punctuation.terminator.java" + } + }, + "contentName": "storage.modifier.import.java", + "end": "\\s*(?:$|(;))", + "endCaptures": { + "1": { + "name": "punctuation.terminator.java" + } + }, + "name": "meta.import.java", + "patterns": [ + { + "match": "\\.", + "name": "punctuation.separator.java" + }, + { + "match": "\\s", + "name": "invalid.illegal.character_not_allowed_here.java" + } + ] + }, + { + "include": "#code" + } + ], + "repository": { + "all-types": { + "patterns": [ + { + "include": "#primitive-arrays" + }, + { + "include": "#primitive-types" + }, + { + "include": "#object-types" + } + ] + }, + "annotations": { + "patterns": [ + { + "begin": "(@[^ (]+)(\\()", + "beginCaptures": { + "1": { + "name": "storage.type.annotation.java" + }, + "2": { + "name": "punctuation.definition.annotation-arguments.begin.java" + } + }, + "end": "(\\))", + "endCaptures": { + "1": { + "name": "punctuation.definition.annotation-arguments.end.java" + } + }, + "name": "meta.declaration.annotation.java", + "patterns": [ + { + "captures": { + "1": { + "name": "constant.other.key.java" + }, + "2": { + "name": "keyword.operator.assignment.java" + } + }, + "match": "(\\w*)\\s*(=)" + }, + { + "include": "#code" + }, + { + "match": ",", + "name": "punctuation.separator.property.java" + } + ] + }, + { + "match": "@\\w*", + "name": "storage.type.annotation.java" + } + ] + }, + "anonymous-classes-and-new": { + "begin": "\\bnew\\b", + "beginCaptures": { + "0": { + "name": "keyword.control.new.java" + } + }, + "end": "(?<=\\)|\\])(?!\\s*{)|(?<=})|(?=;)", + "patterns": [ + { + "begin": "(\\w+)\\s*(?=\\[)", + "beginCaptures": { + "1": { + "name": "storage.type.java" + } + }, + "end": "(})|(?=\\s*(?:,|;|\\)))", + "endCaptures": { + "1": { + "name": "punctuation.section.block.end.java" + } + }, + "patterns": [ + { + "begin": "\\[", + "end": "\\]", + "patterns": [ + { + "include": "#code" + } + ] + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.block.begin.java" + } + }, + "end": "(?=})", + "patterns": [ + { + "include": "#code" + } + ] + } + ] + }, + { + "begin": "(?=\\w.*\\()", + "end": "(?<=\\))", + "patterns": [ + { + "include": "#object-types" + }, + { + "begin": "\\(", + "beginCaptures": { + "1": { + "name": "storage.type.java" + } + }, + "end": "\\)", + "patterns": [ + { + "include": "#code" + } + ] + } + ] + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.inner-class.begin.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.inner-class.end.java" + } + }, + "name": "meta.inner-class.java", + "patterns": [ + { + "include": "#class-body" + } + ] + } + ] + }, + "assertions": { + "patterns": [ + { + "begin": "\\b(assert)\\s", + "beginCaptures": { + "1": { + "name": "keyword.control.assert.java" + } + }, + "end": "$", + "name": "meta.declaration.assertion.java", + "patterns": [ + { + "match": ":", + "name": "keyword.operator.assert.expression-seperator.java" + }, + { + "include": "#code" + } + ] + } + ] + }, + "class": { + "begin": "(?=\\w?[\\w\\s]*(?:class|(?:@)?interface|enum)\\s+\\w+)", + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.class.end.java" + } + }, + "name": "meta.class.java", + "patterns": [ + { + "include": "#storage-modifiers" + }, + { + "include": "#comments" + }, + { + "captures": { + "1": { + "name": "storage.modifier.java" + }, + "2": { + "name": "entity.name.type.class.java" + } + }, + "match": "(class|(?:@)?interface|enum)\\s+(\\w+)", + "name": "meta.class.identifier.java" + }, + { + "begin": "extends", + "beginCaptures": { + "0": { + "name": "storage.modifier.extends.java" + } + }, + "end": "(?={|implements)", + "name": "meta.definition.class.inherited.classes.java", + "patterns": [ + { + "include": "#object-types-inherited" + }, + { + "include": "#comments" + } + ] + }, + { + "begin": "(implements)\\s", + "beginCaptures": { + "1": { + "name": "storage.modifier.implements.java" + } + }, + "end": "(?=\\s*extends|\\{)", + "name": "meta.definition.class.implemented.interfaces.java", + "patterns": [ + { + "include": "#object-types-inherited" + }, + { + "include": "#comments" + } + ] + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.class.begin.java" + } + }, + "end": "(?=})", + "name": "meta.class.body.java", + "patterns": [ + { + "include": "#class-body" + } + ] + } + ] + }, + "class-body": { + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#class" + }, + { + "include": "#enums" + }, + { + "include": "#variables" + }, + { + "include": "#methods" + }, + { + "include": "#annotations" + }, + { + "include": "#storage-modifiers" + }, + { + "include": "#code" + } + ] + }, + "code": { + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#class" + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.block.begin.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.block.end.java" + } + }, + "patterns": [ + { + "include": "#code" + } + ] + }, + { + "include": "#assertions" + }, + { + "include": "#parens" + }, + { + "include": "#constants-and-special-vars" + }, + { + "include": "#anonymous-classes-and-new" + }, + { + "include": "#annotations" + }, + { + "include": "#keywords" + }, + { + "include": "#storage-modifiers" + }, + { + "include": "#method-call" + }, + { + "include": "#strings" + }, + { + "include": "#all-types" + } + ] + }, + "comments": { + "patterns": [ + { + "captures": { + "0": { + "name": "punctuation.definition.comment.java" + } + }, + "match": "/\\*\\*/", + "name": "comment.block.empty.java" + }, + { + "include": "text.html.javadoc" + }, + { + "include": "#comments-inline" + } + ] + }, + "comments-inline": { + "patterns": [ + { + "begin": "/\\*", + "captures": { + "0": { + "name": "punctuation.definition.comment.java" + } + }, + "end": "\\*/", + "name": "comment.block.java" + }, + { + "begin": "(^[ \\t]+)?(?=//)", + "beginCaptures": { + "1": { + "name": "punctuation.whitespace.comment.leading.java" + } + }, + "end": "(?!\\G)", + "patterns": [ + { + "begin": "//", + "beginCaptures": { + "0": { + "name": "punctuation.definition.comment.java" + } + }, + "end": "\\n", + "name": "comment.line.double-slash.java" + } + ] + } + ] + }, + "constants-and-special-vars": { + "patterns": [ + { + "match": "\\b(true|false|null)\\b", + "name": "constant.language.java" + }, + { + "match": "\\b(this|super)\\b", + "name": "variable.language.java" + }, + { + "match": "\\b0[xX]\\h([\\h_]*\\h)?[lL]?(?!\\w|\\.)", + "name": "constant.numeric.hex.java" + }, + { + "match": "\\b0[0-7_]*[0-7][lL]?\\b", + "name": "constant.numeric.octal.java" + }, + { + "match": "\\b0[bB][01]([01_]*[01])?[lL]?\\b", + "name": "constant.numeric.binary.java" + }, + { + "match": "\\b(0|[1-9]([0-9_]*[0-9])?)[lL]?(?!\\w|\\.)", + "name": "constant.numeric.integer.java" + }, + { + "match": "(?x)\n\t\t\t\t\t\t(?\n\t\t\t\t\t\t\t0[xX]\t\t\t\t\t\t\t\t\t# Start literal\n\t\t\t\t\t\t\t(\\h([\\h_]*\\h)?)?\t\t\t\t\t\t# Optional Number\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(?<=\\h)\\.\t\t\t\t\t\t\t# A number must exist on\n\t\t\t\t\t\t | \\.(?=\\h)\t\t\t\t\t\t\t# one side of the decimal\n\t\t\t\t\t\t | (?<=\\h)\t\t\t\t\t\t\t\t# Decimal not required\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t(\\h([\\h_]*\\h)?)?\t\t\t\t\t\t# Optional Number\n\t\t\t\t\t\t\t[pP]\t\t\t\t\t\t\t\t\t# Exponent Indicator\n\t\t\t\t\t\t\t[+-]?(0|[1-9]([0-9_]*[0-9])?)\t\t\t# Signed Integer\n\t\t\t\t\t\t\t[fFdD]?\t\t\t\t\t\t\t\t\t# Float Type Suffix\n\t\t\t\t\t\t)\n\t\t\t\t\t\t(?!\\w)\t\t\t\t\t\t\t\t\t\t# Ensure word boundry\n\t\t\t\t\t", + "name": "constant.numeric.hex-float.java" + }, + { + "match": "(?x)\n\t\t\t\t\t\t(?\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(0|[1-9]([0-9_]*[0-9])?)\t\t\t\t# Leading digits\n\t\t\t\t\t\t\t\t(?=[eEfFdD.])\t\t\t\t\t\t\t# Allow for numbers without .\n\t\t\t\t\t\t\t)?\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(?<=[0-9])(?=[eEfFdD])\t\t\t\t\t# Allow for numbers without .\n\t\t\t\t\t\t\t | \\.\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t[0-9]([0-9_]*[0-9])?\t\t\t\t\t# Numbers after .\n\t\t\t\t\t\t\t)?\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t[eE][+-]?(0|[1-9]([0-9_]*[0-9])?)\t\t# Exponent\n\t\t\t\t\t\t\t)?\n\t\t\t\t\t\t\t[fFdD]?\t\t\t\t\t\t\t\t\t\t# Float Type Suffix\n\t\t\t\t\t\t)\n\t\t\t\t\t\t(?!\\w)\t\t\t\t\t\t\t\t\t\t\t# Ensure word boundry\n\t\t\t\t\t", + "name": "constant.numeric.float.java" + }, + { + "captures": { + "1": { + "name": "keyword.operator.dereference.java" + } + }, + "match": "(\\.)?\\b([A-Z][A-Z0-9_]+)(?!<|\\.class|\\s*\\w+\\s*=)\\b", + "name": "constant.other.java" + } + ] + }, + "enums": { + "begin": "^(?=\\s*[A-Z0-9_]+\\s*({|\\(|,))", + "end": "(?=;|})", + "patterns": [ + { + "begin": "\\w+", + "beginCaptures": { + "0": { + "name": "constant.other.enum.java" + } + }, + "end": "(?=,|;|})", + "name": "meta.enum.java", + "patterns": [ + { + "include": "#parens" + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.enum.begin.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.enum.end.java" + } + }, + "patterns": [ + { + "include": "#class-body" + } + ] + } + ] + }, + { + "include": "#comments" + }, + { + "include": "#annotations" + } + ] + }, + "keywords": { + "patterns": [ + { + "match": "\\b(try|catch|finally|throw)\\b", + "name": "keyword.control.catch-exception.java" + }, + { + "match": "\\?|:", + "name": "keyword.control.ternary.java" + }, + { + "match": "\\b(return|break|case|continue|default|do|while|for|switch|if|else)\\b", + "name": "keyword.control.java" + }, + { + "match": "\\b(instanceof)\\b", + "name": "keyword.operator.java" + }, + { + "match": "(<<|>>>?|~|\\^)", + "name": "keyword.operator.bitwise.java" + }, + { + "match": "((&|\\^|\\||<<|>>>?)=)", + "name": "keyword.operator.assignment.bitwise.java" + }, + { + "match": "(===?|!=|<=|>=|<>|<|>)", + "name": "keyword.operator.comparison.java" + }, + { + "match": "([+*/%-]=)", + "name": "keyword.operator.assignment.arithmetic.java" + }, + { + "match": "(=)", + "name": "keyword.operator.assignment.java" + }, + { + "match": "(\\-\\-|\\+\\+)", + "name": "keyword.operator.increment-decrement.java" + }, + { + "match": "(\\-|\\+|\\*|\\/|%)", + "name": "keyword.operator.arithmetic.java" + }, + { + "match": "(!|&&|\\|\\|)", + "name": "keyword.operator.logical.java" + }, + { + "match": "(\\||&)", + "name": "keyword.operator.bitwise.java" + }, + { + "match": "(?<=\\S)\\.(?=\\S)", + "name": "keyword.operator.dereference.java" + }, + { + "match": ";", + "name": "punctuation.terminator.java" + } + ] + }, + "method-call": { + "begin": "([\\w$]+)(\\()", + "beginCaptures": { + "1": { + "name": "meta.method.java" + }, + "2": { + "name": "punctuation.definition.method-parameters.begin.java" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.method-parameters.end.java" + } + }, + "name": "meta.method-call.java", + "patterns": [ + { + "match": ",", + "name": "punctuation.definition.seperator.parameter.java" + }, + { + "include": "#code" + } + ] + }, + "methods": { + "begin": "(?!new)(?=[\\w<].*\\s+)(?=([^=/]|/(?!/))+\\()", + "end": "(})|(?=;)", + "endCaptures": { + "1": { + "name": "punctuation.section.method.end.java" + } + }, + "name": "meta.method.java", + "patterns": [ + { + "include": "#storage-modifiers" + }, + { + "begin": "(\\w+)\\s*\\(", + "beginCaptures": { + "1": { + "name": "entity.name.function.java" + } + }, + "end": "\\)", + "name": "meta.method.identifier.java", + "patterns": [ + { + "include": "#parameters" + }, + { + "include": "#comments" + } + ] + }, + { + "begin": "<", + "end": ">", + "name": "storage.type.token.java", + "patterns": [ + { + "include": "#object-types" + }, + { + "begin": "<", + "comment": "This is just to support <>'s with no actual type prefix", + "end": ">|[^\\w\\s,\\[\\]<]", + "name": "storage.type.generic.java" + } + ] + }, + { + "begin": "(?=\\w.*\\s+\\w+\\s*\\()", + "end": "(?=\\w+\\s*\\()", + "name": "meta.method.return-type.java", + "patterns": [ + { + "include": "#all-types" + }, + { + "include": "#comments" + } + ] + }, + { + "include": "#throws" + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.method.begin.java" + } + }, + "end": "(?=})", + "name": "meta.method.body.java", + "patterns": [ + { + "include": "#code" + } + ] + }, + { + "include": "#comments" + } + ] + }, + "object-types": { + "patterns": [ + { + "begin": "\\b((?:[a-z]\\w*\\.)*[A-Z]+\\w*)<", + "end": ">|[^\\w\\s,\\?<\\[\\]]", + "name": "storage.type.generic.java", + "patterns": [ + { + "include": "#object-types" + }, + { + "begin": "<", + "comment": "This is just to support <>'s with no actual type prefix", + "end": ">|[^\\w\\s,\\[\\]<]", + "name": "storage.type.generic.java" + } + ] + }, + { + "begin": "\\b((?:[a-z]\\w*\\.)*[A-Z]+\\w*)(?=\\[)", + "end": "(?=[^\\]\\s])", + "name": "storage.type.object.array.java", + "patterns": [ + { + "begin": "\\[", + "end": "\\]", + "patterns": [ + { + "include": "#code" + } + ] + } + ] + }, + { + "captures": { + "1": { + "name": "keyword.operator.dereference.java" + } + }, + "match": "\\b(?:[a-z]\\w*(\\.))*[A-Z]+\\w*\\b", + "name": "storage.type.java" + } + ] + }, + "object-types-inherited": { + "patterns": [ + { + "begin": "\\b((?:[a-z]\\w*\\.)*[A-Z]+\\w*)<", + "end": ">|[^\\w\\s,<]", + "name": "entity.other.inherited-class.java", + "patterns": [ + { + "include": "#object-types" + }, + { + "begin": "<", + "comment": "This is just to support <>'s with no actual type prefix", + "end": ">|[^\\w\\s,<]", + "name": "storage.type.generic.java" + } + ] + }, + { + "captures": { + "1": { + "name": "keyword.operator.dereference.java" + } + }, + "match": "\\b(?:[a-z]\\w*(\\.))*[A-Z]+\\w*", + "name": "entity.other.inherited-class.java" + } + ] + }, + "parameters": { + "patterns": [ + { + "match": "final", + "name": "storage.modifier.java" + }, + { + "include": "#annotations" + }, + { + "include": "#primitive-arrays" + }, + { + "include": "#primitive-types" + }, + { + "include": "#object-types" + }, + { + "match": "\\w+", + "name": "variable.parameter.java" + } + ] + }, + "parens": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#code" + } + ] + }, + "primitive-arrays": { + "patterns": [ + { + "match": "\\b(?:void|boolean|byte|char|short|int|float|long|double)(\\[\\])*\\b", + "name": "storage.type.primitive.array.java" + } + ] + }, + "primitive-types": { + "patterns": [ + { + "match": "\\b(?:void|boolean|byte|char|short|int|float|long|double)\\b", + "name": "storage.type.primitive.java" + } + ] + }, + "storage-modifiers": { + "captures": { + "1": { + "name": "storage.modifier.java" + } + }, + "match": "\\b(public|private|protected|static|final|native|synchronized|volatile|abstract|threadsafe|transient)\\b" + }, + "strings": { + "patterns": [ + { + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.java" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.java" + } + }, + "name": "string.quoted.double.java", + "patterns": [ + { + "match": "\\\\.", + "name": "constant.character.escape.java" + } + ] + }, + { + "begin": "'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.java" + } + }, + "end": "'", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.java" + } + }, + "name": "string.quoted.single.java", + "patterns": [ + { + "match": "\\\\.", + "name": "constant.character.escape.java" + } + ] + } + ] + }, + "throws": { + "begin": "throws", + "beginCaptures": { + "0": { + "name": "storage.modifier.java" + } + }, + "end": "(?={|;)", + "name": "meta.throwables.java", + "patterns": [ + { + "include": "#object-types" + } + ] + }, + "values": { + "patterns": [ + { + "include": "#strings" + }, + { + "include": "#object-types" + }, + { + "include": "#constants-and-special-vars" + } + ] + }, + "variables": { + "applyEndPatternLast": 1, + "patterns": [ + { + "begin": "(?x:(?=\n (?:\n (?:private|protected|public|native|synchronized|volatile|abstract|threadsafe|transient|static|final) # visibility/modifier\n |\n (?:def)\n |\n (?:void|boolean|byte|char|short|int|float|long|double)\n |\n (?:(?:[a-z]\\w*\\.)*[A-Z]+\\w*) # object type\n )\n \\s+\n (?!private|protected|public|native|synchronized|volatile|abstract|threadsafe|transient|static|final|def|void|boolean|byte|char|short|int|float|long|double)\n [\\w\\d_<>\\[\\],\\?][\\w\\d_<>\\[\\],\\? \\t]*\n (?:=|$)\n \n\t\t\t\t\t))", + "end": "(?=;)", + "name": "meta.definition.variable.java", + "patterns": [ + { + "match": "\\s" + }, + { + "captures": { + "1": { + "name": "constant.other.variable.java" + } + }, + "match": "([A-Z_0-9]+)\\s+(?=\\=)" + }, + { + "captures": { + "1": { + "name": "meta.definition.variable.name.java" + } + }, + "match": "(\\w[^\\s,]*)\\s+(?=\\=)" + }, + { + "begin": "=", + "beginCaptures": { + "0": { + "name": "keyword.operator.assignment.java" + } + }, + "end": "(?=;)", + "patterns": [ + { + "include": "#code" + } + ] + }, + { + "captures": { + "1": { + "name": "meta.definition.variable.name.java" + } + }, + "match": "(\\w[^\\s=]*)(?=\\s*;)" + }, + { + "include": "#code" + } + ] + } + ] + } + }, + "scopeName": "source.java", + "uuid": "2B449DF6-6B1D-11D9-94EC-000D93589AF6", + "version": "https://github.com/textmate/java.tmbundle/commit/faffa518d0b22b68b4e5e6b4c939722522b97d40" +} \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.JavaFile.txt b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.JavaFile.txt new file mode 100644 index 000000000..53c05b399 --- /dev/null +++ b/org.eclipse.tm4e.core/src/test/resources/org/eclipse/tm4e/core/benchmark/GrammarBenchmark.JavaFile.txt @@ -0,0 +1,901 @@ +/** + * Copyright (c) 2015-2022 Angelo ZERR. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Angelo Zerr - initial API and implementation + * Pierre-Yves B. - Issue #220 Switch to theme only works once for open editor + * IBM Corporation Gerald Mitchell - bug fix + */ +package org.eclipse.tm4e.ui.text; + +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.CursorLinePainter; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IPainter; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextInputListener; +import org.eclipse.jface.text.ITextListener; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.ITextViewerExtension5; +import org.eclipse.jface.text.PaintManager; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.TextEvent; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.jface.text.presentation.IPresentationDamager; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.IPresentationRepairer; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Control; +import org.eclipse.tm4e.core.TMException; +import org.eclipse.tm4e.core.grammar.IGrammar; +import org.eclipse.tm4e.core.model.IModelTokensChangedListener; +import org.eclipse.tm4e.core.model.ITMModel; +import org.eclipse.tm4e.core.model.ModelTokensChangedEvent; +import org.eclipse.tm4e.core.model.Range; +import org.eclipse.tm4e.core.model.TMToken; +import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; +import org.eclipse.tm4e.ui.TMUIPlugin; +import org.eclipse.tm4e.ui.internal.model.TMDocumentModel; +import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; +import org.eclipse.tm4e.ui.internal.text.TMPresentationReconcilerTestGenerator; +import org.eclipse.tm4e.ui.internal.themes.ThemeManager; +import org.eclipse.tm4e.ui.internal.utils.ClassHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper; +import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; +import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils; +import org.eclipse.tm4e.ui.model.ITMModelManager; +import org.eclipse.tm4e.ui.themes.ITheme; +import org.eclipse.tm4e.ui.themes.IThemeManager; +import org.eclipse.tm4e.ui.themes.ITokenProvider; +import org.eclipse.ui.IEditorPart; + +/** + * TextMate presentation reconciler which must be initialized with: + * + *
      + *
    • a TextMate grammar {@link IGrammar} used to initialize the TextMate model {@link TMDocumentModel}.
    • + *
    • a token provider {@link ITokenProvider} to retrieve the {@link IToken} from a TextMate token type .
    • + *
    + */ +public class TMPresentationReconciler implements IPresentationReconciler { + + /** + * The default text attribute if non is returned as data by the current token + */ + private final Token defaultToken; + + /** The target viewer. */ + @Nullable + private ITextViewer viewer; + + /** The internal listener. */ + private final InternalListener internalListener; + + @Nullable + private IGrammar grammar; + private boolean forcedGrammar; + + @Nullable + private ITokenProvider tokenProvider; + + private final TextAttribute fDefaultTextAttribute; + + @Nullable + private IPreferenceChangeListener themeChangeListener; + + private final List listeners = new ArrayList<>(); + + private boolean initializeViewerColors; + + private boolean updateTextDecorations; + + /** + * true if the presentation reconciler is enabled (grammar and theme are available) and false otherwise. + */ + private boolean enabled; + + /** + * true if a {@link TMException} should be thrown if grammar or theme cannot be found and false otherwise. + */ + private boolean throwError; + + public TMPresentationReconciler() { + this.defaultToken = new Token(null); + this.internalListener = new InternalListener(); + this.fDefaultTextAttribute = new TextAttribute(null); + if (TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/GenerateTest")) { + addTMPresentationReconcilerListener(new TMPresentationReconcilerTestGenerator()); + } + setThrowError(TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/ThrowError")); + } + + /** + * Listener to recolorize editors when E4 Theme from General / Appearance + * preferences changed or TextMate theme changed.. + */ + private final class ThemeChangeListener implements IPreferenceChangeListener { + + @Override + public void preferenceChange(@Nullable final PreferenceChangeEvent event) { + if(event == null) + return; + final IThemeManager themeManager = TMUIPlugin.getThemeManager(); + switch (event.getKey()) { + case PreferenceConstants.E4_THEME_ID: + preferenceThemeChange((String) event.getNewValue(), themeManager); + break; + case PreferenceConstants.THEME_ASSOCIATIONS: + preferenceThemeChange(PreferenceUtils.getE4PreferenceCSSThemeId(), themeManager); + break; + } + } + + void preferenceThemeChange(@Nullable final String eclipseThemeId, final IThemeManager themeManager) { + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) { + return; + } + + final IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + + final var grammar = TMPresentationReconciler.this.grammar; + if (grammar == null) { + return; + } + // Select the well TextMate theme from the given E4 theme id. + final boolean dark = themeManager.isDarkEclipseTheme(eclipseThemeId); + final ITokenProvider newTheme = themeManager.getThemeForScope(grammar.getScopeName(), dark); + setTheme(newTheme); + } + } + + /** + * Internal listener class. + */ + private final class InternalListener implements ITextInputListener, IModelTokensChangedListener, ITextListener { + + void fireInstall(final ITextViewer viewer, final IDocument document) { + synchronized (listeners) { + for (final ITMPresentationReconcilerListener listener : listeners) { + listener.install(viewer, document); + } + } + } + + void fireUninstall() { + synchronized (listeners) { + for (final ITMPresentationReconcilerListener listener : listeners) { + listener.uninstall(); + } + } + } + + @Override + public void inputDocumentAboutToBeChanged(@Nullable final IDocument oldDocument, + @Nullable final IDocument newDocument) { + if (oldDocument == null) + return; + + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer != null) { + viewer.removeTextListener(this); + } + getTMModelManager().disconnect(oldDocument); + fireUninstall(); + } + + @Override + public void inputDocumentChanged(@Nullable final IDocument oldDocument, @Nullable final IDocument newDocument) { + if (newDocument == null) { + return; + } + + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) + return; + + fireInstall(viewer, newDocument); + try { + viewer.addTextListener(this); + // Update the grammar + final IGrammar localGrammar = findGrammar(newDocument); + + if (localGrammar != null) { + TMPresentationReconciler.this.grammar = localGrammar; + } else if (isThrowError()) { + throw new TMException("Cannot find TextMate grammar for the given document"); + } + + // Update the theme + if (localGrammar != null) { + final String scopeName = localGrammar.getScopeName(); + if (tokenProvider == null) { + tokenProvider = TMUIPlugin.getThemeManager().getThemeForScope(scopeName, + viewer.getTextWidget().getBackground().getRGB()); + } + if (tokenProvider != null) { + applyThemeEditor(); + } else if (isThrowError()) { + throw new TMException("Cannot find Theme for the given grammar '" + scopeName + "'"); + } + } + + if (localGrammar != null) { + final var enable = TMPresentationReconciler.this.enabled = tokenProvider != null; + if (enable) { + // Connect a TextModel to the new document. + final ITMModel model = getTMModelManager().connect(newDocument); + model.setGrammar(localGrammar); + + // Add model listener + model.addModelTokensChangedListener(this); + } + } else { + TMPresentationReconciler.this.enabled = false; + } + } catch (final CoreException e) { + Platform.getLog(Platform.getBundle(TMEclipseRegistryPlugin.PLUGIN_ID)).log( + new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, "Error while initializing TextMate model.", e)); + } + } + + /** + * Finds a grammar for the given document. + * + * @throws CoreException + */ + @Nullable + IGrammar findGrammar(final IDocument newDocument) throws CoreException { + final IGrammar localGrammar = forcedGrammar ? TMPresentationReconciler.this.grammar : null; + if (localGrammar != null) { + return localGrammar; + } + final ContentTypeInfo info = ContentTypeHelper.findContentTypes(newDocument); + if (info == null) { + return null; + } + return findGrammar(info); + } + + @Override + public void textChanged(final @Nullable TextEvent e) { + if (e == null || !e.getViewerRedrawState()) { + return; + } + + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) + return; + + // changed text: propagate previous style, which will be overridden later asynchronously by TM + if (e.getDocumentEvent() != null) { + final int diff = e.getText().length() - e.getLength(); + if (diff == 0 || e.getOffset() <= 0) { + return; + } + final StyleRange range = viewer.getTextWidget().getStyleRangeAtOffset(e.getOffset() - 1); + if (range == null) { + return; + } + range.length = Math.max(0, range.length + diff); + viewer.getTextWidget().setStyleRange(range); + return; + } + + // TextViewer#invalidateTextPresentation is called (because of validation, folding, etc) + // case 2), do the colorization. + final IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + final IRegion region = computeRegionToRedraw(e, document); + if (enabled) { + // case where there is grammar & theme -> update text presentation with the grammar tokens + final ITMModel model = getTMModelManager().connect(document); + + // It's possible that there are two or more SourceViewers opened for the same document, + // so when one of them is closed the existing TMModel is also "closed" and its TokenizerThread + // is interrupted and terminated. + // In this case, in order to let the others Source Viewers to continue working a new + // TMModel object is to be created for the document, so it should be initialized + // with the existing grammar as well as new ModelTokenListener is to be added + final var grammar = TMPresentationReconciler.this.grammar; + if (grammar != null) { + model.setGrammar(grammar); + model.addModelTokensChangedListener(this); + } + + try { + TMPresentationReconciler.this.colorize(region, (TMDocumentModel) model); + } catch (final BadLocationException e1) { + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e1.getMessage(), e1)); + } + } else { + // case where there is no grammar & theme -> update text presentation with the + // default styles (ex: to support highlighting with GenericEditor) + final TextPresentation presentation = new TextPresentation(region, 100); + presentation.setDefaultStyleRange( + new StyleRange(region.getOffset(), region.getLength(), null, null)); + applyTextRegionCollection(presentation); + } + } + + IRegion computeRegionToRedraw(final TextEvent e, final IDocument document) { + IRegion region = null; + if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) { + // redraw state change, damage the whole document + region = new Region(0, document.getLength()); + } else { + region = widgetRegion2ModelRegion(e); + } + if (region == null || region.getLength() == 0) { + return new Region(0, 0); + } + return region; + } + + /** + * Translates the given text event into the corresponding range of the viewer's document. + * + * @param e + * the text event + * @return the widget region corresponding the region of the given event or null if none + * + * @since 2.1 + */ + @Nullable + IRegion widgetRegion2ModelRegion(final TextEvent e) { + final String text = e.getText(); + final int length = text == null ? 0 : text.length(); + final var viewer = castNonNull(TMPresentationReconciler.this.viewer); + if (viewer instanceof ITextViewerExtension5) { + final ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; + return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); + } + final IRegion visible = viewer.getVisibleRegion(); + return new Region(e.getOffset() + visible.getOffset(), length); + } + + @Override + public void modelTokensChanged(final ModelTokensChangedEvent event) { + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer != null) { + final Control control = viewer.getTextWidget(); + if (control != null) { + control.getDisplay().asyncExec(() -> { + colorize(event); + }); + } + } + } + + void colorize(final ModelTokensChangedEvent event) { + final var viewer = TMPresentationReconciler.this.viewer; + if (viewer == null) + return; + + final IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + final ITMModel model = event.model; + if (!(model instanceof TMDocumentModel)) { + return; + } + final TMDocumentModel docModel = (TMDocumentModel) model; + for (final Range range : event.ranges) { + try { + final int length = document.getLineOffset(range.toLineNumber - 1) + + document.getLineLength(range.toLineNumber - 1) + - document.getLineOffset(range.fromLineNumber - 1); + final IRegion region = new Region(document.getLineOffset(range.fromLineNumber - 1), length); + TMPresentationReconciler.this.colorize(region, docModel); + } catch (final BadLocationException ex) { + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + } + } + } + + @Nullable + IGrammar findGrammar(@Nullable final ContentTypeInfo info) { + if (info == null) { + return null; + } + final IContentType[] contentTypes = info.getContentTypes(); + // Discover the well grammar from the contentTypes + IGrammar res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); + if (res == null) { + // Discover the well grammar from the filetype + final String fileName = info.getFileName(); + if (fileName.indexOf('.') > -1) { + final String fileType = new Path(fileName).getFileExtension(); + res = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarForFileType(fileType); + } + } + return res; + } + } + + public void setGrammar(@Nullable final IGrammar grammar) { + var viewer = this.viewer; + final boolean changed = (viewer != null && ((this.grammar == null) || !Objects.equals(grammar, this.grammar))); + this.grammar = grammar; + this.forcedGrammar = true; + if (changed) { + // Grammar has changed, recreate the TextMate model + viewer = castNonNull(viewer); + final IDocument document = viewer.getDocument(); + if (document == null) { + return; + } + internalListener.inputDocumentAboutToBeChanged(viewer.getDocument(), null); + internalListener.inputDocumentChanged(null, document); + } + } + + @Nullable + public IGrammar getGrammar() { + return grammar; + } + + @Nullable + public ITokenProvider getTokenProvider() { + return tokenProvider; + } + + public void setTheme(final ITokenProvider newTheme) { + final ITokenProvider oldTheme = this.tokenProvider; + if (!Objects.equals(oldTheme, newTheme) && grammar != null) { + this.tokenProvider = newTheme; + applyThemeEditor(); + final var viewer = this.viewer; + if (viewer == null) + return; + final IDocument document = viewer.getDocument(); + final ITMModel model = getTMModelManager().connect(document); + if (!(model instanceof TMDocumentModel)) { + return; + } + final TMDocumentModel docModel = (TMDocumentModel) model; + try { + colorize(new Region(0, document.getLength()), docModel); + } catch (final BadLocationException e) { + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } + } + } + + @Override + public void install(@Nullable ITextViewer viewer) { + viewer = this.viewer = castNonNull(viewer); + viewer.addTextInputListener(internalListener); + + final IDocument document = viewer.getDocument(); + if (document != null) { + internalListener.inputDocumentChanged(null, document); + } + final var themeChangeListener = this.themeChangeListener = new ThemeChangeListener(); + ThemeManager.getInstance().addPreferenceChangeListener(themeChangeListener); + } + + @Override + public void uninstall() { + final var viewer = castNonNull(this.viewer); + viewer.removeTextInputListener(internalListener); + // Ensure we uninstall all listeners + internalListener.inputDocumentAboutToBeChanged(viewer.getDocument(), null); + final var themeChangeListener = this.themeChangeListener; + if (themeChangeListener != null) { + ThemeManager.getInstance().removePreferenceChangeListener(themeChangeListener); + } + this.themeChangeListener = null; + } + + @Nullable + @Override + public IPresentationDamager getDamager(@Nullable final String contentType) { + return null; + } + + @Nullable + @Override + public IPresentationRepairer getRepairer(@Nullable final String contentType) { + return null; + } + + private ITMModelManager getTMModelManager() { + return TMUIPlugin.getTMModelManager(); + } + + void colorize(final IRegion damage, final TMDocumentModel model) throws BadLocationException { + final IDocument document = model.getDocument(); + final int fromLineNumber = document.getLineOfOffset(damage.getOffset()); + final int toLineNumber = document.getLineOfOffset(damage.getOffset() + damage.getLength()); + applyThemeEditorIfNeeded(); + // Refresh the UI Presentation + TMUIPlugin.trace("Render from: " + fromLineNumber + " to: " + toLineNumber); + final var presentation = new TextPresentation(damage, 1000); + Exception error = null; + try { + int lastStart = presentation.getExtent().getOffset(); + int length = 0; + boolean firstToken = true; + IToken lastToken = Token.UNDEFINED; + TextAttribute lastAttribute = getTokenTextAttribute(lastToken); + + List tokens = null; + for (int line = fromLineNumber; line <= toLineNumber; line++) { + tokens = model.getLineTokens(line); + if (tokens == null) { + // TextMate tokens was not computed for this line. + // This case comes from when the viewer is invalidated (by + // validation for instance) and textChanged is called. + // see https://github.com/eclipse/tm4e/issues/78 + TMUIPlugin.trace("TextMate tokens not available for line " + line); + break; + } + final int startLineOffset = document.getLineOffset(line); + for (int i = 0; i < tokens.size(); i++) { + final TMToken currentToken = tokens.get(i); + final TMToken nextToken = (i + 1 < tokens.size()) ? tokens.get(i + 1) : null; + int tokenStartIndex = currentToken.startIndex; + + if (isBeforeRegion(currentToken, startLineOffset, damage)) { + // The token is before the damage region + if (nextToken != null) { + if (isBeforeRegion(nextToken, startLineOffset, damage)) { + continue; // ignore it + } + tokenStartIndex = damage.getOffset() - startLineOffset; + } else { + tokenStartIndex = damage.getOffset() - startLineOffset; + final IToken token = toToken(currentToken); + lastAttribute = getTokenTextAttribute(token); + length += getTokenLengh(tokenStartIndex, nextToken, line, document); + firstToken = false; + // ignore it + continue; + } + } else if (isAfterRegion(currentToken, startLineOffset, damage)) { + // The token is after the damage region, stop the colorization process + break; + } + + final IToken token = toToken(currentToken); + final TextAttribute attribute = getTokenTextAttribute(token); + if (lastAttribute.equals(attribute)) { + length += getTokenLengh(tokenStartIndex, nextToken, line, document); + firstToken = false; + } else { + if (!firstToken) { + addRange(presentation, lastStart, length, lastAttribute); + } + firstToken = false; + lastToken = token; + lastAttribute = attribute; + lastStart = tokenStartIndex + startLineOffset; + length = getTokenLengh(tokenStartIndex, nextToken, line, document); + } + } + } + // adjust the length + length = Math.min(length, damage.getOffset() + damage.getLength() - lastStart); + addRange(presentation, lastStart, length, lastAttribute); + applyTextRegionCollection(presentation); + } catch (final Exception e) { + error = e; + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } finally { + fireColorize(presentation, error); + } + } + + /** + * Return true if the given token is before the given region and false + * otherwise. + * + * @param token + * @param startLineOffset + * @param damage + * + * @return + */ + private boolean isBeforeRegion(final TMToken token, final int startLineOffset, final IRegion damage) { + return token.startIndex + startLineOffset < damage.getOffset(); + } + + /** + * Return true if the given token is after the given region and false otherwise. + * + * @param t + * @param startLineOffset + * @param damage + * + * @return + */ + private boolean isAfterRegion(final TMToken t, final int startLineOffset, final IRegion damage) { + return t.startIndex + startLineOffset >= damage.getOffset() + damage.getLength(); + } + + private IToken toToken(final TMToken t) { + final var tokenProvider = this.tokenProvider; + if (tokenProvider != null) { + final IToken token = tokenProvider.getToken(t.type); + if (token != null) { + return token; + } + } + return defaultToken; + } + + private int getTokenLengh(final int tokenStartIndex, @Nullable final TMToken nextToken, final int line, + final IDocument document) + throws BadLocationException { + if (nextToken != null) { + return nextToken.startIndex - tokenStartIndex; + } + return document.getLineLength(line) - tokenStartIndex; + } + + /** + * Returns a text attribute encoded in the given token. If the token's data is + * not null and a text attribute it is assumed that it is the + * encoded text attribute. It returns the default text attribute if there is no + * encoded text attribute found. + * + * @param token + * the token whose text attribute is to be determined + * + * @return the token's text attribute + */ + protected TextAttribute getTokenTextAttribute(final IToken token) { + final Object data = token.getData(); + if (data instanceof TextAttribute) { + return (TextAttribute) data; + } + return fDefaultTextAttribute; + } + + /** + * Adds style information to the given text presentation. + * + * @param presentation + * the text presentation to be extended + * @param offset + * the offset of the range to be styled + * @param length + * the length of the range to be styled + * @param attr + * the attribute describing the style of the range to be styled + * @param lastLineStyleRanges + */ + protected void addRange(final TextPresentation presentation, final int offset, final int length, + @Nullable final TextAttribute attr) { + if (attr != null) { + final int style = attr.getStyle(); + final int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); + final StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), + fontStyle); + styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0; + styleRange.underline = (style & TextAttribute.UNDERLINE) != 0; + styleRange.font = attr.getFont(); + presentation.addStyleRange(styleRange); + } + } + + /** + * Applies the given text presentation to the text viewer the presentation + * reconciler is installed on. + * + * @param presentation + * the text presentation to be applied to the text viewer + */ + private void applyTextRegionCollection(final TextPresentation presentation) { + final var viewer = this.viewer; + if (viewer != null) { + viewer.changeTextPresentation(presentation, false); + } + } + + /** + * Add a TextMate presentation reconciler listener. + * + * @param listener + * the TextMate presentation reconciler listener to add. + */ + public void addTMPresentationReconcilerListener(final ITMPresentationReconcilerListener listener) { + synchronized (listeners) { + if (!listeners.contains(listener)) { + listeners.add(listener); + } + } + } + + /** + * Remove a TextMate presentation reconciler listener. + * + * @param listener + * the TextMate presentation reconciler listener to remove. + */ + public void removeTMPresentationReconcilerListener(final ITMPresentationReconcilerListener listener) { + synchronized (listeners) { + listeners.remove(listener); + } + } + + /** + * Fire colorize. + */ + private void fireColorize(final TextPresentation presentation, @Nullable final Throwable error) { + synchronized (listeners) { + for (final ITMPresentationReconcilerListener listener : listeners) { + listener.colorize(presentation, error); + } + } + } + + @Nullable + public static TMPresentationReconciler getTMPresentationReconciler(@Nullable final IEditorPart editorPart) { + if (editorPart == null) { + return null; + } + @Nullable + final ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); + if (target instanceof ITextViewer) { + final ITextViewer textViewer = ((ITextViewer) target); + return TMPresentationReconciler.getTMPresentationReconciler(textViewer); + } + return null; + } + + /** + * Returns the {@link TMPresentationReconciler} of the given text viewer and null otherwise. + * + * @return the {@link TMPresentationReconciler} of the given text viewer and null otherwise. + */ + @Nullable + public static TMPresentationReconciler getTMPresentationReconciler(final ITextViewer textViewer) { + try { + final Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler"); + if (field != null) { + field.trySetAccessible(); + final Object presentationReconciler = field.get(textViewer); + // field is IPresentationRecounciler, looking for TMPresentationReconciler implementation + return presentationReconciler instanceof TMPresentationReconciler + ? (TMPresentationReconciler) presentationReconciler + : null; + } + } catch (SecurityException | NoSuchFieldException e) { + // if SourceViewer class no longer has fPresentationReconciler or changes access level + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } catch (IllegalArgumentException | IllegalAccessException | NullPointerException + | ExceptionInInitializerError iae) { + // This should not be logged as an error. This is an expected possible outcome of field.get(textViewer). + // The method assumes ITextViewer is actually ISourceViewer, and specifically the SourceViewer + // implementation + // that was available at the current build. This code also works with any implementation that follows the + // internal structure if also an ITextViewer. + // If these assumptions are false, the method should return null. Logging causes repeat noise. + } + return null; + } + + /** + * Initialize foreground, background color, current line highlight from the current theme. + */ + private void applyThemeEditor() { + this.initializeViewerColors = false; + this.updateTextDecorations = false; + applyThemeEditorIfNeeded(); + } + + /** + * Initialize foreground, background color, current line highlight from the current theme if needed. + */ + private void applyThemeEditorIfNeeded() { + final var viewer = castNonNull(this.viewer); + final var tokenProvider = castNonNull(this.tokenProvider); + + if (!initializeViewerColors) { + final StyledText styledText = viewer.getTextWidget(); + ((ITheme) tokenProvider).initializeViewerColors(styledText); + initializeViewerColors = true; + } + if (updateTextDecorations) { + return; + } + try { + // Ugly code to update "current line highlight" : + // - get the PaintManager from the ITextViewer with reflection. + // - get the list of IPainter of PaintManager with reflection + // - loop for IPainter to retrieve CursorLinePainter which manages "current line + // highlight". + final PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class); + if (paintManager == null) { + return; + } + final List painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class); + if (painters == null) { + return; + } + for (final IPainter painter : painters) { + if (painter instanceof CursorLinePainter) { + // Update current line highlight + final Color background = tokenProvider.getEditorCurrentLineHighlight(); + if (background != null) { + ((CursorLinePainter) painter).setHighlightColor(background); + } + updateTextDecorations = true; + } + } + } catch (final Exception e) { + TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } + } + + /** + * Set true if a {@link TMException} should be thrown if grammar or theme cannot + * be found and false otherwise. + * + * @param throwError + */ + public void setThrowError(final boolean throwError) { + this.throwError = throwError; + } + + /** + * Return true if a {@link TMException} should be thrown if grammar or theme + * cannot be found and false otherwise. + * + * @return true if a {@link TMException} should be thrown if grammar or theme + * cannot be found and false otherwise. + */ + public boolean isThrowError() { + return throwError; + } + + /** + * Returns true if the presentation reconciler is enabled (grammar and theme are + * available) and false otherwise. + * + * @return true if the presentation reconciler is enabled (grammar and theme are + * available) and false otherwise. + */ + + public boolean isEnabled() { + return enabled; + } +} From 13d020d22251349810b9c27acfa0c17dc9546fd0 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 17:02:55 +0200 Subject: [PATCH 191/202] Use ArrayDeque --- .../core/internal/grammar/LineTokenizer.java | 18 +++++++++--------- .../tm4e/core/internal/grammar/LineTokens.java | 16 ++++++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index 976581741..41b8353f7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -17,11 +17,11 @@ package org.eclipse.tm4e.core.internal.grammar; import static java.lang.System.Logger.Level.*; -import static org.eclipse.tm4e.core.internal.utils.MoreCollections.*; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; import java.lang.System.Logger; import java.lang.System.Logger.Level; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.List; @@ -425,7 +425,7 @@ private void handleCaptures(final Grammar grammar, final OnigString lineText, fi } final int len = Math.min(captures.size(), captureIndices.length); - final List localStack = new ArrayList<>(); + final var localStack = new ArrayDeque(); final int maxEnd = captureIndices[0].end; OnigCaptureIndex captureIndex; @@ -449,14 +449,14 @@ private void handleCaptures(final Grammar grammar, final OnigString lineText, fi } // pop captures while needed - while (!localStack.isEmpty() && getLastElement(localStack).endPos <= captureIndex.start) { + while (!localStack.isEmpty() && localStack.getLast().endPos <= captureIndex.start) { // pop! - lineTokens.produceFromScopes(getLastElement(localStack).scopes, getLastElement(localStack).endPos); - removeLastElement(localStack); + final var lastElem = localStack.removeLast(); + lineTokens.produceFromScopes(lastElem.scopes, lastElem.endPos); } if (!localStack.isEmpty()) { - lineTokens.produceFromScopes(getLastElement(localStack).scopes, captureIndex.start); + lineTokens.produceFromScopes(localStack.getLast().scopes, captureIndex.start); } else { lineTokens.produce(stack, captureIndex.start); } @@ -484,7 +484,7 @@ private void handleCaptures(final Grammar grammar, final OnigString lineText, fi // push final ScopeListElement base = localStack.isEmpty() ? stack.contentNameScopesList - : getLastElement(localStack).scopes; + : localStack.getLast().scopes; final ScopeListElement captureRuleScopesList = base.push(grammar, captureRuleScopeName); localStack.add(new LocalStackElement(captureRuleScopesList, captureIndex.end)); } @@ -492,8 +492,8 @@ private void handleCaptures(final Grammar grammar, final OnigString lineText, fi while (!localStack.isEmpty()) { // pop! - lineTokens.produceFromScopes(getLastElement(localStack).scopes, getLastElement(localStack).endPos); - removeLastElement(localStack); + final var lastElem = localStack.removeLast(); + lineTokens.produceFromScopes(lastElem.scopes, lastElem.endPos); } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java index 0243a160a..e40704cf3 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java @@ -21,8 +21,10 @@ import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*; import java.lang.System.Logger; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; +import java.util.Deque; import java.util.List; import org.eclipse.jdt.annotation.Nullable; @@ -33,6 +35,8 @@ final class LineTokens { private static final Logger LOGGER = System.getLogger(LineTokens.class.getName()); + private static final Deque EMPTY_DEQUE = new ArrayDeque<>(0); + /** * defined only if `LOGGER.isLoggable(TRACE)`. */ @@ -42,7 +46,7 @@ final class LineTokens { /** * used only if `emitBinaryTokens` is false. */ - private final List tokens; + private final Deque tokens; private final boolean emitBinaryTokens; @@ -63,10 +67,10 @@ final class LineTokens { this.emitBinaryTokens = emitBinaryTokens; this.lineText = LOGGER.isLoggable(TRACE) ? lineText : null; // store line only if it's logged if (this.emitBinaryTokens) { - this.tokens = Collections.emptyList(); + this.tokens = EMPTY_DEQUE; this.binaryTokens = new ArrayList<>(); } else { - this.tokens = new ArrayList<>(); + this.tokens = new ArrayDeque<>(); this.binaryTokens = Collections.emptyList(); } this.tokenTypeOverrides = tokenTypeOverrides; @@ -169,15 +173,15 @@ void produceFromScopes(final ScopeListElement scopesList, final int endIndex) { } IToken[] getResult(final StackElement stack, final int lineLength) { - if (!this.tokens.isEmpty() && getLastElement(this.tokens).getStartIndex() == lineLength - 1) { + if (!this.tokens.isEmpty() && this.tokens.getLast().getStartIndex() == lineLength - 1) { // pop produced token for newline - removeLastElement(this.tokens); + this.tokens.removeLast(); } if (this.tokens.isEmpty()) { this.lastTokenEndIndex = -1; this.produce(stack, lineLength); - getLastElement(this.tokens).setStartIndex(0); + this.tokens.getLast().setStartIndex(0); } return this.tokens.toArray(IToken[]::new); From 812df4cb0974f57ffdc941a784ac98f5d57371f5 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 18:55:50 +0200 Subject: [PATCH 192/202] Reorder class modifier --- .../tm4e/core/internal/grammar/ScopeDependencyProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java index 11d8c5abf..7b6145534 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeDependencyProcessor.java @@ -39,7 +39,7 @@ */ class ScopeDependencyProcessor { - private static abstract class ScopeDependency { + private abstract static class ScopeDependency { final String scopeName; ScopeDependency(final String scopeName) { From 678bf8cadce48732d9f493a493fb79048f2d82a3 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 18:56:02 +0200 Subject: [PATCH 193/202] Fix string comparison --- .../eclipse/tm4e/core/internal/grammar/ScopeListElement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java index 98db0df9c..b1ed0b2b1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeListElement.java @@ -59,7 +59,7 @@ private static boolean structuralEquals(@Nullable ScopeListElement a, @Nullable return false; } - if (a.scope != b.scope || a.metadata != b.metadata) { + if (!Objects.equals(a.scope, b.scope) || a.metadata != b.metadata) { return false; } From 44b637d08c21f91051c2197983d7bbeebb56fd97 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 18:56:55 +0200 Subject: [PATCH 194/202] Add private constructor to utility classes --- .../java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java | 3 +++ .../java/org/eclipse/tm4e/core/internal/theme/FontStyle.java | 4 +++- .../tm4e/core/internal/theme/css/sac/SACConstants.java | 4 +++- .../org/eclipse/tm4e/core/internal/utils/CompareUtils.java | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java index 077e2e3ff..6c88aa4e1 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule/RuleFactory.java @@ -259,4 +259,7 @@ private static CompilePatternsResult compilePatterns(@Nullable final Collection< return new CompilePatternsResult(r.stream().mapToInt(Integer::intValue).toArray(), patterns.size() != r.size()); } + + private RuleFactory() { + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/FontStyle.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/FontStyle.java index 1bfa7615f..7bdcf04a4 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/FontStyle.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/FontStyle.java @@ -18,7 +18,7 @@ * "https://github.com/microsoft/vscode-textmate/blob/9157c7f869219dbaf9a5a5607f099c00fe694a29/src/theme.ts#L153"> * github.com/microsoft/vscode-textmate/blob/master/src/theme.ts
    */ -public class FontStyle { +public final class FontStyle { public static final int NotSet = -1; @@ -29,4 +29,6 @@ public class FontStyle { public static final int Underline = 4; public static final int Strikethrough = 8; + private FontStyle() { + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACConstants.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACConstants.java index 19ba7472b..3c901cb4c 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACConstants.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/css/sac/SACConstants.java @@ -17,7 +17,7 @@ * @author Angelo ZERR * */ -public class SACConstants { +public final class SACConstants { /** * org.w3c.flute.parser.Parser SAC Parser. @@ -39,4 +39,6 @@ public class SACConstants { */ public static final String SACPARSER_BATIK = "org.apache.batik.css.parser.Parser"; + private SACConstants() { + } } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java index 35c10479d..9227e3ca0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/utils/CompareUtils.java @@ -48,4 +48,7 @@ public static int strArrCmp(@Nullable final List a, @Nullable final List } return len1 - len2; } + + private CompareUtils() { + } } From 72300e223e8f3f8046d5a0784810296441fbab77 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 18:57:26 +0200 Subject: [PATCH 195/202] Use Map.entrySet() instead of Map.keySet() with Map.get() --- .../org/eclipse/tm4e/core/internal/grammar/Grammar.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java index bb351226a..6d6fc1e7e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java @@ -91,12 +91,14 @@ public Grammar( this.grammar = initGrammar(grammar, null); if (tokenTypes != null) { - for (final var selector : tokenTypes.keySet()) { + for (final var entry : tokenTypes.entrySet()) { + final var selector = entry.getKey(); + final var type = entry.getValue().intValue(); for (final var matcher : Matcher.createMatchers(selector)) { tokenTypeMatchers.add(new TokenTypeMatcher() { @Override public int getType() { - return tokenTypes.get(selector); + return type; } @Override From ba18f15fa3b7c733d90dca8de829e22d0c3d77b8 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 19:00:03 +0200 Subject: [PATCH 196/202] Remove deprecated IModelLines.getSize() --- .../java/org/eclipse/tm4e/core/model/AbstractLineList.java | 6 ------ .../main/java/org/eclipse/tm4e/core/model/IModelLines.java | 6 ------ 2 files changed, 12 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java index b79b4ae70..fcc9311a6 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java @@ -81,10 +81,4 @@ protected void invalidateLine(final int lineIndex) { model.invalidateLine(lineIndex); } } - - @Override - @Deprecated - public int getSize() { - return getNumberOfLines(); - } } \ No newline at end of file diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java index a7de6be30..6086be524 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/IModelLines.java @@ -39,12 +39,6 @@ public interface IModelLines { */ void updateLine(int lineIndex); - /** - * @deprecated use {@link #getNumberOfLines()} - */ - @Deprecated - int getSize(); - /** * @param lineIndex (0-based) * @throws IndexOutOfBoundsException From 2459ece7bcb514e893112839891172497f61f2d9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 19:14:07 +0200 Subject: [PATCH 197/202] Use instanceof before casting --- .../src/main/java/org/eclipse/tm4e/core/model/TMModel.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java index 903629fdf..ebb9c9a39 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java @@ -53,7 +53,9 @@ public class TMModel implements ITMModel { public TMModel(final IModelLines lines) { this.lines = lines; - ((AbstractLineList) lines).setModel(this); + if (lines instanceof AbstractLineList) { + ((AbstractLineList) lines).setModel(this); + } lines.forEach(ModelLine::resetTokenizationState); invalidateLine(0); } @@ -127,8 +129,7 @@ private void revalidateTokensNow(final int startLine, @Nullable final Integer to long currentEstimatedTimeToTokenize = 0; long elapsedTime; final long startTime = System.currentTimeMillis(); - // Tokenize at most 1000 lines. Estimate the tokenization speed per - // character and stop when: + // Tokenize at most 1000 lines. Estimate the tokenization speed per character and stop when: // - MAX_ALLOWED_TIME is reached // - tokenizing the next line would go above MAX_ALLOWED_TIME From 0c6ea58b2e7668e4cba80b2b9e64a81db9c6a8e6 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 19:20:07 +0200 Subject: [PATCH 198/202] Improve benchmark output --- .../java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java index 09bda82d1..021fc3a5c 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/benchmark/BenchmarkRunner.java @@ -85,14 +85,14 @@ private static void runRound(final String label, final int round, final int tota final var heapBytesPerIteration = (startFreeMem - RUNTIME.freeMemory()) / (float) iterations; System.out.println(String.format( - " -> result: %5d ms/round | %,7.2f ops/s | %,5.2f ms/op | %,5.2f MB/op", + " -> result: %,5d ms/round | %,7.2f ops/s | %,5.2f ms/op | %,6.3f MB/op", durationMS, iterationsPerSecond, durationMSPerIteration, heapBytesPerIteration / 1024 / 1024)); } else { System.out.println(String.format( - " -> result: %5d ms/round | %,7.2f ops/s | %,5.2f ms/op", + " -> result: %,5d ms/round | %,7.2f ops/s | %,5.2f ms/op", durationMS, iterationsPerSecond, durationMSPerIteration)); From f20ad04a5c9685ab9da29f1bb375df4b9d3c92f7 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 19:20:15 +0200 Subject: [PATCH 199/202] Specify minimum version for tm4e plugin dependencies --- org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF | 4 ++-- org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF | 6 +++--- org.eclipse.tm4e.registry/META-INF/MANIFEST.MF | 2 +- org.eclipse.tm4e.ui/META-INF/MANIFEST.MF | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF b/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF index 8c40e17c8..71dc936c5 100644 --- a/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF @@ -9,8 +9,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.eclipse.jface.text, org.eclipse.ui.genericeditor, com.google.gson, - org.eclipse.tm4e.core, - org.eclipse.tm4e.ui, + org.eclipse.tm4e.core;bundle-version="0.4.4", + org.eclipse.tm4e.ui;bundle-version="0.5.1", org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.ui, diff --git a/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF b/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF index 386c02068..96c535939 100644 --- a/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF @@ -6,9 +6,9 @@ Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.tm4e.markdown;singleton:=true Bundle-Version: 0.3.6.qualifier Require-Bundle: org.eclipse.core.runtime, - org.eclipse.tm4e.core, - org.eclipse.tm4e.registry, - org.eclipse.tm4e.ui, + org.eclipse.tm4e.core;bundle-version="0.4.4", + org.eclipse.tm4e.registry;bundle-version="0.5.1", + org.eclipse.tm4e.ui;bundle-version="0.5.1", com.google.guava;bundle-version="30.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.eclipse.tm4e.markdown, diff --git a/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF b/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF index 8d718c40a..c72e792e1 100644 --- a/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF @@ -5,7 +5,7 @@ Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.tm4e.registry;singleton:=true Bundle-Version: 0.5.1.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-11 -Require-Bundle: org.eclipse.tm4e.core, +Require-Bundle: org.eclipse.tm4e.core;bundle-version="0.4.4", org.eclipse.core.runtime, com.google.gson, org.eclipse.equinox.preferences diff --git a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF index e1200a303..417066249 100644 --- a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF @@ -5,7 +5,7 @@ Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.tm4e.ui;singleton:=true Bundle-Version: 0.5.1.qualifier -Require-Bundle: org.eclipse.tm4e.core, +Require-Bundle: org.eclipse.tm4e.core;bundle-version="0.4.4", org.eclipse.jface.text, org.eclipse.core.runtime, org.eclipse.ui, From 3248cbc1936117ad0b376553ba1923fc63388a94 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 10 May 2022 21:11:25 +0200 Subject: [PATCH 200/202] Update readme --- README.md | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index f2aef8091..aa76a23b2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://github.com/eclipse/tm4e/actions/workflows/build.yml/badge.svg)](https://github.com/eclipse/tm4e/actions/workflows/build.yml) [![License](https://img.shields.io/github/license/eclipse/tm4e.svg?color=blue)](LICENSE) -TM4E brings Java API to tokenize textual documents according to TextMate grammars with an Eclipse IDE client that can do syntax highlighting according to this tokenization; and Eclipse IDE client for VSCode [Language Configuration](https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages) to support matching bracket, auto close, on enter support. +TM4E brings Java API to tokenize textual documents according to TextMate grammars with an Eclipse IDE client that can do syntax highlighting according to this tokenization; and Eclipse IDE client for VSCode [Language Configuration](https://code.visualstudio.com/api/references/contribution-points#contributes.languages) to support matching bracket, auto close, on enter support. `tm4e` is an [official Eclipse.org project](https://projects.eclipse.org/projects/technology.tm4e) so it conforms to typical Eclipse.org requirements and guarantees. @@ -11,7 +11,7 @@ TM4E brings Java API to tokenize textual documents according to TextMate grammar ### in Eclipse IDE or RCP applications -You can install `tm4e` with the update site [http://download.eclipse.org/tm4e/snapshots/](http://download.eclipse.org/tm4e/snapshots/). TM4E is usually installed together with its consumers, so end-user should usually not need to directly install it. +You can install `tm4e` with the update site [https://download.eclipse.org/tm4e/snapshots/](https://download.eclipse.org/tm4e/snapshots/). TM4E is usually installed together with its consumers, so end-user should usually not need to directly install it. ### as a Java API with Maven @@ -27,35 +27,36 @@ The following class and modules should be used as entry point provides: * [org.eclipse.tm4e.ui](https://github.com/eclipse/tm4e/tree/master/org.eclipse.tm4e.ui) provides the Eclipse **org.eclipse.jface.text.presentation.IPresentationReconciler** [TMPresentationReconciler](https://github.com/eclipse/tm4e/blob/master/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/TMPresentationReconciler.java) which is able to tokenize an editor content by using a given JSON, PList TextMate grammar and do syntax coloration. See [UI](https://github.com/eclipse/tm4e/wiki/UI) section for more information. - * [org.eclipse.tm4e.languageconfiguration](https://github.com/eclipse/tm4e/tree/master/org.eclipse.tm4e.languageconfiguration) provides the VSCode [Language Configuration](https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages) to support matching bracket, auto close, on enter support with a simple **language-configuration.json**. - + * [org.eclipse.tm4e.languageconfiguration](https://github.com/eclipse/tm4e/tree/master/org.eclipse.tm4e.languageconfiguration) provides the VSCode [Language Configuration](https://code.visualstudio.com/api/references/contribution-points#contributes.languages) to support matching bracket, auto close, on enter support with a simple **language-configuration.json**. + Here a sample with TypeScript: -![TypeScript Editor](https://github.com/eclipse/tm4e/wiki/images/TypeScriptEditor.png) +![TypeScript Editor](https://raw.githubusercontent.com/eclipse/wildwebdeveloper/master/documentation-files/typescript38.png) ## 👪 Who is using tm4e? Here are some projects that use tm4e: * Eclipse IDE languages and frameworks integrations - * [Eclipse Corrosion](https://github.com/eclipse/corrosion) Rust development tools in Eclipse IDE. - * [Eclipse aCute](https://github.com/eclipse/aCute) C# edition in Eclipse IDE. - * [Eclipse Wild Web Developer](https://github.com/eclipse/wildwebdeveloper) a simple and productive Web Development Tools in the Eclipse IDE. - * [Eclipse ShellWax](https://github.com/eclipse/shellwax) is a rich Bash script editor in the Eclipse IDE. - * [LiClipseText](http://www.liclipse.com/text/) enables Eclipse to be used as a general-purpose text editor, providing support for several languages out of the box. - * [typescript.java](https://github.com/angelozerr/typescript.java) (Deprecated) TypeScript IDE for Eclipse with JSDT & tsserver. - * [EditorConfig for Eclipse](https://github.com/angelozerr/ec4e) EditorConfig for Eclipse with GenericEditor. - * [Phaser Editor 2D](https://phasereditor2d.com) An IDE for the creation of HTML5 games. - * [Solargraph](https://github.com/PyvesB/eclipse-solargraph) Ruby edition in Eclipse IDE. - * [Dartboard](https://github.com/eclipse/dartboard) Dart language support in the Eclipse IDE. -* [Apache NetBeans](https://github.com/apache/netbeans) is a multi-language IDE written in Java and uses TM4E core parts to support syntax highlighting based on TextMate grammars - + * [Eclipse Corrosion](https://github.com/eclipse/corrosion) - Rust development tools in Eclipse IDE. + * [Eclipse aCute](https://github.com/eclipse/aCute) - C# edition in Eclipse IDE. + * [Eclipse Wild Web Developer](https://github.com/eclipse/wildwebdeveloper) - Simple and productive Web Development Tools in the Eclipse IDE. + * [Eclipse ShellWax](https://github.com/eclipse/shellwax) - A shell script development plugin for the Eclipse IDE, providing a rich edition experience through integration with the [Bash Language Server](https://github.com/bash-lsp/bash-language-server). + * [LiClipseText](https://www.liclipse.com/text/) - An editor which enables Eclipse to be used as a general-purpose text editor, providing support for multiple languages out of the box. + * [typescript.java](https://github.com/angelozerr/typescript.java) *(Deprecated)* - TypeScript IDE for Eclipse with JSDT & tsserver. + * [EditorConfig for Eclipse](https://github.com/angelozerr/ec4e) - EditorConfig for Eclipse with GenericEditor. + * [Phaser Editor 2D](https://phasereditor2d.com) - An IDE for the creation of HTML5 games. + * [Solargraph](https://github.com/PyvesB/eclipse-solargraph) - Ruby development tools for Eclipse. + * [Dartboard](https://github.com/eclipse/dartboard) - Dart language support in the Eclipse IDE. + * [haxe4e](https://github.com/haxe4e/haxe4e) - [Haxe](https://haxe.org/) programming language support for the Eclipse IDE. +* [Apache NetBeans](https://github.com/apache/netbeans) - A multi-language IDE written in Java that uses TM4E core parts to support syntax highlighting based on TextMate grammars. + ## 👷 Get support and contribute -* **License and community**: `tm4e` is a community open-source project licensed under the Eclipse Public License 1.0. -* **Support:** You can ask (and answer!) questions, report bugs, and request features using [GitHub issues](http://github.com/eclipse/tm4e/issues). +* **License and community**: `tm4e` is a community open-source project licensed under the [Eclipse Public License 2.0](LICENSE). +* **Support**: You can ask (and answer!) questions, report bugs, and request features using [GitHub issues](https://github.com/eclipse/tm4e/issues). * **Git**: This `eclipse/tm4e` repository is the reference repository to contribute to `tm4e` -* **Build**: build can be performed with a simple `mvn clean verify`, continuous integration and deployment is performed by CI jobs at https://hudson.eclipse.org/tm4e -* **Continuous testing, integration and deployment** is performed by CI jobs at https://hudson.eclipse.org/tm4e +* **Build**: build can be performed with a simple `mvn clean verify`, continuous integration and deployment is performed by CI jobs at https://ci.eclipse.org/tm4e/ +* **Continuous testing, integration and deployment** is performed by CI jobs at https://ci.eclipse.org/tm4e/ and https://github.com/eclipse/tm4e/actions * **Developers mailing-list**: Contributors are also expected to subscribe the [tm4e-dev mailing-list](https://dev.eclipse.org/mailman/listinfo/tm4e-dev). * **Becoming a committer**: as usual with Eclipse.org projects, anyone who's made significant contributions and who's upheld quality standards alongside good judgement and open-mindedness. From c2298adb5fa4ccaa00933b134755b3c352649e84 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Tue, 10 May 2022 21:58:17 +0200 Subject: [PATCH 201/202] Details about 0.4.4 in README.md --- RELEASE_NOTES.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 8588d5df6..773fe4db2 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,12 +4,21 @@ This page describes the noteworthy improvements provided by each release of Ecli ### Next release... -### 0.4.4 +## 0.4.5 + +* 📅 Release Date (tentative): ? +* All changes: https://github.com/eclipse/tm4e/compare/0.4.4...master ### Latest release -* 📅 Release Date (tentative): ? -* All changes: https://github.com/eclipse/tm4e/compare/0.4.3...master +## 0.4.4 + +* 📅 Release Date (tentative): May 17th 2022 +* All changes: https://github.com/eclipse/tm4e/compare/0.4.3...0.4.4 + +* Many many many... code improvements +* Dependency updates +* Bugfixes in file detection and compare editor ## 0.4.3 From f44d15f268420d9a1fb46e975e4c161fed5cfee2 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Wed, 11 May 2022 14:07:01 +0200 Subject: [PATCH 202/202] Fix 2.4.4 Release date --- RELEASE_NOTES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 773fe4db2..a47433fda 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -13,9 +13,10 @@ This page describes the noteworthy improvements provided by each release of Ecli ## 0.4.4 -* 📅 Release Date (tentative): May 17th 2022 +* 📅 Release Date: May 11th 2022 * All changes: https://github.com/eclipse/tm4e/compare/0.4.3...0.4.4 + * Many many many... code improvements * Dependency updates * Bugfixes in file detection and compare editor