diff --git a/src/main/jastadd/backend/BidirectionalAPI.jadd b/src/main/jastadd/backend/BidirectionalAPI.jadd index fa2688a655699e4fec6facc5fe0303bcd397f66a..4015d240356896604e5bbc1a97f421a495985006 100644 --- a/src/main/jastadd/backend/BidirectionalAPI.jadd +++ b/src/main/jastadd/backend/BidirectionalAPI.jadd @@ -4,7 +4,8 @@ aspect BackendBidirectionalAPI { boolean resolve = resolverHelper || serializer; // Set - sb.append(ind(1) + "public " + getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + String setMethodDecl = getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + setMethodDecl + " {\n"); if (!isOpt()) { sb.append(ind(2) + "assertNotNull(o);\n"); } @@ -30,18 +31,20 @@ aspect BackendBidirectionalAPI { public void RelationComponent.generateBiManyMany(StringBuilder sb) { // Get - sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + "."); if (useJastAddNames) { + String getMethodDecl1 = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".get" + nameCapitalized() + "s()"; + String getMethodDecl2 = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".get" + nameCapitalized() + "List()"; + // getXs - sb.append("get" + nameCapitalized() + "s() {\n"); + sb.append("public " + getMethodDecl1 + " {\n"); sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n"); sb.append(ind(1) + "}\n"); // getXList - sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl()); - sb.append(".get" + nameCapitalized() + "List() {\n"); + sb.append(ind(1) + "public " + getMethodDecl2 + " {\n"); } else { - sb.append(name() + "() {\n"); + String getMethodDecl = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + "." + name() + "()"; + sb.append("public " + getMethodDecl + " {\n"); } sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n"); // resolve the entire list @@ -73,7 +76,8 @@ aspect BackendBidirectionalAPI { sb.append(ind(1) + "}\n"); // Add - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + String addMethodDecl1 = "void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + addMethodDecl1 + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + "if (list == null) {\n"); @@ -90,7 +94,8 @@ aspect BackendBidirectionalAPI { sb.append(ind(1) + "}\n"); // Insert / add at specific position - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n"); + String addMethodDecl2 = "void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(int index, " + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + addMethodDecl2 + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + "if (list == null) {\n"); @@ -107,7 +112,8 @@ aspect BackendBidirectionalAPI { sb.append(ind(1) + "}\n"); // Remove - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".remove" + (useJastAddNames ? "" : "From") + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + String removeMethodDecl = "void " + getTypeUse().decl() + ".remove" + (useJastAddNames ? "" : "From") + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + removeMethodDecl + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); @@ -122,18 +128,20 @@ aspect BackendBidirectionalAPI { public void RelationComponent.generateBiManyOne(StringBuilder sb) { // Get - sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + "."); if (useJastAddNames) { + String getMethodDecl1 = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".get" + nameCapitalized() + "s()"; + String getMethodDecl2 = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".get" + nameCapitalized() + "List()"; + // getXs - sb.append("get" + nameCapitalized() + "s() {\n"); + sb.append("public " + getMethodDecl1 + " {\n"); sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n"); sb.append(ind(1) + "}\n"); // getXList - sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl()); - sb.append(".get" + nameCapitalized() + "List() {\n"); + sb.append(ind(1) + "public " + getMethodDecl2 + " {\n"); } else { - sb.append(name() + "() {\n"); + String getMethodDecl = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + "." + name() + "()"; + sb.append("public " + getMethodDecl + " {\n"); } sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n"); // resolve the entire list @@ -171,7 +179,8 @@ aspect BackendBidirectionalAPI { sb.append(ind(1) + "}\n"); // Add - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + String addMethodDecl1 = "void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + addMethodDecl1 + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "if (o != null && o." + otherSide().getImplAttributeField() + " != null) {\n"); sb.append(ind(3) + ASTNode.listClass + "<" + ofTypeDecl() + "> list2 = o." + otherSide().getImplAttributeField() + "." + getImplAttributeField() + ";\n"); @@ -188,7 +197,8 @@ aspect BackendBidirectionalAPI { sb.append(ind(1) + "}\n"); // Insert / add at specific position - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n"); + String addMethodDecl2 = "void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(int index, " + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + addMethodDecl2 + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "if (o != null && o." + otherSide().getImplAttributeField() + " != null) {\n"); sb.append(ind(3) + ASTNode.listClass + "<" + ofTypeDecl() + "> list2 = o." + otherSide().getImplAttributeField() + "." + getImplAttributeField() + ";\n"); @@ -205,7 +215,8 @@ aspect BackendBidirectionalAPI { sb.append(ind(1) + "}\n"); // Remove - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".remove" + (useJastAddNames ? "" : "From") + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + String removeMethodDecl = "void " + getTypeUse().decl() + ".remove" + (useJastAddNames ? "" : "From") + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + removeMethodDecl + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); @@ -219,8 +230,8 @@ aspect BackendBidirectionalAPI { public void RelationComponent.generateBiOneMany(StringBuilder sb) { // Set - sb.append(ind(1) + "public " + getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() - + "(" + ofTypeDecl() + " o) {\n"); + String setMethodDecl = getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + setMethodDecl + " {\n"); if (!isOpt()) { sb.append(ind(2) + "assertNotNull(o);\n"); } diff --git a/src/main/jastadd/backend/DirectedAPI.jadd b/src/main/jastadd/backend/DirectedAPI.jadd index c390de19d2c140654bfd334b4b4c30de812fc32c..26a6896781877baf4d48505f689a4fc66e5a3245 100644 --- a/src/main/jastadd/backend/DirectedAPI.jadd +++ b/src/main/jastadd/backend/DirectedAPI.jadd @@ -1,9 +1,10 @@ aspect BackendDirectedAPI { public void RelationComponent.generateDirectedZeroOneAPI(StringBuilder sb) { + String setMethodDecl = getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + // Set - sb.append(ind(1) + "public " + getTypeUse().decl() + " " + getTypeUse().decl()); - sb.append(".set" + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + sb.append(ind(1) + "public " + setMethodDecl + " {\n"); if (!isOpt()) { sb.append(ind(2) + "assertNotNull(o);\n"); } @@ -13,19 +14,21 @@ aspect BackendDirectedAPI { } public void RelationComponent.generateDirectedManyAPI(StringBuilder sb) { + // Get - sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + "."); if (useJastAddNames) { + String getMethodDecl1 = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".get" + nameCapitalized() + "s()"; + String getMethodDecl2 = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".get" + nameCapitalized() + "List()"; // getXs - sb.append("get" + nameCapitalized() + "s() {\n"); + sb.append(ind(1) + "public " + getMethodDecl1 + " {\n"); sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n"); sb.append(ind(1) + "}\n"); // getXList - sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl()); - sb.append(".get" + nameCapitalized() + "List() {\n"); + sb.append(ind(1) + "public " + getMethodDecl2 + " {\n"); } else { - sb.append(name() + "() {\n"); + String getMethodDecl = "java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + "." + name() + "()"; + sb.append("public " + getMethodDecl + " {\n"); } sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n"); // resolve the entire list @@ -49,7 +52,8 @@ aspect BackendDirectedAPI { sb.append(ind(1) + "}\n"); // Add - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + String addMethodDecl1 = "void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + addMethodDecl1 + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + "if (list == null) {\n"); @@ -60,7 +64,8 @@ aspect BackendDirectedAPI { sb.append(ind(1) + "}\n"); // Insert / add at specific position - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n"); + String addMethodDecl2 = "void " + getTypeUse().decl() + ".add" + (useJastAddNames ? "" : "To") + nameCapitalized() + "(int index, " + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + addMethodDecl2 + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + "if (list == null) {\n"); @@ -71,7 +76,8 @@ aspect BackendDirectedAPI { sb.append(ind(1) + "}\n"); // Remove - sb.append(ind(1) + "public void " + getTypeUse().decl() + ".remove" + (useJastAddNames ? "" : "From") + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); + String removeMethodDecl = "void " + getTypeUse().decl() + ".remove" + (useJastAddNames ? "" : "From") + nameCapitalized() + "(" + ofTypeDecl() + " o)"; + sb.append(ind(1) + "public " + removeMethodDecl + " {\n"); sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n");