Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 74514ea

Browse files
authored
Merge pull request #15 from abeaumont/feature/improve-annotations
New annotations
2 parents 117f18a + 0df0dea commit 74514ea

26 files changed

Lines changed: 1624 additions & 41 deletions

driver/normalizer/annotation.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,21 @@ var AnnotationRules = On(Any).Self(
6868
On(jdt.IfStatement).Roles(If, Statement).Children(
6969
On(jdt.PropertyExpression).Roles(IfCondition),
7070
On(jdt.PropertyThenStatement).Roles(IfBody),
71-
On(jdt.PropertyElseExpression).Roles(IfElse),
71+
On(jdt.PropertyElseStatement).Roles(IfElse),
7272
),
7373

7474
On(jdt.SwitchStatement).Roles(Switch, Statement).Children(
7575
//TODO: On(jdt.PropertyExpression).Roles(SwitchExpression),
76-
On(jdt.SwitchCase).Roles(SwitchCase),
76+
On(jdt.SwitchCase).Self(
77+
On(HasChild(Any)).Roles(SwitchCase).Children(
78+
On(jdt.PropertyExpression).Roles(SwitchCaseCondition),
79+
),
80+
On(Not(HasChild(Any))).Roles(SwitchDefault),
81+
),
82+
// FIXME: Switch case bodies are not enclosed in a block, thus it may
83+
// contain an arbitrary number of statements (of any kind). So this
84+
// is just an initial approach.
85+
On(jdt.ExpressionStatement).Roles(SwitchCaseBody),
7786
),
7887

7988
// Loops
@@ -149,16 +158,25 @@ var AnnotationRules = On(Any).Self(
149158
),
150159
),
151160

161+
On(jdt.TryStatement).Roles(Try, Statement).Children(
162+
// TODO: TryWithResourcesStatement
163+
On(jdt.PropertyBody).Roles(TryBody),
164+
On(jdt.PropertyCatchClauses).Roles(TryCatch),
165+
On(jdt.PropertyFinally).Roles(TryFinally),
166+
),
167+
168+
On(jdt.ThrowStatement).Roles(Throw, Statement),
169+
152170
On(jdt.AssertStatement).Roles(Assert, Statement),
153171

154172
// Others
155173
On(jdt.Block).Roles(BlockScope, Block),
156174
On(jdt.ExpressionStatement).Roles(Statement),
157175
On(jdt.ReturnStatement).Roles(Return, Statement),
176+
On(jdt.BreakStatement).Roles(Break, Statement),
158177

159178
On(jdt.ThisExpression).Roles(This, Expression),
160179
//TODO: synchronized
161-
//TODO: try-with-resources
162180
On(jdt.Javadoc).Roles(Documentation, Comment),
163181
),
164182
)

tests/boolean_operators.native

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
{
2+
"status": "ok",
3+
"errors": [],
4+
"ast": {
5+
"CompilationUnit": {
6+
"internalClass": "CompilationUnit",
7+
"types": [
8+
{
9+
"bodyDeclarations": [
10+
{
11+
"body": {
12+
"internalClass": "Block",
13+
"statements": [
14+
{
15+
"fragments": [
16+
{
17+
"initializer": {
18+
"internalClass": "InfixExpression",
19+
"leftOperand": {
20+
"booleanValue": "true",
21+
"internalClass": "BooleanLiteral",
22+
"line": 3,
23+
"startPosition": 45
24+
},
25+
"line": 3,
26+
"operator": "&&",
27+
"rightOperand": {
28+
"booleanValue": "false",
29+
"internalClass": "BooleanLiteral",
30+
"line": 3,
31+
"startPosition": 53
32+
},
33+
"startPosition": 45
34+
},
35+
"internalClass": "VariableDeclarationFragment",
36+
"name": {
37+
"identifier": "i",
38+
"internalClass": "SimpleName",
39+
"line": 3,
40+
"startPosition": 41
41+
}
42+
}
43+
],
44+
"internalClass": "VariableDeclarationStatement",
45+
"type": {
46+
"internalClass": "PrimitiveType",
47+
"line": 3,
48+
"primitiveTypeCode": "boolean",
49+
"startPosition": 33
50+
}
51+
},
52+
{
53+
"expression": {
54+
"internalClass": "Assignment",
55+
"leftHandSide": {
56+
"identifier": "i",
57+
"internalClass": "SimpleName",
58+
"line": 4,
59+
"startPosition": 64
60+
},
61+
"line": 4,
62+
"operator": "=",
63+
"rightHandSide": {
64+
"internalClass": "InfixExpression",
65+
"leftOperand": {
66+
"identifier": "i",
67+
"internalClass": "SimpleName",
68+
"line": 4,
69+
"startPosition": 68
70+
},
71+
"line": 4,
72+
"operator": "||",
73+
"rightOperand": {
74+
"booleanValue": "false",
75+
"internalClass": "BooleanLiteral",
76+
"line": 4,
77+
"startPosition": 73
78+
},
79+
"startPosition": 68
80+
},
81+
"startPosition": 64
82+
},
83+
"internalClass": "ExpressionStatement"
84+
},
85+
{
86+
"expression": {
87+
"internalClass": "Assignment",
88+
"leftHandSide": {
89+
"identifier": "i",
90+
"internalClass": "SimpleName",
91+
"line": 5,
92+
"startPosition": 84
93+
},
94+
"line": 5,
95+
"operator": "=",
96+
"rightHandSide": {
97+
"internalClass": "PrefixExpression",
98+
"line": 5,
99+
"operand": {
100+
"identifier": "i",
101+
"internalClass": "SimpleName",
102+
"line": 5,
103+
"startPosition": 89
104+
},
105+
"operator": "!",
106+
"startPosition": 88
107+
},
108+
"startPosition": 84
109+
},
110+
"internalClass": "ExpressionStatement"
111+
}
112+
]
113+
},
114+
"constructor": "false",
115+
"internalClass": "MethodDeclaration",
116+
"line": 2,
117+
"name": {
118+
"identifier": "code",
119+
"internalClass": "SimpleName",
120+
"line": 2,
121+
"startPosition": 20
122+
},
123+
"returnType2": {
124+
"internalClass": "PrimitiveType",
125+
"line": 2,
126+
"primitiveTypeCode": "void",
127+
"startPosition": 15
128+
},
129+
"startPosition": 15
130+
}
131+
],
132+
"interface": "false",
133+
"internalClass": "TypeDeclaration",
134+
"line": 1,
135+
"name": {
136+
"identifier": "Code",
137+
"internalClass": "SimpleName",
138+
"line": 1,
139+
"startPosition": 6
140+
},
141+
"startPosition": 0
142+
}
143+
]
144+
}
145+
}
146+
}

tests/boolean_operators.source

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Code {
2+
void code() {
3+
boolean i = true && false;
4+
i = i || false;
5+
i = !i;
6+
}
7+
}

0 commit comments

Comments
 (0)