Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy types #2 #26

Merged
merged 2 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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