use of com.google.devtools.j2objc.types.ExecutablePair in project j2objc by google.
the class Autoboxer method unbox.
/**
* Convert a wrapper class instance to a specified primitive equivalent.
*/
private void unbox(Expression expr, PrimitiveType primitiveType) {
TypeElement boxedClass = findBoxedSuperclass(expr.getTypeMirror());
if (primitiveType == null && boxedClass != null) {
primitiveType = typeUtil.unboxedType(boxedClass.asType());
}
if (primitiveType == null) {
return;
}
ExecutableElement valueMethod = ElementUtil.findMethod(boxedClass, TypeUtil.getName(primitiveType) + VALUE_METHOD);
assert valueMethod != null : "could not find value method for " + boxedClass;
MethodInvocation invocation = new MethodInvocation(new ExecutablePair(valueMethod), null);
expr.replaceWith(invocation);
invocation.setExpression(expr);
}
use of com.google.devtools.j2objc.types.ExecutablePair 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.types.ExecutablePair 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.types.ExecutablePair 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.types.ExecutablePair in project j2objc by google.
the class ArrayRewriter method endVisit.
@Override
public void endVisit(InstanceofExpression node) {
TypeMirror type = node.getRightOperand().getTypeMirror();
if (!TypeUtil.isArray(type) || ((ArrayType) type).getComponentType().getKind().isPrimitive()) {
return;
}
GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector("isInstance", typeUtil.getBoolean(), TypeUtil.IOS_CLASS);
element.addParameter(GeneratedVariableElement.newParameter("object", TypeUtil.ID_TYPE, element));
MethodInvocation invocation = new MethodInvocation(new ExecutablePair(element), new TypeLiteral(type, typeUtil));
invocation.addArgument(TreeUtil.remove(node.getLeftOperand()));
node.replaceWith(invocation);
}
Aggregations