Class SelectorExpression

  • Direct Known Subclasses:
    EditorSelectorExpression

    public class SelectorExpression
    extends java.lang.Object
    The Selector Expression Parser.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      Constructor Description
      SelectorExpression​(java.lang.String expression)
      Creates the Expression String.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean eval​(Selector selector, EnvProps envProps, int[] index, boolean isDesigner)
      Evaluates an expression at specified index.
      java.lang.String getClassRefactoredExpression​(java.lang.String oldClassName, java.lang.String newClassName)
      Outputs the expression reformatted used for class refactoring.
      java.lang.String getError()
      Gets the error.
      int getErrorPosition()
      Gets the error position.
      java.lang.String getExpression()
      Outputs the expression reformatted.
      SelectorExpression.Reference[] getReferences()
      Gets the selector and class references in the expression.
      void getReferences​(java.util.HashSet<java.lang.String> selectors, java.util.HashSet<java.lang.String> classes)
      Gets the selector and class references in the expression.
      java.lang.String getSelectorRefactoredExpression​(java.lang.String oldSelectorName, java.lang.String newSelectorName)
      Outputs the expression reformatted used for Selector refactoring.
      boolean isSelected​(Selector selector, EnvProps envProps)
      Called to resolve the SelectorExpression by custom Java code.
      boolean isValidWordCharacter​(int ch)
      Checks for valid character in a word.
      static void main​(java.lang.String[] args)
      Command line.
      boolean parse()
      Parses the expression.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SelectorExpression

        public SelectorExpression​(java.lang.String expression)
        Creates the Expression String.

        There are four special sub expressions that are specified within brackets:

        • { dev: "device" } device or OS selection,
        • { lang: "language" } language selection,
        • { sel: "selectorReference" } used to get the result of another selector (circular references not allowed),
        • { wc: environmentVariable: "Wild*Card?String" } matches an environment variable,
        • { regexp: environmentVariable: "RegularExpressionWithinQuotes" } matches an environment variable in a Regular Expression,
        • { java: "javaClassName" } executes a Java class implementing the interface ISelectorExpression.
        Parameters:
        expression - The expression.
    • Method Detail

      • isValidWordCharacter

        public boolean isValidWordCharacter​(int ch)
        Checks for valid character in a word.

        The word has the same syntax validity as Atom names, i.e. the characters :/\{}"'?*^,; are not allowed, but augmented with white space characters - \t \r \n and space.

        Parameters:
        ch - The character to test.
        Returns:
        true for valid character, false otherwise.
      • parse

        public boolean parse()
        Parses the expression.
        Returns:
        true for success, false if errors are present.
      • getErrorPosition

        public int getErrorPosition()
        Gets the error position.
        Returns:
        The error position or -1 for no error.
      • getError

        public java.lang.String getError()
        Gets the error.
        Returns:
        The error, or null for no error.
      • getExpression

        public java.lang.String getExpression()
        Outputs the expression reformatted.

        If an error is present, the original expression is returned.

        Returns:
        The expression reformatted as a string.
      • getClassRefactoredExpression

        public java.lang.String getClassRefactoredExpression​(java.lang.String oldClassName,
                                                             java.lang.String newClassName)
        Outputs the expression reformatted used for class refactoring.

        If an error is present, the original expression is returned.

        Parameters:
        oldClassName - The old class name.
        newClassName - The new class name.
        Returns:
        The expression reformatted as a string.
      • getSelectorRefactoredExpression

        public java.lang.String getSelectorRefactoredExpression​(java.lang.String oldSelectorName,
                                                                java.lang.String newSelectorName)
        Outputs the expression reformatted used for Selector refactoring.

        If an error is present, the original expression is returned.

        Parameters:
        oldSelectorName - The old Selector name.
        newSelectorName - The new Selector name.
        Returns:
        The expression reformatted as a string.
      • getReferences

        public void getReferences​(java.util.HashSet<java.lang.String> selectors,
                                  java.util.HashSet<java.lang.String> classes)
        Gets the selector and class references in the expression.
      • isSelected

        public boolean isSelected​(Selector selector,
                                  EnvProps envProps)
        Called to resolve the SelectorExpression by custom Java code.
        Parameters:
        envProps - The client environment properties to verify for environment.
        Returns:
        true if the Selector is selected to be used, false otherwise.
      • eval

        protected boolean eval​(Selector selector,
                               EnvProps envProps,
                               int[] index,
                               boolean isDesigner)
        Evaluates an expression at specified index.
        Parameters:
        selector - The selector.
        envProps - The client environment properties to verify for environment.
        index - The index in [0] processed.
        isDesigner - If true, Java classes always return true and are not called.
        Returns:
        Result from expression evaluation.
      • main

        public static void main​(java.lang.String[] args)
        Command line.