Skip to content

Commit

Permalink
Fix comment duplication bug.
Browse files Browse the repository at this point in the history
The change on line 130 (filter out ancestor comments) is the relevant
one. This is just a matter of accidentally deleting one tiny bit of code
that was in master.
  • Loading branch information
petervdonovan committed Jul 31, 2023
1 parent 2791e06 commit 0c0171c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/src/main/java/org/lflang/ast/ToLf.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ public MalleableString doSwitch(EObject eObject) {
.forEach(allComments::add);
} else {
Stream<String> precedingComments =
ASTUtils.getPrecedingComments(node, doesNotBelongToPrevious).map(String::strip);
ASTUtils.getPrecedingComments(node, doesNotBelongToPrevious.and(doesNotBelongToAncestor))
.map(String::strip);
precedingComments.forEachOrdered(allComments::add);
getContainedCodeComments(node).stream().map(INode::getText).forEach(allComments::add);
getContainedCodeComments(node).stream()
.filter(doesNotBelongToAncestor)
.map(INode::getText)
.forEach(allComments::add);
}
allComments.addAll(followingComments);
if (allComments.stream().anyMatch(s -> KEEP_FORMAT_COMMENT.matcher(s).matches())) {
Expand All @@ -146,6 +150,7 @@ static Set<INode> getAncestorComments(INode node) {
ancestor = ancestor.getParent()) {
ancestorComments.addAll(getContainedCodeComments(ancestor));
ASTUtils.getPrecedingCommentNodes(ancestor, u -> true).forEachOrdered(ancestorComments::add);
ancestorComments.addAll(getContainedCodeComments(ancestor));
}
return ancestorComments;
}
Expand Down

0 comments on commit 0c0171c

Please sign in to comment.