1.1 --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Fri Jan 24 14:48:36 2014 +0100
1.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Fri Jan 24 15:01:15 2014 +0100
1.3 @@ -813,7 +813,7 @@
1.4 w.append(" }\n");
1.5 */
1.6 writeToString(props, w);
1.7 - writeClone(className, props, w);
1.8 + writeEnumClone(e, className, props, w);
1.9 w.write(" /** Activates this model instance in the current {@link \n"
1.10 + "net.java.html.json.Models#bind(java.lang.Object, net.java.html.BrwsrCtx) browser context}. \n"
1.11 + "In case of using Knockout technology, this means to \n"
1.12 @@ -1826,6 +1826,38 @@
1.13 w.write(" return ret;\n");
1.14 w.write(" }\n");
1.15 }
1.16 + private void writeEnumClone(Element e, String className, Prprt[] props, Writer w) throws IOException {
1.17 + w.write(" public " + className + " clone() {\n");
1.18 + w.write(" return clone(proto.getContext());\n");
1.19 + w.write(" }\n");
1.20 + w.write(" private " + className + " clone(net.java.html.BrwsrCtx ctx) {\n");
1.21 + w.write(" Object newUnion = null;\n");
1.22 + for (Element ec : e.getEnclosedElements()) {
1.23 + if (ec.getKind() != ElementKind.ENUM_CONSTANT) {
1.24 + continue;
1.25 + }
1.26 + w.write(" if (union instanceof " + ec.getSimpleName() + ") newUnion = ((" + ec.getSimpleName() + ")union).clone(ctx);\n");
1.27 + }
1.28 + w.write(" " + className + " ret = new " + className + "(ctx, newUnion);\n");
1.29 + for (Prprt p : props) {
1.30 + if (!p.array()) {
1.31 + boolean isModel[] = { false };
1.32 + boolean isEnum[] = { false };
1.33 + boolean isPrimitive[] = { false };
1.34 + checkType(p, isModel, isEnum, isPrimitive);
1.35 + if (!isModel[0]) {
1.36 + w.write(" ret.prop_" + p.name() + " = prop_" + p.name() + ";\n");
1.37 + continue;
1.38 + }
1.39 + w.write(" ret.prop_" + p.name() + " = prop_" + p.name() + " == null ? null : prop_" + p.name() + ".clone();\n");
1.40 + } else {
1.41 + w.write(" proto.cloneList(ret.prop_" + p.name() + ", ctx, prop_" + p.name() + ");\n");
1.42 + }
1.43 + }
1.44 +
1.45 + w.write(" return ret;\n");
1.46 + w.write(" }\n");
1.47 + }
1.48
1.49 private String inPckName(Element e) {
1.50 while (!(e instanceof TypeElement)) {
2.1 --- a/json/src/test/java/org/netbeans/html/json/impl/PlainEnumTest.java Fri Jan 24 14:48:36 2014 +0100
2.2 +++ b/json/src/test/java/org/netbeans/html/json/impl/PlainEnumTest.java Fri Jan 24 15:01:15 2014 +0100
2.3 @@ -75,7 +75,10 @@
2.4 }
2.5
2.6 @Test public void cloneUnionB() {
2.7 - Union on = Union.createB(new Union.B("9.9"), 11, 1.1).clone();
2.8 + Union old = Union.createB(new Union.B("9.9"), 11, 1.1);
2.9 + Union on = old.clone();
2.10 + assertNotSame(old.getB(), on.getB());
2.11 +
2.12 assertEquals(on.getX(), 11);
2.13 assertEquals(on.getY(), 1.1);
2.14