Skip to content

Commit

Permalink
Fix some easy javadoc related intellij issues
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbosch committed Jan 20, 2017
1 parent a0283fb commit 6009624
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
Expand Up @@ -45,13 +45,13 @@ public static Javadoc parse(JavadocComment comment) {
public static Javadoc parse(String commentContent) {
List<String> cleanLines = cleanLines(commentContent);
int index = -1;
for (int i=0;i<cleanLines.size() && index == -1;i++) {
for (int i = 0; i < cleanLines.size() && index == -1; i++) {
if (isABlockLine(cleanLines.get(i))) {
index = i;
}
}
List<String> blockLines = null;
String descriptionText = null;
List<String> blockLines;
String descriptionText;
if (index == -1) {
descriptionText = trimRight(String.join("\n", cleanLines));
blockLines = Collections.emptyList();
Expand Down Expand Up @@ -82,29 +82,25 @@ private static String trimRight(String string) {
return string;
}

private static JavadocDescription parseText(String content) {
return JavadocDescription.parseText(content);
}

private static List<String> cleanLines(String content) {
String[] lines = content.split("\n");
List<String> cleanedLines = Arrays.stream(lines).map(l -> {
int asteriskIndex = startsWithAsterisk(l);
if (asteriskIndex == -1) {
return l;
} else {
// if a line starts with space followed by an asterisk drop to the asterisk
// if there is a space immediately after the asterisk drop it also
if (l.length() > (asteriskIndex + 1)) {
int asteriskIndex = startsWithAsterisk(l);
if (asteriskIndex == -1) {
return l;
} else {
// if a line starts with space followed by an asterisk drop to the asterisk
// if there is a space immediately after the asterisk drop it also
if (l.length() > (asteriskIndex + 1)) {

char c = l.charAt(asteriskIndex + 1);
if (c == ' ' || c == '\t') {
return l.substring(asteriskIndex + 2);
}
}
return l.substring(asteriskIndex + 1);
char c = l.charAt(asteriskIndex + 1);
if (c == ' ' || c == '\t') {
return l.substring(asteriskIndex + 2);
}
}).collect(Collectors.toList());
}
return l.substring(asteriskIndex + 1);
}
}).collect(Collectors.toList());
// lines containing only whitespace are normalized to empty lines
cleanedLines = cleanedLines.stream().map(l -> l.trim().isEmpty() ? "" : l).collect(Collectors.toList());
// if the first starts with a space, remove it
Expand Down
Expand Up @@ -117,7 +117,7 @@ public Optional<String> getName() {
}

public String toText() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("@");
sb.append(tagName);
if (name.isPresent()) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public class JavadocDescription {
public static JavadocDescription parseText(String text) {
JavadocDescription instance = new JavadocDescription();
int index = 0;
Pair<Integer, Integer> nextInlineTagPos = null;
Pair<Integer, Integer> nextInlineTagPos;
while ((nextInlineTagPos = indexOfNextInlineTag(text, index)) != null) {
if (nextInlineTagPos.a != index) {
instance.addElement(new JavadocSnippet(text.substring(index, nextInlineTagPos.a)));
Expand Down
Expand Up @@ -97,8 +97,7 @@ public boolean equals(Object o) {

JavadocInlineTag that = (JavadocInlineTag) o;

if (type != that.type) return false;
return content.equals(that.content);
return type == that.type && content.equals(that.content);

}

Expand Down
Expand Up @@ -34,19 +34,19 @@ public class JavadocParserTest {
@Test
public void parseSimplestContent() {
Assert.assertEquals(new Javadoc(JavadocDescription.parseText("A simple line of text")),
new JavadocParser().parse("A simple line of text"));
JavadocParser.parse("A simple line of text"));
}

@Test
public void parseSingleLineWithSpacing() {
assertEquals(new Javadoc(JavadocDescription.parseText("The line number of the first character of this Token.")),
new JavadocParser().parse(" The line number of the first character of this Token. "));
JavadocParser.parse(" The line number of the first character of this Token. "));
}

@Test
public void parseSingleLineWithNewLines() {
assertEquals(new Javadoc(JavadocDescription.parseText("The string image of the token.")),
new JavadocParser().parse("\n" +
JavadocParser.parse("\n" +
" * The string image of the token.\n" +
" "));
}
Expand All @@ -61,7 +61,7 @@ public void parseCommentWithNewLines() {
assertEquals(new Javadoc(JavadocDescription.parseText("The version identifier for this Serializable class.\n" +
"Increment only if the <i>serialized</i> form of the\n" +
"class changes.")),
new JavadocParser().parse(text));
JavadocParser.parse(text));
}

@Test
Expand All @@ -74,11 +74,11 @@ public void parseCommentWithIndentation() {
" * to the following switch statement. Then you can cast matchedToken";
assertEquals(new Javadoc(JavadocDescription.parseText("Returns a new Token object, by default.\n" +
"However, if you want, you can create and return subclass objects based on the value of ofKind.\n" +
"\n" +
" case MyParserConstants.ID : return new IDToken(ofKind, image);\n" +
"\n" +
"to the following switch statement. Then you can cast matchedToken")),
new JavadocParser().parse(text));
"\n" +
" case MyParserConstants.ID : return new IDToken(ofKind, image);\n" +
"\n" +
"to the following switch statement. Then you can cast matchedToken")),
JavadocParser.parse(text));
}

@Test
Expand All @@ -89,7 +89,7 @@ public void parseBlockTagsAndEmptyDescription() {
" ";
assertEquals(new Javadoc(JavadocDescription.parseText(""))
.addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.DEPRECATED, ""))
.addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.SEE, "#getEndColumn")), new JavadocParser().parse(text));
.addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.SEE, "#getEndColumn")), JavadocParser.parse(text));
}

@Test
Expand All @@ -102,7 +102,7 @@ public void parseParamBlockTags() {
" * @param modifiers the modifiers like {@link Modifier#PUBLIC}\n" +
" * @return the {@link FieldDeclaration} created\n" +
" ";
Javadoc res = new JavadocParser().parse(text);
Javadoc res = JavadocParser.parse(text);
assertEquals(new Javadoc(JavadocDescription.parseText("Add a field to this and automatically add the import of the type if needed"))
.addBlockTag(JavadocBlockTag.createParamBlockTag("typeClass", "the type of the field"))
.addBlockTag(JavadocBlockTag.createParamBlockTag("name", "the name of the field"))
Expand Down

0 comments on commit 6009624

Please sign in to comment.