Package spoon.pattern

Class Match

java.lang.Object
spoon.pattern.Match

public class Match extends Object
Represents a single match of Pattern
  • Constructor Details

  • Method Details

    • getMatchingElements

      public List<CtElement> getMatchingElements()
      Returns:
      List of elements, which match to the Pattern. Use getMatchingElement() if the Pattern matches single root element. But when Pattern contains sequence of root elements, then this is the right way how to get them all
    • getMatchingElements

      public <T> List<T> getMatchingElements(Class<T> clazz)
      Same like getMatchingElement() but additionally it checks that each matching element is instance of `clazz`
      Parameters:
      clazz - the required type of all elements.
      Returns:
      a List typed to `clazz` or throws SpoonException if Pattern matched different elements
    • getMatchingElement

      public CtElement getMatchingElement()
      Returns:
      a matching element of a Pattern It fails if Pattern is designed to match sequence of elements. In such case use getMatchingElements()
    • getMatchingElement

      public <T> T getMatchingElement(Class<T> clazz)
      Same like getMatchingElement(), but checks that matching element is expected class and casts returned value to that type
      Parameters:
      clazz - required type
      Returns:
      matched element cast to `clazz`
    • getParameters

      public ImmutableMap getParameters()
      Returns:
      ImmutableMap with values of Pattern parameters, which fits to current match
    • getParametersMap

      public Map<String,​Object> getParametersMap()
      Returns:
      Map with values of Pattern parameters, which fits to current match
    • toString

      public String toString()
      Overrides:
      toString in class Object