From 3c0f419f41d1e83256757acaeabe5564398fdb56 Mon Sep 17 00:00:00 2001 From: Markus Keller Date: Tue, 12 Mar 2013 00:07:29 +0100 Subject: Bug 380397: [bidi] Should bidi bundle version be 1.0.0 - more cleanup - removed some default structured text types: math, property, system--- .../.settings/org.eclipse.pde.prefs | 33 +++++ bundles/org.eclipse.equinox.bidi.tests/plugin.xml | 17 ++- .../tests/StructuredTextExtensionsTest.java | 23 ++-- .../bidi/internal/tests/StructuredTextMath.java | 65 ++++++++++ .../internal/tests/StructuredTextMathTest.java | 5 +- .../internal/tests/StructuredTextProperty.java | 27 ++++ .../bidi/internal/tests/StructuredTextSystem.java | 27 ++++ .../.settings/org.eclipse.pde.api.tools.prefs | 2 +- bundles/org.eclipse.equinox.bidi/plugin.properties | 5 +- bundles/org.eclipse.equinox.bidi/plugin.xml | 17 +-- .../schema/StructuredTextType.exsd | 142 --------------------- .../org.eclipse.equinox.bidi/schema/bidiTypes.exsd | 140 ++++++++++++++++++++ .../equinox/bidi/StructuredTextProcessor.java | 57 ++++----- .../bidi/StructuredTextTypeHandlerFactory.java | 46 ++----- .../bidi/advanced/StructuredTextExpertFactory.java | 7 +- .../bidi/custom/StructuredTextTypeHandler.java | 3 + .../equinox/bidi/internal/StructuredTextImpl.java | 83 ++++++------ .../internal/StructuredTextTypesCollector.java | 3 - .../internal/consumable/StructuredTextMath.java | 65 ---------- .../consumable/StructuredTextProperty.java | 27 ---- .../internal/consumable/StructuredTextSystem.java | 27 ---- 21 files changed, 418 insertions(+), 403 deletions(-) create mode 100644 bundles/org.eclipse.equinox.bidi.tests/.settings/org.eclipse.pde.prefs create mode 100644 bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMath.java create mode 100644 bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextProperty.java create mode 100644 bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextSystem.java delete mode 100644 bundles/org.eclipse.equinox.bidi/schema/StructuredTextType.exsd create mode 100644 bundles/org.eclipse.equinox.bidi/schema/bidiTypes.exsd delete mode 100644 bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextMath.java delete mode 100644 bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextProperty.java delete mode 100644 bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextSystem.java diff --git a/bundles/org.eclipse.equinox.bidi.tests/.settings/org.eclipse.pde.prefs b/bundles/org.eclipse.equinox.bidi.tests/.settings/org.eclipse.pde.prefs new file mode 100644 index 000000000..48f0b5113 --- /dev/null +++ b/bundles/org.eclipse.equinox.bidi.tests/.settings/org.eclipse.pde.prefs @@ -0,0 +1,33 @@ +compilers.f.unresolved-features=1 +compilers.f.unresolved-plugins=1 +compilers.incompatible-environment=1 +compilers.p.build=1 +compilers.p.build.bin.includes=1 +compilers.p.build.encodings=2 +compilers.p.build.java.compiler=1 +compilers.p.build.java.compliance=1 +compilers.p.build.missing.output=2 +compilers.p.build.output.library=1 +compilers.p.build.source.library=1 +compilers.p.build.src.includes=1 +compilers.p.deprecated=1 +compilers.p.discouraged-class=1 +compilers.p.internal=1 +compilers.p.matching-pom-version=0 +compilers.p.missing-packages=1 +compilers.p.missing-version-export-package=2 +compilers.p.missing-version-import-package=1 +compilers.p.missing-version-require-bundle=1 +compilers.p.no-required-att=0 +compilers.p.not-externalized-att=2 +compilers.p.unknown-attribute=1 +compilers.p.unknown-class=1 +compilers.p.unknown-element=1 +compilers.p.unknown-identifier=1 +compilers.p.unknown-resource=1 +compilers.p.unresolved-ex-points=0 +compilers.p.unresolved-import=0 +compilers.s.create-docs=false +compilers.s.doc-folder=doc +compilers.s.open-tags=1 +eclipse.preferences.version=1 diff --git a/bundles/org.eclipse.equinox.bidi.tests/plugin.xml b/bundles/org.eclipse.equinox.bidi.tests/plugin.xml index 5c9249331..ecd3ddaef 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/plugin.xml +++ b/bundles/org.eclipse.equinox.bidi.tests/plugin.xml @@ -9,7 +9,22 @@ description="Test" type="test.ID"> - + + + + + + + diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextExtensionsTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextExtensionsTest.java index 6ff0cc5d8..5641d38fa 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextExtensionsTest.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextExtensionsTest.java @@ -19,6 +19,9 @@ import org.eclipse.equinox.bidi.advanced.*; */ public class StructuredTextExtensionsTest extends StructuredTextTestBase { + private static final String PROPERTY = "property"; + private static final String SYSTEM_USER = "system"; + private StructuredTextEnvironment env = StructuredTextEnvironment.DEFAULT; private StructuredTextEnvironment envArabic = new StructuredTextEnvironment("ar", false, StructuredTextEnvironment.ORIENT_LTR); private StructuredTextEnvironment envHebrew = new StructuredTextEnvironment("he", false, StructuredTextEnvironment.ORIENT_LTR); @@ -40,7 +43,7 @@ public class StructuredTextExtensionsTest extends StructuredTextTestBase { assertEquals(label + " data = " + data, result, toPseudo(full)); } - public void testExtensions() { + public void testDefaultExtensions() { String data; expert = StructuredTextExpertFactory.getExpert(StructuredTextTypeHandlerFactory.COMMA_DELIMITED, env); @@ -78,11 +81,6 @@ public class StructuredTextExtensionsTest extends StructuredTextTestBase { doTest1("Java #9", "A = //B+C* D;", "A@ = //B+C* D;"); doTest1("Java #10", "A = //B+C`|D+E;", "A@ = //B+C`|D@+E;"); - expert = StructuredTextExpertFactory.getExpert(StructuredTextTypeHandlerFactory.PROPERTY, env); - doTest1("Property #0", "NAME,VAL1,VAL2", "NAME,VAL1,VAL2"); - doTest1("Property #1", "NAME=VAL1,VAL2", "NAME@=VAL1,VAL2"); - doTest1("Property #2", "NAME=VAL1,VAL2=VAL3", "NAME@=VAL1,VAL2=VAL3"); - expert = StructuredTextExpertFactory.getStatefulExpert(StructuredTextTypeHandlerFactory.REGEXP, env); data = toUT16("ABC(?") + "#" + toUT16("DEF)GHI"); doTest2("Regex #0.0", data, "A@B@C@(?#DEF)@G@H@I"); @@ -185,9 +183,6 @@ public class StructuredTextExtensionsTest extends StructuredTextTestBase { doTest1("SQL #12", "ABC\"DEF \"\" G I\" JKL,MN", "ABC@\"DEF \"\" G I\"@ JKL@,MN"); doTest1("SQL #13", "ABC--DEF GHI`|JKL MN", "ABC@--DEF GHI`|JKL@ MN"); - expert = StructuredTextExpertFactory.getExpert(StructuredTextTypeHandlerFactory.SYSTEM_USER, env); - doTest1("System #1", "HOST(JACK)", "HOST@(JACK)"); - expert = StructuredTextExpertFactory.getExpert(StructuredTextTypeHandlerFactory.UNDERSCORE, env); doTest1("Underscore #1", "A_B_C_d_e_F_G", "A@_B@_C_d_e_F@_G"); @@ -209,4 +204,14 @@ public class StructuredTextExtensionsTest extends StructuredTextTestBase { doTest3("DelimsEsc #6", "DEF.GHI (A\\\\):C ;JK ", "DEF@.GHI @(A\\\\)@:C @;JK "); doTest3("DelimsEsc #7", "DEF.GHI (A\\):C ;JK ", "DEF@.GHI @(A\\):C ;JK "); } + + public void testTestExtensions() { + expert = StructuredTextExpertFactory.getExpert(PROPERTY, env); + doTest1("Property #0", "NAME,VAL1,VAL2", "NAME,VAL1,VAL2"); + doTest1("Property #1", "NAME=VAL1,VAL2", "NAME@=VAL1,VAL2"); + doTest1("Property #2", "NAME=VAL1,VAL2=VAL3", "NAME@=VAL1,VAL2=VAL3"); + + expert = StructuredTextExpertFactory.getExpert(SYSTEM_USER, env); + doTest1("System #1", "HOST(JACK)", "HOST@(JACK)"); + } } diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMath.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMath.java new file mode 100644 index 000000000..210a8f619 --- /dev/null +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMath.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2010, 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.internal.tests; + +import org.eclipse.equinox.bidi.advanced.IStructuredTextExpert; +import org.eclipse.equinox.bidi.custom.StructuredTextCharTypes; +import org.eclipse.equinox.bidi.custom.StructuredTextTypeHandler; + +/** + * Handler adapted to processing arithmetic expressions with + * a possible right-to-left base direction. + */ +public class StructuredTextMath extends StructuredTextTypeHandler { + static final byte L = Character.DIRECTIONALITY_LEFT_TO_RIGHT; + static final byte R = Character.DIRECTIONALITY_RIGHT_TO_LEFT; + static final byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; + static final byte AN = Character.DIRECTIONALITY_ARABIC_NUMBER; + + public StructuredTextMath() { + super("+-/*()="); //$NON-NLS-1$ + } + + public int getDirection(IStructuredTextExpert expert, String text) { + return getDirection(expert, text, new StructuredTextCharTypes(expert, text)); + } + + /** + * @return {@link IStructuredTextExpert#DIR_RTL DIR_RTL} if the following + * conditions are satisfied: + * + * Otherwise, returns {@link IStructuredTextExpert#DIR_LTR DIR_LTR}. + */ + public int getDirection(IStructuredTextExpert expert, String text, StructuredTextCharTypes charTypes) { + String language = expert.getEnvironment().getLanguage(); + if (!language.equals("ar")) //$NON-NLS-1$ + return IStructuredTextExpert.DIR_LTR; + boolean flagAN = false; + for (int i = 0; i < text.length(); i++) { + byte charType = charTypes.getBidiTypeAt(i); + if (charType == AL) + return IStructuredTextExpert.DIR_RTL; + if (charType == L || charType == R) + return IStructuredTextExpert.DIR_LTR; + if (charType == AN) + flagAN = true; + } + if (flagAN) + return IStructuredTextExpert.DIR_RTL; + return IStructuredTextExpert.DIR_LTR; + } +} diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMathTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMathTest.java index 2505cd6f9..d2aad261a 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMathTest.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextMathTest.java @@ -11,7 +11,6 @@ package org.eclipse.equinox.bidi.internal.tests; -import org.eclipse.equinox.bidi.StructuredTextTypeHandlerFactory; import org.eclipse.equinox.bidi.advanced.*; /** @@ -22,8 +21,8 @@ public class StructuredTextMathTest extends StructuredTextTestBase { private StructuredTextEnvironment envLTR = new StructuredTextEnvironment("ar", false, StructuredTextEnvironment.ORIENT_LTR); private StructuredTextEnvironment envRTL = new StructuredTextEnvironment("ar", false, StructuredTextEnvironment.ORIENT_RTL); - private IStructuredTextExpert expertLTR = StructuredTextExpertFactory.getExpert(StructuredTextTypeHandlerFactory.MATH, envLTR); - private IStructuredTextExpert expertRTL = StructuredTextExpertFactory.getExpert(StructuredTextTypeHandlerFactory.MATH, envRTL); + private IStructuredTextExpert expertLTR = StructuredTextExpertFactory.getStatefulExpert(new StructuredTextMath(), envLTR); + private IStructuredTextExpert expertRTL = StructuredTextExpertFactory.getStatefulExpert(new StructuredTextMath(), envRTL); private void verifyOneLine(String msg, String data, String resLTR, String resRTL) { String lean = toUT16(data); diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextProperty.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextProperty.java new file mode 100644 index 000000000..3ae72696b --- /dev/null +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextProperty.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010, 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.internal.tests; + +import org.eclipse.equinox.bidi.internal.StructuredTextSingle; + +/** + * Handler adapted to processing property file statements. + * It expects the following string format: + *
+ *    name=value
+ *  
+ */ +public class StructuredTextProperty extends StructuredTextSingle { + + public StructuredTextProperty() { + super("="); //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextSystem.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextSystem.java new file mode 100644 index 000000000..82173dad7 --- /dev/null +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/StructuredTextSystem.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010, 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.internal.tests; + +import org.eclipse.equinox.bidi.internal.StructuredTextSingle; + +/** + * Handler adapted to processing structured text with the following format: + *
+ *    system(user)
+ *  
+ */ +public class StructuredTextSystem extends StructuredTextSingle { + + public StructuredTextSystem() { + super("("); //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.equinox.bidi/.settings/org.eclipse.pde.api.tools.prefs b/bundles/org.eclipse.equinox.bidi/.settings/org.eclipse.pde.api.tools.prefs index 249808520..7387d4266 100644 --- a/bundles/org.eclipse.equinox.bidi/.settings/org.eclipse.pde.api.tools.prefs +++ b/bundles/org.eclipse.equinox.bidi/.settings/org.eclipse.pde.api.tools.prefs @@ -60,7 +60,7 @@ INTERFACE_ELEMENT_TYPE_REMOVED_FIELD=Ignore INTERFACE_ELEMENT_TYPE_REMOVED_METHOD=Ignore INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Ignore INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Ignore -INVALID_JAVADOC_TAG=Ignore +INVALID_JAVADOC_TAG=Error INVALID_REFERENCE_IN_SYSTEM_LIBRARIES=Error LEAK_EXTEND=Warning LEAK_FIELD_DECL=Warning diff --git a/bundles/org.eclipse.equinox.bidi/plugin.properties b/bundles/org.eclipse.equinox.bidi/plugin.properties index 5bb3e28ec..aca3d2be4 100644 --- a/bundles/org.eclipse.equinox.bidi/plugin.properties +++ b/bundles/org.eclipse.equinox.bidi/plugin.properties @@ -10,18 +10,15 @@ ############################################################################### pluginName = Bidirectional Text Support providerName = Eclipse.org - Equinox -bidiExpressionPointName = Add new structured text type +bidiExtensionPointName = Bidi structured text types bidiExtensionName = Default bidirectional processors commaProcessorName = Processor for comma-separated lists emailProcessorName = Processor for E-mail addresses fileProcessorName = Processor for file and directory names javaProcessorName = Processor for Java statements -mathProcessorName = Processor for arithmetic expressions -propertyProcessorName = Processor for property file lines regexProcessorName = Processor for regular expressions sqlProcessorName = Processor for SQL statements -systemProcessorName = Processor for system(user) statements underscoreProcessorName = Processor for names segmented by underscores urlProcessorName = Processor for URLs xpathProcessorName = Processor for XPath expressions diff --git a/bundles/org.eclipse.equinox.bidi/plugin.xml b/bundles/org.eclipse.equinox.bidi/plugin.xml index 4db67dd65..5df58f40a 100644 --- a/bundles/org.eclipse.equinox.bidi/plugin.xml +++ b/bundles/org.eclipse.equinox.bidi/plugin.xml @@ -1,7 +1,7 @@ - + - - - - - - - - - - - - - - Use this extension point to describe processing for strings that need special bidirectional handling, such as file paths, SQL statements, or Java code. - - - - - - - - - - - - - - - - - - - - - - - - Unique identifier of this extension - - - - - - - - - - - - - - - - - - - - - - Type of the structured text that this processor will work on. - - - - - - - The processor that provides specialized bidirectional handling for this type of strings. - - - - - - - - - - The description of the string type. - - - - - - - - - - - - - - - 1.0 - - - - - - - - - A processor for the structured text strings that support "minus" delimiters can be described as: - -<pre> -public class StructuredTextSepMinus extends StructuredTextProcessor -{ - public StructuredTextSepMinus() - { - super("-"); - } -} -</pre> - - - - - - - - - TBD - - - - - - - - - All the classes mentioned as Examples - - - - - - - - - Copyright (c) 2011 IBM Corporation and others.<br> -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 -<a -href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> - - - - diff --git a/bundles/org.eclipse.equinox.bidi/schema/bidiTypes.exsd b/bundles/org.eclipse.equinox.bidi/schema/bidiTypes.exsd new file mode 100644 index 000000000..f457bdcde --- /dev/null +++ b/bundles/org.eclipse.equinox.bidi/schema/bidiTypes.exsd @@ -0,0 +1,140 @@ + + + + + + + + + Use this extension point to describe processing for strings that need special bidirectional handling, such as file paths, SQL statements, or Java code. + + + + + + + + + + + + + + + + + + + + + + + + Unique identifier of this extension + + + + + + + + + + + + + + + + + + + + + + Type of the structured text that this processor will work on. + + + + + + + The processor that provides specialized bidirectional handling for this type of strings. + + + + + + + + + + The description of the string type. + + + + + + + + + + + + + + + 0.10 + + + + + + + + + A processor for the structured text strings that support "minus" delimiters can be described as: + +<pre> +public class StructuredTextSepMinus extends StructuredTextTypeHandler { + public StructuredTextSepMinus() { + super("-"); + } +} +</pre> + + + + + + + + + TBD + + + + + + + + + All the classes mentioned as Examples + + + + + + + + + Copyright (c) 2011 IBM Corporation and others.<br> +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 +<a +href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> + + + + diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextProcessor.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextProcessor.java index 27aa08e6a..59190f1c1 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextProcessor.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextProcessor.java @@ -14,19 +14,18 @@ import org.eclipse.equinox.bidi.advanced.*; import org.eclipse.equinox.bidi.custom.StructuredTextTypeHandler; /** - * Provides methods to process bidirectional text with a specific - * structure. The methods in this class are the most straightforward - * way to add directional formatting characters to the source text to - * ensure correct presentation, or to remove those characters to - * restore the original text - * (for more explanations, please see the - * package documentation). + * Provides methods to process bidirectional text with a specific + * structure. The methods in this class are the most straightforward + * way to add directional formatting characters to the source text to + * ensure correct presentation, or to remove those characters to + * restore the original text + * (for more explanations, please see the + * {@link org.eclipse.equinox.bidi package documentation}. *

* This class can be used without OSGi running (but only the structured text types declared * in {@link StructuredTextTypeHandlerFactory} are available in that mode). *

* - * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. */ public final class StructuredTextProcessor { @@ -57,25 +56,25 @@ public final class StructuredTextProcessor { } /** - * Processes the given (lean) text and returns a string with appropriate - * directional formatting characters (full text). This is equivalent to - * calling {@link #process(String str, String separators)} with the default - * set of separators. - *

- * The processing adds directional formatting characters so that presentation - * using the Unicode Bidirectional Algorithm will provide the expected result. - * The text is segmented according to the provided separators. - * Each segment has the Unicode Bidi Algorithm applied to it, - * but as a whole, the string is oriented left to right. - *

- * For example, a file path such as d:\myfolder\FOLDER\MYFILE.java - * (where capital letters indicate RTL text) should render as - * d:\myfolder\REDLOF\ELIFYM.java. - *

- * - * @param str the lean text to process. + * Processes the given (lean) text and returns a string with appropriate + * directional formatting characters (full text). This is equivalent to + * calling {@link #process(String str, String separators)} with the default + * set of separators. + *

+ * The processing adds directional formatting characters so that presentation + * using the Unicode Bidirectional Algorithm will provide the expected result. + * The text is segmented according to the provided separators. + * Each segment has the Unicode Bidi Algorithm applied to it, + * but as a whole, the string is oriented left to right. + *

+ * For example, a file path such as d:\myfolder\FOLDER\MYFILE.java + * (where capital letters indicate RTL text) should render as + * d:\myfolder\REDLOF\ELIFYM.java. + *

+ * + * @param str the lean text to process * - * @return the processed string (full text). + * @return the processed string (full text) * * @see #deprocess(String) */ @@ -88,10 +87,10 @@ public final class StructuredTextProcessor { * it correctly on bidi locales. * For more details, see {@link #process(String)}. * - * @param str the lean text to process. - * @param separators characters by which the string will be segmented. + * @param str the lean text to process + * @param separators characters by which the string will be segmented * - * @return the processed string (full text). + * @return the processed string (full text) * * @see #deprocess(String) */ diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextTypeHandlerFactory.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextTypeHandlerFactory.java index 62e494eef..74410f4f6 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextTypeHandlerFactory.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/StructuredTextTypeHandlerFactory.java @@ -34,7 +34,7 @@ import org.eclipse.equinox.bidi.internal.StructuredTextTypesCollector; * {@link StructuredTextExpertFactory#getStatefulExpert(StructuredTextTypeHandler, StructuredTextEnvironment)}. *

* This class can be used without OSGi running, but only the structured text types declared - * in {@link StructuredTextTypeHandlerFactory} and as string constants in this class are available in that mode. + * as string constants in this class are available in that mode. *

* * @noinstantiate This class is not intended to be instantiated by clients. @@ -65,24 +65,6 @@ public final class StructuredTextTypeHandlerFactory { */ public static final String JAVA = "java"; //$NON-NLS-1$ - /** - * Structured text handler identifier for basic arithmetic expressions. - *

- * Currently supported operators are: +-/*()= - *

- * This set my be extended in the future. - *

- */ - public static final String MATH = "math"; //$NON-NLS-1$ - - /** - * Structured text handler identifier for property file statements. It expects the following format: - *

-	 *  name=value
-	 * 
- */ - public static final String PROPERTY = "property"; //$NON-NLS-1$ - /** * Structured text handler identifier for regular expressions, * possibly spanning multiple lines. @@ -95,14 +77,6 @@ public final class StructuredTextTypeHandlerFactory { */ public static final String SQL = "sql"; //$NON-NLS-1$ - /** - * Structured text handler identifier for strings with the following format: - *
-	 *  system(user)
-	 * 
- */ - public static final String SYSTEM_USER = "system"; //$NON-NLS-1$ - /** * Structured text handler identifier for compound names. It expects text to be made of one or more * parts separated by underscores: @@ -132,12 +106,18 @@ public final class StructuredTextTypeHandlerFactory { } /** - * Obtains a structured text handler of a given type. - * - * @param id the string identifying a structured text handler. - * - * @return a handler of the required type, or null - * if the type is unknown. + * Obtains a structured text handler of a given type. + * + * Supported type ids are: + *
    + *
  • the String constants in {@link StructuredTextTypeHandlerFactory}
  • + *
  • if OSGi is running, the types that have been contributed to the + * org.eclipse.equinox.bidi.bidiTypes extension point.
  • + *
+ * + * @param id the string identifying a structured text handler + * @return a handler of the required type, or null + * if the type is unknown */ static public StructuredTextTypeHandler getHandler(String id) { return StructuredTextTypesCollector.getInstance().getHandler(id); diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/StructuredTextExpertFactory.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/StructuredTextExpertFactory.java index 36c1a31f0..bd1f5fe91 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/StructuredTextExpertFactory.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/StructuredTextExpertFactory.java @@ -191,11 +191,12 @@ final public class StructuredTextExpertFactory { * null, in which case the * {@link StructuredTextEnvironment#DEFAULT} * environment should be assumed. - * @return the IStructuredTextExpert instance. - * @throws IllegalArgumentException if type is not a known type - * identifier. + * @return the IStructuredTextExpert instance + * @throws IllegalArgumentException if the handler is null */ static public IStructuredTextExpert getStatefulExpert(StructuredTextTypeHandler handler, StructuredTextEnvironment environment) { + if (handler == null) + throw new IllegalArgumentException("handler must not be null"); //$NON-NLS-1$ if (environment == null) environment = StructuredTextEnvironment.DEFAULT; return new StructuredTextImpl(handler, environment, true); diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/StructuredTextTypeHandler.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/StructuredTextTypeHandler.java index e73549cc8..2da3b23c7 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/StructuredTextTypeHandler.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/StructuredTextTypeHandler.java @@ -360,4 +360,7 @@ public class StructuredTextTypeHandler { return false; } + public String toString() { + return super.toString() + " [" + separators + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } } diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextImpl.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextImpl.java index 790395a76..435385c27 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextImpl.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextImpl.java @@ -204,46 +204,46 @@ public class StructuredTextImpl implements IStructuredTextExpert { } /** - * When the orientation is ORIENT_LTR and the - * structured text has a RTL base direction, - * {@link IStructuredTextExpert#leanToFullText leanToFullText} - * adds RLE+RLM at the head of the full text and RLM+PDF at its - * end. - *

- * When the orientation is ORIENT_RTL and the - * structured text has a LTR base direction, - * {@link IStructuredTextExpert#leanToFullText leanToFullText} - * adds LRE+LRM at the head of the full text and LRM+PDF at its - * end. - *

- * When the orientation is ORIENT_CONTEXTUAL_LTR or - * ORIENT_CONTEXTUAL_RTL and the data content would resolve - * to a RTL orientation while the structured text has a LTR base - * direction, {@link IStructuredTextExpert#leanToFullText leanToFullText} - * adds LRM at the head of the full text. - *

- * When the orientation is ORIENT_CONTEXTUAL_LTR or - * ORIENT_CONTEXTUAL_RTL and the data content would resolve - * to a LTR orientation while the structured text has a RTL base - * direction, {@link IStructuredTextExpert#leanToFullText leanToFullText} - * adds RLM at the head of the full text. - *

- * When the orientation is ORIENT_UNKNOWN and the - * structured text has a LTR base direction, - * {@link IStructuredTextExpert#leanToFullText leanToFullText} - * adds LRE+LRM at the head of the full text and LRM+PDF at its - * end. - *

- * When the orientation is ORIENT_UNKNOWN and the - * structured text has a RTL base direction, - * {@link IStructuredTextExpert#leanToFullText leanToFullText} - * adds RLE+RLM at the head of the full text and RLM+PDF at its - * end. - *

- * When the orientation is ORIENT_IGNORE, - * {@link IStructuredTextExpert#leanToFullText leanToFullText} does not add any directional - * formatting characters as either prefix or suffix of the full text. - *

+ * When the orientation is ORIENT_LTR and the + * structured text has a RTL base direction, + * {@link IStructuredTextExpert#leanToFullText leanToFullText} + * adds RLE+RLM at the head of the full text and RLM+PDF at its + * end. + *

+ * When the orientation is ORIENT_RTL and the + * structured text has a LTR base direction, + * {@link IStructuredTextExpert#leanToFullText leanToFullText} + * adds LRE+LRM at the head of the full text and LRM+PDF at its + * end. + *

+ * When the orientation is ORIENT_CONTEXTUAL_LTR or + * ORIENT_CONTEXTUAL_RTL and the data content would resolve + * to a RTL orientation while the structured text has a LTR base + * direction, {@link IStructuredTextExpert#leanToFullText leanToFullText} + * adds LRM at the head of the full text. + *

+ * When the orientation is ORIENT_CONTEXTUAL_LTR or + * ORIENT_CONTEXTUAL_RTL and the data content would resolve + * to a LTR orientation while the structured text has a RTL base + * direction, {@link IStructuredTextExpert#leanToFullText leanToFullText} + * adds RLM at the head of the full text. + *

+ * When the orientation is ORIENT_UNKNOWN and the + * structured text has a LTR base direction, + * {@link IStructuredTextExpert#leanToFullText leanToFullText} + * adds LRE+LRM at the head of the full text and LRM+PDF at its + * end. + *

+ * When the orientation is ORIENT_UNKNOWN and the + * structured text has a RTL base direction, + * {@link IStructuredTextExpert#leanToFullText leanToFullText} + * adds RLE+RLM at the head of the full text and RLM+PDF at its + * end. + *

+ * When the orientation is ORIENT_IGNORE, + * {@link IStructuredTextExpert#leanToFullText leanToFullText} does not add any directional + * formatting characters as either prefix or suffix of the full text. + *

*/ public String leanToFullText(String text) { int len = text.length(); @@ -542,4 +542,7 @@ public class StructuredTextImpl implements IStructuredTextExpert { return new String(fullChars); } + public String toString() { + return super.toString() + " [handler=" + handler.toString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } } diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextTypesCollector.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextTypesCollector.java index ed5f4bd7b..1d702bbc1 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextTypesCollector.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/StructuredTextTypesCollector.java @@ -144,11 +144,8 @@ public class StructuredTextTypesCollector implements IRegistryEventListener { types.put(StructuredTextTypeHandlerFactory.EMAIL, new StructuredTextEmail()); types.put(StructuredTextTypeHandlerFactory.FILE, new StructuredTextFile()); types.put(StructuredTextTypeHandlerFactory.JAVA, new StructuredTextJava()); - types.put(StructuredTextTypeHandlerFactory.MATH, new StructuredTextMath()); - types.put(StructuredTextTypeHandlerFactory.PROPERTY, new StructuredTextProperty()); types.put(StructuredTextTypeHandlerFactory.REGEXP, new StructuredTextRegex()); types.put(StructuredTextTypeHandlerFactory.SQL, new StructuredTextSql()); - types.put(StructuredTextTypeHandlerFactory.SYSTEM_USER, new StructuredTextSystem()); types.put(StructuredTextTypeHandlerFactory.UNDERSCORE, new StructuredTextUnderscore()); types.put(StructuredTextTypeHandlerFactory.URL, new StructuredTextURL()); types.put(StructuredTextTypeHandlerFactory.XPATH, new StructuredTextXPath()); diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextMath.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextMath.java deleted file mode 100644 index bae7763fa..000000000 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextMath.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 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.internal.consumable; - -import org.eclipse.equinox.bidi.advanced.IStructuredTextExpert; -import org.eclipse.equinox.bidi.custom.StructuredTextCharTypes; -import org.eclipse.equinox.bidi.custom.StructuredTextTypeHandler; - -/** - * Handler adapted to processing arithmetic expressions with - * a possible right-to-left base direction. - */ -public class StructuredTextMath extends StructuredTextTypeHandler { - static final byte L = Character.DIRECTIONALITY_LEFT_TO_RIGHT; - static final byte R = Character.DIRECTIONALITY_RIGHT_TO_LEFT; - static final byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; - static final byte AN = Character.DIRECTIONALITY_ARABIC_NUMBER; - - public StructuredTextMath() { - super("+-/*()="); //$NON-NLS-1$ - } - - public int getDirection(IStructuredTextExpert expert, String text) { - return getDirection(expert, text, new StructuredTextCharTypes(expert, text)); - } - - /** - * @return {@link IStructuredTextExpert#DIR_RTL DIR_RTL} if the following - * conditions are satisfied: - *

    - *
  • The current locale (as expressed by the environment - * language) is Arabic.
  • - *
  • The first strong character is an Arabic letter.
  • - *
  • If there is no strong character in the text, there is - * at least one Arabic-Indic digit in the text.
  • - *
- * Otherwise, returns {@link IStructuredTextExpert#DIR_LTR DIR_LTR}. - */ - public int getDirection(IStructuredTextExpert expert, String text, StructuredTextCharTypes charTypes) { - String language = expert.getEnvironment().getLanguage(); - if (!language.equals("ar")) //$NON-NLS-1$ - return IStructuredTextExpert.DIR_LTR; - boolean flagAN = false; - for (int i = 0; i < text.length(); i++) { - byte charType = charTypes.getBidiTypeAt(i); - if (charType == AL) - return IStructuredTextExpert.DIR_RTL; - if (charType == L || charType == R) - return IStructuredTextExpert.DIR_LTR; - if (charType == AN) - flagAN = true; - } - if (flagAN) - return IStructuredTextExpert.DIR_RTL; - return IStructuredTextExpert.DIR_LTR; - } -} diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextProperty.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextProperty.java deleted file mode 100644 index 54ead37ce..000000000 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextProperty.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 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.internal.consumable; - -import org.eclipse.equinox.bidi.internal.StructuredTextSingle; - -/** - * Handler adapted to processing property file statements. - * It expects the following string format: - *
- *    name=value
- *  
- */ -public class StructuredTextProperty extends StructuredTextSingle { - - public StructuredTextProperty() { - super("="); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextSystem.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextSystem.java deleted file mode 100644 index a2b6373e2..000000000 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/StructuredTextSystem.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 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.internal.consumable; - -import org.eclipse.equinox.bidi.internal.StructuredTextSingle; - -/** - * Handler adapted to processing structured text with the following format: - *
- *    system(user)
- *  
- */ -public class StructuredTextSystem extends StructuredTextSingle { - - public StructuredTextSystem() { - super("("); //$NON-NLS-1$ - } - -} -- cgit v1.2.3