Skip to content
Snippets Groups Projects
Commit 7ed6c1fe authored by Johannes Mey's avatar Johannes Mey
Browse files

check uniqueness during serialisation, fix nullpointer issues in rewrite...

check uniqueness during serialisation, fix nullpointer issues in rewrite checks, add test for node removal
parent ff493449
Branches
Tags
1 merge request!1Mquat2
Pipeline #3052 passed
......@@ -368,7 +368,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(3) + "get" + getImplAttributeName() + "().set" + otherSide().getImplAttributeName() + "(null);\n");
sb.append(ind(2) + "}\n");
if (resolverHelper | serializer) {
sb.append(ind(2) + "if (!o.unresolved() && o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
sb.append(ind(2) + "if (o != null && !o.unresolved() && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
} else {
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
}
......@@ -376,7 +376,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(2) + "}\n");
sb.append(ind(2) + "set" + getImplAttributeName() + "(o);\n");
if (resolverHelper | serializer) {
sb.append(ind(2) + "if (!o.unresolved()) {\n");
sb.append(ind(2) + "if (o == null || !o.unresolved()) {\n");
if (isOpt) {
sb.append(ind(3) + "if (o != null) {\n");
sb.append(ind(4) + "o.set" + otherSide().getImplAttributeName() + "(this);\n");
......@@ -1294,7 +1294,7 @@ aspect Serializer {
sb.append(ind(1) + "protected String ASTNode.__uid = null;\n");
sb.append("\n");
sb.append(ind(1) + "protected String ASTNode.__uid() {\n");
sb.append(ind(2) + "String customUID = serializationID();\n");
sb.append(ind(2) + "String customUID = customID();\n");
sb.append(ind(2) + "if (customUID == null) {\n");
sb.append(ind(3) + "if (__uid == null) {\n");
sb.append(ind(4) + "__uid = UIDProvider.getUID();\n");
......@@ -1305,7 +1305,7 @@ aspect Serializer {
sb.append(ind(2) + "}\n");
sb.append(ind(1) + "}\n");
sb.append("\n");
sb.append(ind(1) + "protected String ASTNode.serializationID() {\n");
sb.append(ind(1) + "protected String ASTNode.customID() {\n");
sb.append(ind(2) + "return null;\n");
sb.append(ind(1) + "}\n");
......@@ -1322,7 +1322,11 @@ aspect Serializer {
sb.append(ind(1) + "}\n");
sb.append(ind(1) + "protected java.util.Map<String, ASTNode> ASTNode.__uidMap(java.util.Map<String, ASTNode> map) {\n");
sb.append(ind(2) + "map.put(this.__uid, this);\n");
sb.append(ind(2) + "if (map.keySet().contains(__uid())) {\n");
sb.append(ind(3) + "throw new RuntimeException(new SerializationException(\"UID \" + this.__uid + \" is not unique\"));\n");
sb.append(ind(2) + "} else {\n");
sb.append(ind(3) + "map.put(this.__uid, this);\n");
sb.append(ind(2) + "}\n");
sb.append(ind(2) + "for (ASTNode child : astChildren()) {\n");
sb.append(ind(3) + "child.__uidMap(map);\n");
sb.append(ind(2) + "}\n");
......
......@@ -93,9 +93,9 @@ class Serializer {
a2.addDi3(b2);
// Bi1
a1.setBi1(b1);
a2.setBi1(b3);
a3.setBi1(b2);
a1.setBi1(b3);
a2.setBi1(b2);
a3.setBi1(b1);
// Bi2
a1.setBi2(b1);
......@@ -112,23 +112,46 @@ class Serializer {
a2.setBi5(b3);
// Bi6
a2.setBi6(b2);
a3.setBi6(b2);
a2.setBi6(b3);
a3.setBi6(b3);
// Bi9
a1.addBi9(b1);
a1.addBi9(b2);
a2.addBi9(b2);
File f = File.createTempFile("original", ".json");
System.out.println(f.getAbsoluteFile());
r.serialize(f);
Root copy = Root.deserialize(f);
File f2 = File.createTempFile("copy", ".json");
copy.serialize(f2);
assertThat(f2).hasSameContentAs(f);
a1.addBi9(b3);
a2.addBi9(b3);
File f1a = File.createTempFile("original", ".json");
System.out.println(f1a.getAbsoluteFile());
r.serialize(f1a);
Root copy = Root.deserialize(f1a);
File f1b = File.createTempFile("copy", ".json");
copy.serialize(f1b);
assertThat(f1b).hasSameContentAs(f1a);
// remove a2
a1.setDi1(b3);
a1.setDi2(b3);
a1.removeDi3(b2);
a1.removeDi3(b2);
a1.setBi3(b1);
a3.setBi3(b1);
b3.clearBi5();
b3.removeBi6(a2);
b3.removeBi9(a2);
r.getAList().removeChild(r.getAList().getIndexOfChild(a2));
r.getBList().removeChild(r.getBList().getIndexOfChild(b2));
File f2a = File.createTempFile("original", ".json");
System.out.println(f2a.getAbsoluteFile());
r.serialize(f2a);
copy = Root.deserialize(f2a);
File f2b = File.createTempFile("copy", ".json");
copy.serialize(f2b);
assertThat(f2b).hasSameContentAs(f2a);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment