diff --git a/migrator/src/com/ohos/migrator/java/JavaTransformer.java b/migrator/src/com/ohos/migrator/java/JavaTransformer.java index 4f4b3b720e132848ddcaa192365fa738d6a72438..1ab71e5f40ff8c11571f660a086f20d4a7615788 100644 --- a/migrator/src/com/ohos/migrator/java/JavaTransformer.java +++ b/migrator/src/com/ohos/migrator/java/JavaTransformer.java @@ -246,6 +246,10 @@ public class JavaTransformer extends ASTVisitor implements Transformer { // almost never by accept, so it's hard to count // them properly. Assume we handle them all and ignore. !(node instanceof Name) && + // if array creation node has array initializer, + // we translate only the latter. + (node.getNodeType() != ASTNode.ARRAY_CREATION || + ((ArrayCreation)node).getInitializer() == null) && node.getNodeType() != ASTNode.SWITCH_EXPRESSION && node.getNodeType() != ASTNode.TEXT_BLOCK) ++countExprTotal; @@ -337,6 +341,10 @@ public class JavaTransformer extends ASTVisitor implements Transformer { Type rt = node.getReturnType2(); if (rt != null) rt.accept(this); + List typeParams = node.typeParameters(); + for (TypeParameter typeParam : typeParams) + typeParam.accept(this); + List params = node.parameters(); for (SingleVariableDeclaration param : params) param.accept(this); @@ -411,6 +419,24 @@ public class JavaTransformer extends ASTVisitor implements Transformer { return false; } + + @Override + public boolean visit(Initializer node) { + // We don't visit the block itself, only statements inside it. + visitBodyStatements(node.getBody()); + + return false; + } + + @Override + public boolean visit(SynchronizedStatement node) { + node.getExpression().accept(this); + + // We don't visit the block itself, only statements inside it. + visitBodyStatements(node.getBody()); + + return false; + } }); } @@ -894,6 +920,9 @@ public class JavaTransformer extends ASTVisitor implements Transformer { popCurrent(); // stsVarOrConstDecl popCurrent(); // stsClassOrInterField popCurrent(); // stsClassOrInterMember + + // Each VariableDeclarationFragment is a separate declaration construct! + declTransformed.add(javaVarDeclFragment); } declTransformed.add(javaFieldDecl); @@ -3152,6 +3181,7 @@ public class JavaTransformer extends ASTVisitor implements Transformer { pushCurrent(new TypeAnnotationContext(stsCurrent, 0)); javaParam.getType().accept(this); popCurrent(); // TypeAnnotationContext + declTransformed.add(javaParam); // Loop variable is a separate declaration construct! stsCurrent.addChild(NodeBuilder.terminalNode(StaticTSParser.Of));