Skip to content

Commit

Permalink
Corrections for PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Jun 24, 2018
1 parent c119d88 commit 913fe67
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@ public abstract class Comment extends AbstractNode {
// or the start of line within a multine comment (*). It removes the end of the comment (*/) if existing.
private static final Pattern COMMENT_LINE_COMBINED = Pattern.compile("^(?://|/\\*\\*?|\\*)?(.*?)(?:\\*/|/)?$");

// Same as "\\R" - but \\R is only available with java8+
static final Pattern NEWLINES_PATTERN = Pattern.compile("\\u000D\\u000A|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029]");

protected Comment(Token t) {
super(-1, t.beginLine, t.endLine, t.beginColumn, t.endColumn);

@@ -54,7 +57,7 @@ public String getFilteredComment() {
* @return List of lines of the comments
*/
private List<String> multiLinesIn() {
String[] lines = getImage().split("\\R");
String[] lines = NEWLINES_PATTERN.split(getImage());
List<String> filteredLines = new ArrayList<>(lines.length);

for (String rawLine : lines) {
@@ -87,7 +90,7 @@ static List<String> trim(List<String> lines) {
List<String> tempList = new ArrayList<>();
boolean foundFirstNonEmptyLine = false;
for (String line : lines) {
if (StringUtils.isNoneBlank(line)) {
if (StringUtils.isNotBlank(line)) {
// new non-empty line: add all previous empty lines occurred before
result.addAll(tempList);
tempList.clear();
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ public static List<String> multiLinesIn(String comment) {
Token t = new Token();
t.image = comment;
MultiLineComment node = new MultiLineComment(t);
return Arrays.asList(node.getFilteredComment().split("\\R"));
return Arrays.asList(Comment.NEWLINES_PATTERN.split(node.getFilteredComment()));
}

/**
Original file line number Diff line number Diff line change
@@ -6,36 +6,39 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.javadoc.JavadocTag;

public class FormalComment extends Comment {

private static final Pattern JAVADOC_TAG = Pattern.compile("@([A-Za-z0-9]+)");

public FormalComment(Token t) {
super(t);

findJavadocs(t.image);
findJavadocs();
}

@Override
public String getXPathNodeName() {
return "FormalComment";
}

private void findJavadocs(String commentText) {
private void findJavadocs() {
Collection<JavadocElement> kids = new ArrayList<>();

Map<String, Integer> tags = CommentUtil.javadocTagsIn(commentText);
for (Map.Entry<String, Integer> entry : tags.entrySet()) {
JavadocTag tag = JavadocTag.tagFor(entry.getKey());
if (tag == null) {
continue;
Matcher javadocTagMatcher = JAVADOC_TAG.matcher(getFilteredComment());
while (javadocTagMatcher.find()) {
JavadocTag tag = JavadocTag.tagFor(javadocTagMatcher.group(1));
int tagStartIndex = javadocTagMatcher.start(1);
if (tag != null) {
kids.add(new JavadocElement(getBeginLine(), getBeginLine(),
// TODO valid?
tagStartIndex, tagStartIndex + tag.label.length() + 1, tag));
}
kids.add(new JavadocElement(getBeginLine(), getBeginLine(),
// TODO valid?
entry.getValue() + 1, entry.getValue() + tag.label.length() + 1, tag));
}

children = kids.toArray(new Node[0]);

0 comments on commit 913fe67

Please sign in to comment.