use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class TreeConverter method convertAbstractTypeDeclaration.
private static TreeNode convertAbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration node, AbstractTypeDeclaration newNode) {
convertBodyDeclaration(node, newNode);
ITypeBinding typeBinding = node.resolveBinding();
Set<IMethodBinding> declaredInAst = new HashSet<>();
for (Object bodyDecl : node.bodyDeclarations()) {
if (bodyDecl instanceof org.eclipse.jdt.core.dom.MethodDeclaration) {
declaredInAst.add(((org.eclipse.jdt.core.dom.MethodDeclaration) bodyDecl).resolveBinding());
}
newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl));
}
for (IMethodBinding method : typeBinding.getDeclaredMethods()) {
if (method.isConstructor() && method.getParameterTypes().length == 0 && !declaredInAst.contains(method)) {
MethodDeclaration defaultConstructor = new MethodDeclaration(BindingConverter.getExecutableElement(method)).setBody(new Block());
addImplicitSuperCall(defaultConstructor);
newNode.addBodyDeclaration(0, defaultConstructor);
break;
}
}
return newNode.setName((SimpleName) convert(node.getName())).setTypeElement(BindingConverter.getTypeElement(typeBinding));
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class TreeConverter method createAnonymousConstructor.
private static MethodDeclaration createAnonymousConstructor(JdtExecutableElement constructorElem, IMethodBinding constructorBinding) {
MethodDeclaration constructor = new MethodDeclaration(constructorElem);
Block body = new Block();
constructor.setBody(body);
IMethodBinding superConstructorBinding = findSuperConstructor(constructorBinding);
ExecutablePair superConstructor = new ExecutablePair(BindingConverter.getExecutableElement(superConstructorBinding), BindingConverter.getType(superConstructorBinding));
SuperConstructorInvocation superCall = new SuperConstructorInvocation(superConstructor);
body.addStatement(superCall);
Iterator<? extends VariableElement> params = constructorElem.getParameters().iterator();
if (constructorElem.hasSuperOuter()) {
VariableElement param = params.next();
constructor.addParameter(new SingleVariableDeclaration(param));
superCall.setExpression(new SimpleName(param));
}
while (params.hasNext()) {
VariableElement param = params.next();
constructor.addParameter(new SingleVariableDeclaration(param));
superCall.addArgument(new SimpleName(param));
}
assert constructor.getParameters().size() == constructorElem.getParameters().size();
return constructor;
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class ArrayRewriter method newSingleDimensionArrayInvocation.
private MethodInvocation newSingleDimensionArrayInvocation(ArrayType arrayType, Expression dimensionExpr, boolean retainedResult) {
TypeMirror componentType = arrayType.getComponentType();
TypeElement iosArrayElement = typeUtil.getIosArray(componentType);
boolean isPrimitive = componentType.getKind().isPrimitive();
String selector = (retainedResult ? "newArray" : "array") + "WithLength:" + (isPrimitive ? "" : "type:");
GeneratedExecutableElement methodElement = GeneratedExecutableElement.newMethodWithSelector(selector, iosArrayElement.asType(), iosArrayElement).addModifiers(Modifier.PUBLIC, Modifier.STATIC);
methodElement.addParameter(GeneratedVariableElement.newParameter("length", typeUtil.getInt(), methodElement));
if (!isPrimitive) {
methodElement.addParameter(GeneratedVariableElement.newParameter("type", TypeUtil.IOS_CLASS.asType(), methodElement));
}
MethodInvocation invocation = new MethodInvocation(new ExecutablePair(methodElement), arrayType, new SimpleName(iosArrayElement));
// Add the array length argument.
invocation.addArgument(dimensionExpr.copy());
// Add the type argument for object arrays.
if (!isPrimitive) {
invocation.addArgument(new TypeLiteral(componentType, typeUtil));
}
return invocation;
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class Autoboxer method boxWithClass.
private void boxWithClass(Expression expr, TypeElement boxedClass) {
PrimitiveType primitiveType = typeUtil.unboxedType(boxedClass.asType());
assert primitiveType != null;
ExecutableElement wrapperMethod = ElementUtil.findMethod(boxedClass, VALUEOF_METHOD, TypeUtil.getQualifiedName(primitiveType));
assert wrapperMethod != null : "could not find valueOf method for " + boxedClass;
MethodInvocation invocation = new MethodInvocation(new ExecutablePair(wrapperMethod), new SimpleName(boxedClass));
expr.replaceWith(invocation);
invocation.addArgument(expr);
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class ComplexExpressionExtractor method handleNode.
private void handleNode(Expression node, Collection<Expression> children) {
if (node.getParent() instanceof Statement) {
return;
}
int depth = 0;
for (Expression child : children) {
Integer childDepth = depths.get(child);
depth = Math.max(depth, childDepth != null ? childDepth : 1);
}
if (depth >= maxDepth) {
VariableElement newVar = GeneratedVariableElement.newLocalVar("complex$" + count++, node.getTypeMirror(), currentMethod);
Statement newStmt = new VariableDeclarationStatement(newVar, node.copy());
assert currentStatement != null;
TreeUtil.insertBefore(currentStatement, newStmt);
node.replaceWith(new SimpleName(newVar));
} else {
depths.put(node, depth + 1);
}
}
Aggregations