Skip to content

Commit

Permalink
Merge pull request #26 from schlothauer-wauer/copy_types
Browse files Browse the repository at this point in the history
Copy types #2
  • Loading branch information
OkieOth authored Oct 17, 2018
2 parents 7c22824 + 91a01ff commit 06e1f22
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class TypeStringManipulation {
propsContainsTag: propsContainsTag,
filterProps: filterProps,
filterPropsPerform: filterPropsPerform,
printLines: printLines
printLines: printLines,
copyType: copyType
]
}

Expand Down Expand Up @@ -276,5 +277,13 @@ class TypeStringManipulation {
lists.flatten().each { line -> out << "${prefix}${line}\n" }
}

/**
* Returns a copy of the provided type.
* @param type the type to copy
*/
def copyType = { type ->
return Type.copyOf(type, [:])
}

private final static String EMPTY=''
}
27 changes: 23 additions & 4 deletions src/main/groovy/de/lisaplus/atlas/model/BaseType.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.lisaplus.atlas.model

import com.sun.org.apache.xpath.internal.operations.Or

/**
* Type used in meta model
* Created by eiko on 01.06.17.
Expand Down Expand Up @@ -31,22 +29,40 @@ abstract class BaseType {
switch(type) {
// handle immutable by just returning them
case BooleanType:
BooleanType copyB = new BooleanType()
copyB.isArray = type.isArray
return copyB
case VoidType:
VoidType copyV = new VoidType()
copyV.isArray = type.isArray
return copyV
case UnsupportedType:
UnsupportedType copyU = new UnsupportedType()
copyU.isArray = type.isArray
return copyU
case UUIDType:
case BooleanType:
UUIDType copyUU = new UUIDType()
copyUU.isArray = type.isArray
return copyUU
case DateType:
DateType copyD = new DateType()
copyD.isArray = type.isArray
return copyD
case DateTimeType:
return type
DateTimeType copyDT = new DateTimeType()
copyDT.isArray = type.isArray
return copyDT
case StringType:
StringType copyS = new StringType()
copyS.isArray = type.isArray
// Assume immutable!
copyS.minLength = type.minLength
copyS.maxLength = type.maxLength
copyS.pattern = type.pattern
return copyS
case IntType:
IntType copyI = new IntType()
copyI.isArray = type.isArray
// Assume immutable!
copyI.min = type.min
copyI.max = type.max
Expand All @@ -55,6 +71,7 @@ abstract class BaseType {
return copyI
case NumberType:
NumberType copyN = new NumberType()
copyN.isArray = type.isArray
// Assume immutable!
copyN.min = type.min
copyN.max = type.max
Expand All @@ -63,13 +80,15 @@ abstract class BaseType {
return copyN
case RefType:
RefType copyR = new RefType()
copyR.isArray = type.isArray
// Assume immutable!
copyR.typeName = type.typeName
// if (type.type != null) println "RefType triggers copy of type ${type.type.name}"
copyR.type = type.type == null ? null : Type.copyOf(type.type, typeCopies)
return copyR
case ComplexType:
ComplexType copyC = new ComplexType()
copyC.isArray = type.isArray
// if (type.type != null) println "ComplexType triggers copy of type ${type.type.name}"
copyC.type = type.type == null ? null : Type.copyOf(type.type, typeCopies)
return copyC
Expand Down

0 comments on commit 06e1f22

Please sign in to comment.