Class ElementUtils

java.lang.Object
de.floydkretschmar.fixturize.ElementUtils

public class ElementUtils extends Object
Defines utility methods that are used to work with Element instances.
  • Constructor Details

    • ElementUtils

      public ElementUtils()
  • Method Details

    • findMethodWithModifiersByReturnType

      public static ExecutableElement findMethodWithModifiersByReturnType(Element element, String returnTypeName, Modifier... modifiers)
      Returns the first method on a Element whose return type matches the specified return type name and which have the specified modifiers. Returns null if no matching method could be found.
      Parameters:
      element - - from which the methods will be returned
      returnTypeName - - of the method
      modifiers - - of the method
      Returns:
      the matching method
    • findSetterForFields

      public static <T> Stream<Map.Entry<T,Optional<ExecutableElement>>> findSetterForFields(Element element, List<T> fields, TypeMirror returnType, Modifier... modifiers)
      Returns all methods on the provided element that can be setter for the provided list of fields. A method is considered a match if
      • it contains the specified modifiers
      • its name matches the pattern "[set]*{fieldName}" case insensitvely
      • it has exactly one parameter
      • the return type of the method matches the specified return type
      Type Parameters:
      T - the type of the fields whose toString methods will be used to determine {fieldName}
      Parameters:
      element - - from which the methods will be returned
      fields - - for which corresponding setters should be retrieved
      returnType - - of the setters
      modifiers - - of the setters
      Returns:
      a map of field to setter pairs
    • toLinkedMap

      public static <T, K, U> Collector<T,?,Map<K,U>> toLinkedMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
      Returns a collector for a LinkedHashMap for the specified key and value mappers.
      Parameters:
      keyMapper - - for collecting keys
      valueMapper - - for collecting values
      Returns:
      the collector for linked has maps