GitLab update scheduled for Friday, January 21th between 08:15 and 08:45 CET. If unpleasant, please contact René or Martin.

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

Working on #29 and expand constructor test.

parent d37f1e35
Pipeline #8215 passed with stages
in 3 minutes and 18 seconds
...@@ -97,19 +97,20 @@ aspect ComponentAnalysis { ...@@ -97,19 +97,20 @@ aspect ComponentAnalysis {
// find a matching component on the RHS of the (current) super type // find a matching component on the RHS of the (current) super type
Component c = findComponent(td, getID()); Component c = findComponent(td, getID());
if (c != null && !this.isEqual(c)) return c; if (c != null && !this.usesSameTypeAs(c)) return c;
} }
return null; return null;
} }
//--- isEqual --- //--- usesSameTypeAs ---
syn boolean Component.isEqual(Component c) = this.getClass() == c.getClass() && getTypeUse().isEqual(c.getTypeUse()); syn boolean Component.usesSameTypeAs(Component c) = this.getClass() == c.getClass() && getTypeUse().isEqual(c.getTypeUse());
/** /**
* TokenComponents may be specialized by NTATokenComponents and vice versa * TokenComponents may be specialized by NTATokenComponents and vice versa
*/ */
eq TokenComponent.isEqual(Component c) = (c instanceof TokenComponent) && getTypeUse().isEqual(c.getTypeUse()); eq TokenComponent.usesSameTypeAs(Component c) = (c instanceof TokenComponent) && getTypeUse().isEqual(c.getTypeUse());
// --- isEqual ---
syn boolean TypeUse.isEqual(TypeUse u); syn boolean TypeUse.isEqual(TypeUse u);
eq SimpleTypeUse.isEqual(TypeUse u) = u instanceof SimpleTypeUse && getID().equals(u.getID()); eq SimpleTypeUse.isEqual(TypeUse u) = u instanceof SimpleTypeUse && getID().equals(u.getID());
eq ParameterizedTypeUse.isEqual(TypeUse u) { eq ParameterizedTypeUse.isEqual(TypeUse u) {
...@@ -123,6 +124,8 @@ aspect ComponentAnalysis { ...@@ -123,6 +124,8 @@ aspect ComponentAnalysis {
return true; return true;
} }
syn boolean Component.isEqual(Component other) = this.usesSameTypeAs(other) && this.getID().equals(other.getID());
//--- matches --- //--- matches ---
/** /**
* @return true, if the component has both type and role, its type matches the given typeDecl and its name matches the given name * @return true, if the component has both type and role, its type matches the given typeDecl and its name matches the given name
...@@ -225,14 +228,20 @@ aspect Constructors { ...@@ -225,14 +228,20 @@ aspect Constructors {
//--- componentsTransitive --- //--- componentsTransitive ---
syn Collection<Component> TypeDecl.componentsTransitive() { syn Collection<Component> TypeDecl.componentsTransitive() {
ArrayList<Component> list = new ArrayList<>(); ArrayList<Component> list = new ArrayList<>();
if (hasSuper() && getSuper().decl() != null) {
list.addAll(getSuper().decl().componentsTransitive());
}
for (Component c: getComponents()) { for (Component c: getComponents()) {
if (c.inConstructor()) { if (c.inConstructor()) {
list.add(c); list.add(c);
} }
} }
int insertionIndex = 0;
if (hasSuper() && getSuper().decl() != null) {
for (Component c : getSuper().decl().componentsTransitive()) {
if (!list.stream().anyMatch(c::isEqual)) {
list.add(insertionIndex, c);
insertionIndex++;
}
}
}
return list; return list;
} }
......
...@@ -3,6 +3,7 @@ S ::= S1:A S2:A* [S3:A] /S4:A/ /S5:A*/ /[S6:A]/ /<S7>/ /<S8:long>/; ...@@ -3,6 +3,7 @@ S ::= S1:A S2:A* [S3:A] /S4:A/ /S5:A*/ /[S6:A]/ /<S7>/ /<S8:long>/;
B : S ::= B1:A B2:A* [B3:A] /B4:A/ /B5:A*/ /[B6:A]/ /<B7>/ /<B8:long>/; B : S ::= B1:A B2:A* [B3:A] /B4:A/ /B5:A*/ /[B6:A]/ /<B7>/ /<B8:long>/;
X; X;
Y; Y;
C : B ::= /<B8:long>/ /<B7>/ /[B6:A]/ /B5:A*/ /B4:A/ [B3:A] B2:A* B1:A;
rel A.r1 -> X; rel A.r1 -> X;
rel S.r2* <-> Y.r2; rel S.r2* <-> Y.r2;
......
...@@ -39,6 +39,9 @@ public class ConstructorsTest { ...@@ -39,6 +39,9 @@ public class ConstructorsTest {
A a = new A(); A a = new A();
S s0 = new S(); S s0 = new S();
S s1 = new S(a, new List<>(), new Opt<>()); S s1 = new S(a, new List<>(), new Opt<>());
// S1:A S2:A* [S3:A] S.r2*
// \------ S ------/ \- rel of S -/
S s2 = new S(a, new List<>(), new Opt<>(), new ArrayList<>()); S s2 = new S(a, new List<>(), new Opt<>(), new ArrayList<>());
Assertions.assertEquals(3, numberOfConstructors(S.class)); Assertions.assertEquals(3, numberOfConstructors(S.class));
} }
...@@ -48,10 +51,25 @@ public class ConstructorsTest { ...@@ -48,10 +51,25 @@ public class ConstructorsTest {
A a = new A(); A a = new A();
B b0 = new B(); B b0 = new B();
B b1 = new B(a, new List<>(), new Opt<>(), a, new List<>(), new Opt<>()); B b1 = new B(a, new List<>(), new Opt<>(), a, new List<>(), new Opt<>());
// S1:A S2:A* [S3:A] S.r2* B1:A B2:A* [B3:A] B.r3?
// \------ S ------/ \- rel of S -/ \------ B ------/ \- rel of B -/
B b2 = new B(a, new List<>(), new Opt<>(), new ArrayList<>(), a, new List<>(), new Opt<>(), null); B b2 = new B(a, new List<>(), new Opt<>(), new ArrayList<>(), a, new List<>(), new Opt<>(), null);
Assertions.assertEquals(3, numberOfConstructors(B.class)); Assertions.assertEquals(3, numberOfConstructors(B.class));
} }
@Test
public void testC() {
A a = new A();
C c0 = new C();
C c1 = new C(a, new List<>(), new Opt<>(), new Opt<>(), new List<>(), a);
// S1:A S2:A* [S3:A] S.r2* B.r3? [B3:A] B2:A* B1:A
// \------ S ------/ \- rel of S -/ \- rel of B -/ \------ C ------/
C c2 = new C(a, new List<>(), new Opt<>(), new ArrayList<>(), null, new Opt<>(), new List<>(), a);
Assertions.assertEquals(3, numberOfConstructors(B.class));
}
private int numberOfConstructors(Class<?> clazz) { private int numberOfConstructors(Class<?> clazz) {
return clazz.getConstructors().length; return clazz.getConstructors().length;
} }
......
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