Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
JastAdd
relational-rags
Commits
26317618
Commit
26317618
authored
Nov 02, 2020
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/jastadd/Analysis.jrag
View file @
26317618
...
...
@@ -97,19 +97,20 @@ aspect ComponentAnalysis {
// find a matching component on the RHS of the (current) super type
Component c = findComponent(td, getID());
if (c != null && !this.
isEqual
(c)) return c;
if (c != null && !this.
usesSameTypeAs
(c)) return c;
}
return null;
}
//---
isEqual
---
syn boolean Component.
isEqual
(Component c) = this.getClass() == c.getClass() && getTypeUse().isEqual(c.getTypeUse());
//---
usesSameTypeAs
---
syn boolean Component.
usesSameTypeAs
(Component c) = this.getClass() == c.getClass() && getTypeUse().isEqual(c.getTypeUse());
/**
* 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);
eq SimpleTypeUse.isEqual(TypeUse u) = u instanceof SimpleTypeUse && getID().equals(u.getID());
eq ParameterizedTypeUse.isEqual(TypeUse u) {
...
...
@@ -123,6 +124,8 @@ aspect ComponentAnalysis {
return true;
}
syn boolean Component.isEqual(Component other) = this.usesSameTypeAs(other) && this.getID().equals(other.getID());
//--- matches ---
/**
* @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 {
//--- componentsTransitive ---
syn Collection<Component> TypeDecl.componentsTransitive() {
ArrayList<Component> list = new ArrayList<>();
if (hasSuper() && getSuper().decl() != null) {
list.addAll(getSuper().decl().componentsTransitive());
}
for (Component c: getComponents()) {
if (c.inConstructor()) {
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;
}
...
...
src/test/jastadd/constructors/Constructors.relast
View file @
26317618
...
...
@@ -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>/;
X;
Y;
C : B ::= /<B8:long>/ /<B7>/ /[B6:A]/ /B5:A*/ /B4:A/ [B3:A] B2:A* B1:A;
rel A.r1 -> X;
rel S.r2* <-> Y.r2;
...
...
src/test/java/org/jastadd/relast/tests/ConstructorsTest.java
View file @
26317618
...
...
@@ -39,6 +39,9 @@ public class ConstructorsTest {
A
a
=
new
A
();
S
s0
=
new
S
();
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
<>());
Assertions
.
assertEquals
(
3
,
numberOfConstructors
(
S
.
class
));
}
...
...
@@ -48,10 +51,25 @@ public class ConstructorsTest {
A
a
=
new
A
();
B
b0
=
new
B
();
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
);
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
)
{
return
clazz
.
getConstructors
().
length
;
}
...
...
René Schöne
@rschoene
mentioned in issue
relast2uml#3
·
Nov 02, 2020
mentioned in issue
relast2uml#3
mentioned in issue relast2uml#3
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment