From 1e059685baed1e4fd18d3c0dbfb15fc096e9cf54 Mon Sep 17 00:00:00 2001 From: Danny van Bruggen Date: Sat, 10 Mar 2018 22:11:15 +0100 Subject: [PATCH] Rename a setting that had a long and hard to understand name --- .../github/javaparser/CommentsInserter.java | 21 ++++++++----------- .../javaparser/ParserConfiguration.java | 21 ++++++++++++++++--- .../bdd/steps/CommentParsingSteps.java | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java index 869883cbfd..9c786b243e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java @@ -57,8 +57,7 @@ private void insertComments(CompilationUnit cu, TreeSet 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 @@ -87,13 +86,11 @@ void insertComments(Node node, TreeSet 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 children = node.getChildNodes(); @@ -103,7 +100,7 @@ void insertComments(Node node, TreeSet 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); } @@ -121,7 +118,7 @@ void insertComments(Node node, TreeSet commentsToAttribute) { childrenAndComments.addAll(commentsToAttribute); PositionUtils.sortByBeginPosition(childrenAndComments, - configuration.isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution()); + configuration.isIgnoreAnnotationsWhenAttributingComments()); for (Node thing : childrenAndComments) { if (thing instanceof Comment) { @@ -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 diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java index e5be2b80ab..00bb804e4a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java @@ -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; @@ -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; } diff --git a/javaparser-testing/src/test/java/com/github/javaparser/bdd/steps/CommentParsingSteps.java b/javaparser-testing/src/test/java/com/github/javaparser/bdd/steps/CommentParsingSteps.java index 3257c4342e..e2398ba454 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/bdd/steps/CommentParsingSteps.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/bdd/steps/CommentParsingSteps.java @@ -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")