From 2470dbe9fb837288d8b6377d1912a11e3b31d16a Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 14 Jun 2023 20:44:22 +0200 Subject: [PATCH] feat: add ITMDocumentModel interface --- .../ui/internal/model/TMDocumentModel.java | 4 +++- .../tm4e/ui/model/ITMDocumentModel.java | 21 +++++++++++++++++++ .../tm4e/ui/model/ITMModelManager.java | 3 +-- .../ui/text/TMPresentationReconciler.java | 8 +++---- 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMDocumentModel.java 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 2cef0ee00..cbea96346 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 @@ -13,8 +13,9 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.tm4e.core.model.TMModel; +import org.eclipse.tm4e.ui.model.ITMDocumentModel; -public final class TMDocumentModel extends TMModel { +public final class TMDocumentModel extends TMModel implements ITMDocumentModel { private final IDocument document; @@ -23,6 +24,7 @@ public TMDocumentModel(final IDocument document) { this.document = document; } + @Override public IDocument getDocument() { return document; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMDocumentModel.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMDocumentModel.java new file mode 100644 index 000000000..523f7ad1b --- /dev/null +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/model/ITMDocumentModel.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2023 Vegard IT GmbH 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.ui.model; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.tm4e.core.model.ITMModel; + +public interface ITMDocumentModel extends ITMModel { + + IDocument getDocument(); +} 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 76d514b46..55b4d6317 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 @@ -12,7 +12,6 @@ package org.eclipse.tm4e.ui.model; import org.eclipse.jface.text.IDocument; -import org.eclipse.tm4e.core.model.ITMModel; /** * TextMate model manager API. @@ -27,7 +26,7 @@ public interface ITMModelManager { * * @return the TextMate model connected to the document. */ - ITMModel connect(IDocument document); + ITMDocumentModel connect(IDocument document); /** * Disconnect the TextMate model of the given document. 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 793a5fbb0..173358fe7 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 @@ -65,7 +65,6 @@ 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.model.TMModelManager; import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants; import org.eclipse.tm4e.ui.internal.text.TMPresentationReconcilerTestGenerator; @@ -75,6 +74,7 @@ import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo; import org.eclipse.tm4e.ui.internal.utils.MarkerUtils; import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils; +import org.eclipse.tm4e.ui.model.ITMDocumentModel; import org.eclipse.tm4e.ui.themes.ITheme; import org.eclipse.tm4e.ui.themes.IThemeManager; import org.eclipse.tm4e.ui.themes.ITokenProvider; @@ -84,7 +84,7 @@ * TextMate presentation reconciler which must be initialized with: * *
    - *
  1. a TextMate grammar {@link IGrammar} used to initialize the {@link TMDocumentModel}.
  2. + *
  3. a TextMate grammar {@link IGrammar} used to initialize the {@link ITMDocumentModel}.
  4. *
  5. a token provider {@link ITokenProvider} to retrieve the {@link IToken} from a {@link TMToken} type .
  6. *
*/ @@ -396,7 +396,7 @@ void colorize(final ModelTokensChangedEvent event) { return; } final ITMModel model = event.model; - if (model instanceof final TMDocumentModel docModel) { + if (model instanceof final ITMDocumentModel docModel) { for (final Range range : event.ranges) { try { final int length = document.getLineOffset(range.toLineNumber - 1) @@ -514,7 +514,7 @@ public IPresentationRepairer getRepairer(@Nullable final String contentType) { return null; } - private void colorize(final IRegion damage, final TMDocumentModel model) throws BadLocationException { + private void colorize(final IRegion damage, final ITMDocumentModel model) throws BadLocationException { final IDocument doc = model.getDocument(); final int fromLineIndex = doc.getLineOfOffset(damage.getOffset()); final int toLineIndex = doc.getLineOfOffset(damage.getOffset() + damage.getLength());