-
-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for a bug concerning multiples comments before a catch block #1074
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import spoon.reflect.code.CtBlock; | ||
import spoon.reflect.code.CtBodyHolder; | ||
import spoon.reflect.code.CtCase; | ||
import spoon.reflect.code.CtCatch; | ||
import spoon.reflect.code.CtComment; | ||
import spoon.reflect.code.CtConditional; | ||
import spoon.reflect.code.CtIf; | ||
|
@@ -187,6 +188,7 @@ private void insertCommentInAST(final CtComment comment) { | |
// visitor that inserts the comment in the element | ||
CtInheritanceScanner insertionVisitor = new CtInheritanceScanner() { | ||
private boolean isScanned = false; | ||
|
||
@Override | ||
public void scan(CtElement e) { | ||
if (e == null) { | ||
|
@@ -373,6 +375,14 @@ public <T> void visitCtNewArray(CtNewArray<T> e) { | |
public <T> void visitCtParameter(CtParameter<T> e) { | ||
e.addComment(comment); | ||
} | ||
|
||
@Override | ||
public void visitCtCatch(CtCatch e) { | ||
if (comment.getPosition().getLine() <= e.getPosition().getLine()) { | ||
e.addComment(comment); | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call super.visitCtCatch() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This super call is directly implemented in the |
||
} | ||
}; | ||
insertionVisitor.scan(commentParent); | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package spoon.test.comment.testclasses; | ||
|
||
// comment 1 | ||
// comment 2 | ||
public class Comment1 { | ||
|
||
public void code_1() | ||
{ | ||
try { } | ||
// A | ||
// B | ||
catch (Exception ex) | ||
{ } | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package spoon.test.comment.testclasses; | ||
|
||
public class Comment2 { | ||
|
||
// C | ||
@interface Code_2{} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use sourceStart() instead of getLine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I used the same
getLine
which is used invisitCtClass
which manage properly multiple inline comments. If I use heresourceStart()
one comment is missing when writing something like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is strange because getLine uses sourceStart() to perform the line number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I understand is that
sourceStart
starts at the same position than the first comment, which means the equality is respected and the comment is included (it was the previous implementation). But then the sourceStart of the second comment is greater than this sourcePosition and so it's not considered.Now with getLine either it considers all are on the same line, either it computes well the different lines using the line separator position, which is the case I think.