A case class that represents the fields for a product type.
A case class that represents the fields for a product type.
the product type
the fields of the product type (computed from the arguments in the apply method)
the matched apply method
the matched unapply method
TRUE if all fields correspond to a public no arg member method with the same name and type in the product type (e.g. this is true for all case classes and tuple types)
Try to compute the product type fields for a type.
Try to compute the product type fields for a type.
The product type fields are computed by finding the first unapply/apply method pair in the type's companion object with matching type signatures. The type signature of apply methods is equal to the sequence of the types of its arguments. Unapply methods may have one or two type signatures based on its return type. First, the inner type parameter of the Option return type is extracted. If the inner type parameter is a tuple type, then both the tuple type and the list of tuple type parameters form possible type signatures. Otherwise, if the inner type parameter is not a tuple type then the type signature is equal to the single type parameter. Once an apply/unapply match is made, the symbols of the apply method's argument list are returned as the product type fields for the type. For tuple types and case classes, this will be the list of it's fields.
Example1: class A(...) { ... } object A { def apply(i: Int, s: String) : A = ??? def apply(i: Int, s: String, f: Float) : A = ??? def unapply(a: A) : Option[(Int,String)] = ??? } The first apply method's type signature = List(Int,String) The unapply method's type signature = List(List((Int,String)),Int,String) Product type fields = List(i:Int,s:String)
Example2: class B(...) { ... } object B { def apply(tuple: (String,Int)) : A = ??? def apply(i: Int, s: String) : A = ??? def unapply(b: B) : Option[(Int,String)] = ??? } The first apply method's type signature = List((String,Int)) The unapply method's type signature = List(List((String,Int)), List(String,Int)) Product type fields = List(tuple: (String, Int))
Example3: class Enum(...) { ... } object Enum { def apply(value: String) : A = ??? def unapply(e: Enum) : Option[String] = ??? } The first apply method's type signature = List(String) The unapply method's type signature = List(List(String)) Product type fields = List(value: String)
Example4: case class CaseClass(i: Int, s: String) The first apply method's type signature = List(Int,String) The unapply method's type signature = List(List((Int,String)), List(Int,String)) Product type fields = List(i:Int,s:String)
Example5: class Tuple2[T1,T2](val _1: T1,val _2 : T2) The first apply method's type signature = List(T1,T2) The unapply method's type signature = List(T1,T2) Product type fields = List(_1:T1,_2:T2)
If no product type can be computed, None is returned and an error message is logged to logger
type whose companion object should be searched for apply and unapply methods
if successful, Some(product type) otherwise None
if the method exists, the method symbol otherwise an error message
If Result is success the value of the Result. If Result is failure, c.abort is invoked ending the macro. All issues are logged to the Context
if inferred, a Tree representing the implicit otherwise an error message
TRUE if type is a tuple type (e.g. Tuple2[T1,T2], etc)
Log all issues to the Context
Log all issues to the Context
Override to show debug messages
Override to show debug messages