Skip to content

Commit

Permalink
refactor: DefaultJavaPrettyPrinter uses CommentHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Sep 7, 2017
1 parent faecc15 commit b1556e6
Showing 1 changed file with 8 additions and 78 deletions.
86 changes: 8 additions & 78 deletions src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java
Expand Up @@ -109,6 +109,7 @@
import spoon.reflect.reference.CtWildcardReference;
import spoon.reflect.visitor.PrintingContext.Writable;
import spoon.reflect.visitor.filter.PotentialVariableDeclarationFunction;
import spoon.reflect.visitor.printer.CommentHelper;
import spoon.reflect.visitor.printer.CommentOffset;
import spoon.reflect.visitor.printer.ElementPrinterHelper;
import spoon.reflect.visitor.printer.ListPrinter;
Expand Down Expand Up @@ -911,91 +912,20 @@ public void visitCtJavaDoc(CtJavaDoc comment) {

@Override
public void visitCtJavaDocTag(CtJavaDocTag docTag) {
printer.write(COMMENT_STAR);
printer.write(CtJavaDocTag.JAVADOC_TAG_PREFIX);
printer.write(docTag.getType().name().toLowerCase());
printer.write(" ");
if (docTag.getType().hasParam()) {
printer.write(docTag.getParam()).writeln().writeTabs();
}

String[] tagLines = docTag.getContent().split(CtComment.LINE_SEPARATOR);
for (int i = 0; i < tagLines.length; i++) {
String com = tagLines[i];
if (i > 0 || docTag.getType().hasParam()) {
printer.write(COMMENT_STAR);
}
if (docTag.getType().hasParam()) {
printer.write("\t\t");
}
printer.write(com.trim()).writeln().writeTabs();
}
/*
* is not called during normal printing of java sources.
* It can be called only when CtJavaDocTag has to be printed directly.
* E.g. from CtJavaDocTag#toString
*/
CommentHelper.printJavaDocTag(printer, docTag);
}

@Override
public void visitCtComment(CtComment comment) {
if (!env.isCommentsEnabled() && context.elementStack.size() > 1) {
return;
}
switch (comment.getCommentType()) {
case FILE:
printer.write(JAVADOC_START).writeln();
break;
case JAVADOC:
printer.write(JAVADOC_START).writeln().writeTabs();
break;
case INLINE:
printer.write(INLINE_COMMENT_START);
break;
case BLOCK:
printer.write(BLOCK_COMMENT_START);
break;
}
String content = comment.getContent();
switch (comment.getCommentType()) {
case INLINE:
printer.write(content);
break;
default:
String[] lines = content.split(CtComment.LINE_SEPARATOR);
for (int i = 0; i < lines.length; i++) {
String com = lines[i];
if (comment.getCommentType() == CtComment.CommentType.BLOCK) {
printer.write(com);
if (lines.length > 1) {
printer.writeln().writeTabs();
}
} else {
if (com.length() > 0) {
printer.write(COMMENT_STAR + com).writeln().writeTabs();
} else {
printer.write(" *" /* no trailing space */ + com).writeln().writeTabs();
}
}

}
if (comment instanceof CtJavaDoc) {
if (!((CtJavaDoc) comment).getTags().isEmpty()) {
printer.write(" *").writeln().writeTabs();
}
for (CtJavaDocTag docTag : ((CtJavaDoc) comment).getTags()) {
scan(docTag);
}
}
break;
}

switch (comment.getCommentType()) {
case BLOCK:
printer.write(BLOCK_COMMENT_END);
break;
case FILE:
printer.write(BLOCK_COMMENT_END);
break;
case JAVADOC:
printer.write(BLOCK_COMMENT_END);
break;
}
CommentHelper.printComment(printer, comment);
}

@Override
Expand Down

0 comments on commit b1556e6

Please sign in to comment.