#61 Moving method for assignment check to Type

This commit is contained in:
Gunnar Morling 2013-08-14 21:43:09 +02:00
parent 585f944574
commit 01c487d342
3 changed files with 16 additions and 17 deletions

View File

@ -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;

View File

@ -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.",

View File

@ -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 );
}
}