fromNativeValue static method

ASTType fromNativeValue(
  1. dynamic o
)

Implementation

static ASTType fromNativeValue(dynamic o) {
  if (o == null) return ASTTypeNull.instance;

  if (o is String) return ASTTypeString.instance;
  if (o is int) return ASTTypeInt.instance;
  if (o is double) return ASTTypeDouble.instance;

  if (o is List) {
    if (o is List<String>) {
      return ASTTypeArray.instanceOfString;
    } else if (o is List<int>) {
      return ASTTypeArray.instanceOfInt;
    } else if (o is List<double>) {
      return ASTTypeArray.instanceOfDouble;
    } else if (o is List<Object>) {
      return ASTTypeArray.instanceOfObject;
    } else if (o is List<List<String>>) {
      return ASTTypeArray2D<ASTTypeString, String>.fromElementType(
          ASTTypeString.instance);
    } else if (o is List<List<int>>) {
      return ASTTypeArray2D<ASTTypeInt, int>.fromElementType(
          ASTTypeInt.instance);
    } else if (o is List<List<double>>) {
      return ASTTypeArray2D<ASTTypeDouble, double>.fromElementType(
          ASTTypeDouble.instance);
    } else if (o is List<List<Object>>) {
      return ASTTypeArray2D<ASTTypeObject, Object>.fromElementType(
          ASTTypeObject.instance);
    } else if (o is List<List<dynamic>>) {
      return ASTTypeArray2D<ASTTypeDynamic, dynamic>.fromElementType(
          ASTTypeDynamic.instance);
    } else if (o is List<List<List<String>>>) {
      return ASTTypeArray3D<ASTTypeString, String>.fromElementType(
          ASTTypeString.instance);
    } else if (o is List<List<List<int>>>) {
      return ASTTypeArray3D<ASTTypeInt, int>.fromElementType(
          ASTTypeInt.instance);
    } else if (o is List<List<List<double>>>) {
      return ASTTypeArray3D<ASTTypeDouble, double>.fromElementType(
          ASTTypeDouble.instance);
    } else if (o is List<List<List<Object>>>) {
      return ASTTypeArray3D<ASTTypeObject, Object>.fromElementType(
          ASTTypeObject.instance);
    } else if (o is List<List<List<dynamic>>>) {
      return ASTTypeArray3D<ASTTypeDynamic, dynamic>.fromElementType(
          ASTTypeDynamic.instance);
    }

    var genericType = o.genericType;

    if (genericType == dynamic) {
      return ASTTypeArray(ASTTypeDynamic.instance);
    } else {
      var t = ASTType.from(genericType);
      return ASTTypeArray(t);
    }
  }

  if (o.runtimeType == Object) return ASTTypeObject.instance;

  return ASTTypeDynamic.instance;
}