Skip to content

Commit

Permalink
Fixed conversion of enum constants with class bodies, incompatible st…
Browse files Browse the repository at this point in the history
…ripping.

	Change on 2017/01/03 by tball <tball@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143451467
  • Loading branch information
tomball committed Jan 6, 2017
1 parent 50d29da commit d3c4862
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -26,6 +26,7 @@
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCImport;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.tree.TreeScanner;
Expand Down Expand Up @@ -180,6 +181,8 @@ private String getFirstComponent(JCTree name) {
return ((JCIdent) name).getName().toString();
case MEMBER_SELECT:
return getFirstComponent(((JCFieldAccess) name).getExpression());
case METHOD_INVOCATION:
return getFirstComponent(((JCMethodInvocation) name).getMethodSelect());
default:
throw new AssertionError("unexpected kind: " + name.getKind());
}
Expand All @@ -191,6 +194,8 @@ private String getLastComponent(JCTree name) {
return ((JCIdent) name).getName().toString();
case MEMBER_SELECT:
return ((JCFieldAccess) name).getIdentifier().toString();
case METHOD_INVOCATION:
return getLastComponent(((JCMethodInvocation) name).getMethodSelect());
default:
throw new AssertionError("unexpected kind: " + name.getKind());
}
Expand Down
Expand Up @@ -672,6 +672,10 @@ private TreeNode convertEnum(JCTree.JCClassDecl node) {
} else {
newNode.addBodyDeclaration((BodyDeclaration) var);
}
} else if (bodyDecl.getKind() == Kind.BLOCK) {
JCTree.JCBlock javacBlock = (JCTree.JCBlock) bodyDecl;
Block block = (Block) convert(javacBlock);
newNode.addBodyDeclaration(new Initializer(block, javacBlock.isStatic()));
} else {
newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl));
}
Expand Down Expand Up @@ -1225,8 +1229,9 @@ private TreeNode getAssociatedJavaDoc(JCTree node, Element element) {
}

private Comment convertAssociatedComment(JCTree node, Element element) {
boolean docCommentsEnabled = newUnit.getEnv().options().docCommentsEnabled();
DocCommentTable docComments = unit.docComments;
if (docComments == null || !docComments.hasComment(node)) {
if (!docCommentsEnabled || docComments == null || !docComments.hasComment(node)) {
return null;
}
com.sun.tools.javac.parser.Tokens.Comment javacComment = docComments.getComment(node);
Expand All @@ -1236,7 +1241,7 @@ private Comment convertAssociatedComment(JCTree node, Element element) {
comment = new BlockComment();
break;
case JAVADOC:
comment = newUnit.getEnv().options().docCommentsEnabled()
comment = docCommentsEnabled
? convertJavadocComment(element) : new Javadoc();
break;
case LINE:
Expand Down

0 comments on commit d3c4862

Please sign in to comment.