private ReferenceBinding typeToRecord(TypeBinding type) {
    if (type == null) return null;
    while (type.isArrayType()) type = ((ArrayBinding) type).leafComponentType();

    switch (type.kind()) {
      case Binding.BASE_TYPE:
      case Binding.TYPE_PARAMETER:
      case Binding.WILDCARD_TYPE:
      case Binding.INTERSECTION_TYPE:
      case Binding.INTERSECTION_TYPE18: // constituents would have been recorded.
      case Binding.POLY_TYPE: // not a real type, will mutate into one, hopefully soon.
        return null;
      case Binding.PARAMETERIZED_TYPE:
      case Binding.RAW_TYPE:
        type = type.erasure();
    }
    ReferenceBinding refType = (ReferenceBinding) type;
    if (refType.isLocalType()) return null;
    return refType;
  }