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

Commit aafc1f8

Browse files
committed
[annotations] Add assert statement annotation.
1 parent 21d422e commit aafc1f8

4 files changed

Lines changed: 212 additions & 0 deletions

File tree

driver/normalizer/annotation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ var AnnotationRules = On(Any).Self(
149149
),
150150
),
151151

152+
On(jdt.AssertStatement).Roles(Assert, Statement),
153+
152154
// Others
153155
On(jdt.Block).Roles(BlockScope, Block),
154156
On(jdt.ExpressionStatement).Roles(Statement),

tests/assert.native

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
"expression": {
16+
"booleanValue": "true",
17+
"internalClass": "BooleanLiteral",
18+
"line": 3,
19+
"startPosition": 40
20+
},
21+
"internalClass": "AssertStatement"
22+
},
23+
{
24+
"expression": {
25+
"booleanValue": "true",
26+
"internalClass": "BooleanLiteral",
27+
"line": 4,
28+
"startPosition": 57
29+
},
30+
"internalClass": "AssertStatement",
31+
"message": {
32+
"booleanValue": "false",
33+
"internalClass": "BooleanLiteral",
34+
"line": 4,
35+
"startPosition": 64
36+
}
37+
}
38+
]
39+
},
40+
"constructor": "false",
41+
"internalClass": "MethodDeclaration",
42+
"line": 2,
43+
"name": {
44+
"identifier": "code",
45+
"internalClass": "SimpleName",
46+
"line": 2,
47+
"startPosition": 20
48+
},
49+
"returnType2": {
50+
"internalClass": "PrimitiveType",
51+
"line": 2,
52+
"primitiveTypeCode": "void",
53+
"startPosition": 15
54+
},
55+
"startPosition": 15
56+
}
57+
],
58+
"interface": "false",
59+
"internalClass": "TypeDeclaration",
60+
"line": 1,
61+
"name": {
62+
"identifier": "Code",
63+
"internalClass": "SimpleName",
64+
"line": 1,
65+
"startPosition": 6
66+
},
67+
"startPosition": 0
68+
}
69+
]
70+
}
71+
}
72+
}

tests/assert.source

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

tests/assert.uast

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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: AssertStatement {
73+
. . . . . . . . . Roles: Assert,Statement
74+
. . . . . . . . . Properties: {
75+
. . . . . . . . . . internalRole: statements
76+
. . . . . . . . . }
77+
. . . . . . . . . Children: {
78+
. . . . . . . . . . 0: BooleanLiteral {
79+
. . . . . . . . . . . Roles: BooleanLiteral
80+
. . . . . . . . . . . StartPosition: {
81+
. . . . . . . . . . . . Offset: 40
82+
. . . . . . . . . . . . Line: 3
83+
. . . . . . . . . . . . Col: 0
84+
. . . . . . . . . . . }
85+
. . . . . . . . . . . Properties: {
86+
. . . . . . . . . . . . booleanValue: true
87+
. . . . . . . . . . . . internalRole: expression
88+
. . . . . . . . . . . }
89+
. . . . . . . . . . }
90+
. . . . . . . . . }
91+
. . . . . . . . }
92+
. . . . . . . . 1: AssertStatement {
93+
. . . . . . . . . Roles: Assert,Statement
94+
. . . . . . . . . Properties: {
95+
. . . . . . . . . . internalRole: statements
96+
. . . . . . . . . }
97+
. . . . . . . . . Children: {
98+
. . . . . . . . . . 0: BooleanLiteral {
99+
. . . . . . . . . . . Roles: BooleanLiteral
100+
. . . . . . . . . . . StartPosition: {
101+
. . . . . . . . . . . . Offset: 57
102+
. . . . . . . . . . . . Line: 4
103+
. . . . . . . . . . . . Col: 0
104+
. . . . . . . . . . . }
105+
. . . . . . . . . . . Properties: {
106+
. . . . . . . . . . . . booleanValue: true
107+
. . . . . . . . . . . . internalRole: expression
108+
. . . . . . . . . . . }
109+
. . . . . . . . . . }
110+
. . . . . . . . . . 1: BooleanLiteral {
111+
. . . . . . . . . . . Roles: BooleanLiteral
112+
. . . . . . . . . . . StartPosition: {
113+
. . . . . . . . . . . . Offset: 64
114+
. . . . . . . . . . . . Line: 4
115+
. . . . . . . . . . . . Col: 0
116+
. . . . . . . . . . . }
117+
. . . . . . . . . . . Properties: {
118+
. . . . . . . . . . . . booleanValue: false
119+
. . . . . . . . . . . . internalRole: message
120+
. . . . . . . . . . . }
121+
. . . . . . . . . . }
122+
. . . . . . . . . }
123+
. . . . . . . . }
124+
. . . . . . . }
125+
. . . . . . }
126+
. . . . . }
127+
. . . . }
128+
. . . }
129+
. . }
130+
. }
131+
}
132+

0 commit comments

Comments
 (0)