@@ -165,8 +165,21 @@ sealed interface SimpleType {
165165 }
166166 }
167167
168+ class Custom (
169+ override val className : ClassName ,
170+ override val pathClassName : ClassName ,
171+ override val pathTypeName : TypeName
172+ ) : SimpleType {
173+ override fun render (name : String ): PropertySpec {
174+ return PropertySpec
175+ .builder(name, pathTypeName)
176+ .initializer(" ${pathClassName} (forProperty(\" $name \" ))" )
177+ .build()
178+ }
179+ }
180+
168181 object Mapper {
169- private val typeMap : Map <ClassName , SimpleType > = mutableMapOf<KClass <* >, SimpleType > ()
182+ private val simpleTypeMap : Map <ClassName , SimpleType > = mutableMapOf<KClass <* >, SimpleType > ()
170183 .apply {
171184 this [Any ::class ] = Simple (Any ::class .asClassName())
172185 this [Char ::class ] = Comparable (Char ::class .asClassName())
@@ -215,8 +228,54 @@ sealed interface SimpleType {
215228 }
216229 .mapKeys { it.key.asClassName() }
217230
231+ private val customTypeMap: Map <ClassName , SimpleType > = mutableMapOf<ClassName , SimpleType >()
232+ .apply {
233+ val mapping = mutableMapOf<ClassName , ClassName >()
234+ apply {
235+ val map = mapOf (
236+ " Geometry" to " GeometryPath" ,
237+ " GeometryCollection" to " GeometryCollectionPath" ,
238+ " LinearRing" to " LinearRingPath" ,
239+ " LineString" to " LineStringPath" ,
240+ " MultiLineString" to " MultiLineStringPath" ,
241+ " MultiPoint" to " MultiPointPath" ,
242+ " MultiPolygon" to " MultiPolygonPath" ,
243+ " Point" to " PointPath" ,
244+ " Polygon" to " PolygonPath"
245+ )
246+ for (entry in map) {
247+ mapping[ClassName (" org.geolatte.geom" , entry.key)] = ClassName (" com.querydsl.spatial" , entry.value)
248+ }
249+ }
250+
251+ apply {
252+ val map = mapOf (
253+ " Geometry" to " JTSGeometryPath" ,
254+ " GeometryCollection" to " JTSGeometryCollectionPath" ,
255+ " LinearRing" to " JTSLinearRingPath" ,
256+ " LineString" to " JTSLineStringPath" ,
257+ " MultiLineString" to " JTSMultiLineStringPath" ,
258+ " MultiPoint" to " JTSMultiPointPath" ,
259+ " MultiPolygon" to " JTSMultiPolygonPath" ,
260+ " Point" to " JTSPointPath" ,
261+ " Polygon" to " JTSPolygonPath" ,
262+ )
263+ for (entry in map) {
264+ mapping[ClassName (" com.vividsolutions.jts.geom" , entry.key)] = ClassName (" com.querydsl.spatial.jts" , entry.value)
265+ mapping[ClassName (" org.locationtech.jts.geom" , entry.key)] = ClassName (" com.querydsl.spatial.locationtech.jts" , entry.value)
266+ }
267+ }
268+ for (entry in mapping) {
269+ this [entry.key] = Custom (
270+ entry.key,
271+ entry.value,
272+ entry.value.parameterizedBy(entry.key)
273+ )
274+ }
275+ }
276+
218277 fun get (className : ClassName ): SimpleType ? {
219- return typeMap [className]
278+ return simpleTypeMap[className] ? : customTypeMap [className]
220279 }
221280 }
222281}
0 commit comments