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

Commit 3080d15

Browse files
committed
annotations: Add BinaryExpression* annotations
* Add the annotations * Update the ANNOTATION documentation * Update the integration tests * Add a new specific test for theses roles
1 parent df43b92 commit 3080d15

10 files changed

Lines changed: 316 additions & 64 deletions

ANNOTATION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='DoStatement'\] | DoWhile |
5353
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='DoStatement'\]/\*\[@internalRole\]\[@internalRole='expression'\] | DoWhileCondition |
5454
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='DoStatement'\]/\*\[@internalRole\]\[@internalRole='body'\] | DoWhileBody |
55+
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\] | BinaryExpression |
5556
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\+'\] | OpAdd |
5657
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\-'\] | OpSubstract |
5758
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\*'\] | OpMultiply |
@@ -65,6 +66,8 @@
6566
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='&&'\] | OpBooleanAnd |
6667
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\|\|'\] | OpBooleanOr |
6768
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='^'\] | OpBooleanXor |
69+
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/\*\[@internalRole\]\[@internalRole='leftOperand'\] | BinaryExpressionLeft |
70+
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/\*\[@internalRole\]\[@internalRole='rightOperand'\] | BinaryExpressionRight |
6871
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='PostfixExpression'\]/self::\*\[@operator\]\[@operator='\+\+'\] | OpPostIncrement |
6972
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='PostfixExpression'\]/self::\*\[@operator\]\[@operator='\-\-'\] | OpPostDecrement |
7073
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='PrefixExpression'\]/self::\*\[@operator\]\[@operator='\+\+'\] | OpPreIncrement |

driver/normalizer/annotation.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var AnnotationRules = On(Any).Self(
109109
On(jdt.PropertyBody).Roles(DoWhileBody),
110110
),
111111

112-
On(jdt.InfixExpression).Self(
112+
On(jdt.InfixExpression).Roles(BinaryExpression, BinaryExpressionOp).Self(
113113
On(HasProperty("operator", "+")).Roles(OpAdd),
114114
On(HasProperty("operator", "-")).Roles(OpSubstract),
115115
On(HasProperty("operator", "*")).Roles(OpMultiply),
@@ -123,6 +123,9 @@ var AnnotationRules = On(Any).Self(
123123
On(HasProperty("operator", "&&")).Roles(OpBooleanAnd),
124124
On(HasProperty("operator", "||")).Roles(OpBooleanOr),
125125
On(HasProperty("operator", "^")).Roles(OpBooleanXor),
126+
).Children(
127+
On(jdt.PropertyLeftOperand).Roles(BinaryExpressionLeft),
128+
On(jdt.PropertyRightOperand).Roles(BinaryExpressionRight),
126129
),
127130

128131
On(jdt.PostfixExpression).Self(

tests/binary_expression.native

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
"internalClass": "NumberLiteral",
21+
"line": 3,
22+
"startPosition": 41,
23+
"token": "3"
24+
},
25+
"line": 3,
26+
"operator": "+",
27+
"rightOperand": {
28+
"internalClass": "NumberLiteral",
29+
"line": 3,
30+
"startPosition": 45,
31+
"token": "4"
32+
},
33+
"startPosition": 41
34+
},
35+
"internalClass": "VariableDeclarationFragment",
36+
"name": {
37+
"identifier": "a",
38+
"internalClass": "SimpleName",
39+
"line": 3,
40+
"startPosition": 37
41+
}
42+
}
43+
],
44+
"internalClass": "VariableDeclarationStatement",
45+
"type": {
46+
"internalClass": "PrimitiveType",
47+
"line": 3,
48+
"primitiveTypeCode": "int",
49+
"startPosition": 33
50+
}
51+
}
52+
]
53+
},
54+
"constructor": "false",
55+
"internalClass": "MethodDeclaration",
56+
"line": 2,
57+
"name": {
58+
"identifier": "code",
59+
"internalClass": "SimpleName",
60+
"line": 2,
61+
"startPosition": 20
62+
},
63+
"returnType2": {
64+
"internalClass": "PrimitiveType",
65+
"line": 2,
66+
"primitiveTypeCode": "void",
67+
"startPosition": 15
68+
},
69+
"startPosition": 15
70+
}
71+
],
72+
"interface": "false",
73+
"internalClass": "TypeDeclaration",
74+
"line": 1,
75+
"name": {
76+
"identifier": "Code",
77+
"internalClass": "SimpleName",
78+
"line": 1,
79+
"startPosition": 6
80+
},
81+
"startPosition": 0
82+
}
83+
]
84+
}
85+
}
86+
}

tests/binary_expression.source

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Code {
2+
void code() {
3+
int a = 3 + 4;
4+
}
5+
}

tests/binary_expression.uast

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
Status: ok
2+
Errors:
3+
UAST:
4+
CompilationUnit {
5+
. Roles: File
6+
. Children: {
7+
. . 0: TypeDeclaration {
8+
. . . Roles: VisibleFromPackage,TypeDeclaration
9+
. . . StartPosition: {
10+
. . . . Offset: 0
11+
. . . . Line: 1
12+
. . . . Col: 0
13+
. . . }
14+
. . . Properties: {
15+
. . . . interface: false
16+
. . . . internalRole: types
17+
. . . }
18+
. . . Children: {
19+
. . . . 0: SimpleName {
20+
. . . . . Roles: SimpleIdentifier
21+
. . . . . TOKEN "Code"
22+
. . . . . StartPosition: {
23+
. . . . . . Offset: 6
24+
. . . . . . Line: 1
25+
. . . . . . Col: 0
26+
. . . . . }
27+
. . . . . Properties: {
28+
. . . . . . internalRole: name
29+
. . . . . }
30+
. . . . }
31+
. . . . 1: MethodDeclaration {
32+
. . . . . Roles: VisibleFromPackage,FunctionDeclaration
33+
. . . . . StartPosition: {
34+
. . . . . . Offset: 15
35+
. . . . . . Line: 2
36+
. . . . . . Col: 0
37+
. . . . . }
38+
. . . . . Properties: {
39+
. . . . . . constructor: false
40+
. . . . . . internalRole: bodyDeclarations
41+
. . . . . }
42+
. . . . . Children: {
43+
. . . . . . 0: PrimitiveType {
44+
. . . . . . . TOKEN "void"
45+
. . . . . . . StartPosition: {
46+
. . . . . . . . Offset: 15
47+
. . . . . . . . Line: 2
48+
. . . . . . . . Col: 0
49+
. . . . . . . }
50+
. . . . . . . Properties: {
51+
. . . . . . . . internalRole: returnType2
52+
. . . . . . . }
53+
. . . . . . }
54+
. . . . . . 1: SimpleName {
55+
. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName
56+
. . . . . . . TOKEN "code"
57+
. . . . . . . StartPosition: {
58+
. . . . . . . . Offset: 20
59+
. . . . . . . . Line: 2
60+
. . . . . . . . Col: 0
61+
. . . . . . . }
62+
. . . . . . . Properties: {
63+
. . . . . . . . internalRole: name
64+
. . . . . . . }
65+
. . . . . . }
66+
. . . . . . 2: Block {
67+
. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block
68+
. . . . . . . Properties: {
69+
. . . . . . . . internalRole: body
70+
. . . . . . . }
71+
. . . . . . . Children: {
72+
. . . . . . . . 0: VariableDeclarationStatement {
73+
. . . . . . . . . Properties: {
74+
. . . . . . . . . . internalRole: statements
75+
. . . . . . . . . }
76+
. . . . . . . . . Children: {
77+
. . . . . . . . . . 0: PrimitiveType {
78+
. . . . . . . . . . . TOKEN "int"
79+
. . . . . . . . . . . StartPosition: {
80+
. . . . . . . . . . . . Offset: 33
81+
. . . . . . . . . . . . Line: 3
82+
. . . . . . . . . . . . Col: 0
83+
. . . . . . . . . . . }
84+
. . . . . . . . . . . Properties: {
85+
. . . . . . . . . . . . internalRole: type
86+
. . . . . . . . . . . }
87+
. . . . . . . . . . }
88+
. . . . . . . . . . 1: VariableDeclarationFragment {
89+
. . . . . . . . . . . Properties: {
90+
. . . . . . . . . . . . internalRole: fragments
91+
. . . . . . . . . . . }
92+
. . . . . . . . . . . Children: {
93+
. . . . . . . . . . . . 0: SimpleName {
94+
. . . . . . . . . . . . . Roles: SimpleIdentifier
95+
. . . . . . . . . . . . . TOKEN "a"
96+
. . . . . . . . . . . . . StartPosition: {
97+
. . . . . . . . . . . . . . Offset: 37
98+
. . . . . . . . . . . . . . Line: 3
99+
. . . . . . . . . . . . . . Col: 0
100+
. . . . . . . . . . . . . }
101+
. . . . . . . . . . . . . Properties: {
102+
. . . . . . . . . . . . . . internalRole: name
103+
. . . . . . . . . . . . . }
104+
. . . . . . . . . . . . }
105+
. . . . . . . . . . . . 1: InfixExpression {
106+
. . . . . . . . . . . . . Roles: BinaryExpression,BinaryExpressionOp,OpAdd
107+
. . . . . . . . . . . . . StartPosition: {
108+
. . . . . . . . . . . . . . Offset: 41
109+
. . . . . . . . . . . . . . Line: 3
110+
. . . . . . . . . . . . . . Col: 0
111+
. . . . . . . . . . . . . }
112+
. . . . . . . . . . . . . Properties: {
113+
. . . . . . . . . . . . . . internalRole: initializer
114+
. . . . . . . . . . . . . . operator: +
115+
. . . . . . . . . . . . . }
116+
. . . . . . . . . . . . . Children: {
117+
. . . . . . . . . . . . . . 0: NumberLiteral {
118+
. . . . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionLeft
119+
. . . . . . . . . . . . . . . StartPosition: {
120+
. . . . . . . . . . . . . . . . Offset: 41
121+
. . . . . . . . . . . . . . . . Line: 3
122+
. . . . . . . . . . . . . . . . Col: 0
123+
. . . . . . . . . . . . . . . }
124+
. . . . . . . . . . . . . . . Properties: {
125+
. . . . . . . . . . . . . . . . internalRole: leftOperand
126+
. . . . . . . . . . . . . . . . token: 3
127+
. . . . . . . . . . . . . . . }
128+
. . . . . . . . . . . . . . }
129+
. . . . . . . . . . . . . . 1: NumberLiteral {
130+
. . . . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionRight
131+
. . . . . . . . . . . . . . . StartPosition: {
132+
. . . . . . . . . . . . . . . . Offset: 45
133+
. . . . . . . . . . . . . . . . Line: 3
134+
. . . . . . . . . . . . . . . . Col: 0
135+
. . . . . . . . . . . . . . . }
136+
. . . . . . . . . . . . . . . Properties: {
137+
. . . . . . . . . . . . . . . . internalRole: rightOperand
138+
. . . . . . . . . . . . . . . . token: 4
139+
. . . . . . . . . . . . . . . }
140+
. . . . . . . . . . . . . . }
141+
. . . . . . . . . . . . . }
142+
. . . . . . . . . . . . }
143+
. . . . . . . . . . . }
144+
. . . . . . . . . . }
145+
. . . . . . . . . }
146+
. . . . . . . . }
147+
. . . . . . . }
148+
. . . . . . }
149+
. . . . . }
150+
. . . . }
151+
. . . }
152+
. . }
153+
. }
154+
}
155+

