Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relast
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Niklas Fors
relast
Commits
d057855e
Commit
d057855e
authored
6 years ago
by
Niklas Fors
Browse files
Options
Downloads
Patches
Plain Diff
Make returned list immutable and minor refactorings
parent
519223aa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
spec/jastadd/Backend.jadd
+24
-30
24 additions, 30 deletions
spec/jastadd/Backend.jadd
test/Test.java
+37
-2
37 additions, 2 deletions
test/Test.java
with
61 additions
and
32 deletions
spec/jastadd/Backend.jadd
+
24
−
30
View file @
d057855e
...
...
@@ -72,7 +72,8 @@ aspect BackendAspect {
}
public void Program.generateAspect(StringBuilder sb) {
sb.append("import java.util.*;\n");
sb.append("import java.util.ArrayList;\n");
sb.append("import java.util.Collections;\n");
sb.append("aspect RelAstAPI {\n");
for (TypeDecl td: getTypeDecls()) {
if (td.needsConstructor()) {
...
...
@@ -142,10 +143,7 @@ aspect BackendDirectedAPI {
}
public void RelationComponent.generateDirectedZeroOneAPI(StringBuilder sb, boolean optional) {
// Get
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "return get" + getImplAttributeName() + "();\n");
sb.append(ind(1) + "}\n");
generateGetOne(sb);
// Set
sb.append(ind(1) + "public void " + toTypeDecl());
...
...
@@ -159,11 +157,7 @@ aspect BackendDirectedAPI {
public void ManyRelationComponent.generateDirectedAPI(StringBuilder sb) {
// Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "return l != null ? l : Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
generateGetMany(sb);
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
...
...
@@ -188,6 +182,13 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
}
public void RelationComponent.generateGetOne(StringBuilder sb) {
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "return get" + getImplAttributeName() + "();\n");
sb.append(ind(1) + "}\n");
}
public void RelationComponent.generateExtraOptAPI(StringBuilder sb) {
// has
sb.append(ind(1) + "public boolean " + toTypeDecl());
...
...
@@ -201,6 +202,15 @@ aspect BackendDirectedAPI {
sb.append(ind(2) + "set" + nameCapitalized() + "(null);\n");
sb.append(ind(1) + "}\n");
}
public void RelationComponent.generateGetMany(StringBuilder sb) {
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> l = get"
+ getImplAttributeName() + "();\n");
sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
}
}
aspect BackendBidirectionalAPI {
...
...
@@ -246,10 +256,7 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiOneOne(StringBuilder sb, boolean isOpt) {
// Get
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "return get" + getImplAttributeName() + "();\n");
sb.append(ind(1) + "}\n");
generateGetOne(sb);
// Set
sb.append(ind(1) + "public void " + toTypeDecl());
...
...
@@ -280,12 +287,7 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyMany(StringBuilder sb) {
// Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> l = get"
+ getImplAttributeName() + "();\n");
sb.append(ind(2) + "return l != null ? l : Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
generateGetMany(sb);
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
...
...
@@ -324,12 +326,7 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyOne(StringBuilder sb) {
// Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> l = get"
+ getImplAttributeName() + "();\n");
sb.append(ind(2) + "return l != null ? l : Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
generateGetMany(sb);
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
...
...
@@ -367,10 +364,7 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiOneMany(StringBuilder sb, boolean isOpt) {
// Get
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "return get" + getImplAttributeName() + "();\n");
sb.append(ind(1) + "}\n");
generateGetOne(sb);
// Set
sb.append(ind(1) + "public void " + toTypeDecl() + ".set" + nameCapitalized()
...
...
This diff is collapsed.
Click to expand it.
test/Test.java
+
37
−
2
View file @
d057855e
...
...
@@ -29,6 +29,8 @@ public class Test {
testBi8
();
testBi9
();
testImmutableList
();
System
.
out
.
println
(
"TESTS OK"
);
}
...
...
@@ -50,7 +52,7 @@ public class Test {
try
{
a3
.
setDi1
(
null
);
check
(
false
,
"should throw e
xception
"
);
assertE
xception
(
);
}
catch
(
Exception
e
)
{
// OK
}
...
...
@@ -231,7 +233,7 @@ public class Test {
try
{
a2
.
setBi3
(
null
);
check
(
false
,
"exception should be thrown"
);
assertException
(
);
}
catch
(
Exception
e
)
{
// OK
}
...
...
@@ -504,6 +506,36 @@ public class Test {
}
public
void
testImmutableList
()
{
setup
();
a1
.
addToDi3
(
b1
);
a1
.
addToDi3
(
b2
);
try
{
a1
.
di3
().
add
(
b3
);
assertException
();
}
catch
(
Exception
e
)
{
// OK
}
a1
.
addToBi7
(
b1
);
a1
.
addToBi7
(
b2
);
try
{
a1
.
bi7
().
add
(
b3
);
assertException
();
}
catch
(
Exception
e
)
{
// OK
}
a1
.
addToBi9
(
b1
);
a1
.
addToBi9
(
b2
);
try
{
a1
.
bi9
().
add
(
b3
);
assertException
();
}
catch
(
Exception
e
)
{
// OK
}
}
private
void
setup
()
{
r
=
new
Root
();
...
...
@@ -522,6 +554,9 @@ public class Test {
r
.
addB
(
b3
);
}
private
void
assertException
()
{
check
(
false
,
"should throw exception"
);
}
private
void
assertTrue
(
boolean
b
)
{
check
(
b
,
"value should be true (is false)"
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment