Skip to content

Commit

Permalink
https://github.com/miho/VMF/issues/55
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed Mar 18, 2024
1 parent 1ca5a0f commit 4255181
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,48 @@ public static class Builder${VMF_IMPL_CLASS_EXT} implements ${type.typeName}.Bui
return result;
}

#foreach( $t in $type.allInheritedTypes )
public Builder applyFrom(${t.typeName} o) {
#foreach( $prop in ${t.implementation.properties} )

### now, set "p.name" to "prop.name" of "type.name", because in "t.name" they are potentially more generic
### search by "prop.name" name by another foreach
#foreach( $pOfType in ${type.implementation.properties} )
#if($pOfType.name == $prop.name)
#set($p = $pOfType)
#end
#end ## foreach property

// we cast types to the type of the property in the current class (runtime exception if not possible)

###if($type.immutable || $prop.propType != "COLLECTION")
#if($prop.propType == "COLLECTION")
#if(${prop.genericType})
#set($genericCollArg = "${prop.genericType.typeName}")
#else## if genericType is modelType
#set($genericCollArg = "${prop.genericPackageName}.${prop.genericTypeName}")
#end## if genericType is modelType
if(!this.appendCollections||this.__vmf_prop_${prop.name}==null) {
// ensure that this collection property is really immutable
this.__vmf_prop_${prop.name} = ${VCOLL_PKG}.VList.newInstance(
java.util.Collections.
unmodifiableList(
new java.util.ArrayList<$genericCollArg>( (${p.typeName}) o.${prop.getterPrefix}${prop.nameWithUpperCase}())
)
);
} else {
this.__vmf_prop_${prop.name}.addAll( (${p.typeName}) o.${prop.getterPrefix}${prop.nameWithUpperCase}());
}
#else## if property is collection
this.__vmf_prop_${prop.name} = (${p.typeName}) o.${prop.getterPrefix}${prop.nameWithUpperCase}();
#end## if property is collection
###end## if type is immutable or property is no collection
#end## foreach property

return this;
}
#end ## foreach inherited type

public Builder applyFrom(${type.typeName} o) {
#foreach( $prop in ${type.implementation.properties} )
###if($type.immutable || $prop.propType != "COLLECTION")
Expand Down Expand Up @@ -277,6 +319,7 @@ public static class Builder${VMF_IMPL_CLASS_EXT} implements ${type.typeName}.Bui

return this;
}

#if(!$type.immutable)
public Builder applyTo(${type.typeName} o) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@
*/
public Builder applyFrom($type.typeName o);

#foreach( $t in $type.allInheritedTypes )
/**
* Applies all properties from the specified object to this builder.
* @param o object to apply properties from
* @return this builder
* @see #[[#]]#applyTo($type.typeName)
*/
public Builder applyFrom($t.typeName o);
#end##end foreach inherited type

#if(!$type.immutable)
/**
* Applies all properties from this builder to the specified object.
Expand Down
4 changes: 3 additions & 1 deletion test-suite/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# README #

Sams awesome testsuite for VMF.
A comprehensive test-suite is available in the `test-suite` directory. The test-suite contains a set of examples that
demonstrate and test the features of VMF. The examples are used to ensure that VMF works as expected and to prevent
regressions.

0 comments on commit 4255181

Please sign in to comment.