Class TargetSelector

java.lang.Object
org.spongepowered.asm.mixin.injection.selectors.TargetSelector

public final class TargetSelector extends Object
Utility class for parsing selectors
  • Method Details

    • register

      public static void register(Class<? extends ITargetSelectorDynamic> type, 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 ITargetSelector parseAndValidate(IAnnotationHandle annotation, ISelectorContext context) throws InvalidSelectorException
      Parse a target selector from the supplied annotation and perform validation
      Parameters:
      annotation - Annotation to parse target selector from
      context - Context to use for reference mapping
      Returns:
      parsed target selector
      Throws:
      InvalidSelectorException
    • parseAndValidate

      public static ITargetSelector parseAndValidate(String string, ISelectorContext context) throws InvalidSelectorException
      Parse a target selector from a string and perform validation
      Parameters:
      string - String to parse target selector from
      context - Context to use for reference mapping
      Returns:
      parsed target selector
      Throws:
      InvalidSelectorException
    • parseAndValidate

      public static Set<ITargetSelector> parseAndValidate(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 Set<ITargetSelector> parse(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 Set<ITargetSelector> parse(Iterable<?> selectors, ISelectorContext context, 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(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 String parseName(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, 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(Iterable<ITargetSelector> selector, 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