INRIA / INRIA/spoon

[Bug]: Comments not in method included in method

Open
#5,172 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Describe the bug

When I prettyprint a CtMethod, comments that are in the class but not in the method are included.

### Source code you are trying to analyze/transform

```Java
public class CommentExample {
// This is another comment

public int method1() {
//A comment
}
}
```

### Source code for your Spoon processing

```Java
val launcher = Launcher()
launcher.factory.environment.setCommentEnabled(true)
launcher.addInputResource("src/main/resources/TestCases/comment.java")
launcher.buildModel()
launcher.model.processWith(ExtractClones())

class ExtractClones : AbstractProcessor>() {
override fun process(element: CtClass<*>) {
element.methods.forEach { println(it.prettyprint()) }
}
}
```

### Actual output

```Java
// This is another comment
public int method1() {
// A comment
}
```

### Expected output

```Java
public int method1() {
// A comment
}
```

### Spoon Version

10.3.0

### JVM Version

17

### What operating system are you using?

Windows 11

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.