Class Labels

java.lang.Object
com.karuslabs.elementary.junit.Labels
All Implemented Interfaces:
Iterable<Map.Entry<String,Element>>

public class Labels extends Object implements Iterable<Map.Entry<String,Element>>
Utilities to find and manipulate elements annotated with @Label in an annotation processing round when used in conjunction with ToolsExtension.
  • Constructor Details

    • Labels

      public Labels(RoundEnvironment environment)
      Creates a Labels for the given annotation processing round.
      Parameters:
      environment - the round's environment
  • Method Details

    • get

      public Element get(String label)
      Returns an element annotated with the given label in the annotation processing round.
      Parameters:
      label - the index of the element
      Returns:
      the element at the given index
      Throws:
      NoSuchElementException - if no element with the given label exists
    • single

      public Element single()
      Returns an element if this annotation processing round contains exactly a single element annotated with @Label.
      Returns:
      the only element annotated with @Label; otherwise null
      Throws:
      IllegalStateException - if there is no elements or more than 1 elements
    • group

      public Map<String,Element> group(String group)
      Returns elements annotated with @Label and the given get.
      Parameters:
      group - the get
      Returns:
      the annotated elements
      Throws:
      NoSuchElementException - if no elements with the given group exists
    • all

      public Map<String,Element> all()
      Returns all elements annotated with @Label in this annotation processing round.
      Returns:
      the annotated elements
    • groups

      public Map<String,Map<String,Element>> groups()
      Returns all elements annotated with @Label in this annotation processing round.
      Returns:
      the annotated elements
    • iterator

      public Iterator<Map.Entry<String,Element>> iterator()
      Returns an iterator over the Elements annotated with @Label.
      Specified by:
      iterator in interface Iterable<Map.Entry<String,Element>>
      Returns:
      an iterator
    • size

      public int size()
      Returns the number of elements annotated with @Label in this annotation processing round.
      Returns:
      the number of elements