Package de.floydkretschmar.fixturize
Class ElementUtils
java.lang.Object
de.floydkretschmar.fixturize.ElementUtils
Defines utility methods that are used to work with
Element instances.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExecutableElementfindMethodWithModifiersByReturnType(Element element, String returnTypeName, Modifier... modifiers) Returns the first method on aElementwhose return type matches the specified return type name and which have the specified modifiers.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.toLinkedMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) Returns a collector for aLinkedHashMapfor the specified key and value mappers.
-
Constructor Details
-
ElementUtils
public ElementUtils()
-
-
Method Details
-
findMethodWithModifiersByReturnType
public static ExecutableElement findMethodWithModifiersByReturnType(Element element, String returnTypeName, Modifier... modifiers) Returns the first method on aElementwhose 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 returnedreturnTypeName- - of the methodmodifiers- - 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 returnedfields- - for which corresponding setters should be retrievedreturnType- - of the settersmodifiers- - of the setters- Returns:
- a map of field to setter pairs
-
toLinkedMap
public static <T,K, Collector<T,U> ?, toLinkedMapMap<K, U>> (Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) Returns a collector for aLinkedHashMapfor the specified key and value mappers.- Parameters:
keyMapper- - for collecting keysvalueMapper- - for collecting values- Returns:
- the collector for linked has maps
-