mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#61 Moving method for assignment check to Type
This commit is contained in:
parent
585f944574
commit
01c487d342
@ -148,6 +148,21 @@ public class Type extends AbstractModelElement implements Comparable<Type> {
|
||||
Collections.<Type>emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this type is assignable to the given other type.
|
||||
*
|
||||
* @param other The other type.
|
||||
*
|
||||
* @return {@code true} if and only if this type is assignable to the given other type.
|
||||
*/
|
||||
public boolean isAssignableTo(Type other) {
|
||||
if ( equals( other ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return typeUtils.isAssignable( typeMirror, other.typeMirror );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -207,7 +207,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
}
|
||||
|
||||
if ( returnType.getTypeMirror().getKind() != TypeKind.VOID &&
|
||||
!typeFactory.isAssignable( resultType, returnType ) ) {
|
||||
!resultType.isAssignableTo( returnType ) ) {
|
||||
messager.printMessage(
|
||||
Kind.ERROR,
|
||||
"The result type is not assignable to the the return type.",
|
||||
|
@ -173,20 +173,4 @@ public class TypeFactory {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type1 first type
|
||||
* @param type2 second type
|
||||
*
|
||||
* @return {@code true} if and only if the first type is assignable to the second
|
||||
*/
|
||||
public boolean isAssignable(Type type1, Type type2) {
|
||||
if ( type1.equals( type2 ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TypeMirror mirror1 = type1.getTypeMirror();
|
||||
TypeMirror mirror2 = type2.getTypeMirror();
|
||||
return null != mirror1 && null != mirror2 && typeUtils.isAssignable( mirror1, mirror2 );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user