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
db3908ff
Commit
db3908ff
authored
Oct 01, 2019
by
René Schöne
Browse files
Add LeftDirection ('<-') for relations.
- Also add some tests for left direction
parent
3b305708
Pipeline
#4421
passed with stage
in 2 minutes and 29 seconds
Changes
16
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/jastadd/Analysis.jrag
View file @
db3908ff
...
...
@@ -29,11 +29,15 @@ aspect TypeAnalysis {
aspect ComponentAnalysis {
syn boolean Component.isTargetOfDirectedRelation() = false;
eq RelationComponent.isTargetOfDirectedRelation() = isTargetOfRightDirection();
eq RelationComponent.isTargetOfDirectedRelation() = isTargetOfRightDirection()
| isTargetOfLeftDirection()
;
inh boolean RelationComponent.isTargetOfRightDirection();
eq Relation.getRight().isTargetOfRightDirection()
= getDirection() instanceof RightDirection;
eq Program.getChild().isTargetOfRightDirection() = false;
inh boolean RelationComponent.isTargetOfLeftDirection();
eq Relation.getLeft().isTargetOfLeftDirection()
= getDirection() instanceof LeftDirection;
eq Program.getChild().isTargetOfLeftDirection() = false;
syn String Component.name() = getID();
...
...
src/main/jastadd/Backend.jadd
View file @
db3908ff
...
...
@@ -216,6 +216,9 @@ aspect BackendDirectedAPI {
public void RightDirection.generateAPI(StringBuilder sb) {
relation().getLeft().generateDirectedAPI(sb);
}
public void LeftDirection.generateAPI(StringBuilder sb) {
relation().getRight().generateDirectedAPI(sb);
}
public abstract void RelationComponent.generateDirectedAPI(StringBuilder sb);
public void OneRelationComponent.generateDirectedAPI(StringBuilder sb) {
...
...
@@ -904,6 +907,9 @@ aspect NameResolutionHelper {
public void RightDirection.generateContextDependentNameResolution(StringBuilder sb) {
relation().getLeft().generateContextDependentNameResolution(sb);
}
public void LeftDirection.generateContextDependentNameResolution(StringBuilder sb) {
relation().getRight().generateContextDependentNameResolution(sb);
}
public void Bidirectional.generateContextDependentNameResolution(StringBuilder sb) {
relation().getLeft().generateContextDependentNameResolution(sb);
relation().getRight().generateContextDependentNameResolution(sb);
...
...
@@ -1451,6 +1457,9 @@ aspect PrettyPrint {
public String RightDirection.prettyPrint() {
return "->";
}
public String LeftDirection.prettyPrint() {
return "<-";
}
public String Bidirectional.prettyPrint() {
return "<->";
}
...
...
src/main/jastadd/RelAst.ast
View file @
db3908ff
...
...
@@ -21,4 +21,5 @@ OptionalRelationComponent : RelationComponent;
ManyRelationComponent : RelationComponent;
abstract Direction;
RightDirection : Direction;
LeftDirection : Direction;
Bidirectional : Direction;
src/main/jastadd/RelAst.flex
View file @
db3908ff
...
...
@@ -62,6 +62,7 @@ ID = [a-zA-Z$_][a-zA-Z0-9$_]*
"/"
{
return
sym
(
Terminals
.
SLASH
);
}
"?"
{
return
sym
(
Terminals
.
QUESTION_MARK
);
}
"->"
{
return
sym
(
Terminals
.
RIGHT
);
}
"<-"
{
return
sym
(
Terminals
.
LEFT
);
}
"<->"
{
return
sym
(
Terminals
.
BIDIRECTIONAL
);
}
//
ID
...
...
src/main/jastadd/RelAst.parser
View file @
db3908ff
...
...
@@ -101,5 +101,6 @@ RelationComponent relation_comp =
Direction direction =
RIGHT {: return new RightDirection(); :}
| LEFT {: return new LeftDirection(); :}
| BIDIRECTIONAL {: return new Bidirectional(); :}
;
src/main/java/org/jastadd/relast/compiler/Compiler.java
View file @
db3908ff
...
...
@@ -14,7 +14,7 @@ import java.util.List;
public
class
Compiler
{
private
static
final
String
VERSION
=
"0.2.
2
"
;
private
static
final
String
VERSION
=
"0.2.
3
"
;
private
ArrayList
<
Option
<?>>
options
;
private
FlagOption
optionWriteToFile
;
...
...
src/test/jastadd/errors/ErrorsLeft.expected
0 → 100644
View file @
db3908ff
Errors:
$FILENAME Line 5, column 10: Role name missing for type 'A'
$FILENAME Line 6, column 15: Role name missing for type 'B'
$FILENAME Line 7, column 5: The target of a directed relation cannot have a role name
$FILENAME Line 8, column 5: The target of a directed relation may only have multiplicity 1
src/test/jastadd/errors/ErrorsLeft.relast
0 → 100644
View file @
db3908ff
Program ::= A* B*;
A;
B;
rel B <- A;
rel A.bs* <-> B*;
rel B.b <- A.b;
rel B* <- A.b2;
src/test/jastadd/errors/InheritanceLeft.expected
0 → 100644
View file @
db3908ff
Errors:
$FILENAME Line 2, column 12: Component 'X' is already declared for type 'B1'
$FILENAME Line 6, column 10: Component 'X' is already declared for type 'B2'
src/test/jastadd/errors/InheritanceLeft.relast
0 → 100644
View file @
db3908ff
A ::= X;
B1 : A ::= X;
B2 : A;
X;
rel X <- B2.X;
src/test/jastadd/errors/MultipleLeft.expected
0 → 100644
View file @
db3908ff
Errors:
$FILENAME1 Line 5, column 10: Role name missing for type 'A'
$FILENAME1 Line 6, column 15: Role name missing for type 'B'
$FILENAME2 Line 1, column 5: The target of a directed relation cannot have a role name
$FILENAME2 Line 2, column 5: The target of a directed relation may only have multiplicity 1
src/test/jastadd/errors/MultipleLeft_1.relast
0 → 100644
View file @
db3908ff
Program ::= A* B*;
A;
B;
rel B <- A;
rel A.bs* <-> B*;
src/test/jastadd/errors/MultipleLeft_2.relast
0 → 100644
View file @
db3908ff
rel B.b <- A.b;
rel B* <- A.b2;
src/test/jastadd/relations/Relations.relast
View file @
db3908ff
...
...
@@ -17,3 +17,8 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi7* <-> B.Bi7;
rel A.Bi8* <-> B.Bi8?;
rel A.Bi9* <-> B.Bi9*;
rel A <- Root.AaLeft?;
rel B <- A.Di1Left ;
rel B <- A.Di2Left?;
rel B <- A.Di3Left*;
src/test/java/org/jastadd/relast/tests/Errors.java
View file @
db3908ff
...
...
@@ -27,16 +27,31 @@ class Errors {
test
(
"Errors"
);
}
@Test
void
test1Left
()
throws
IOException
{
test
(
"ErrorsLeft"
);
}
@Test
void
test2
()
throws
IOException
{
test
(
"Inheritance"
);
}
@Test
void
test2Left
()
throws
IOException
{
test
(
"InheritanceLeft"
);
}
@Test
void
test3
()
throws
IOException
{
test
(
"Multiple"
,
"Multiple_1"
,
"Multiple_2"
);
}
@Test
void
test3Left
()
throws
IOException
{
test
(
"MultipleLeft"
,
"MultipleLeft_1"
,
"MultipleLeft_2"
);
}
private
void
test
(
String
name
,
String
...
inFilenames
)
throws
IOException
{
List
<
String
>
inFiles
=
Arrays
.
stream
(
inFilenames
.
length
>
0
?
inFilenames
:
new
String
[]{
name
})
.
map
(
f
->
"./src/test/jastadd/errors/"
+
f
+
".relast"
)
...
...
src/test/java/org/jastadd/relast/tests/Relations.java
View file @
db3908ff
...
...
@@ -132,6 +132,100 @@ class Relations {
assertEquals
(
a3
.
getDi3List
(),
Arrays
.
asList
());
}
/**
* rel A.Di1 -> B;
*/
@Test
void
testDi1Left
()
{
setup
();
a1
.
setDi1Left
(
b2
);
a2
.
setDi1Left
(
b1
);
assertSame
(
a1
.
getDi1Left
(),
b2
);
assertSame
(
a2
.
getDi1Left
(),
b1
);
a2
.
setDi1Left
(
b2
);
assertSame
(
a1
.
getDi1Left
(),
b2
);
assertSame
(
a2
.
getDi1Left
(),
b2
);
try
{
a3
.
setDi1Left
(
null
);
fail
(
"should throw an exception"
);
}
catch
(
Exception
e
)
{
// OK
}
}
/**
* rel A.Di2? -> B;
*/
@Test
void
testDi2Left
()
{
setup
();
a1
.
setDi2Left
(
b2
);
a2
.
setDi2Left
(
b1
);
assertSame
(
a1
.
getDi2Left
(),
b2
);
assertSame
(
a2
.
getDi2Left
(),
b1
);
a2
.
setDi2Left
(
b2
);
assertSame
(
a1
.
getDi2Left
(),
b2
);
assertSame
(
a2
.
getDi2Left
(),
b2
);
a2
.
clearDi2Left
();
assertSame
(
a1
.
getDi2Left
(),
b2
);
assertNull
(
a2
.
getDi2Left
());
assertTrue
(
a1
.
hasDi2Left
());
assertFalse
(
a2
.
hasDi2Left
());
assertFalse
(
a3
.
hasDi2Left
());
}
/**
* rel A.Di3* -> B;
*/
@Test
void
testDi3Left
()
{
setup
();
a1
.
addDi3Left
(
b1
);
a1
.
addDi3Left
(
b2
);
a1
.
addDi3Left
(
b3
);
a2
.
addDi3Left
(
b2
);
assertEquals
(
a1
.
getDi3Lefts
(),
Arrays
.
asList
(
b1
,
b2
,
b3
));
assertEquals
(
a1
.
getDi3LeftList
(),
Arrays
.
asList
(
b1
,
b2
,
b3
));
assertEquals
(
a2
.
getDi3Lefts
(),
Arrays
.
asList
(
b2
));
assertEquals
(
a2
.
getDi3LeftList
(),
Arrays
.
asList
(
b2
));
assertEquals
(
a3
.
getDi3Lefts
(),
Arrays
.
asList
());
assertEquals
(
a3
.
getDi3LeftList
(),
Arrays
.
asList
());
a1
.
addDi3Left
(
b1
);
a2
.
addDi3Left
(
b1
);
a2
.
addDi3Left
(
b2
);
assertEquals
(
a1
.
getDi3Lefts
(),
Arrays
.
asList
(
b1
,
b2
,
b3
,
b1
));
assertEquals
(
a1
.
getDi3LeftList
(),
Arrays
.
asList
(
b1
,
b2
,
b3
,
b1
));
assertEquals
(
a2
.
getDi3Lefts
(),
Arrays
.
asList
(
b2
,
b1
,
b2
));
assertEquals
(
a2
.
getDi3LeftList
(),
Arrays
.
asList
(
b2
,
b1
,
b2
));
assertEquals
(
a3
.
getDi3Lefts
(),
Arrays
.
asList
());
assertEquals
(
a3
.
getDi3LeftList
(),
Arrays
.
asList
());
a1
.
removeDi3Left
(
b1
);
a2
.
removeDi3Left
(
b2
);
assertEquals
(
a1
.
getDi3Lefts
(),
Arrays
.
asList
(
b2
,
b3
,
b1
));
assertEquals
(
a1
.
getDi3LeftList
(),
Arrays
.
asList
(
b2
,
b3
,
b1
));
assertEquals
(
a2
.
getDi3Lefts
(),
Arrays
.
asList
(
b1
,
b2
));
assertEquals
(
a2
.
getDi3LeftList
(),
Arrays
.
asList
(
b1
,
b2
));
assertEquals
(
a3
.
getDi3Lefts
(),
Arrays
.
asList
());
assertEquals
(
a3
.
getDi3LeftList
(),
Arrays
.
asList
());
}
/**
* rel A.Bi1 <-> B.Bi1;
...
...
Write
Preview
Markdown
is supported
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