Commit dcfe383c authored by René Schöne's avatar René Schöne
Browse files

Changes generated accessors.

- "addToX" -> "addX"
- "removeFromX" -> "removeX"
- "x()" -> "getXs" and "getXList"
parent 6cbd6486
......@@ -187,7 +187,7 @@ aspect BackendDirectedAPI {
generateGetMany(sb);
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -199,7 +199,7 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom");
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -211,7 +211,7 @@ aspect BackendDirectedAPI {
public void RelationComponent.generateGetOne(StringBuilder sb) {
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(".get" + nameCapitalized() + "() {\n");
sb.append(ind(2) + "return get" + getImplAttributeName() + "();\n");
sb.append(ind(1) + "}\n");
}
......@@ -220,7 +220,7 @@ aspect BackendDirectedAPI {
// has
sb.append(ind(1) + "public boolean " + toTypeDecl());
sb.append(".has" + nameCapitalized() + "() {\n");
sb.append(ind(2) + "return " + name() + "() != null;\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "() != null;\n");
sb.append(ind(1) + "}\n");
// clear
......@@ -231,8 +231,15 @@ aspect BackendDirectedAPI {
}
public void RelationComponent.generateGetMany(StringBuilder sb) {
// getXs
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(".get" + nameCapitalized() + "s() {\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() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get"
+ getImplAttributeName() + "();\n");
sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n");
......@@ -317,7 +324,7 @@ aspect BackendBidirectionalAPI {
generateGetMany(sb);
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -336,7 +343,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom");
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -356,7 +363,7 @@ aspect BackendBidirectionalAPI {
generateGetMany(sb);
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
......@@ -376,7 +383,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom");
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -470,7 +477,7 @@ aspect LowerBoundCheck {
}
public void OneRelationComponent.generateLowerBoundCheck(StringBuilder sb) {
sb.append(ind(2) + "if (" + name() + "() == null) {\n");
sb.append(ind(2) + "if (get" + nameCapitalized() + "() == null) {\n");
sb.append(ind(3) + "list.add(new Pair<>(this, \"" + name() + "\"));\n");
sb.append(ind(2) + "}\n");
}
......@@ -542,4 +549,4 @@ aspect Utils {
}
return s;
}
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -2,18 +2,18 @@ Root ::= A* B*;
A ::= <Name>;
B ::= <Name>;
rel A.di1 -> B;
rel A.di2? -> B;
rel A.di3* -> B;
rel A.Di1 -> B;
rel A.Di2? -> B;
rel A.Di3* -> B;
rel A.bi1 <-> B.bi1;
rel A.bi2 <-> B.bi2?;
rel A.bi3 <-> B.bi3*;
rel A.Bi1 <-> B.Bi1;
rel A.Bi2 <-> B.Bi2?;
rel A.Bi3 <-> B.Bi3*;
rel A.bi4? <-> B.bi4;
rel A.bi5? <-> B.bi5?;
rel A.bi6? <-> B.bi6*;
rel A.Bi4? <-> B.Bi4;
rel A.Bi5? <-> B.Bi5?;
rel A.Bi6? <-> B.Bi6*;
rel A.bi7* <-> B.bi7;
rel A.bi8* <-> B.bi8?;
rel A.bi9* <-> B.bi9*;
rel A.Bi7* <-> B.Bi7;
rel A.Bi8* <-> B.Bi8?;
rel A.Bi9* <-> B.Bi9*;
......@@ -10,9 +10,9 @@ public class LowerBounds extends AbstractTests {
* A ::= <Name> [C];
* B ::= <Name>;
* C ::= <Name>;
* rel A.b -> B;
* rel B.c <-> C.b;
* rel Root.aa? -> A;
* rel A.Br -> B;
* rel B.Cr <-> C.Br;
* rel Root.Aa? -> A;
*/
public void test() {
Root r = new Root();
......@@ -29,19 +29,19 @@ public class LowerBounds extends AbstractTests {
assertTrue(r.violatesLowerBounds());
a1.setB(b1);
a2.setB(b2);
b1.setC(c1);
b2.setC(c2);
a1.setBr(b1);
a2.setBr(b2);
b1.setCr(c1);
b2.setCr(c2);
assertFalse(r.violatesLowerBounds());
b2.setC(c1);
b2.setCr(c1);
assertTrue(r.violatesLowerBounds());
b1.setC(c2);
b1.setCr(c2);
assertFalse(r.violatesLowerBounds());
}
}
\ No newline at end of file
}
......@@ -3,6 +3,6 @@ A ::= <Name> [C];
B ::= <Name>;
C ::= <Name>;
rel A.b -> B;
rel B.c <-> C.b;
rel Root.aa? -> A;
rel A.Br -> B;
rel B.Cr <-> C.Br;
rel Root.Aa? -> A;
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