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 {
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");
}
......
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");
......
Markdown is supported
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