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

Commit 3846cf2

Browse files
Denys Smirnovdennwc
authored andcommitted
fix annotation of empty switch statements; fix #98
Signed-off-by: Denys Smirnov <[email protected]>
1 parent 5435997 commit 3846cf2

File tree

5 files changed

+121
-23
lines changed

5 files changed

+121
-23
lines changed

driver/normalizer/annotation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ func (opSwitchStmtGroup) Kinds() nodes.Kind {
558558

559559
func (op opSwitchStmtGroup) Check(st *State, n nodes.Node) (bool, error) {
560560
cases, ok := n.(nodes.Array)
561-
if !ok {
561+
if !ok && n != nil {
562562
return false, nil
563563
}
564564
var out nodes.Array
@@ -602,7 +602,7 @@ func (op opSwitchStmtGroup) Construct(st *State, _ nodes.Node) (nodes.Node, erro
602602
return nil, err
603603
}
604604
stmts, ok := o.(nodes.Array)
605-
if !ok {
605+
if !ok && o != nil {
606606
return nil, ErrExpectedList.New(o)
607607
}
608608
var out nodes.Array

fixtures/switch.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ void code() {
66
case 2: System.out.println("1"); break;
77
default: System.out.println("default"); break;
88
}
9+
switch (1) {
10+
}
911
}
1012
}

fixtures/switch.java.native

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
col: 1,
99
},
1010
end: { '@type': "uast:Position",
11-
offset: 285,
11+
offset: 316,
1212
col: 0,
1313
},
1414
},
@@ -24,8 +24,8 @@
2424
col: 1,
2525
},
2626
end: { '@type': "uast:Position",
27-
offset: 284,
28-
line: 10,
27+
offset: 315,
28+
line: 12,
2929
col: 2,
3030
},
3131
},
@@ -39,8 +39,8 @@
3939
col: 5,
4040
},
4141
end: { '@type': "uast:Position",
42-
offset: 282,
43-
line: 9,
42+
offset: 313,
43+
line: 11,
4444
col: 6,
4545
},
4646
},
@@ -53,8 +53,8 @@
5353
col: 17,
5454
},
5555
end: { '@type': "uast:Position",
56-
offset: 282,
57-
line: 9,
56+
offset: 313,
57+
line: 11,
5858
col: 6,
5959
},
6060
},
@@ -713,6 +713,38 @@
713713
},
714714
],
715715
},
716+
{ '@type': "SwitchStatement",
717+
'@role': [Unannotated],
718+
'@pos': { '@type': "uast:Positions",
719+
start: { '@type': "uast:Position",
720+
offset: 285,
721+
line: 9,
722+
col: 9,
723+
},
724+
end: { '@type': "uast:Position",
725+
offset: 307,
726+
line: 10,
727+
col: 10,
728+
},
729+
},
730+
expression: { '@type': "NumberLiteral",
731+
'@role': [Unannotated],
732+
'@pos': { '@type': "uast:Positions",
733+
start: { '@type': "uast:Position",
734+
offset: 293,
735+
line: 9,
736+
col: 17,
737+
},
738+
end: { '@type': "uast:Position",
739+
offset: 294,
740+
line: 9,
741+
col: 18,
742+
},
743+
},
744+
token: "1",
745+
},
746+
statements: ~,
747+
},
716748
],
717749
},
718750
constructor: "false",

fixtures/switch.java.sem.uast

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
col: 1,
88
},
99
end: { '@type': "uast:Position",
10-
offset: 285,
10+
offset: 316,
1111
col: 0,
1212
},
1313
},
@@ -23,8 +23,8 @@
2323
col: 1,
2424
},
2525
end: { '@type': "uast:Position",
26-
offset: 284,
27-
line: 10,
26+
offset: 315,
27+
line: 12,
2828
col: 2,
2929
},
3030
},
@@ -37,8 +37,8 @@
3737
col: 5,
3838
},
3939
end: { '@type': "uast:Position",
40-
offset: 282,
41-
line: 9,
40+
offset: 313,
41+
line: 11,
4242
col: 6,
4343
},
4444
},
@@ -70,8 +70,8 @@
7070
col: 17,
7171
},
7272
end: { '@type': "uast:Position",
73-
offset: 282,
74-
line: 9,
73+
offset: 313,
74+
line: 11,
7575
col: 6,
7676
},
7777
},
@@ -742,6 +742,38 @@
742742
},
743743
],
744744
},
745+
{ '@type': "java:SwitchStatement",
746+
'@role': [Statement, Switch],
747+
'@pos': { '@type': "uast:Positions",
748+
start: { '@type': "uast:Position",
749+
offset: 285,
750+
line: 9,
751+
col: 9,
752+
},
753+
end: { '@type': "uast:Position",
754+
offset: 307,
755+
line: 10,
756+
col: 10,
757+
},
758+
},
759+
expression: { '@type': "java:NumberLiteral",
760+
'@role': [Expression, Literal, Number, Switch],
761+
'@pos': { '@type': "uast:Positions",
762+
start: { '@type': "uast:Position",
763+
offset: 293,
764+
line: 9,
765+
col: 17,
766+
},
767+
end: { '@type': "uast:Position",
768+
offset: 294,
769+
line: 9,
770+
col: 18,
771+
},
772+
},
773+
token: "1",
774+
},
775+
statements: [],
776+
},
745777
],
746778
},
747779
Type: { '@type': "uast:FunctionType",

fixtures/switch.java.uast

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
col: 1,
88
},
99
end: { '@type': "uast:Position",
10-
offset: 285,
10+
offset: 316,
1111
col: 0,
1212
},
1313
},
@@ -23,8 +23,8 @@
2323
col: 1,
2424
},
2525
end: { '@type': "uast:Position",
26-
offset: 284,
27-
line: 10,
26+
offset: 315,
27+
line: 12,
2828
col: 2,
2929
},
3030
},
@@ -38,8 +38,8 @@
3838
col: 5,
3939
},
4040
end: { '@type': "uast:Position",
41-
offset: 282,
42-
line: 9,
41+
offset: 313,
42+
line: 11,
4343
col: 6,
4444
},
4545
},
@@ -52,8 +52,8 @@
5252
col: 17,
5353
},
5454
end: { '@type': "uast:Position",
55-
offset: 282,
56-
line: 9,
55+
offset: 313,
56+
line: 11,
5757
col: 6,
5858
},
5959
},
@@ -720,6 +720,38 @@
720720
},
721721
],
722722
},
723+
{ '@type': "SwitchStatement",
724+
'@role': [Statement, Switch],
725+
'@pos': { '@type': "uast:Positions",
726+
start: { '@type': "uast:Position",
727+
offset: 285,
728+
line: 9,
729+
col: 9,
730+
},
731+
end: { '@type': "uast:Position",
732+
offset: 307,
733+
line: 10,
734+
col: 10,
735+
},
736+
},
737+
expression: { '@type': "NumberLiteral",
738+
'@role': [Expression, Literal, Number, Switch],
739+
'@pos': { '@type': "uast:Positions",
740+
start: { '@type': "uast:Position",
741+
offset: 293,
742+
line: 9,
743+
col: 17,
744+
},
745+
end: { '@type': "uast:Position",
746+
offset: 294,
747+
line: 9,
748+
col: 18,
749+
},
750+
},
751+
token: "1",
752+
},
753+
statements: [],
754+
},
723755
],
724756
},
725757
constructor: "false",

0 commit comments

Comments
 (0)