diff options
14 files changed, 94 insertions, 140 deletions
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java index db4f1c74b..ee6edc849 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java @@ -67,14 +67,14 @@ public class STextFullToLeanTest extends STextTestBase { data = "update \"AB_CDE\" set \"COL1\"@='01', \"COL2\"@='02' /* GH IJK"; text = toUT16(data); - ISTextExpertStateful expertLTR = STextExpertFactory.getPrivateExpert(type, envLTR); + ISTextExpert expertLTR = STextExpertFactory.getPrivateExpert(type, envLTR); expertLTR.resetState(); lean = expertLTR.fullToLeanText(text); state1 = expertLTR.getState(); model = "update \"AB_CDE\" set \"COL1\"='01', \"COL2\"='02' /* GH IJK"; assertEquals(msg + "LTR lean", model, toPseudo(lean)); - ISTextExpertStateful expertLTR2 = STextExpertFactory.getPrivateExpert(type, envLTR); + ISTextExpert expertLTR2 = STextExpertFactory.getPrivateExpert(type, envLTR); expertLTR2.resetState(); full = expertLTR2.leanToFullText(lean); diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler1.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler1.java index 62d1f953c..0e2fff292 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler1.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler1.java @@ -10,6 +10,7 @@ ******************************************************************************/
package org.eclipse.equinox.bidi.internal.tests;
+import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
import org.eclipse.equinox.bidi.custom.*;
@@ -23,7 +24,7 @@ public class TestHandler1 extends STextTypeHandler { return fromIndex;
}
- public int processSpecial(STextEnvironment env, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) {
+ public int processSpecial(ISTextExpert expert, STextEnvironment env, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
int len = text.length();
for (int i = len - 1; i >= 0; i--) {
STextTypeHandler.insertMark(text, charTypes, offsets, i);
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java index a5dfe98ac..46e221fed 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java @@ -258,4 +258,18 @@ public interface ISTextExpert { */
public int getCurDirection(String text);
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ // Expert's state handling - can be used only for non-shared experts
+
+ // TBD is there a case where we get a shared expert and setting state is a "must"?
+ // Javadoc note: shared experts will ignore this
+ public void setState(Object state);
+
+ // Javadoc note: may return null. Will return null for shared experts
+ public Object getState();
+
+ /**
+ * Resets state to initial.
+ */
+ public void resetState();
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java deleted file mode 100644 index befbd206d..000000000 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java +++ /dev/null @@ -1,24 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2011 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.equinox.bidi.advanced;
-
-public interface ISTextExpertStateful extends ISTextExpert {
-
- public void setState(Object state);
-
- public Object getState();
-
- /**
- * Resets non-shared expert state to initial.
- */
- public void resetState();
-
-}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java index fdf6aaae9..9329fc330 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java @@ -36,7 +36,7 @@ final public class STextExpertFactory { static public ISTextExpert getExpert() {
if (defaultExpert == null) {
STextTypeHandler handler = new STextTypeHandler(defaultSeparators);
- defaultExpert = new STextImpl(handler, STextEnvironment.DEFAULT, null);
+ defaultExpert = new STextImpl(handler, STextEnvironment.DEFAULT, false);
}
return defaultExpert;
}
@@ -49,7 +49,7 @@ final public class STextExpertFactory { STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
if (handler == null)
return null;
- expert = new STextImpl(handler, STextEnvironment.DEFAULT, null);
+ expert = new STextImpl(handler, STextEnvironment.DEFAULT, false);
sharedDefaultExperts.put(type, expert);
}
}
@@ -69,7 +69,7 @@ final public class STextExpertFactory { STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
if (handler == null)
return null;
- expert = new STextImpl(handler, environment, null);
+ expert = new STextImpl(handler, environment, false);
experts.put(type, expert);
}
}
@@ -77,18 +77,18 @@ final public class STextExpertFactory { }
static public ISTextExpert getExpert(STextTypeHandler handler, STextEnvironment environment) {
- return new STextImpl(handler, environment, STextState.createState());
+ return new STextImpl(handler, environment, true);
}
- static public ISTextExpertStateful getPrivateExpert(String type) {
+ static public ISTextExpert getPrivateExpert(String type) {
return getPrivateExpert(type, STextEnvironment.DEFAULT);
}
- static public ISTextExpertStateful getPrivateExpert(String type, STextEnvironment environment) {
+ static public ISTextExpert getPrivateExpert(String type, STextEnvironment environment) {
STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
if (handler == null)
return null;
- return new STextImpl(handler, environment, STextState.createState());
+ return new STextImpl(handler, environment, true);
}
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextState.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextState.java deleted file mode 100644 index 68ba497f5..000000000 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextState.java +++ /dev/null @@ -1,47 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2011 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.equinox.bidi.advanced;
-
-final public class STextState {
-
- private STextState() {
- // prevent instantiation
- }
-
- public static Object createState() {
- return new Object[1];
- }
-
- public static Object getValueAndReset(Object state) {
- if (state instanceof Object[]) {
- Object[] values = (Object[]) state;
- if (values.length > 0) {
- Object value = values[0];
- values[0] = null;
- return value;
- }
- }
- throw new IllegalArgumentException("Invalid state argument"); //$NON-NLS-1$
- }
-
- public static void setValue(Object state, Object value) {
- if (state == null)
- return;
- if (state instanceof Object[]) {
- Object[] values = (Object[]) state;
- if (values.length > 0)
- values[0] = value;
- return;
- }
- throw new IllegalArgumentException("Invalid state argument"); //$NON-NLS-1$
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java index b63001509..f79906ab6 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java @@ -210,7 +210,7 @@ public class STextTypeHandler { * number of special cases is zero, which means that
* <code>processSpecial</code> should never be called for them.
*/
- public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) {
+ public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
// This method must be overridden by all subclasses with any special case.
throw new IllegalStateException("A handler with specialsCount > 0 must have a processSpecial() method."); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java index bcddf10cf..81e3767db 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; @@ -58,7 +59,7 @@ public abstract class STextDelims extends STextTypeHandler { * @return the position after the matching end delimiter, or the length * of <code>text</code> if no end delimiter is found. */ - public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { + public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) { STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); int loc = separLocation + 1; char delim = getDelimiters().charAt((caseNumber * 2) - 1); diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java index 49552f20d..73e8571da 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; @@ -49,7 +50,7 @@ public abstract class STextDelimsEsc extends STextDelims { * and skips until after the matching end delimiter, * ignoring possibly escaped end delimiters. */ - public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { + public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) { STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); int location = separLocation + 1; char delim = getDelimiters().charAt((caseNumber * 2) - 1); diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java index a004be198..001322ba0 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java @@ -11,10 +11,11 @@ package org.eclipse.equinox.bidi.internal; import org.eclipse.equinox.bidi.STextDirection; -import org.eclipse.equinox.bidi.advanced.*; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; +import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; -public class STextImpl implements ISTextExpertStateful { +public class STextImpl implements ISTextExpert { static final String EMPTY_STRING = ""; //$NON-NLS-1$ @@ -49,36 +50,39 @@ public class STextImpl implements ISTextExpertStateful { protected STextTypeHandler structuredTextHandler; protected STextEnvironment environment; + protected Object state; - public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, Object state) { + protected boolean sharedExpert; + + public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, boolean shared) { this.structuredTextHandler = structuredTextHandler; this.environment = environment; - this.state = state; + sharedExpert = shared; } public String leanToFullText(String text) { - return STextImpl.leanToFullText(structuredTextHandler, environment, text, state); + return leanToFullText(structuredTextHandler, environment, text, state); } public int[] leanToFullMap(String text) { - return STextImpl.leanToFullMap(structuredTextHandler, environment, text, state); + return leanToFullMap(structuredTextHandler, environment, text, state); } public int[] leanBidiCharOffsets(String text) { - return STextImpl.leanBidiCharOffsets(structuredTextHandler, environment, text, state); + return leanBidiCharOffsets(structuredTextHandler, environment, text, state); } public String fullToLeanText(String text) { - return STextImpl.fullToLeanText(structuredTextHandler, environment, text, state); + return fullToLeanText(structuredTextHandler, environment, text, state); } public int[] fullToLeanMap(String text) { - return STextImpl.fullToLeanMap(structuredTextHandler, environment, text, state); + return fullToLeanMap(structuredTextHandler, environment, text, state); } public int[] fullBidiCharOffsets(String text) { - return STextImpl.fullBidiCharOffsets(structuredTextHandler, environment, text, state); + return fullBidiCharOffsets(structuredTextHandler, environment, text, state); } public int getCurDirection(String text) { @@ -86,24 +90,20 @@ public class STextImpl implements ISTextExpertStateful { } public void resetState() { - STextState.setValue(state, null); + if (sharedExpert) + state = null; } public void setState(Object newState) { - STextState.setValue(state, newState); - } - - public static void setState(Object state, Object newState) { - STextState.setValue(state, newState); + if (sharedExpert) + state = newState; } public Object getState() { - Object value = STextState.getValueAndReset(state); - STextState.setValue(state, value); - return value; + return state; } - static long computeNextLocation(STextTypeHandler handler, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) { + long computeNextLocation(STextTypeHandler handler, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) { String separators = handler.getSeparators(environment); int separCount = separators.length(); int specialsCount = handler.getSpecialsCount(environment); @@ -142,7 +142,7 @@ public class STextImpl implements ISTextExpertStateful { return nextLocation + (((long) idxLocation) << 32); } - public static void processSeparator(String text, STextCharTypes charTypes, STextOffsets offsets, int separLocation) { + static public void processSeparator(String text, STextCharTypes charTypes, STextOffsets offsets, int separLocation) { int len = text.length(); int direction = charTypes.getDirection(); if (direction == STextDirection.DIR_RTL) { @@ -243,7 +243,7 @@ public class STextImpl implements ISTextExpertStateful { * <p> * @see ISTextExpert#leanToFullText STextEngine.leanToFullText */ - public static String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { + public String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { int len = text.length(); if (len == 0) return text; @@ -290,7 +290,7 @@ public class STextImpl implements ISTextExpertStateful { return new String(fullChars); } - public static int[] leanToFullMap(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { + public int[] leanToFullMap(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { int len = text.length(); if (len == 0) return EMPTY_INT_ARRAY; @@ -310,7 +310,7 @@ public class STextImpl implements ISTextExpertStateful { return map; } - public static int[] leanBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { + public int[] leanBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { int len = text.length(); if (len == 0) return EMPTY_INT_ARRAY; @@ -319,7 +319,7 @@ public class STextImpl implements ISTextExpertStateful { return offsets.getArray(); } - static STextOffsets leanToFullCommon(STextTypeHandler handler, STextEnvironment environment, String text, Object state, STextCharTypes charTypes) { + public STextOffsets leanToFullCommon(STextTypeHandler handler, STextEnvironment environment, String text, Object state, STextCharTypes charTypes) { if (environment == null) environment = STextEnvironment.DEFAULT; int len = text.length(); @@ -334,11 +334,9 @@ public class STextImpl implements ISTextExpertStateful { } // current position int curPos = 0; - Object value; - if (state != null && (value = STextState.getValueAndReset(state)) != null) { - STextState.setValue(state, value); // restore the value + if (state != null) { offsets.ensureRoom(); - curPos = handler.processSpecial(environment, text, charTypes, offsets, state, 0, -1); + curPos = handler.processSpecial(this, environment, text, charTypes, offsets, 0, -1); } while (true) { // location of next token to handle @@ -356,7 +354,7 @@ public class STextImpl implements ISTextExpertStateful { curPos = nextLocation + 1; } else { idxLocation -= (separCount - 1); // because caseNumber starts from 1 - curPos = handler.processSpecial(environment, text, charTypes, offsets, state, idxLocation, nextLocation); + curPos = handler.processSpecial(this, environment, text, charTypes, offsets, idxLocation, nextLocation); } if (curPos >= len) break; @@ -379,7 +377,7 @@ public class STextImpl implements ISTextExpertStateful { return offsets; } - public static String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { + public String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { if (text.length() == 0) return text; if (environment == null) @@ -467,7 +465,7 @@ public class STextImpl implements ISTextExpertStateful { return lean; } - public static int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { + public int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { int lenFull = full.length(); if (lenFull == 0) return EMPTY_INT_ARRAY; @@ -498,7 +496,7 @@ public class STextImpl implements ISTextExpertStateful { return map; } - public static int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { + public int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { int lenFull = full.length(); if (lenFull == 0) return EMPTY_INT_ARRAY; diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java index d4ff00e18..6822bd8f1 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; @@ -50,7 +51,7 @@ public class STextSingle extends STextTypeHandler { * * @return the length of <code>text</code>. */ - public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { + public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) { STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); return text.length(); } diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java index fa8e702d4..4b42661c9 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java @@ -10,7 +10,8 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.advanced.*; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; +import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; import org.eclipse.equinox.bidi.internal.STextActivator; @@ -36,7 +37,7 @@ import org.eclipse.equinox.bidi.internal.STextActivator; public class STextJava extends STextTypeHandler { private static final byte WS = Character.DIRECTIONALITY_WHITESPACE; static final String lineSep = STextActivator.getInstance().getProperty("line.separator"); //$NON-NLS-1$ - private static final Integer INTEGER_3 = new Integer(3); + private static final Integer STATE_SLASH_ASTER_COMMENT = new Integer(3); public STextJava() { super("[](){}.+-<>=~!&*/%^|?:,;\t"); //$NON-NLS-1$ @@ -82,12 +83,14 @@ public class STextJava extends STextTypeHandler { * <li>skip until after a line separator</li> * </ol> */ - public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { + public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) { int location, counter, i; STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); - if (separLocation < 0) - caseNumber = ((Integer) STextState.getValueAndReset(state)).intValue(); + if (separLocation < 0) { + caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined" + expert.resetState(); + } switch (caseNumber) { case 1 : /* space */ separLocation++; @@ -116,7 +119,7 @@ public class STextJava extends STextTypeHandler { location = separLocation + 2; // skip the opening slash-aster location = text.indexOf("*/", location); //$NON-NLS-1$ if (location < 0) { - STextState.setValue(state, INTEGER_3); + expert.setState(STATE_SLASH_ASTER_COMMENT); return text.length(); } // we need to call processSeparator since text may follow the diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java index 93edff294..08c4a7007 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java @@ -11,7 +11,8 @@ package org.eclipse.equinox.bidi.internal.consumable; import org.eclipse.equinox.bidi.STextDirection; -import org.eclipse.equinox.bidi.advanced.*; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; +import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; /** @@ -62,8 +63,8 @@ public class STextRegex extends STextTypeHandler { static final byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; static final byte AN = Character.DIRECTIONALITY_ARABIC_NUMBER; static final byte EN = Character.DIRECTIONALITY_EUROPEAN_NUMBER; - private static final Integer INTEGER_1 = new Integer(1); - private static final Integer INTEGER_17 = new Integer(17); + private static final Integer STATE_COMMENT = new Integer(1); + private static final Integer STATE_QUOTED_SEQUENCE = new Integer(17); /** * This method retrieves the number of special cases handled by this handler. @@ -146,11 +147,13 @@ public class STextRegex extends STextTypeHandler { /** * This method process the special cases. */ - public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { + public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) { int location; - if (separLocation < 0) - caseNumber = ((Integer) STextState.getValueAndReset(state)).intValue(); + if (separLocation < 0) { + caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined" + expert.resetState(); + } switch (caseNumber) { case 1 : /* comment (?#...) */ if (separLocation < 0) { @@ -163,7 +166,7 @@ public class STextRegex extends STextTypeHandler { } location = text.indexOf(')', location); if (location < 0) { - STextState.setValue(state, INTEGER_1); + expert.setState(STATE_COMMENT); return text.length(); } return location + 1; @@ -203,7 +206,7 @@ public class STextRegex extends STextTypeHandler { } location = text.indexOf("\\E", location); //$NON-NLS-1$ if (location < 0) { - STextState.setValue(state, INTEGER_17); + expert.setState(STATE_QUOTED_SEQUENCE); return text.length(); } // set the charType for the "E" to L (Left to Right character) diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java index bee84c98b..c1219bcfb 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java @@ -10,7 +10,8 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.advanced.*; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; +import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; import org.eclipse.equinox.bidi.internal.STextActivator; @@ -36,8 +37,8 @@ import org.eclipse.equinox.bidi.internal.STextActivator; public class STextSql extends STextTypeHandler { private static final byte WS = Character.DIRECTIONALITY_WHITESPACE; static final String lineSep = STextActivator.getInstance().getProperty("line.separator"); //$NON-NLS-1$ - private static final Integer INTEGER_2 = new Integer(2); - private static final Integer INTEGER_4 = new Integer(4); + private static final Integer STATE_LITERAL = new Integer(2); + private static final Integer STATE_SLASH_ASTER_COMMENT = new Integer(4); public STextSql() { super("\t!#%&()*+,-./:;<=>?|[]{}"); //$NON-NLS-1$ @@ -87,12 +88,14 @@ public class STextSql extends STextTypeHandler { * <li>skip until after a line separator</li> * </ol> */ - public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { + public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) { int location; STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); - if (separLocation < 0) - caseNumber = ((Integer) STextState.getValueAndReset(state)).intValue(); + if (separLocation < 0) { + caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined" + expert.resetState(); + } switch (caseNumber) { case 1 : /* space */ separLocation++; @@ -106,7 +109,7 @@ public class STextSql extends STextTypeHandler { while (true) { location = text.indexOf('\'', location); if (location < 0) { - STextState.setValue(state, INTEGER_2); + expert.setState(STATE_LITERAL); return text.length(); } if ((location + 1) < text.length() && text.charAt(location + 1) == '\'') { @@ -135,7 +138,7 @@ public class STextSql extends STextTypeHandler { location = separLocation + 2; // skip the opening slash-aster location = text.indexOf("*/", location); //$NON-NLS-1$ if (location < 0) { - STextState.setValue(state, INTEGER_4); + expert.setState(STATE_SLASH_ASTER_COMMENT); return text.length(); } // we need to call processSeparator since text may follow the |