use of com.google.devtools.j2objc.ast.ArrayCreation in project j2objc by google.
the class TreeConverter method convertNewArray.
private TreeNode convertNewArray(JCTree.JCNewArray node) {
ArrayCreation newNode = new ArrayCreation();
List<Expression> dimensions = new ArrayList<>();
for (JCTree.JCExpression dimension : node.getDimensions()) {
dimensions.add((Expression) convert(dimension));
}
javax.lang.model.type.ArrayType type = (javax.lang.model.type.ArrayType) node.type;
if (node.getInitializers() != null) {
ArrayInitializer initializers = new ArrayInitializer(type);
for (JCTree.JCExpression initializer : node.getInitializers()) {
initializers.addExpression((Expression) convert(initializer));
}
newNode.setInitializer(initializers);
}
return newNode.setType((ArrayType) new ArrayType(type).setPosition(getPosition(node))).setDimensions(dimensions);
}
use of com.google.devtools.j2objc.ast.ArrayCreation in project j2objc by google.
the class TreeConverter method convertNewArray.
private TreeNode convertNewArray(NewArrayTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
ArrayCreation newNode = new ArrayCreation();
List<Expression> dimensions = new ArrayList<>();
for (ExpressionTree dimension : node.getDimensions()) {
dimensions.add((Expression) convert(dimension, path));
}
javax.lang.model.type.ArrayType type = (javax.lang.model.type.ArrayType) getTypeMirror(path);
if (node.getInitializers() != null) {
ArrayInitializer initializers = new ArrayInitializer(type);
for (ExpressionTree initializer : node.getInitializers()) {
initializers.addExpression((Expression) convert(initializer, path));
}
newNode.setInitializer(initializers);
}
return newNode.setType((ArrayType) new ArrayType(type).setPosition(getPosition(node))).setDimensions(dimensions);
}
use of com.google.devtools.j2objc.ast.ArrayCreation in project j2objc by google.
the class TreeConverter method convertArrayCreation.
private static TreeNode convertArrayCreation(org.eclipse.jdt.core.dom.ArrayCreation node) {
ArrayCreation newNode = new ArrayCreation();
convertExpression(node, newNode);
List<Expression> dimensions = new ArrayList<>();
for (Object dimension : node.dimensions()) {
dimensions.add((Expression) convert(dimension));
}
return newNode.setType((ArrayType) convert(node.getType())).setDimensions(dimensions).setInitializer((ArrayInitializer) convert(node.getInitializer()));
}
use of com.google.devtools.j2objc.ast.ArrayCreation in project j2objc by google.
the class MethodTranslator method visitArrayCreationExpression.
@Override
public TreeNode visitArrayCreationExpression(ArrayCreationExpression node, Void data) {
Type baseType = (Type) node.getType().acceptVisitor(this, null);
AstNodeCollection<com.strobel.decompiler.languages.java.ast.Expression> dimexprs = node.getDimensions();
ArrayInitializerExpression init = node.getInitializer();
ArrayType arrayType = new ArrayType(typeUtil.getArrayType(baseType.getTypeMirror(), dimexprs.size() + node.getAdditionalArraySpecifiers().size()));
if (init.isNull()) {
List<Expression> dimensions = dimexprs.stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
return new ArrayCreation().setType(arrayType).setDimensions(dimensions);
} else {
ArrayInitializer arrayInit = (ArrayInitializer) init.acceptVisitor(this, null);
return new ArrayCreation().setType(arrayType).setInitializer(arrayInit.setTypeMirror(arrayType.getTypeMirror()));
}
}
use of com.google.devtools.j2objc.ast.ArrayCreation in project j2objc by google.
the class VarargsRewriter method rewriteVarargs.
private void rewriteVarargs(ExecutableElement method, TypeMirror varargsType, List<Expression> args) {
if (varargsType == null) {
return;
}
varargsType = typeUtil.erasure(varargsType);
int numRegularParams = method.getParameters().size() - 1;
List<Expression> varargs = args.subList(numRegularParams, args.size());
List<Expression> varargsCopy = Lists.newArrayList(varargs);
varargs.clear();
if (varargsCopy.isEmpty()) {
args.add(new ArrayCreation(typeUtil.getArrayType(varargsType), typeUtil, 0));
} else {
ArrayInitializer newInit = new ArrayInitializer(typeUtil.getArrayType(varargsType));
newInit.getExpressions().addAll(varargsCopy);
args.add(new ArrayCreation(newInit));
}
}
Aggregations