public static TypeMirror substituteMethodReturnType(TypeMirror methodType,TypeMirror substitutedReceiverType){
  if (methodType.getKind() != TypeKind.TYPEVAR) {
    return methodType;
  }
  String t=methodType.toString();
  Type finalReceiverType=(Type)substitutedReceiverType;
  int i=0;
  for (  TypeSymbol typeParam : finalReceiverType.tsym.getTypeParameters()) {
    if (t.equals(typeParam.toString())) {
      return finalReceiverType.getTypeArguments().get(i);
    }
    i++;
  }
  assert false;
  return null;
}

public static TypeMirror substituteMethodReturnType ( TypeMirror methodType , TypeMirror substitutedReceiverType ) { if ( methodType . getKind ( ) != TypeKind . TYPEVAR ) { return methodType ; } String t = methodType . toString ( ) ; Type finalReceiverType = ( Type ) substitutedReceiverType ; int i = 0 ; for ( TypeSymbol typeParam : finalReceiverType . tsym . getTypeParameters ( ) ) { if ( t . equals ( typeParam . toString ( ) ) ) { return finalReceiverType . getTypeArguments ( ) . get ( i ) ; } i ++ ; } assert false ; return null ; }
returns the return type of a method , where the " raw " return type of that method is given ( i . e . , the return type might still contain unsubstituted type variables ) , given the receiver of the method call .
