Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 201469 Details for
Bug 183164
[Implementation for] Display of Complex Expressions Containing Bidirectional Text
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
CHange state to Object
patch_bidi_20110814C.txt (text/plain), 19.17 KB, created by
Matitiahu Allouche
on 2011-08-14 00:35:29 EDT
(
hide
)
Description:
CHange state to Object
Filename:
MIME Type:
Creator:
Matitiahu Allouche
Created:
2011-08-14 00:35:29 EDT
Size:
19.17 KB
patch
obsolete
>diff --git src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java >index e1b986f..a5dfe98 100644 >--- src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java >+++ src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java >@@ -61,8 +61,7 @@ > * code in order to obtain the <i>full</i> > * text corresponding to the <i>lean</i> text of each line. > * <pre> >- * int[] state = new int[1]; >- * state[0] = STextEngine.STATE_INITIAL; >+ * Object state = STextState.createState(); > * String leanText = "int i = 3; // first Java statement"; > * String fullText = STextEngine.leanToFullText(STextEngine.PROC_JAVA, null, leanText, state); > * System.out.println("full text = " + fullText); >diff --git src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java >index cebf2fd..befbd20 100644 >--- src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java >+++ src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java >@@ -12,9 +12,9 @@ > > public interface ISTextExpertStateful extends ISTextExpert { > >- public void setState(int state); >+ public void setState(Object state); > >- public int getState(); >+ public Object getState(); > > /** > * Resets non-shared expert state to initial. >diff --git src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java >index 220de73..fdf6aaa 100644 >--- src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java >+++ src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java >@@ -77,7 +77,7 @@ > } > > static public ISTextExpert getExpert(STextTypeHandler handler, STextEnvironment environment) { >- return new STextImpl(handler, environment, new int[1]); >+ return new STextImpl(handler, environment, STextState.createState()); > } > > static public ISTextExpertStateful getPrivateExpert(String type) { >@@ -88,7 +88,7 @@ > STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type); > if (handler == null) > return null; >- return new STextImpl(handler, environment, new int[1]); >+ return new STextImpl(handler, environment, STextState.createState()); > } > > } >diff --git src/org/eclipse/equinox/bidi/advanced/STextState.java src/org/eclipse/equinox/bidi/advanced/STextState.java >new file mode 0 >index 0000000..e1dbdbd 0 >--- /dev/null >+++ src/org/eclipse/equinox/bidi/advanced/STextState.java >@@ -0,0 +1,37 @@ >+package org.eclipse.equinox.bidi.advanced; >+ >+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 src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java >index 993033e..846d70b 100644 >--- src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java >+++ src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java >@@ -210,7 +210,7 @@ > * 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, int[] state, int caseNumber, int separLocation) { >+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, 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 src/org/eclipse/equinox/bidi/internal/STextDelims.java src/org/eclipse/equinox/bidi/internal/STextDelims.java >index ce86629..bcddf10 100644 >--- src/org/eclipse/equinox/bidi/internal/STextDelims.java >+++ src/org/eclipse/equinox/bidi/internal/STextDelims.java >@@ -58,7 +58,7 @@ > * @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, int[] state, int caseNumber, int separLocation) { >+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { > STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); > int loc = separLocation + 1; > char delim = getDelimiters().charAt((caseNumber * 2) - 1); >diff --git src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java >index 3f81242..49552f2 100644 >--- src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java >+++ src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java >@@ -49,7 +49,7 @@ > * and skips until after the matching end delimiter, > * ignoring possibly escaped end delimiters. > */ >- public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) { >+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { > STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); > int location = separLocation + 1; > char delim = getDelimiters().charAt((caseNumber * 2) - 1); >diff --git src/org/eclipse/equinox/bidi/internal/STextImpl.java src/org/eclipse/equinox/bidi/internal/STextImpl.java >index 1137826..a004be1 100644 >--- src/org/eclipse/equinox/bidi/internal/STextImpl.java >+++ src/org/eclipse/equinox/bidi/internal/STextImpl.java >@@ -46,13 +46,12 @@ > static final int FIXES_LENGTH = PREFIX_LENGTH + SUFFIX_LENGTH; > static final int[] EMPTY_INT_ARRAY = new int[0]; > static final STextEnvironment IGNORE_ENVIRONMENT = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE); >- static final int STATE_INITIAL = 0; > > protected STextTypeHandler structuredTextHandler; > protected STextEnvironment environment; >- protected int[] state; >+ protected Object state; > >- public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, int[] state) { >+ public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, Object state) { > this.structuredTextHandler = structuredTextHandler; > this.environment = environment; > this.state = state; >@@ -87,20 +86,21 @@ > } > > public void resetState() { >- state[0] = STATE_INITIAL; >+ STextState.setValue(state, null); > } > >- public void setState(int newState) { >- state[0] = newState; >+ public void setState(Object newState) { >+ STextState.setValue(state, newState); > } > >- public static void setState(int[] state, int newState) { >- if (state != null) >- state[0] = newState; >+ public static void setState(Object state, Object newState) { >+ STextState.setValue(state, newState); > } > >- public int getState() { >- return state[0]; >+ public Object getState() { >+ Object value = STextState.getValueAndReset(state); >+ STextState.setValue(state, value); >+ return value; > } > > static long computeNextLocation(STextTypeHandler handler, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) { >@@ -243,7 +243,7 @@ > * <p> > * @see ISTextExpert#leanToFullText STextEngine.leanToFullText > */ >- public static String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { >+ public static String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { > int len = text.length(); > if (len == 0) > return text; >@@ -290,7 +290,7 @@ > return new String(fullChars); > } > >- public static int[] leanToFullMap(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { >+ public static 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 @@ > return map; > } > >- public static int[] leanBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { >+ public static 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 @@ > return offsets.getArray(); > } > >- static STextOffsets leanToFullCommon(STextTypeHandler handler, STextEnvironment environment, String text, int[] state, STextCharTypes charTypes) { >+ static 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,11 @@ > } > // current position > int curPos = 0; >- if (state != null && state[0] > STATE_INITIAL) { >+ Object value; >+ if (state != null && (value = STextState.getValueAndReset(state)) != null) { >+ STextState.setValue(state, value); // restore the value > offsets.ensureRoom(); >- int initState = state[0]; >- state[0] = STATE_INITIAL; >- curPos = handler.processSpecial(environment, text, charTypes, offsets, state, initState, -1); >+ curPos = handler.processSpecial(environment, text, charTypes, offsets, state, 0, -1); > } > while (true) { > // location of next token to handle >@@ -379,7 +379,7 @@ > return offsets; > } > >- public static String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { >+ public static String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { > if (text.length() == 0) > return text; > if (environment == null) >@@ -467,7 +467,7 @@ > return lean; > } > >- public static int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, int[] state) { >+ public static int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { > int lenFull = full.length(); > if (lenFull == 0) > return EMPTY_INT_ARRAY; >@@ -498,7 +498,7 @@ > return map; > } > >- public static int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, int[] state) { >+ public static int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { > int lenFull = full.length(); > if (lenFull == 0) > return EMPTY_INT_ARRAY; >diff --git src/org/eclipse/equinox/bidi/internal/STextSingle.java src/org/eclipse/equinox/bidi/internal/STextSingle.java >index 3ea4d4a..d4ff00e 100644 >--- src/org/eclipse/equinox/bidi/internal/STextSingle.java >+++ src/org/eclipse/equinox/bidi/internal/STextSingle.java >@@ -50,7 +50,7 @@ > * > * @return the length of <code>text</code>. > */ >- public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) { >+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { > STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); > return text.length(); > } >diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java >index 5e3d49c..fa8e702 100644 >--- src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java >+++ src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java >@@ -10,11 +10,9 @@ > ******************************************************************************/ > package org.eclipse.equinox.bidi.internal.consumable; > >-import org.eclipse.equinox.bidi.advanced.ISTextExpert; >-import org.eclipse.equinox.bidi.advanced.STextEnvironment; >+import org.eclipse.equinox.bidi.advanced.*; > import org.eclipse.equinox.bidi.custom.*; > import org.eclipse.equinox.bidi.internal.STextActivator; >-import org.eclipse.equinox.bidi.internal.STextImpl; > > /** > * <code>STextJava</code> is a handler for structured text >@@ -38,6 +36,7 @@ > 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); > > public STextJava() { > super("[](){}.+-<>=~!&*/%^|?:,;\t"); //$NON-NLS-1$ >@@ -83,10 +82,12 @@ > * <li>skip until after a line separator</li> > * </ol> > */ >- public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) { >+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { > int location, counter, i; > > STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); >+ if (separLocation < 0) >+ caseNumber = ((Integer) STextState.getValueAndReset(state)).intValue(); > switch (caseNumber) { > case 1 : /* space */ > separLocation++; >@@ -115,7 +116,7 @@ > location = separLocation + 2; // skip the opening slash-aster > location = text.indexOf("*/", location); //$NON-NLS-1$ > if (location < 0) { >- STextImpl.setState(state, caseNumber); >+ STextState.setValue(state, INTEGER_3); > return text.length(); > } > // we need to call processSeparator since text may follow the >diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java >index 4816d4e..93edff2 100644 >--- src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java >+++ src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java >@@ -11,10 +11,8 @@ > package org.eclipse.equinox.bidi.internal.consumable; > > import org.eclipse.equinox.bidi.STextDirection; >-import org.eclipse.equinox.bidi.advanced.ISTextExpert; >-import org.eclipse.equinox.bidi.advanced.STextEnvironment; >+import org.eclipse.equinox.bidi.advanced.*; > import org.eclipse.equinox.bidi.custom.*; >-import org.eclipse.equinox.bidi.internal.STextImpl; > > /** > * <code>STextRegex</code> is a handler for regular expressions. >@@ -64,6 +62,8 @@ > 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); > > /** > * This method retrieves the number of special cases handled by this handler. >@@ -146,9 +146,11 @@ > /** > * This method process the special cases. > */ >- public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) { >+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { > int location; > >+ if (separLocation < 0) >+ caseNumber = ((Integer) STextState.getValueAndReset(state)).intValue(); > switch (caseNumber) { > case 1 : /* comment (?#...) */ > if (separLocation < 0) { >@@ -161,7 +163,7 @@ > } > location = text.indexOf(')', location); > if (location < 0) { >- STextImpl.setState(state, caseNumber); >+ STextState.setValue(state, INTEGER_1); > return text.length(); > } > return location + 1; >@@ -201,7 +203,7 @@ > } > location = text.indexOf("\\E", location); //$NON-NLS-1$ > if (location < 0) { >- STextImpl.setState(state, caseNumber); >+ STextState.setValue(state, INTEGER_17); > return text.length(); > } > // set the charType for the "E" to L (Left to Right character) >diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java >index 3b74b43..bee84c9 100644 >--- src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java >+++ src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java >@@ -10,11 +10,9 @@ > ******************************************************************************/ > package org.eclipse.equinox.bidi.internal.consumable; > >-import org.eclipse.equinox.bidi.advanced.ISTextExpert; >-import org.eclipse.equinox.bidi.advanced.STextEnvironment; >+import org.eclipse.equinox.bidi.advanced.*; > import org.eclipse.equinox.bidi.custom.*; > import org.eclipse.equinox.bidi.internal.STextActivator; >-import org.eclipse.equinox.bidi.internal.STextImpl; > > /** > * <code>STextSql</code> is a handler for structured text >@@ -38,6 +36,8 @@ > 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); > > public STextSql() { > super("\t!#%&()*+,-./:;<=>?|[]{}"); //$NON-NLS-1$ >@@ -87,10 +87,12 @@ > * <li>skip until after a line separator</li> > * </ol> > */ >- public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) { >+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, Object state, int caseNumber, int separLocation) { > int location; > > STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); >+ if (separLocation < 0) >+ caseNumber = ((Integer) STextState.getValueAndReset(state)).intValue(); > switch (caseNumber) { > case 1 : /* space */ > separLocation++; >@@ -104,7 +106,7 @@ > while (true) { > location = text.indexOf('\'', location); > if (location < 0) { >- STextImpl.setState(state, caseNumber); >+ STextState.setValue(state, INTEGER_2); > return text.length(); > } > if ((location + 1) < text.length() && text.charAt(location + 1) == '\'') { >@@ -133,7 +135,7 @@ > location = separLocation + 2; // skip the opening slash-aster > location = text.indexOf("*/", location); //$NON-NLS-1$ > if (location < 0) { >- STextImpl.setState(state, caseNumber); >+ STextState.setValue(state, INTEGER_4); > return text.length(); > } > // we need to call processSeparator since text may follow the
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
ob1.eclipse
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 183164
:
148967
|
157821
|
158092
|
158531
|
160015
|
160017
|
160081
|
160698
|
160858
|
162228
|
162229
|
164476
|
186038
|
186054
|
186488
|
186490
|
188406
|
188407
|
188408
|
188627
|
194078
|
194079
|
195082
|
195084
|
196575
|
196576
|
199068
|
199070
|
199113
|
199855
|
200008
|
200389
|
200629
|
200630
|
200631
|
200742
|
200743
|
200803
|
200805
|
200905
|
200907
|
201464
|
201465
|
201467
|
201468
| 201469 |
201470
|
201676
|
201677
|
201785
|
201787
|
202172
|
202173
|
205767
|
205768
|
206588
|
210657