From 24b4dde7892aea3ef5e3cf89c47884582b29ce93 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 Jun 2022 16:50:21 +0200 Subject: [PATCH] Refactor Eclipse logging --- .../LanguageConfigurationPlugin.java | 17 +++++- .../LanguageConfigurationPreferencePage.java | 5 +- .../preferences/PreferenceHelper.java | 8 +-- .../LanguageConfigurationDefinition.java | 8 +-- org.eclipse.tm4e.registry/.options | 1 - org.eclipse.tm4e.registry/build.properties | 1 - .../registry/TMEclipseRegistryPlugin.java | 61 ++++++++++++------- org.eclipse.tm4e.ui/.options | 2 - .../java/org/eclipse/tm4e/ui/TMUIPlugin.java | 37 ++++++----- .../ui/internal/model/DocumentModelLines.java | 6 +- .../preferences/ThemePreferencePage.java | 6 +- .../tm4e/ui/internal/utils/MarkerUtils.java | 6 +- .../ui/internal/utils/PreferenceUtils.java | 11 +++- .../ui/text/TMPresentationReconciler.java | 31 +++++----- .../tm4e/ui/themes/css/CSSTokenProvider.java | 6 +- 15 files changed, 117 insertions(+), 89 deletions(-) delete mode 100644 org.eclipse.tm4e.registry/.options diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationPlugin.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationPlugin.java index 1b4bd3376..a5b365afe 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationPlugin.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/LanguageConfigurationPlugin.java @@ -12,6 +12,7 @@ package org.eclipse.tm4e.languageconfiguration; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -39,12 +40,22 @@ public static LanguageConfigurationPlugin getDefault() { } public static void log(final IStatus status) { - final var plugin = LanguageConfigurationPlugin.plugin; - if (plugin != null) { - plugin.getLog().log(status); + final var p = plugin; + if (p != null) { + p.getLog().log(status); + } else { + System.out.println(status); } } + public static void logError(final Exception ex) { + log(new Status(IStatus.ERROR, PLUGIN_ID, ex.getMessage(), ex)); + } + + public static void logError(final String message, @Nullable final Exception ex) { + log(new Status(IStatus.ERROR, PLUGIN_ID, message, ex)); + } + @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/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java index a008a205f..fe7e1140e 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 @@ -43,6 +43,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.tm4e.languageconfiguration.LanguageConfigurationPlugin; import org.eclipse.tm4e.languageconfiguration.internal.registry.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.internal.registry.ILanguageConfigurationRegistryManager; import org.eclipse.tm4e.languageconfiguration.internal.registry.LanguageConfigurationRegistryManager; @@ -279,8 +280,8 @@ public void setVisible(final boolean visible) { public boolean performOk() { try { manager.save(); - } catch (final BackingStoreException e) { - // TODO: Log + } catch (final BackingStoreException ex) { + LanguageConfigurationPlugin.logError(ex); } return super.performOk(); } 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 cd7e21928..c2ee1afb5 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,8 +15,6 @@ 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.NonNullByDefault; import org.eclipse.tm4e.languageconfiguration.LanguageConfigurationPlugin; import org.eclipse.tm4e.languageconfiguration.internal.registry.ILanguageConfigurationDefinition; @@ -44,9 +42,9 @@ public final class PreferenceHelper { 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)); + LanguageConfigurationPlugin.logError( + "Cannot load language configuration with unknown content type ID " + contentTypeId, + null); return null; } return new LanguageConfigurationDefinition(contentType, // $NON-NLS-1$ diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java index 3c59597c3..aef36eb07 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java @@ -136,12 +136,8 @@ public IContentType getContentType() { public ILanguageConfiguration getLanguageConfiguration() { try (var in = getInputStream()) { return LanguageConfiguration.load(new InputStreamReader(in, Charset.defaultCharset())); - } catch (final IOException e) { - final var plugin = LanguageConfigurationPlugin.getDefault(); - if (plugin != null) { - plugin.getLog().log( - new Status(IStatus.ERROR, LanguageConfigurationPlugin.PLUGIN_ID, e.getMessage(), e)); - } + } catch (final IOException ex) { + LanguageConfigurationPlugin.logError(ex); return null; } } diff --git a/org.eclipse.tm4e.registry/.options b/org.eclipse.tm4e.registry/.options deleted file mode 100644 index 84823e574..000000000 --- a/org.eclipse.tm4e.registry/.options +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.tm4e.registry/debug/log/Grammar = false \ No newline at end of file diff --git a/org.eclipse.tm4e.registry/build.properties b/org.eclipse.tm4e.registry/build.properties index d51a4353e..00867dbbd 100644 --- a/org.eclipse.tm4e.registry/build.properties +++ b/org.eclipse.tm4e.registry/build.properties @@ -5,7 +5,6 @@ bin.includes = META-INF/,\ plugin.xml,\ plugin.properties,\ .,\ - .options,\ about.html # https://codeiseasy.wordpress.com/2013/03/08/tycho-and-jdt-null-analysis/ 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 fa4a366e7..eed33164c 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,45 +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 + * Contributors: + * Angelo Zerr - initial API and implementation */ package org.eclipse.tm4e.registry; -import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; 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 class TMEclipseRegistryPlugin extends Plugin { + /** The plug-in ID */ public static final String PLUGIN_ID = "org.eclipse.tm4e.registry"; + /** The shared instance */ @Nullable - private static BundleContext context; + private static volatile TMEclipseRegistryPlugin plugin; + /** + * Returns the shared instance + * + * @return the shared instance + */ @Nullable - static BundleContext getContext() { - return context; + public static TMEclipseRegistryPlugin getDefault() { + return plugin; + } + + public static void log(final IStatus status) { + final var p = plugin; + if (p != null) { + p.getLog().log(status); + } else { + System.out.println(status); + } + } + + public static void logError(final Exception ex) { + log(new Status(IStatus.ERROR, PLUGIN_ID, ex.getMessage(), ex)); + } + + public static void logError(final String message, @Nullable final Exception ex) { + log(new Status(IStatus.ERROR, PLUGIN_ID, message, ex)); } @Override public void start(@Nullable final BundleContext bundleContext) throws Exception { - TMEclipseRegistryPlugin.context = bundleContext; + super.start(bundleContext); + plugin = this; } @Override public void stop(@Nullable final BundleContext bundleContext) throws Exception { - TMEclipseRegistryPlugin.context = null; + plugin = null; + super.stop(bundleContext); } /** @@ -50,16 +77,4 @@ public void stop(@Nullable final BundleContext bundleContext) throws Exception { 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(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.ui/.options b/org.eclipse.tm4e.ui/.options index cb7b69c66..d05fbf50d 100644 --- a/org.eclipse.tm4e.ui/.options +++ b/org.eclipse.tm4e.ui/.options @@ -1,5 +1,3 @@ org.eclipse.tm4e.ui/debug/log/GenerateTest = false -org.eclipse.tm4e.ui/debug/log/TMPresentationReconciler = false org.eclipse.tm4e.ui/debug/log/ThrowError = false -org.eclipse.tm4e.ui/debug/log/TMModelManager = false org.eclipse.tm4e.ui/trace = false \ No newline at end of file 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 8a269c3de..73d8fa52f 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 @@ -44,35 +44,42 @@ public class TMUIPlugin extends AbstractUIPlugin { private static volatile TMUIPlugin plugin; public static void log(final IStatus status) { - final var plugin = TMUIPlugin.plugin; - if (plugin != null) { - plugin.getLog().log(status); + final var p = plugin; + if (p != null) { + p.getLog().log(status); + } else { + System.out.println(status); } } - public static void trace(final String message) { - if (Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID))) { + public static void logError(Exception ex) { + log(new Status(IStatus.ERROR, PLUGIN_ID, ex.getMessage(), ex)); + } + + public static void logTrace(final String message) { + if (isLogTraceEnabled()) { log(new Status(IStatus.INFO, PLUGIN_ID, message)); } } + public static boolean isLogTraceEnabled() { + return Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID)); + } + @Override public void start(@Nullable final BundleContext context) throws Exception { super.start(context); plugin = this; - final boolean isDebugOn = Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID)); - if (isDebugOn) { - final Logger tm4eCoreLogger = Logger.getLogger("org.eclipse.tm4e"); + if (isLogTraceEnabled()) { + // if the trace option is enabled publish all TM4E CORE JDK logging output to the Eclipse Error Log + final var tm4eCorePluginId = "org.eclipse.tm4e.core"; + final var tm4eCoreLogger = Logger.getLogger(tm4eCorePluginId); tm4eCoreLogger.setLevel(Level.FINEST); tm4eCoreLogger.addHandler(new Handler() { - @Override - public void publish(@Nullable final LogRecord record) { - if (record != null) { - log(new Status( - toSeverity(record.getLevel()), - "org.eclipse.tm4e.core", - record.getMessage())); + public void publish(@Nullable final LogRecord entry) { + if (entry != null) { + log(new Status(toSeverity(entry.getLevel()), tm4eCorePluginId, entry.getMessage())); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentModelLines.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentModelLines.java index 2136eb2c9..d7954a5e3 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentModelLines.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/model/DocumentModelLines.java @@ -11,8 +11,6 @@ */ 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; @@ -50,7 +48,7 @@ public void documentAboutToBeChanged(@Nullable final DocumentEvent event) { default: } } catch (final BadLocationException ex) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } } @@ -86,7 +84,7 @@ public void documentChanged(@Nullable final DocumentEvent event) { } } } catch (final BadLocationException ex) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } } 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 3c5f94724..aac939127 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 @@ -18,8 +18,6 @@ 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; @@ -378,8 +376,8 @@ public boolean performOk() { themeManager.save(); grammarRegistryManager.save(); return true; - } catch (final BackingStoreException e) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } catch (final BackingStoreException ex) { + TMUIPlugin.logError(ex); return false; } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java index 868629796..a957f7eb8 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java @@ -73,7 +73,7 @@ public static void updateTextMarkers(final ModelTokensChangedEvent event) { try { updateTextMarkers(docModel, event.ranges.get(0).fromLineNumber); } catch (final CoreException ex) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } } } @@ -164,7 +164,7 @@ public static void updateTextMarkers(final TMDocumentModel docModel, final int s res.createMarker(markerConfig.type, attrs); } } catch (final Exception ex) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } } @@ -184,7 +184,7 @@ private static Integer getLineNumber(final IMarker marker) { if (lineNumberAttr instanceof final Integer lineNumber) return lineNumber; } catch (final CoreException ex) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } return null; } 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 f84e0fa59..dceaac127 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 @@ -11,6 +11,7 @@ */ package org.eclipse.tm4e.ui.internal.utils; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jdt.annotation.Nullable; @@ -23,7 +24,12 @@ 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$ - private PreferenceUtils() { + public static boolean isDebugGenerateTest() { + return Boolean.parseBoolean(Platform.getDebugOption(TMUIPlugin.PLUGIN_ID + "/debug/log/GenerateTest")); + } + + public static boolean isDebugThrowError() { + return Boolean.parseBoolean(Platform.getDebugOption(TMUIPlugin.PLUGIN_ID + "/debug/log/ThrowError")); } /** @@ -67,4 +73,7 @@ public static IPreferenceStore getTM4EPreferencesStore() { final var plugin = TMUIPlugin.getDefault(); return plugin == null ? null : plugin.getPreferenceStore(); } + + private PreferenceUtils() { + } } 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 dfa0d432c..493d78bdc 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 @@ -128,10 +128,10 @@ 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")) { + if (PreferenceUtils.isDebugGenerateTest()) { addTMPresentationReconcilerListener(new TMPresentationReconcilerTestGenerator()); } - setThrowError(TMEclipseRegistryPlugin.isDebugOptionEnabled("org.eclipse.tm4e.ui/debug/log/ThrowError")); + setThrowError(PreferenceUtils.isDebugThrowError()); } /** @@ -335,7 +335,7 @@ public void textChanged(final @Nullable TextEvent event) { try { TMPresentationReconciler.this.colorize(region, docModel); } catch (final BadLocationException ex) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } } else { // case where there is no grammar & theme -> update text presentation with the @@ -409,7 +409,7 @@ void colorize(final ModelTokensChangedEvent event) { final var 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)); + TMUIPlugin.logError(ex); } } } @@ -474,8 +474,8 @@ public void setTheme(final ITokenProvider newTheme) { final var docModel = TMModelManager.INSTANCE.connect(document); try { colorize(new Region(0, document.getLength()), docModel); - } catch (final BadLocationException e) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } catch (final BadLocationException ex) { + TMUIPlugin.logError(ex); } } } @@ -524,7 +524,8 @@ private void colorize(final IRegion damage, final TMDocumentModel model) throws final int toLineIndex = doc.getLineOfOffset(damage.getOffset() + damage.getLength()); applyThemeEditorIfNeeded(); // Refresh the UI Presentation - TMUIPlugin.trace("Render from: " + fromLineIndex + " to: " + toLineIndex); + if (TMUIPlugin.isLogTraceEnabled()) + TMUIPlugin.logTrace("Render from: " + fromLineIndex + " to: " + toLineIndex); final var presentation = new TextPresentation(damage, 1000); Exception error = null; try { @@ -538,11 +539,11 @@ private void colorize(final IRegion damage, final TMDocumentModel model) throws for (int lineIndex = fromLineIndex; lineIndex <= toLineIndex; lineIndex++) { tokens = model.getLineTokens(lineIndex); 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. + // TextMate tokens was not computed for this line. This happens 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 " + lineIndex); + if (TMUIPlugin.isLogTraceEnabled()) + TMUIPlugin.logTrace("TextMate tokens not available for line " + lineIndex); break; } final int startLineOffset = doc.getLineOffset(lineIndex); @@ -595,7 +596,7 @@ private void colorize(final IRegion damage, final TMDocumentModel model) throws applyTextRegionCollection(presentation); } catch (final Exception ex) { error = ex; - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } finally { fireColorize(presentation, error); } @@ -759,9 +760,9 @@ public static TMPresentationReconciler getTMPresentationReconciler(final ITextVi ? tmPresentationReconciler : null; } - } catch (SecurityException | NoSuchFieldException e) { + } catch (SecurityException | NoSuchFieldException ex) { // if SourceViewer class no longer has fPresentationReconciler or changes access level - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + TMUIPlugin.logError(ex); } catch (IllegalArgumentException | IllegalAccessException | NullPointerException | ExceptionInInitializerError iae) { // This should not be logged as an error. This is an expected possible outcome of field.get(textViewer). @@ -823,7 +824,7 @@ private void applyThemeEditorIfNeeded() { } } } catch (final Exception ex) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, ex.getMessage(), ex)); + TMUIPlugin.logError(ex); } } 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 83d022a1c..d0ddeb28c 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 @@ -15,8 +15,6 @@ import java.util.HashMap; import java.util.Map; -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; @@ -64,8 +62,8 @@ public CSSTokenProvider(final InputStream in) { new Token(new TextAttribute(ColorManager.getInstance().getColor(color), null, s))); } } - } catch (final Exception e) { - TMUIPlugin.log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e)); + } catch (final Exception ex) { + TMUIPlugin.logError(ex); } }