Skip to content

Commit

Permalink
Format java files in o.e.equinox.bidi
Browse files Browse the repository at this point in the history
This was achieved by running:
eclipse -consolelog -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
  -config .settings/org.eclipse.jdt.core.prefs . -data `mktemp -d`

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson committed Oct 1, 2023
1 parent 9472ed8 commit a4422c2
Show file tree
Hide file tree
Showing 24 changed files with 1,254 additions and 1,183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
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
* {@link org.eclipse.equinox.bidi 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}.
* <p>
* This class can be used without OSGi running (but only the structured text types declared
* in {@link StructuredTextTypeHandlerFactory} are available in that mode).
* This class can be used without OSGi running (but only the structured text
* types declared in {@link StructuredTextTypeHandlerFactory} are available in
* that mode).
* </p>
*
* @noinstantiate This class is not intended to be instantiated by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public final class StructuredTextProcessor {

/**
* The default set of separators used to segment a string: dot,
* colon, slash, backslash.
* The default set of separators used to segment a string: dot, colon, slash,
* backslash.
*/
private static final String defaultSeparators = ".:/\\"; //$NON-NLS-1$

Expand All @@ -60,23 +60,24 @@ private StructuredTextProcessor() {

/**
* Processes the given (<i>lean</i>) text and returns a string with appropriate
* directional formatting characters (<i>full</i> text). This is equivalent to
* calling {@link #process(String str, String separators)} with the default
* set of separators.
* directional formatting characters (<i>full</i> text). This is equivalent to
* calling {@link #process(String str, String separators)} with the default set
* of separators.
* <p>
* The processing adds directional formatting characters so that presentation
* 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.
* </p><p>
* 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.
* </p>
* <p>
* For example, a file path such as <code>d:\myfolder\FOLDER\MYFILE.java</code>
* (where capital letters indicate RTL text) should render as
* <code>d:\myfolder\REDLOF\ELIFYM.java</code>.
* </p>
*
* @param str the <i>lean</i> text to process
*
*
* @return the processed string (<i>full</i> text)
*
* @see #deprocess(String)
Expand All @@ -86,11 +87,11 @@ public static String process(String str) {
}

/**
* Processes a string that has a particular semantic meaning to render
* it correctly in bidi environments.
* For more details, see {@link #process(String)}.
* Processes a string that has a particular semantic meaning to render it
* correctly in bidi environments. For more details, see
* {@link #process(String)}.
*
* @param str the <i>lean</i> text to process
* @param str the <i>lean</i> text to process
* @param separators characters by which the string will be segmented
*
* @return the processed string (<i>full</i> text)
Expand All @@ -105,11 +106,12 @@ public static String process(String str, String separators) {
if (str.charAt(0) == LRE && str.charAt(str.length() - 1) == PDF)
return str;

StructuredTextEnvironment env = new StructuredTextEnvironment(null, false, StructuredTextEnvironment.ORIENT_UNKNOWN);
StructuredTextEnvironment env = new StructuredTextEnvironment(null, false,
StructuredTextEnvironment.ORIENT_UNKNOWN);
// do not process a string if all the following conditions are true:
// a) it has no RTL characters
// b) it starts with a LTR character
// c) it ends with a LTR character or a digit
// a) it has no RTL characters
// b) it starts with a LTR character
// c) it ends with a LTR character or a digit
boolean isStringBidi = false;
int strLength = str.length();
char c;
Expand Down Expand Up @@ -139,17 +141,17 @@ public static String process(String str, String separators) {
}

/**
* Processes a string that has a particular semantic meaning to render
* it correctly in bidi environments.
* For more details, see {@link #process(String)}.
* Processes a string that has a particular semantic meaning to render it
* correctly in bidi environments. For more details, see
* {@link #process(String)}.
*
* @param str the <i>lean</i> text to process.
* @param textType an identifier for the structured text handler appropriate for
* the type of the text submitted. It may be one of the
* identifiers defined in
* {@link StructuredTextTypeHandlerFactory} or a type handler
* identifier registered by a plug-in.
*
* @param str the <i>lean</i> text to process.
* @param textType an identifier for the structured text handler
* appropriate for the type of the text submitted.
* It may be one of the identifiers defined in
* {@link StructuredTextTypeHandlerFactory} or a type handler identifier
* registered by a plug-in.
*
* @return the processed string (<i>full</i> text).
*
* @see #deprocessTyped
Expand All @@ -164,15 +166,16 @@ public static String processTyped(String str, String textType) {
return str;

// make sure that LRE/PDF are added around the string
StructuredTextEnvironment env = new StructuredTextEnvironment(null, false, StructuredTextEnvironment.ORIENT_UNKNOWN);
StructuredTextEnvironment env = new StructuredTextEnvironment(null, false,
StructuredTextEnvironment.ORIENT_UNKNOWN);
IStructuredTextExpert expert = StructuredTextExpertFactory.getExpert(textType, env);
return expert.leanToFullText(str);
}

/**
* Removes directional formatting characters in the given string.
*
* @param str string with directional characters to remove (<i>full</i> text).
* @param str string with directional characters to remove (<i>full</i> text).
*
* @return string without directional formatting characters (<i>lean</i> text).
*/
Expand All @@ -185,14 +188,14 @@ public static String deprocess(String str) {
for (int i = 0; i < strLen; i++) {
char c = str.charAt(i);
switch (c) {
case LRM :
continue;
case LRE :
continue;
case PDF :
continue;
default :
buf.append(c);
case LRM:
continue;
case LRE:
continue;
case PDF:
continue;
default:
buf.append(c);
}
}
return buf.toString();
Expand All @@ -201,13 +204,14 @@ public static String deprocess(String str) {
/**
* Removes directional formatting characters in the given string.
*
* @param str string with directional characters to remove (<i>full</i> text).
* @param textType an identifier for the structured text handler
* appropriate for the type of the text submitted.
* It may be one of the identifiers defined in
* {@link StructuredTextTypeHandlerFactory} or a type handler identifier
* registered by a plug-in.
*
* @param str string with directional characters to remove (<i>full</i>
* text).
* @param textType an identifier for the structured text handler appropriate for
* the type of the text submitted. It may be one of the
* identifiers defined in
* {@link StructuredTextTypeHandlerFactory} or a type handler
* identifier registered by a plug-in.
*
* @return string without directional formatting characters (<i>lean</i> text).
*
* @see #processTyped(String, String)
Expand All @@ -217,14 +221,15 @@ public static String deprocessTyped(String str, String textType) {
return str;

// make sure that LRE/PDF are removed from the string
StructuredTextEnvironment env = new StructuredTextEnvironment(null, false, StructuredTextEnvironment.ORIENT_UNKNOWN);
StructuredTextEnvironment env = new StructuredTextEnvironment(null, false,
StructuredTextEnvironment.ORIENT_UNKNOWN);
IStructuredTextExpert expert = StructuredTextExpertFactory.getExpert(textType, env);
return expert.fullToLeanText(str);
}

/**
* Returns a string containing all the default separator characters to be
* used to segment a given string.
* Returns a string containing all the default separator characters to be used
* to segment a given string.
*
* @return string containing all separators.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,31 @@
* A structured text handler is a subclass of {@link StructuredTextTypeHandler}
* adapted for a given type of structured text.
* <p>
* The constants in this class are identifiers for structured text
* handlers which are defined and supported "out of the box" by this package.
* Text handler identifiers can be used when invoking {@link StructuredTextProcessor#processTyped(String, String)},
* or when invoking <code>getExpert</code> methods in {@link StructuredTextExpertFactory}.
* The constants in this class are identifiers for structured text handlers
* which are defined and supported "out of the box" by this package. Text
* handler identifiers can be used when invoking
* {@link StructuredTextProcessor#processTyped(String, String)}, or when
* invoking <code>getExpert</code> methods in
* {@link StructuredTextExpertFactory}.
* <p>
* The {@link #getHandler} method in this class can be used to get a
* structured text handler reference for one of the handlers defined in this
* package or for additional structured text handlers registered by plug-ins via
* the <code>org.eclipse.equinox.bidi.bidiTypes</code> extension point.
* Text handler references can be used when invoking
* The {@link #getHandler} method in this class can be used to get a structured
* text handler reference for one of the handlers defined in this package or for
* additional structured text handlers registered by plug-ins via the
* <code>org.eclipse.equinox.bidi.bidiTypes</code> extension point. Text handler
* references can be used when invoking
* {@link StructuredTextExpertFactory#getStatefulExpert(StructuredTextTypeHandler, StructuredTextEnvironment)}.
* <p>
* This class can be used without OSGi running, but only the structured text types declared
* as string constants in this class are available in that mode.
* This class can be used without OSGi running, but only the structured text
* types declared as string constants in this class are available in that mode.
* </p>
*
*
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public final class StructuredTextTypeHandlerFactory {

/**
* Structured text handler identifier for comma-delimited lists, such as:
*
* <pre>
* part1,part2,part3
* </pre>
Expand All @@ -63,28 +66,29 @@ public final class StructuredTextTypeHandlerFactory {
public static final String FILE = "file"; //$NON-NLS-1$

/**
* Structured text handler identifier for Java code,
* possibly spanning multiple lines.
* Structured text handler identifier for Java code, possibly spanning multiple
* lines.
*/
public static final String JAVA = "java"; //$NON-NLS-1$

/**
* Structured text handler identifier for regular expressions,
* possibly spanning multiple lines.
* Structured text handler identifier for regular expressions, possibly spanning
* multiple lines.
*/
public static final String REGEX = "regex"; //$NON-NLS-1$

/**
* Structured text handler identifier for SQL statements,
* possibly spanning multiple lines.
* Structured text handler identifier for SQL statements, possibly spanning
* multiple lines.
*/
public static final String SQL = "sql"; //$NON-NLS-1$

/**
* Structured text handler identifier for compound names. It expects text to be made of one or more
* parts separated by underscores:
* Structured text handler identifier for compound names. It expects text to be
* made of one or more parts separated by underscores:
*
* <pre>
* part1_part2_part3
* part1_part2_part3
* </pre>
*/
public static final String UNDERSCORE = "underscore"; //$NON-NLS-1$
Expand All @@ -99,7 +103,8 @@ public final class StructuredTextTypeHandlerFactory {
*/
public static final String XPATH = "xpath"; //$NON-NLS-1$

// *** New types must be added to StructuredTextTypesCollector#getDefaultTypeHandlers()!
// *** New types must be added to
// StructuredTextTypesCollector#getDefaultTypeHandlers()!

/**
* Prevents instantiation
Expand All @@ -113,14 +118,15 @@ private StructuredTextTypeHandlerFactory() {
*
* Supported type ids are:
* <ul>
* <li>the <code>String</code> constants in {@link StructuredTextTypeHandlerFactory}</li>
* <li>the <code>String</code> constants in
* {@link StructuredTextTypeHandlerFactory}</li>
* <li>if OSGi is running, the types that have been contributed to the
* <code>org.eclipse.equinox.bidi.bidiTypes</code> extension point.</li>
* <code>org.eclipse.equinox.bidi.bidiTypes</code> extension point.</li>
* </ul>
*
* @param id the string identifying a structured text handler
* @return a handler of the required type, or <code>null</code>
* if the type is unknown
* @return a handler of the required type, or <code>null</code> if the type is
* unknown
*/
static public StructuredTextTypeHandler getHandler(String id) {
return StructuredTextTypesCollector.getInstance().getHandler(id);
Expand Down
Loading

0 comments on commit a4422c2

Please sign in to comment.