Class MethodMatcher
- java.lang.Object
-
- org.mapstruct.ap.internal.model.source.MethodMatcher
-
public class MethodMatcher extends java.lang.ObjectSourceMethodMatcher $8.4 of the JavaLanguage specification describes a method body as such:SourceMethodDeclaration: SourceMethodHeader SourceMethodBody SourceMethodHeader: SourceMethodModifiers TypeParameters Result SourceMethodDeclarator Throws SourceMethodDeclarator: Identifier ( FormalParameterList ) example <T extends String & Serializable> T getResult(? extends T) throws Exception \-------------------------------/ \-/ \---------/ TypeParameters Result ParameterListMatches a given method with given ParameterList and Result type obeying the constraints in the TypeParameters block.For more info on java-generics: http://www.javacodegeeks.com/2011/04/java-generics-quick-tutorial.html http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html
The following situations is not supported / tested:
- Multiple bounds were the bound itself is again a generic type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMethodMatcher.GenericAnalyserprivate static classMethodMatcher.TypeVarCandidate
-
Field Summary
Fields Modifier and Type Field Description private SourceMethodcandidateMethodprivate TypeFactorytypeFactoryprivate TypeUtilstypeUtils
-
Constructor Summary
Constructors Constructor Description MethodMatcher(TypeUtils typeUtils, TypeFactory typeFactory, SourceMethod candidateMethod)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanisPrimitiveToObject(Type type, Type isAssignableTo)Primitive to Object (Boxed Type) should be handled by a type conversion rather than a direct mapping Direct mapping runs the risk of null pointer exceptions: e.g.(package private) booleanmatches(java.util.List<Type> sourceTypes, Type targetType)Whether the given source and target types are matched by this matcher's candidate method.
-
-
-
Field Detail
-
candidateMethod
private final SourceMethod candidateMethod
-
typeUtils
private final TypeUtils typeUtils
-
typeFactory
private final TypeFactory typeFactory
-
-
Constructor Detail
-
MethodMatcher
MethodMatcher(TypeUtils typeUtils, TypeFactory typeFactory, SourceMethod candidateMethod)
-
-
Method Detail
-
matches
boolean matches(java.util.List<Type> sourceTypes, Type targetType)
Whether the given source and target types are matched by this matcher's candidate method.- Parameters:
sourceTypes- the source typestargetType- the target type- Returns:
truewhen both, source type and target types match the signature of this matcher's method;falseotherwise.
-
isPrimitiveToObject
private boolean isPrimitiveToObject(Type type, Type isAssignableTo)
Primitive to Object (Boxed Type) should be handled by a type conversion rather than a direct mapping Direct mapping runs the risk of null pointer exceptions: e.g. in the assignment of Integer to int, Integer can be null.- Parameters:
type- the type to be assignedisAssignableTo- the type to which @param type should be assignable to- Returns:
- true if isAssignable is a primitive type and type is an object
-
-