File tree 3 files changed +19
-3
lines changed
main/java/spoon/support/compiler/jdt
3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -372,7 +372,7 @@ public <E> void visitCtSwitch(CtSwitch<E> e) {
372
372
}
373
373
previous = ctCase ;
374
374
}
375
- if (previous .getPosition ().getSourceEnd () < comment .getPosition ().getSourceStart ()) {
375
+ if (previous != null && previous .getPosition ().getSourceEnd () < comment .getPosition ().getSourceStart ()) {
376
376
addCommentToNear (comment , new ArrayList <>(previous .getStatements ()));
377
377
try {
378
378
comment .getParent ();
Original file line number Diff line number Diff line change @@ -1120,17 +1120,23 @@ public void testCommentGetRawContent() {
1120
1120
" * @version 1.0\r " +
1121
1121
" */" , type .getComments ().get (0 ).getRawContent ());
1122
1122
}
1123
+
1123
1124
@ Test
1124
1125
public void testEmptyStatementComments () {
1125
1126
//contract: model building should not produce NPE, comments should exist
1126
1127
Launcher launcher = new Launcher ();
1127
1128
launcher .addInputResource ("./src/test/java/spoon/test/comment/testclasses/EmptyStatementComments.java" );
1128
1129
launcher .getEnvironment ().setCommentEnabled (true );
1129
1130
1130
- CtModel model = launcher .buildModel ();
1131
- List <CtIf > conditions = model .getElements (new TypeFilter <>(CtIf .class ));
1131
+ List <CtMethod <?>> methods = launcher .buildModel ().getElements (new TypeFilter <>(CtMethod .class ));
1132
+
1133
+ List <CtIf > conditions = methods .get (0 ).getElements (new TypeFilter <>(CtIf .class ));
1132
1134
assertEquals ("comment" , conditions .get (0 ).getComments ().get (0 ).getContent ());
1133
1135
assertEquals ("comment" , conditions .get (1 ).getComments ().get (0 ).getContent ());
1136
+
1137
+ List <CtSwitch <?>> switches = methods .get (1 ).getElements (new TypeFilter <>(CtSwitch .class ));
1138
+ assertEquals ("commentInline" , switches .get (0 ).getComments ().get (0 ).getContent ());
1139
+ assertEquals ("commentBlock" , switches .get (1 ).getComments ().get (0 ).getContent ());
1134
1140
}
1135
1141
1136
1142
@ Test
Original file line number Diff line number Diff line change @@ -8,4 +8,14 @@ void m1() {
8
8
if (true ) /* comment */
9
9
;
10
10
}
11
+
12
+ void m2 (int value ) {
13
+ switch (value ) {
14
+ // commentInline
15
+ }
16
+
17
+ switch (value ) {
18
+ /* commentBlock */
19
+ }
20
+ }
11
21
}
You can’t perform that action at this time.
0 commit comments