@@ -21,15 +21,15 @@ package com.ckkloverdos.convert
21
21
* @author Christos KK Loverdos <loverdos@gmail.com>.
22
22
*/
23
23
class SourceTargetConverter [SS , TT ](
24
- val sourceType : Manifest [SS ],
25
- val targetType : Manifest [TT ],
24
+ val sourceType : Type [SS ],
25
+ val targetType : Type [TT ],
26
26
val isStrictSource : Boolean ,
27
27
val function : SS => TT )
28
28
extends Converter {
29
29
30
- def canConvertType [S : Manifest , T : Manifest ]: Boolean = {
31
- val sm = manifest [S ]
32
- val tm = manifest [T ]
30
+ def canConvertType [S : Type , T : Type ]: Boolean = {
31
+ val sm = typeOf [S ]
32
+ val tm = typeOf [T ]
33
33
34
34
// logger.debug("canConvertType(%s, %s), sourceType=%s, targetType=%s".format(sm, tm, sourceType, targetType))
35
35
@@ -39,7 +39,7 @@ class SourceTargetConverter[SS, TT](
39
39
canConvertNonStrictSource(sm, tm)
40
40
}
41
41
42
- private [this ] def canConvertStrictSource (sm : Manifest [_], tm : Manifest [_]) = {
42
+ private [this ] def canConvertStrictSource (sm : Type [_], tm : Type [_]) = {
43
43
SourceTargetConverter .canConvertWithStrictSource(
44
44
sourceType,
45
45
targetType,
@@ -48,7 +48,7 @@ class SourceTargetConverter[SS, TT](
48
48
)
49
49
}
50
50
51
- private [this ] def canConvertNonStrictSource (sm : Manifest [_], tm : Manifest [_]) = {
51
+ private [this ] def canConvertNonStrictSource (sm : Type [_], tm : Type [_]) = {
52
52
SourceTargetConverter .canConvertWithNonStrictSource(
53
53
sourceType,
54
54
targetType,
@@ -59,8 +59,8 @@ class SourceTargetConverter[SS, TT](
59
59
60
60
61
61
@ throws(classOf [ConverterException ])
62
- def convertEx [T : Manifest ](sourceValue : Any ): T = {
63
- val tm = manifest [T ]
62
+ def convertEx [T : Type ](sourceValue : Any ): T = {
63
+ val tm = typeOf [T ]
64
64
if (targetType != tm) {
65
65
ConverterException (" Unexpeced target type %s. It should have been %s" .format(tm, targetType))
66
66
}
@@ -79,50 +79,50 @@ class SourceTargetConverter[SS, TT](
79
79
}
80
80
81
81
object SourceTargetConverter {
82
- def canConvertWithStrictSource [SS , TT , S , T ](sourceType : Manifest [SS ],
83
- targetType : Manifest [TT ],
84
- givenSourceType : Manifest [S ],
85
- givenTargetType : Manifest [T ]): Boolean = {
82
+ def canConvertWithStrictSource [SS , TT , S , T ](sourceType : Type [SS ],
83
+ targetType : Type [TT ],
84
+ givenSourceType : Type [S ],
85
+ givenTargetType : Type [T ]): Boolean = {
86
86
87
87
canConvertWithStrictSource(sourceType.erasure, targetType.erasure, givenSourceType, givenTargetType)
88
88
}
89
89
90
90
def canConvertWithStrictSource [SS , TT , S , T ](sourceType : Class [SS ],
91
91
targetType : Class [TT ],
92
- givenSourceType : Manifest [S ],
93
- givenTargetType : Manifest [T ]): Boolean = {
92
+ givenSourceType : Type [S ],
93
+ givenTargetType : Type [T ]): Boolean = {
94
94
95
95
sourceType.equals(givenSourceType.erasure) && targetType.equals(givenTargetType.erasure)
96
96
}
97
97
98
- def canConvertWithNonStrictSource [SS , TT , S , T ](sourceType : Manifest [SS ],
99
- targetType : Manifest [TT ],
100
- givenSourceType : Manifest [S ],
101
- givenTargetType : Manifest [T ]): Boolean = {
98
+ def canConvertWithNonStrictSource [SS , TT , S , T ](sourceType : Type [SS ],
99
+ targetType : Type [TT ],
100
+ givenSourceType : Type [S ],
101
+ givenTargetType : Type [T ]): Boolean = {
102
102
103
103
canConvertWithNonStrictSource(sourceType.erasure, targetType.erasure, givenSourceType, givenTargetType)
104
104
}
105
105
106
106
def canConvertWithNonStrictSource [SS , TT , S , T ](sourceType : Class [SS ],
107
107
targetType : Class [TT ],
108
- givenSourceType : Manifest [S ],
109
- givenTargetType : Manifest [T ]): Boolean = {
108
+ givenSourceType : Type [S ],
109
+ givenTargetType : Type [T ]): Boolean = {
110
110
111
111
sourceType.isAssignableFrom(givenSourceType.erasure) && targetType.equals(givenTargetType.erasure)
112
112
}
113
113
}
114
114
115
- abstract class StrictSourceConverterSkeleton [SS : Manifest , TT : Manifest ]extends Converter {
116
- final def canConvertType [S : Manifest , T : Manifest ]: Boolean = {
117
- SourceTargetConverter .canConvertWithStrictSource(manifest [SS ], manifest [TT ], manifest [S ], manifest [T ])
115
+ abstract class StrictSourceConverterSkeleton [SS : Type , TT : Type ]extends Converter {
116
+ final def canConvertType [S : Type , T : Type ]: Boolean = {
117
+ SourceTargetConverter .canConvertWithStrictSource(typeOf [SS ], typeOf [TT ], typeOf [S ], typeOf [T ])
118
118
}
119
119
120
120
final def isStrictSource = true
121
121
}
122
122
123
- abstract class NonStrictSourceConverterSkeleton [SS : Manifest , TT : Manifest ]extends Converter {
124
- final def canConvertType [S : Manifest , T : Manifest ]: Boolean = {
125
- SourceTargetConverter .canConvertWithNonStrictSource(manifest [SS ], manifest [TT ], manifest [S ], manifest [T ])
123
+ abstract class NonStrictSourceConverterSkeleton [SS : Type , TT : Type ]extends Converter {
124
+ final def canConvertType [S : Type , T : Type ]: Boolean = {
125
+ SourceTargetConverter .canConvertWithNonStrictSource(typeOf [SS ], typeOf [TT ], typeOf [S ], typeOf [T ])
126
126
}
127
127
128
128
final def isStrictSource = false
0 commit comments