CommentType.FILE is no longer set to comments
- Dominant language
- Java
- Stars
- 2k
- Forks
- 392
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 36
Description
Hello!
I’d like to deal with a problem that I met and make a pull request!
But having studied the code I’m not sure in edits due to ambiguous behavior, which changed after the commit https://github.com/INRIA/spoon/commit/85a3ab11f6e5caacd09f8402d0b674310c9d8ce5#diff-f80a163103a0ba658d685183151e22e3 (file src/main/java/spoon/support/compiler/jdt/JDTCommentBuilder.java in the method insertCommentInAST(....)).
CommentType.FILE is no longer set to comments!
simple example:
```
// package comment
package some.pack;
//class comment
public class SomeClass {}
```
in Spoon 7.5.0 the package comment got in ctClass with the type CommentType.FILE
and I could get the comment in the following way:
```
Launcher launcher = new Launcher();
launcher.addInputResource("SomeClass.java");
CtModel model = launcher.buildModel();
List comments = model.getElements(new TypeFilter<>(CtComment.class));
// comments : [package comment, class comment]
```
but in Spoon 8.0.0 I can't get all comments in the same way:
```
result ->
// comments : [class comment]
```
in spoon 8.0.0 this comments got in ctPackageDeclaration, or ctCompilationUnit, or ctImport (in this case, it's logical)
and if I understand correctly model.getElements(new TypeFilter<>(CtComment.class)) traverses only spoonUnit.getDeclaredTypes, which doesn't let us catch our set comments in the file header.
now I can reach comments only in this way:
```
ctClass.getPosition().getCompilationUnit().getComments();
ctClass.getPosition().getCompilationUnit().getPackageDeclaration().getComments();
ctClass.getPosition().getCompilationUnit().getImports().get(0).getComments();
```
questions:
- Does is correspond to the logic that CommentType.FILE is no longer set to comments?
- Is it a normal situation that now we can't reach comments through model.getElements(new TypeFilter<>(CtComment.class)) ?
Contributor guide
Assessment
This issue has not been assessed yet.