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

Add flag `--useJastAddNames` generate names in the form of addX, removeX and...

Add flag `--useJastAddNames` generate names in the form of addX, removeX and setX. If omitted, relast will default to the original naming scheme addToX, removeFromX and setX.
parent a2afc0cc
Pipeline #3042 passed with stage
in 46 seconds
......@@ -110,7 +110,7 @@ task preprocessRelationTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/relations/Relations.relast', '--file', '--grammarName=src/test/jastadd/relations/Relations'
args 'src/test/jastadd/relations/Relations.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations'
}
task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
......@@ -121,7 +121,7 @@ task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/relations/Relations.ast', '--file', '--grammarName=src/test/jastadd/relations/Relations2'
args 'src/test/jastadd/relations/Relations.ast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations2'
}
task compileRelationTest(type: JavaExec, group: 'verification') {
......@@ -135,6 +135,50 @@ task compileRelationTest(type: JavaExec, group: 'verification') {
args '--o=src/test/java-gen/', '--package=relations.ast', 'src/test/jastadd/relations/Relations.ast', 'src/test/jastadd/relations/Relations.jadd', 'src/test/jastadd/Utils.jadd'
}
task preprocessDefaultNamesTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/relations/Relations.ast', 'src/test/jastadd/relations/Relations.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/relations/Relations.relast', '--file', '--grammarName=src/test/jastadd/relations/Relations'
}
task compileDefaultNamesTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/java-gen/relations'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.JastAdd'
args '--o=src/test/java-gen/', '--package=defaultnames.ast', 'src/test/jastadd/relations/Relations.ast', 'src/test/jastadd/relations/Relations.jadd', 'src/test/jastadd/Utils.jadd'
}
task preprocessDefaultNamesResolverTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/resolver/Resolver.ast', 'src/test/jastadd/resolver/Resolver.jadd', 'src/test/jastadd/resolver/ResolverRefResolver.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/resolver/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver/Resolver', '--resolverHelper'
}
task compileDefaultNamesResolverTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/java-gen/resolver'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.JastAdd'
args '--o=src/test/java-gen/', '--package=defaultnames.resolver.ast', 'src/test/jastadd/resolver/Resolver.ast', 'src/test/jastadd/resolver/Resolver.jadd', 'src/test/jastadd/resolver/ResolverUtils.jadd', 'src/test/jastadd/resolver/ResolverRefResolver.jadd', 'src/test/jastadd/resolver/MyRefResolver.jadd', 'src/test/jastadd/Utils.jadd'
}
task preprocessLowerBoundsTest(type: JavaExec, group: 'verification') {
doFirst {
......@@ -143,7 +187,7 @@ task preprocessLowerBoundsTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/lowerbounds/LowerBounds.relast', '--file', '--grammarName=src/test/jastadd/lowerbounds/LowerBounds'
args 'src/test/jastadd/lowerbounds/LowerBounds.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/lowerbounds/LowerBounds'
}
task compileLowerBoundsTest(type: JavaExec, group: 'verification') {
......@@ -165,7 +209,7 @@ task preprocessMultipleTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/multiple/Part1.relast', 'src/test/jastadd/multiple/Part2.relast', 'src/test/jastadd/multiple/Part3.relast', '--file', '--grammarName=src/test/jastadd/multiple/Multiple'
args 'src/test/jastadd/multiple/Part1.relast', '--useJastAddNames', 'src/test/jastadd/multiple/Part2.relast', 'src/test/jastadd/multiple/Part3.relast', '--file', '--grammarName=src/test/jastadd/multiple/Multiple'
}
task compileMultipleTest(type: JavaExec, group: 'verification') {
......@@ -187,7 +231,7 @@ task preprocessResolverTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/resolver/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver/Resolver', '--resolverHelper'
args 'src/test/jastadd/resolver/Resolver.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/resolver/Resolver', '--resolverHelper'
}
task compileResolverTest(type: JavaExec, group: 'verification') {
......@@ -210,7 +254,7 @@ task preprocessResolver2Test(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/resolver2/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver2/Resolver', '--resolverHelper'
args 'src/test/jastadd/resolver2/Resolver.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/resolver2/Resolver', '--resolverHelper'
}
task compileResolver2Test(type: JavaExec, group: 'verification') {
......@@ -232,7 +276,7 @@ task preprocessListNamesTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/listnames/ListNames.relast', '--file', '--grammarName=src/test/jastadd/listnames/ListNames', '--jastAddList=ListyMcListface'
args 'src/test/jastadd/listnames/ListNames.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/listnames/ListNames', '--jastAddList=ListyMcListface'
}
task compileListNamesTest(type: JavaExec, group: 'verification') {
......@@ -257,6 +301,11 @@ test.dependsOn compileRelationTest
compileRelationTest.dependsOn doublePreprocessRelationTest
doublePreprocessRelationTest.dependsOn preprocessRelationTest
test.dependsOn compileDefaultNamesTest
compileDefaultNamesTest.dependsOn preprocessDefaultNamesTest
test.dependsOn compileDefaultNamesResolverTest
compileDefaultNamesResolverTest.dependsOn preprocessDefaultNamesResolverTest
test.dependsOn compileLowerBoundsTest
compileLowerBoundsTest.dependsOn preprocessLowerBoundsTest
......@@ -270,4 +319,4 @@ test.dependsOn compileResolver2Test
compileResolver2Test.dependsOn preprocessResolver2Test
test.dependsOn compileListNamesTest
compileListNamesTest.dependsOn preprocessListNamesTest
\ No newline at end of file
compileListNamesTest.dependsOn preprocessListNamesTest
......@@ -2,8 +2,8 @@ aspect BackendAbstractGrammar {
public static String ASTNode.listClass = "ArrayList";
public static String ASTNode.jastAddListType = "List";
public static boolean ASTNode.resolverHelper = false;
public static boolean ASTNode.resolverHelper = false;
public static boolean ASTNode.useJastAddNames = false;
public String Program.generateAbstractGrammar() {
StringBuilder sb = new StringBuilder();
......@@ -188,15 +188,19 @@ aspect BackendDirectedAPI {
public void ManyRelationComponent.generateDirectedAPI(StringBuilder sb) {
// Get
// getXs
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl() + ".");
if (useJastAddNames) {
// getXs
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");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
}
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list
if (resolverHelper) {
......@@ -220,6 +224,9 @@ aspect BackendDirectedAPI {
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -231,7 +238,11 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + toTypeDecl() + ".add" + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list == null) {\n");
......@@ -243,6 +254,9 @@ aspect BackendDirectedAPI {
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -253,8 +267,13 @@ aspect BackendDirectedAPI {
}
public void RelationComponent.generateGetOne(StringBuilder sb) {
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "() {\n");
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl() + ".");
if (useJastAddNames) {
sb.append("get" + nameCapitalized());
} else {
sb.append(name());
}
sb.append("() {\n");
if (resolverHelper) {
sb.append(ind(2) + "if (get" + getImplAttributeName() + "() != null && get" + getImplAttributeName() + "().unresolved()) {\n");
sb.append(ind(3) + "set" + nameCapitalized() + "(resolve" + nameCapitalized() + "ByToken(get" + getImplAttributeName() + "().asUnresolved().get__token()));\n");
......@@ -268,7 +287,13 @@ aspect BackendDirectedAPI {
// has
sb.append(ind(1) + "public boolean " + toTypeDecl());
sb.append(".has" + nameCapitalized() + "() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "() != null;\n");
sb.append(ind(2) + "return ");
if (useJastAddNames) {
sb.append("get" + nameCapitalized());
} else {
sb.append(name());
}
sb.append("() != null;\n");
sb.append(ind(1) + "}\n");
// clear
......@@ -372,15 +397,19 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyMany(StringBuilder sb, RelationComponent opposite) {
// Get
// getXs
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl() + ".");
if (useJastAddNames) {
// getXs
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");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
}
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list
if (resolverHelper) {
......@@ -412,6 +441,9 @@ aspect BackendBidirectionalAPI {
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -430,7 +462,11 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + toTypeDecl() + ".add" + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list == null) {\n");
......@@ -449,6 +485,9 @@ aspect BackendBidirectionalAPI {
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -465,15 +504,19 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyOne(StringBuilder sb, RelationComponent opposite) {
// Get
// getXs
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl() + ".");
if (useJastAddNames) {
// getXs
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");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
}
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list
if (resolverHelper) {
......@@ -507,6 +550,9 @@ aspect BackendBidirectionalAPI {
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
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");
......@@ -526,7 +572,11 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + toTypeDecl() + ".add" + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
sb.append(ind(3) + ASTNode.listClass + "<" + ofTypeDecl() + "> list2 = o.get" + otherSide().getImplAttributeName() + "().get" + getImplAttributeName() + "();\n");
......@@ -544,6 +594,9 @@ aspect BackendBidirectionalAPI {
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -638,7 +691,13 @@ aspect LowerBoundCheck {
}
public void OneRelationComponent.generateLowerBoundCheck(StringBuilder sb) {
sb.append(ind(2) + "if (get" + nameCapitalized() + "() == null) {\n");
sb.append(ind(2) + "if (");
if (useJastAddNames) {
sb.append("get" + nameCapitalized());
} else {
sb.append(name());
}
sb.append("() == null) {\n");
sb.append(ind(3) + "list.add(new Pair<>(this, \"" + name() + "\"));\n");
sb.append(ind(2) + "}\n");
}
......@@ -847,7 +906,13 @@ aspect NameResolutionHelper {
sb.append(ind(1) + "// enforce resolving of all non-containment relations of the current non-terminal\n");
sb.append(ind(1) + "public void " + getID() + ".resolveAll() {\n");
for (RelationComponent relationComponent : relationComponents()) {
sb.append(ind(2) + "get" + relationComponent.nameCapitalized() + (relationComponent.isMany()?"List":"") + "();\n");
sb.append(ind(2));
if (useJastAddNames) {
sb.append("get" + relationComponent.nameCapitalized());
} else {
sb.append(relationComponent.name());
}
sb.append(relationComponent.isMany() && useJastAddNames ? "List" : "").append("();\n");
}
sb.append(ind(2) + "super.resolveAll();\n");
sb.append(ind(1) + "}\n");
......
......@@ -22,6 +22,7 @@ public class Compiler {
private StringOption optionJastAddList;
private StringOption optionGrammarName;
private FlagOption optionResolverHelper;
private FlagOption optionUseJastaddNames;
private CommandLine commandLine;
public Compiler(String[] args) throws CommandLineException {
......@@ -80,6 +81,11 @@ public class Compiler {
ASTNode.listClass = optionListClass.getValue();
}
if (optionUseJastaddNames.isSet()) {
System.out.println("Using JastAdd names");
ASTNode.useJastAddNames = true;
}
String grammarName = "Grammar";
if (optionGrammarName.isSet()) {
grammarName = optionGrammarName.getValue();
......@@ -130,7 +136,7 @@ public class Compiler {
optionGrammarName = addOption(new StringOption("grammarName", "name of the generated grammar and aspect (without file extension)"));
optionResolverHelper = addOption(new FlagOption("resolverHelper", "create a subtype for each type containing a string that can be used to resolve the type later"));
optionJastAddList = addOption(new StringOption("jastAddList", "set the name of the List type in JastAdd (has to match the option '--List' or its default List)"));
optionUseJastaddNames = addOption(new FlagOption("useJastAddNames", "generate names in the form of addX, removeX and setX. If omitted, the default, original naming scheme resulting in addToX, removeFromX and setX will be used."));
}
private <OptionType extends Option<?>> OptionType addOption(OptionType option) {
......
package org.jastadd.relast.tests;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import defaultnames.ast.A;
import defaultnames.ast.B;
import defaultnames.ast.Root;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import static org.jastadd.relast.tests.TestHelpers.readFile;
import static org.junit.jupiter.api.Assertions.*;
@SuppressWarnings({"ArraysAsListWithZeroOrOneArgument", "Duplicates"})
class DefaultNames {
private Root r;
private A a1;
private A a2;
private A a3;
private B b1;
private B b2;
private B b3;
@Test
void doubleRelastRun() throws IOException {
String firstRun = "./src/test/jastadd/relations/Relations.ast";
String secondRun = "./src/test/jastadd/relations/Relations2.ast";
String first = readFile(firstRun, Charset.defaultCharset());
String second = readFile(secondRun, Charset.defaultCharset());
Assertions.assertEquals(first, second);
}
/**
* rel A.Di1 -> B;
*/
@Test
void testDi1() {
setup();
a1.setDi1(b2);
a2.setDi1(b1);
assertSame(a1.Di1(), b2);
assertSame(a2.Di1(), b1);
a2.setDi1(b2);
assertSame(a1.Di1(), b2);
assertSame(a2.Di1(), b2);
try {
a3.setDi1(null);
fail("should throw an exception");
} catch (Exception e) {
// OK
}
}
/**
* rel A.Di2? -> B;
*/
@Test
void testDi2() {
setup();
a1.setDi2(b2);
a2.setDi2(b1);
assertSame(a1.Di2(), b2);
assertSame(a2.Di2(), b1);
a2.setDi2(b2);
assertSame(a1.Di2(), b2);
assertSame(a2.Di2(), b2);
a2.clearDi2();
assertSame(a1.Di2(), b2);
assertNull(a2.Di2());
assertTrue(a1.hasDi2());
assertFalse(a2.hasDi2());
assertFalse(a3.hasDi2());
}
/**
* rel A.Di3* -> B;
*/
@Test
void testDi3() {
setup();
a1.addToDi3(b1);
a1.addToDi3(b2);
a1.addToDi3(b3);
a2.addToDi3(b2);
assertEquals(a1.Di3(), Arrays.asList(b1, b2, b3));
assertEquals(a2.Di3(), Arrays.asList(b2));
assertEquals(a3.Di3(), Arrays.asList());
a1.addToDi3(b1);
a2.addToDi3(b1);
a2.addToDi3(b2);
assertEquals(a1.Di3(), Arrays.asList(b1, b2, b3, b1));
assertEquals(a2.Di3(), Arrays.asList(b2, b1, b2));
assertEquals(a3.Di3(), Arrays.asList());
a1.removeFromDi3(b1);
a2.removeFromDi3(b2);
assertEquals(a1.Di3(), Arrays.asList(b2, b3, b1));
assertEquals(a2.Di3(), Arrays.asList(b1, b2));
assertEquals(a3.Di3(), Arrays.asList());
}
/**
* rel A.Bi1 <-> B.Bi1;
*/
@Test
void testBi11() {
// Init
setup();
a1.setBi1(b1);
a2.setBi1(b2);
// Change
a2.setBi1(b1);
assertNull(a1.Bi1());
assertSame(a2.Bi1(), b1);
assertSame(b1.Bi1(), a2);
assertNull(b2.Bi1());
}
@Test
void testBi12() {
// Init
setup();
a1.setBi1(b2);
// Change
a2.setBi1(b2);
assertNull(a1.Bi1());
assertSame(a2.Bi1(), b2);
assertNull(b1.Bi1());
assertSame(b2.Bi1(), a2);
}
/**
* rel A.Bi2 <-> B.Bi2?;
*/
@Test
void testBi21() {
// Init
setup();
a1.setBi2(b1);
a2.setBi2(b2);
// Change
a2.setBi2(b1);
assertNull(a1.Bi2());
assertSame(a2.Bi2(), b1);
assertSame(b1.Bi2(), a2);
assertNull(b2.Bi2());
}
@Test
void testBi22() {
// Init
setup();
a1.setBi2(b2);
// Change
a2.setBi2(b2);
assertNull(a1.Bi2());
assertSame(a2.Bi2(), b2);
assertNull(b1.Bi2());
assertSame(b2.Bi2(), a2);
}
/**
* rel A.Bi3 <-> B.Bi3*;
*/
@Test
void testBi3() {
setup();
a2.setBi3(b2);
assertNull(a1.Bi3());
assertSame(a2.Bi3(), b2);
assertEquals(b1.Bi3(), Arrays.asList());
assertEquals(b2.Bi3(), Arrays.asList(a2));
assertEquals(b3.Bi3(), Arrays.asList());
a2.setBi3(b3);
assertNull(a1.Bi3());
assertSame(a2.Bi3(), b3);
assertEquals(b1.Bi3(), Arrays.asList());
assertEquals(b2.Bi3(), Arrays.asList());
assertEquals(b3.Bi3(), Arrays.asList(a2));