Package org.eclipse.equinox.p2.metadata.expression

## Class ExpressionUtil

- java.lang.Object
- - org.eclipse.equinox.p2.metadata.expression.ExpressionUtil

    public final class ExpressionUtil
    extends Object

Global access to factory, parser, and methods for introspection

Since:
  2.0
Restriction:
  This class is not intended to be subclassed by clients.
Restriction:
  This class is not intended to be instantiated by clients.

### Field Summary

Fields
`static IExpression` `FALSE_EXPRESSION`
`static IExpression` `TRUE_EXPRESSION`

### Method Summary

All Methods Static Methods Concrete Methods
`static IExpressionFactory` `getFactory()` Returns the global expression factory
`static IExpression` `getLHS​(IExpression expression)` Obtains the Left Hand Side (LHS) of a binary expression.
`static String` `getName​(IExpression expression)` Obtains the name of a variable or member expression.
`static IExpression` `getOperand​(IExpression expression)` Obtains the operand of an unary expression
`static IExpression[]` `getOperands​(IExpression expression)` Obtains the operands of an n-ary expression
`static IExpressionParser` `getParser()` Creates and returns a new expression parser
`static IExpression` `getRHS​(IExpression expression)` Obtains the Right Hand Side (RHS) of a binary expression.
`static Object` `getValue​(IExpression expression)` Obtains the value of a literal expression
`static IExpression` `parse​(String expression)` Create a new expression.
`static IFilterExpression` `parseLDAP​(String filter)` Parse an LDAP filter from the `filter` string.
`static IExpression` `parseQuery​(String expression)` Create an arbitrary expression.
`static String` `trimmedOrNull​(String str)` If `str` is `null`, then this method returns `null`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### TRUE_EXPRESSION

    public static final IExpression TRUE_EXPRESSION

#### FALSE_EXPRESSION

    public static final IExpression FALSE_EXPRESSION

### Method Detail

#### getFactory

    public static IExpressionFactory getFactory()

Returns the global expression factory

Returns:
  The global expression factory.

#### getParser

    public static IExpressionParser getParser()

Creates and returns a new expression parser

Returns:
  The new parser

#### parseLDAP

    public static IFilterExpression parseLDAP​(String filter)
                                       throws IllegalArgumentException

Parse an LDAP filter from the `filter` string. If `filter` is `null` or a string that is empty or only consists of whitespace, then this method returns `null`.

Parameters:
  `filter` - The filter to parse. Can be `null` or empty.
Returns:
  An expression that corresponds to the LDAP filter or `null`.
Throws:
  `ExpressionParseException` - If the syntax was invalid
  `IllegalArgumentException`

#### parse

    public static IExpression parse​(String expression)

Create a new expression. The expression will have access to the global variable 'this' and to the context parameters.

Parameters:
  `expression` - The string representing the boolean expression.
Returns:
  The resulting expression tree.
Throws:
  `ExpressionParseException` - If the syntax was invalid

#### parseQuery

    public static IExpression parseQuery​(String expression)

Create an arbitrary expression. The expression will have access to the global variable 'everything' and to the context parameters.

Parameters:
  `expression` - The string representing the boolean expression.
Returns:
  The resulting expression tree.
Throws:
  `ExpressionParseException` - If the syntax was invalid

#### trimmedOrNull

    public static String trimmedOrNull​(String str)

If `str` is `null`, then this method returns `null`. Otherwise `str` is trimmed from whitespace at both ends. If the result of the trim is an empty string, then `null` is returned, otherwise the result of the trim is returned.

Parameters:
  `str` - The string to trim. Can be `null`.
Returns:
  The trimmed string or `null`.

#### getLHS

    public static IExpression getLHS​(IExpression expression)

Obtains the Left Hand Side (LHS) of a binary expression.

Parameters:
  `expression` - The expression to introspect
Returns:
  The left hand side operator
Throws:
  `IllegalArgumentException` - if the expression is not a binary expression
See Also:
  `IExpression.TYPE_AT`, `IExpression.TYPE_EQUALS`, `IExpression.TYPE_GREATER`, `IExpression.TYPE_GREATER_EQUAL`, `IExpression.TYPE_LESS`, `IExpression.TYPE_LESS_EQUAL`, `IExpression.TYPE_MATCHES`, `IExpression.TYPE_NOT_EQUALS`

#### getName

    public static String getName​(IExpression expression)

Obtains the name of a variable or member expression.

Parameters:
  `expression` - The expression to introspect
Returns:
  The name of the expression
Throws:
  `IllegalArgumentException` - if the expression is not a variable or a member
See Also:
  `IExpression.TYPE_MEMBER`, `IExpression.TYPE_VARIABLE`

#### getOperand

    public static IExpression getOperand​(IExpression expression)

Obtains the operand of an unary expression

Parameters:
  `expression` - The expression to introspect
Returns:
  The expression operand
Throws:
  `IllegalArgumentException` - if the expression is not an unary expression
See Also:
  `IExpression.TYPE_ALL`, `IExpression.TYPE_EXISTS`, `IExpression.TYPE_LAMBDA`, `IExpression.TYPE_NOT`

#### getOperands

    public static IExpression[] getOperands​(IExpression expression)

Obtains the operands of an n-ary expression

Parameters:
  `expression` - The expression to introspect
Returns:
  The expression operand
Throws:
  `IllegalArgumentException` - if the expression is not a n-ary expression
See Also:
  `IExpression.TYPE_AND`, `IExpression.TYPE_OR`

#### getRHS

    public static IExpression getRHS​(IExpression expression)

Obtains the Right Hand Side (RHS) of a binary expression.

Parameters:
  `expression` - The expression to introspect
Returns:
  The right hand side operator
Throws:
  `IllegalArgumentException` - if the expression is not a binary expression
See Also:
  `IExpression.TYPE_AT`, `IExpression.TYPE_EQUALS`, `IExpression.TYPE_GREATER`, `IExpression.TYPE_GREATER_EQUAL`, `IExpression.TYPE_LESS`, `IExpression.TYPE_LESS_EQUAL`, `IExpression.TYPE_MATCHES`, `IExpression.TYPE_NOT_EQUALS`

#### getValue

    public static Object getValue​(IExpression expression)

Obtains the value of a literal expression

Parameters:
  `expression` - The expression to introspect
Returns:
  The literal value
Throws:
  `IllegalArgumentException` - if the expression is not a literal
See Also:
  `IExpression.TYPE_LITERAL`