Skip to content

Commit

Permalink
Rename a setting that had a long and hard to understand name
Browse files Browse the repository at this point in the history
  • Loading branch information
matozoid committed Mar 10, 2018
1 parent b0185a7 commit 1e05968
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
Expand Up @@ -57,8 +57,7 @@ private void insertComments(CompilationUnit cu, TreeSet<Comment> comments) {
return;

/* I should sort all the direct children and the comments, if a comment
is the first thing then it
a comment to the CompilationUnit */
is the first thing then it is a comment to the CompilationUnit */

// FIXME if there is no package it could be also a comment to the following class...
// so I could use some heuristics in these cases to distinguish the two
Expand Down Expand Up @@ -87,13 +86,11 @@ void insertComments(Node node, TreeSet<Comment> commentsToAttribute) {
insertComments((CompilationUnit) node, commentsToAttribute);
}

// the comments can:
// 1) Inside one of the child, then it is the child that have to
// associate them
// 2) If they are not inside a child they could be preceeding nothing, a
// comment or a child
// if they preceed a child they are assigned to it, otherweise they
// remain "orphans"
/* the comment can...
1) be inside one of the children, then the comment should be associated to this child
2) be outside all children. They could be preceding nothing, a comment or a child.
If they preceed a child they are assigned to it, otherwise they remain "orphans"
*/

List<Node> children = node.getChildNodes();

Expand All @@ -103,7 +100,7 @@ void insertComments(Node node, TreeSet<Comment> commentsToAttribute) {
commentsToAttribute.stream()
.filter(c -> c.getRange().isPresent())
.filter(c -> PositionUtils.nodeContains(child, c,
configuration.isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution())).collect(Collectors.toList()));
configuration.isIgnoreAnnotationsWhenAttributingComments())).collect(Collectors.toList()));
commentsToAttribute.removeAll(commentsInsideChild);
insertComments(child, commentsInsideChild);
}
Expand All @@ -121,7 +118,7 @@ void insertComments(Node node, TreeSet<Comment> commentsToAttribute) {

childrenAndComments.addAll(commentsToAttribute);
PositionUtils.sortByBeginPosition(childrenAndComments,
configuration.isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution());
configuration.isIgnoreAnnotationsWhenAttributingComments());

for (Node thing : childrenAndComments) {
if (thing instanceof Comment) {
Expand Down Expand Up @@ -176,7 +173,7 @@ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineCom
if (!node.getRange().isPresent() || !lineComment.getRange().isPresent()) {
return false;
}

// The node start and end at the same line as the comment,
// let's give to it the comment
if (node.getBegin().get().line == lineComment.getBegin().get().line
Expand Down
Expand Up @@ -88,7 +88,7 @@ public enum LanguageLevel {
private boolean storeTokens = true;
private boolean attributeComments = true;
private boolean doNotAssignCommentsPrecedingEmptyLines = true;
private boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution = false;
private boolean ignoreAnnotationsWhenAttributingComments = false;
private boolean lexicalPreservationEnabled = false;
private SymbolResolver symbolResolver = null;
private int tabSize = 1;
Expand Down Expand Up @@ -151,12 +151,27 @@ public ParserConfiguration setDoNotAssignCommentsPrecedingEmptyLines(boolean doN
return this;
}

/**
* @deprecated this setting has been renamed to ignoreAnnotationsWhenAttributingComments
*/
@Deprecated
public boolean isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution() {
return doNotConsiderAnnotationsAsNodeStartForCodeAttribution;
return isIgnoreAnnotationsWhenAttributingComments();
}

/**
* @deprecated this setting has been renamed to ignoreAnnotationsWhenAttributingComments
*/
@Deprecated
public ParserConfiguration setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution) {
this.doNotConsiderAnnotationsAsNodeStartForCodeAttribution = doNotConsiderAnnotationsAsNodeStartForCodeAttribution;
return setIgnoreAnnotationsWhenAttributingComments(doNotConsiderAnnotationsAsNodeStartForCodeAttribution);
}
public boolean isIgnoreAnnotationsWhenAttributingComments() {
return ignoreAnnotationsWhenAttributingComments;
}

public ParserConfiguration setIgnoreAnnotationsWhenAttributingComments(boolean ignoreAnnotationsWhenAttributingComments) {
this.ignoreAnnotationsWhenAttributingComments = ignoreAnnotationsWhenAttributingComments;
return this;
}

Expand Down
Expand Up @@ -86,7 +86,7 @@ public void whenTheClassIsParsedByTheCommentParser() throws IOException {

@When("the do not consider annotations as node start for code attribution is $value on the Java parser")
public void whenTheDoNotConsiderAnnotationsAsNodeStartForCodeAttributionIsTrueOnTheJavaParser(boolean value) {
configuration.setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(value);
configuration.setIgnoreAnnotationsWhenAttributingComments(value);
}

@When("the do not assign comments preceding empty lines is $value on the Java parser")
Expand Down

0 comments on commit 1e05968

Please sign in to comment.