Class TargetSelector


  • public final class TargetSelector
    extends java.lang.Object
    Utility class for parsing selectors
    • Method Detail

      • register

        public static void register​(java.lang.Class<? extends ITargetSelectorDynamic> type,
                                    java.lang.String namespace)
        Register a dynamic target selector class. The supplied class must be decorated with an ITargetSelectorDynamic.SelectorId annotation for registration to succeed.
        Parameters:
        type - ITargetSelectorDynamic to register
        namespace - namespace for SelectorId
      • parseAndValidate

        public static java.util.Set<ITargetSelector> parseAndValidate​(java.lang.Iterable<?> selectors,
                                                                      ISelectorContext context)
                                                               throws InvalidSelectorException
        Parse a collection of target selector representations (strings, annotations, class literals) into selectors.
        Parameters:
        selectors - Selectors to parse
        context - Selection context
        Returns:
        parsed collection of selectors, uses LinkedHashSet to preserve parse ordering
        Throws:
        InvalidSelectorException
      • parse

        public static java.util.Set<ITargetSelector> parse​(java.lang.Iterable<?> selectors,
                                                           ISelectorContext context)
        Parse a collection of target selector representations (strings, annotations, class literals) into selectors.
        Parameters:
        selectors - Selectors to parse
        context - Selection context
        Returns:
        parsed collection of selectors, uses LinkedHashSet to preserve parse ordering
      • parse

        public static java.util.Set<ITargetSelector> parse​(java.lang.Iterable<?> selectors,
                                                           ISelectorContext context,
                                                           java.util.Set<ITargetSelector> parsed)
        Parse a collection of target selector representations (strings, annotations, class literals) into selectors and store them in the provided collection.
        Parameters:
        selectors - Selectors to parse
        context - Selection context
        parsed - Collection to add parsed selectors to, initialised as a LinkedHashSet if null
        Returns:
        the same collection passed in via the parsed parameter, for convenience
      • parse

        public static ITargetSelector parse​(IAnnotationHandle annotation,
                                            ISelectorContext context)
        Parse a target selector from the supplied annotation
        Parameters:
        annotation - String to parse target selector from
        context - Context to use for reference mapping
        Returns:
        parsed target selector
      • parse

        public static ITargetSelector parse​(java.lang.String string,
                                            ISelectorContext context)
        Parse a target selector from a string
        Parameters:
        string - String to parse target selector from
        context - Context to use for reference mapping
        Returns:
        parsed target selector
      • parseName

        public static java.lang.String parseName​(java.lang.String name,
                                                 ISelectorContext context)
        Parse a target selector from the supplied name, and then return the name of the match. This is used mainly to remap input names in the same context as a selector without needing the selector itself. If the supplied name does not successfully parse to a name-based selector, then the name is returned unchanged.
        Parameters:
        name - Name to parse
        context - Mixin context
        Returns:
        remapped name or original name
      • run

        public static <TNode> TargetSelector.Result<TNode> run​(ITargetSelector selector,
                                                               java.lang.Iterable<ElementNode<TNode>> nodes)
        Run query on supplied target nodes
        Type Parameters:
        TNode - Node type
        Parameters:
        selector - Target selector
        nodes - Node collection to enumerate
        Returns:
        query result
      • run

        public static <TNode> TargetSelector.Result<TNode> run​(java.lang.Iterable<ITargetSelector> selector,
                                                               java.lang.Iterable<ElementNode<TNode>> nodes)
        Run query on supplied target nodes
        Type Parameters:
        TNode - Node type
        Parameters:
        selector - Target selector
        nodes - Node collection to enumerate
        Returns:
        query result