package dex

sealed trait DexType {}

object DexType {

  case class VoidType private[DexType] () extends DexType {}

  case class PrimitiveType private[DexType] () extends DexType {}

  case class ObjectType private[DexType] (className: String) extends DexType {}

  case class ArrayType private[DexType] (dexType: DexType) extends DexType {}

  def apply(param: String): DexType = {
    param match {
      case "V" => VoidType()
      case "Z" // Boolean
          | "B" // Byte
          | "S" // Short
          | "C" // Char
          | "I" // Integer
          | "J" // Long
          | "F" // Float
          | "D" // Double
          =>
        PrimitiveType()
      case className if className.startsWith("L") => ObjectType(className)
      case arrayType if arrayType.startsWith("[") =>
        ArrayType(apply(arrayType.substring(1)))
    }
  }
}
