Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1393: Bug escaped literal #1394

Merged
merged 5 commits into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 48 additions & 49 deletions src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -880,63 +880,63 @@ public void visitCtComment(CtComment comment) {
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;
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(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();
case INLINE:
printer.write(content);
break;
default:
String[] lines = content.split(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 {
printer.write(" *" /* no trailing space */ + com).writeln().writeTabs();
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);
if (comment instanceof CtJavaDoc) {
if (!((CtJavaDoc) comment).getTags().isEmpty()) {
printer.write(" *").writeln().writeTabs();
}
for (CtJavaDocTag docTag : ((CtJavaDoc) comment).getTags()) {
scan(docTag);
}
}
}
break;
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;
case BLOCK:
printer.write(BLOCK_COMMENT_END);
break;
case FILE:
printer.write(BLOCK_COMMENT_END);
break;
case JAVADOC:
printer.write(BLOCK_COMMENT_END);
break;
}
}

Expand Down Expand Up @@ -1150,7 +1150,7 @@ public <T> void visitCtLiteral(CtLiteral<T> literal) {
// if the string in the source is not the same as the string in the literal, the string may contains special characters
mayContainsSpecialCharacter = stringLength != 1;
}
printer.writeStringLiteral(new String(new char[] { (Character) literal.getValue() }), mayContainsSpecialCharacter);
printer.writeCharLiteral((Character) literal.getValue(), mayContainsSpecialCharacter);

printer.write("'");
} else if (literal.getValue() instanceof String) {
Expand Down Expand Up @@ -1387,8 +1387,7 @@ private <T> void printConstructorCall(CtConstructorCall<T> ctConstructorCall) {
* we check that the reference has a declaring type with generics.
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=474593
*
* @param reference
* Type reference concerned by the bug.
* @param reference Type reference concerned by the bug.
* @return true if a declaring type have generic types.
*/
private <T> boolean hasDeclaringTypeWithGenerics(CtTypeReference<T> reference) {
Expand Down
Loading