Skip to content

Commit 628d836

Browse files
committed
Add tracing to org.eclipse.text text stores
This change adds an activator to org.eclipse.text, as well as debug tracing to set/replace methods in CopyOnWriteTextStore and GapTextStore. Fixes: #3800
1 parent db33b10 commit 628d836

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

bundles/org.eclipse.text/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Bundle-SymbolicName: org.eclipse.text
55
Bundle-Version: 3.14.600.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
8+
Bundle-Activator: org.eclipse.text.internal.TextPlugin
89
Export-Package:
910
org.eclipse.jface.text; text="split"; mandatory:="text",
1011
org.eclipse.jface.text.link; text="split"; mandatory:="text",
@@ -14,6 +15,7 @@ Export-Package:
1415
org.eclipse.jface.text.templates; text="split"; mandatory:="text",
1516
org.eclipse.text.edits,
1617
org.eclipse.text.html,
18+
org.eclipse.text.internal;x-internal:=true,
1719
org.eclipse.text.readers,
1820
org.eclipse.text.templates,
1921
org.eclipse.text.undo
@@ -24,3 +26,4 @@ Require-Bundle:
2426
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)"
2527
Bundle-RequiredExecutionEnvironment: JavaSE-17
2628
Automatic-Module-Name: org.eclipse.text
29+
Bundle-ActivationPolicy: lazy

bundles/org.eclipse.text/src/org/eclipse/jface/text/CopyOnWriteTextStore.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import org.eclipse.core.runtime.Assert;
1717

18+
import org.eclipse.text.internal.TextPlugin;
19+
1820

1921
/**
2022
* Copy-on-write <code>ITextStore</code> wrapper.
@@ -135,6 +137,9 @@ public int getLength() {
135137

136138
@Override
137139
public void replace(int offset, int length, String text) {
140+
if (TextPlugin.DEBUG) {
141+
TextPlugin.trace("CopyOnWriteTextStore.replace() offset=" + offset + ", length=" + length + ", text=" + text); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
142+
}
138143
if (fTextStore != fModifiableTextStore) {
139144
String content= fTextStore.get(0, fTextStore.getLength());
140145
fTextStore= fModifiableTextStore;
@@ -145,8 +150,12 @@ public void replace(int offset, int length, String text) {
145150

146151
@Override
147152
public void set(String text) {
153+
if (TextPlugin.DEBUG) {
154+
TextPlugin.trace("CopyOnWriteTextStore.set() text=" + text); //$NON-NLS-1$
155+
}
148156
fTextStore= new StringTextStore(text);
149157
fModifiableTextStore.set(""); //$NON-NLS-1$
150158
}
151159

160+
152161
}

bundles/org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import org.eclipse.core.runtime.Assert;
1717

18+
import org.eclipse.text.internal.TextPlugin;
19+
1820

1921
/**
2022
* Implements a gap managing text store. The gap text store relies on the assumption that
@@ -186,6 +188,9 @@ public final void set(String text) {
186188

187189
@Override
188190
public final void replace(int offset, int length, String text) {
191+
if (TextPlugin.DEBUG) {
192+
TextPlugin.trace("GapTextStore.replace() offset=" + offset + ", length=" + length + ", text=" + text); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
193+
}
189194
if (text == null) {
190195
adjustGap(offset, length, 0);
191196
} else {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*******************************************************************************
2+
* Copyright (c) Simeon Andreev and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Simeon Andreev - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.text.internal;
15+
16+
import java.util.Hashtable;
17+
18+
import org.osgi.framework.BundleActivator;
19+
import org.osgi.framework.BundleContext;
20+
21+
import org.eclipse.osgi.service.debug.DebugOptions;
22+
import org.eclipse.osgi.service.debug.DebugOptionsListener;
23+
import org.eclipse.osgi.service.debug.DebugTrace;
24+
25+
public class TextPlugin implements BundleActivator, DebugOptionsListener {
26+
27+
public static final String PLUGIN_ID = "org.eclipse.text"; //$NON-NLS-1$
28+
29+
private static final String DEBUG_FLAG = PLUGIN_ID + "/debug"; //$NON-NLS-1$
30+
31+
private static DebugTrace debugTrace;
32+
33+
public static boolean DEBUG = false;
34+
35+
@Override
36+
public void start(BundleContext context) throws Exception {
37+
Hashtable<String, String> props = new Hashtable<>(2);
38+
props.put(DebugOptions.LISTENER_SYMBOLICNAME, PLUGIN_ID);
39+
context.registerService(DebugOptionsListener.class.getName(), this, props);
40+
}
41+
42+
@Override
43+
public void optionsChanged(DebugOptions options) {
44+
debugTrace = options.newDebugTrace(PLUGIN_ID, TextPlugin.class);
45+
DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
46+
}
47+
48+
@Override
49+
public void stop(BundleContext context) throws Exception {
50+
}
51+
52+
/**
53+
* Prints the given message to the OSGi tracing (if enabled)
54+
*
55+
* @param message the message or <code>null</code>
56+
*/
57+
public static void trace(String message) {
58+
if (DEBUG) {
59+
debugTrace.trace(null, message, null);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)