Commit da6d43be authored by Johannes Mey's avatar Johannes Mey
Browse files

extract method names for later reuse

parent 90551c73
...@@ -4,7 +4,8 @@ aspect BackendBidirectionalAPI { ...@@ -4,7 +4,8 @@ aspect BackendBidirectionalAPI {
boolean resolve = resolverHelper || serializer; boolean resolve = resolverHelper || serializer;
// Set // 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()) { if (!isOpt()) {
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
} }
...@@ -30,18 +31,20 @@ aspect BackendBidirectionalAPI { ...@@ -30,18 +31,20 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyMany(StringBuilder sb) { public void RelationComponent.generateBiManyMany(StringBuilder sb) {
// Get // Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".");
if (useJastAddNames) { 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 // getXs
sb.append("get" + nameCapitalized() + "s() {\n"); sb.append("public " + getMethodDecl1 + " {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n"); sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// getXList // getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl()); sb.append(ind(1) + "public " + getMethodDecl2 + " {\n");
sb.append(".get" + nameCapitalized() + "List() {\n");
} else { } 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"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list // resolve the entire list
...@@ -73,7 +76,8 @@ aspect BackendBidirectionalAPI { ...@@ -73,7 +76,8 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Add // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n");
sb.append(ind(2) + "if (list == null) {\n"); sb.append(ind(2) + "if (list == null) {\n");
...@@ -90,7 +94,8 @@ aspect BackendBidirectionalAPI { ...@@ -90,7 +94,8 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Insert / add at specific position // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n");
sb.append(ind(2) + "if (list == null) {\n"); sb.append(ind(2) + "if (list == null) {\n");
...@@ -107,7 +112,8 @@ aspect BackendBidirectionalAPI { ...@@ -107,7 +112,8 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Remove // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n");
sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n");
...@@ -122,18 +128,20 @@ aspect BackendBidirectionalAPI { ...@@ -122,18 +128,20 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyOne(StringBuilder sb) { public void RelationComponent.generateBiManyOne(StringBuilder sb) {
// Get // Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".");
if (useJastAddNames) { 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 // getXs
sb.append("get" + nameCapitalized() + "s() {\n"); sb.append("public " + getMethodDecl1 + " {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n"); sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// getXList // getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl()); sb.append(ind(1) + "public " + getMethodDecl2 + " {\n");
sb.append(".get" + nameCapitalized() + "List() {\n");
} else { } 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"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list // resolve the entire list
...@@ -171,7 +179,8 @@ aspect BackendBidirectionalAPI { ...@@ -171,7 +179,8 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Add // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + "if (o != null && o." + otherSide().getImplAttributeField() + " != null) {\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"); sb.append(ind(3) + ASTNode.listClass + "<" + ofTypeDecl() + "> list2 = o." + otherSide().getImplAttributeField() + "." + getImplAttributeField() + ";\n");
...@@ -188,7 +197,8 @@ aspect BackendBidirectionalAPI { ...@@ -188,7 +197,8 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Insert / add at specific position // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + "if (o != null && o." + otherSide().getImplAttributeField() + " != null) {\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"); sb.append(ind(3) + ASTNode.listClass + "<" + ofTypeDecl() + "> list2 = o." + otherSide().getImplAttributeField() + "." + getImplAttributeField() + ";\n");
...@@ -205,7 +215,8 @@ aspect BackendBidirectionalAPI { ...@@ -205,7 +215,8 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Remove // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n");
sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n");
...@@ -219,8 +230,8 @@ aspect BackendBidirectionalAPI { ...@@ -219,8 +230,8 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiOneMany(StringBuilder sb) { public void RelationComponent.generateBiOneMany(StringBuilder sb) {
// Set // Set
sb.append(ind(1) + "public " + getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() String setMethodDecl = getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() + "(" + ofTypeDecl() + " o)";
+ "(" + ofTypeDecl() + " o) {\n"); sb.append(ind(1) + "public " + setMethodDecl + " {\n");
if (!isOpt()) { if (!isOpt()) {
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
} }
......
aspect BackendDirectedAPI { aspect BackendDirectedAPI {
public void RelationComponent.generateDirectedZeroOneAPI(StringBuilder sb) { public void RelationComponent.generateDirectedZeroOneAPI(StringBuilder sb) {
String setMethodDecl = getTypeUse().decl() + " " + getTypeUse().decl() + ".set" + nameCapitalized() + "(" + ofTypeDecl() + " o)";
// Set // Set
sb.append(ind(1) + "public " + getTypeUse().decl() + " " + getTypeUse().decl()); sb.append(ind(1) + "public " + setMethodDecl + " {\n");
sb.append(".set" + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
if (!isOpt()) { if (!isOpt()) {
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
} }
...@@ -13,19 +14,21 @@ aspect BackendDirectedAPI { ...@@ -13,19 +14,21 @@ aspect BackendDirectedAPI {
} }
public void RelationComponent.generateDirectedManyAPI(StringBuilder sb) { public void RelationComponent.generateDirectedManyAPI(StringBuilder sb) {
// Get // Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl() + ".");
if (useJastAddNames) { 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 // 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(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// getXList // getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + getTypeUse().decl()); sb.append(ind(1) + "public " + getMethodDecl2 + " {\n");
sb.append(".get" + nameCapitalized() + "List() {\n");
} else { } 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"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list // resolve the entire list
...@@ -49,7 +52,8 @@ aspect BackendDirectedAPI { ...@@ -49,7 +52,8 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Add // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n");
sb.append(ind(2) + "if (list == null) {\n"); sb.append(ind(2) + "if (list == null) {\n");
...@@ -60,7 +64,8 @@ aspect BackendDirectedAPI { ...@@ -60,7 +64,8 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Insert / add at specific position // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n");
sb.append(ind(2) + "if (list == null) {\n"); sb.append(ind(2) + "if (list == null) {\n");
...@@ -71,7 +76,8 @@ aspect BackendDirectedAPI { ...@@ -71,7 +76,8 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
// Remove // 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) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = " + getImplAttributeField() + ";\n");
sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment