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 30, 2017
1 parent 13a1158 commit b0c8b6d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
Expand Up @@ -45,7 +45,7 @@ public static Javadoc parse(JavadocComment comment) {
public static Javadoc parse(String commentContent) { public static Javadoc parse(String commentContent) {
List<String> cleanLines = cleanLines(commentContent); List<String> cleanLines = cleanLines(commentContent);
int index = -1; 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))) { if (isABlockLine(cleanLines.get(i))) {
index = i; index = i;
} }
Expand Down Expand Up @@ -82,29 +82,25 @@ private static String trimRight(String string) {
return string; return string;
} }


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

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


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


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


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


} }


Expand Down
Expand Up @@ -34,19 +34,19 @@ public class JavadocParserTest {
@Test @Test
public void parseSimplestContent() { public void parseSimplestContent() {
Assert.assertEquals(new Javadoc(JavadocDescription.parseText("A simple line of text")), 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 @Test
public void parseSingleLineWithSpacing() { public void parseSingleLineWithSpacing() {
assertEquals(new Javadoc(JavadocDescription.parseText("The line number of the first character of this Token.")), 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 @Test
public void parseSingleLineWithNewLines() { public void parseSingleLineWithNewLines() {
assertEquals(new Javadoc(JavadocDescription.parseText("The string image of the token.")), 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" + " * 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" + assertEquals(new Javadoc(JavadocDescription.parseText("The version identifier for this Serializable class.\n" +
"Increment only if the <i>serialized</i> form of the\n" + "Increment only if the <i>serialized</i> form of the\n" +
"class changes.")), "class changes.")),
new JavadocParser().parse(text)); JavadocParser.parse(text));
} }


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


@Test @Test
Expand All @@ -89,7 +89,7 @@ public void parseBlockTagsAndEmptyDescription() {
" "; " ";
assertEquals(new Javadoc(JavadocDescription.parseText("")) assertEquals(new Javadoc(JavadocDescription.parseText(""))
.addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.DEPRECATED, "")) .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 @Test
Expand All @@ -102,7 +102,7 @@ public void parseParamBlockTags() {
" * @param modifiers the modifiers like {@link Modifier#PUBLIC}\n" + " * @param modifiers the modifiers like {@link Modifier#PUBLIC}\n" +
" * @return the {@link FieldDeclaration} created\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")) 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("typeClass", "the type of the field"))
.addBlockTag(JavadocBlockTag.createParamBlockTag("name", "the name of the field")) .addBlockTag(JavadocBlockTag.createParamBlockTag("name", "the name of the field"))
Expand Down

0 comments on commit b0c8b6d

Please sign in to comment.