Ejemplo n.º 1
0
  public static boolean isMoreSpecific(
      @NotNull CallableDescriptor a, @NotNull CallableDescriptor b) {
    KotlinType aReturnType = a.getReturnType();
    KotlinType bReturnType = b.getReturnType();

    assert aReturnType != null : "Return type of " + a + " is null";
    assert bReturnType != null : "Return type of " + b + " is null";

    if (!isVisibilityMoreSpecific(a, b)) return false;

    if (a instanceof SimpleFunctionDescriptor) {
      assert b instanceof SimpleFunctionDescriptor : "b is " + b.getClass();

      return isReturnTypeMoreSpecific(a, aReturnType, b, bReturnType);
    }
    if (a instanceof PropertyDescriptor) {
      assert b instanceof PropertyDescriptor : "b is " + b.getClass();

      PropertyDescriptor pa = (PropertyDescriptor) a;
      PropertyDescriptor pb = (PropertyDescriptor) b;

      if (!isAccessorMoreSpecific(pa.getSetter(), pb.getSetter())) return false;

      if (pa.isVar() && pb.isVar()) {
        return DEFAULT
            .createTypeChecker(a.getTypeParameters(), b.getTypeParameters())
            .equalTypes(aReturnType, bReturnType);
      } else {
        // both vals or var vs val: val can't be more specific then var
        return !(!pa.isVar() && pb.isVar())
            && isReturnTypeMoreSpecific(a, aReturnType, b, bReturnType);
      }
    }
    throw new IllegalArgumentException("Unexpected callable: " + a.getClass());
  }