tests/boolean_operators.uast

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ CompilationUnit {
103103
. . . . . . . . . . . . . }
104104
. . . . . . . . . . . . }
105105
. . . . . . . . . . . . 1: InfixExpression {
106-
. . . . . . . . . . . . . Roles: OpBooleanAnd
106+
. . . . . . . . . . . . . Roles: BinaryExpression,BinaryExpressionOp,OpBooleanAnd
107107
. . . . . . . . . . . . . StartPosition: {
108108
. . . . . . . . . . . . . . Offset: 45
109109
. . . . . . . . . . . . . . Line: 3
@@ -115,7 +115,7 @@ CompilationUnit {
115115
. . . . . . . . . . . . . }
116116
. . . . . . . . . . . . . Children: {
117117
. . . . . . . . . . . . . . 0: BooleanLiteral {
118-
. . . . . . . . . . . . . . . Roles: BooleanLiteral
118+
. . . . . . . . . . . . . . . Roles: BooleanLiteral,BinaryExpressionLeft
119119
. . . . . . . . . . . . . . . StartPosition: {
120120
. . . . . . . . . . . . . . . . Offset: 45
121121
. . . . . . . . . . . . . . . . Line: 3
@@ -127,7 +127,7 @@ CompilationUnit {
127127
. . . . . . . . . . . . . . . }
128128
. . . . . . . . . . . . . . }
129129
. . . . . . . . . . . . . . 1: BooleanLiteral {
130-
. . . . . . . . . . . . . . . Roles: BooleanLiteral
130+
. . . . . . . . . . . . . . . Roles: BooleanLiteral,BinaryExpressionRight
131131
. . . . . . . . . . . . . . . StartPosition: {
132132
. . . . . . . . . . . . . . . . Offset: 53
133133
. . . . . . . . . . . . . . . . Line: 3
@@ -175,7 +175,7 @@ CompilationUnit {
175175
. . . . . . . . . . . . . }
176176
. . . . . . . . . . . . }
177177
. . . . . . . . . . . . 1: InfixExpression {
178-
. . . . . . . . . . . . . Roles: OpBooleanOr,AssignmentValue
178+
. . . . . . . . . . . . . Roles: BinaryExpression,BinaryExpressionOp,OpBooleanOr,AssignmentValue
179179
. . . . . . . . . . . . . StartPosition: {
180180
. . . . . . . . . . . . . . Offset: 68
181181
. . . . . . . . . . . . . . Line: 4
@@ -187,7 +187,7 @@ CompilationUnit {
187187
. . . . . . . . . . . . . }
188188
. . . . . . . . . . . . . Children: {
189189
. . . . . . . . . . . . . . 0: SimpleName {
190-
. . . . . . . . . . . . . . . Roles: SimpleIdentifier
190+
. . . . . . . . . . . . . . . Roles: SimpleIdentifier,BinaryExpressionLeft
191191
. . . . . . . . . . . . . . . TOKEN "i"
192192
. . . . . . . . . . . . . . . StartPosition: {
193193
. . . . . . . . . . . . . . . . Offset: 68
@@ -199,7 +199,7 @@ CompilationUnit {
199199
. . . . . . . . . . . . . . . }
200200
. . . . . . . . . . . . . . }
201201
. . . . . . . . . . . . . . 1: BooleanLiteral {
202-
. . . . . . . . . . . . . . . Roles: BooleanLiteral
202+
. . . . . . . . . . . . . . . Roles: BooleanLiteral,BinaryExpressionRight
203203
. . . . . . . . . . . . . . . StartPosition: {
204204
. . . . . . . . . . . . . . . . Offset: 73
205205
. . . . . . . . . . . . . . . . Line: 4

tests/do_while.uast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ CompilationUnit {
239239
. . . . . . . . . . . }
240240
. . . . . . . . . . }
241241
. . . . . . . . . . 1: InfixExpression {
242-
. . . . . . . . . . . Roles: DoWhileCondition
242+
. . . . . . . . . . . Roles: DoWhileCondition,BinaryExpression,BinaryExpressionOp
243243
. . . . . . . . . . . StartPosition: {
244244
. . . . . . . . . . . . Offset: 120
245245
. . . . . . . . . . . . Line: 7
@@ -251,7 +251,7 @@ CompilationUnit {
251251
. . . . . . . . . . . }
252252
. . . . . . . . . . . Children: {
253253
. . . . . . . . . . . . 0: SimpleName {
254-
. . . . . . . . . . . . . Roles: SimpleIdentifier
254+
. . . . . . . . . . . . . Roles: SimpleIdentifier,BinaryExpressionLeft
255255
. . . . . . . . . . . . . TOKEN "i"
256256
. . . . . . . . . . . . . StartPosition: {
257257
. . . . . . . . . . . . . . Offset: 120
@@ -263,7 +263,7 @@ CompilationUnit {
263263
. . . . . . . . . . . . . }
264264
. . . . . . . . . . . . }
265265
. . . . . . . . . . . . 1: NumberLiteral {
266-
. . . . . . . . . . . . . Roles: NumberLiteral
266+
. . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionRight
267267
. . . . . . . . . . . . . StartPosition: {
268268
. . . . . . . . . . . . . . Offset: 124
269269
. . . . . . . . . . . . . . Line: 7

tests/for.uast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ CompilationUnit {
126126
. . . . . . . . . . . }
127127
. . . . . . . . . . }
128128
. . . . . . . . . . 1: InfixExpression {
129-
. . . . . . . . . . . Roles: ForExpression
129+
. . . . . . . . . . . Roles: ForExpression,BinaryExpression,BinaryExpressionOp
130130
. . . . . . . . . . . StartPosition: {
131131
. . . . . . . . . . . . Offset: 49
132132
. . . . . . . . . . . . Line: 3
@@ -138,7 +138,7 @@ CompilationUnit {
138138
. . . . . . . . . . . }
139139
. . . . . . . . . . . Children: {
140140
. . . . . . . . . . . . 0: SimpleName {
141-
. . . . . . . . . . . . . Roles: SimpleIdentifier
141+
. . . . . . . . . . . . . Roles: SimpleIdentifier,BinaryExpressionLeft
142142
. . . . . . . . . . . . . TOKEN "i"
143143
. . . . . . . . . . . . . StartPosition: {
144144
. . . . . . . . . . . . . . Offset: 49
@@ -150,7 +150,7 @@ CompilationUnit {
150150
. . . . . . . . . . . . . }
151151
. . . . . . . . . . . . }
152152
. . . . . . . . . . . . 1: NumberLiteral {
153-
. . . . . . . . . . . . . Roles: NumberLiteral
153+
. . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionRight
154154
. . . . . . . . . . . . . StartPosition: {
155155
. . . . . . . . . . . . . . Offset: 53
156156
. . . . . . . . . . . . . . Line: 3

0 commit comments

Comments
 (0)