use of com.google.devtools.j2objc.types.GeneratedExecutableElement in project j2objc by google.
the class BindingConverter method unwrapGeneratedElement.
private static IBinding unwrapGeneratedElement(GeneratedElement element) {
IBinding binding = generatedBindingCache.get(element);
if (binding != null) {
return binding;
}
if (element instanceof GeneratedVariableElement) {
binding = new GeneratedVariableBinding((GeneratedVariableElement) element);
generatedBindingCache.put(element, binding);
return binding;
}
if (element instanceof GeneratedExecutableElement) {
binding = new GeneratedMethodBinding((GeneratedExecutableElement) element);
generatedBindingCache.put(element, binding);
return binding;
}
if (element instanceof GeneratedTypeElement) {
throw new AssertionError("not supported");
}
if (element instanceof GeneratedPackageElement) {
binding = new GeneratedPackageBinding(((GeneratedPackageElement) element).getName());
generatedBindingCache.put(element, binding);
return binding;
}
throw new AssertionError("unknown generated element kind");
}
use of com.google.devtools.j2objc.types.GeneratedExecutableElement in project j2objc by google.
the class JavaToIOSMethodTranslator method addCopyWithZoneMethod.
private void addCopyWithZoneMethod(TypeDeclaration node) {
// Create copyWithZone: method.
GeneratedExecutableElement copyElement = GeneratedExecutableElement.newMethodWithSelector("copyWithZone:", TypeUtil.ID_TYPE, node.getTypeElement());
MethodDeclaration copyDecl = new MethodDeclaration(copyElement);
copyDecl.setHasDeclaration(false);
// Add NSZone *zone parameter.
VariableElement zoneParam = GeneratedVariableElement.newParameter("zone", NSZONE_TYPE, copyElement);
copyElement.addParameter(zoneParam);
copyDecl.addParameter(new SingleVariableDeclaration(zoneParam));
Block block = new Block();
copyDecl.setBody(block);
ExecutableElement cloneElement = ElementUtil.findMethod(typeUtil.getJavaObject(), "clone");
MethodInvocation invocation = new MethodInvocation(new ExecutablePair(cloneElement), null);
if (options.useReferenceCounting()) {
invocation = new MethodInvocation(new ExecutablePair(RETAIN_METHOD), invocation);
}
block.addStatement(new ReturnStatement(invocation));
node.addBodyDeclaration(copyDecl);
}
use of com.google.devtools.j2objc.types.GeneratedExecutableElement in project j2objc by google.
the class AbstractMethodRewriter method newReturnTypeNarrowingDeclaration.
private MethodDeclaration newReturnTypeNarrowingDeclaration(String selector, ExecutablePair method, TypeElement declaringClass) {
GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector(selector, method.type().getReturnType(), declaringClass).addModifiers(ElementUtil.getVisibilityModifiers(method.element())).addModifiers(Modifier.ABSTRACT);
MethodDeclaration decl = new MethodDeclaration(element);
if (!declaringClass.getKind().isInterface()) {
unit.setHasIncompleteImplementation();
}
int argCount = 0;
for (TypeMirror paramType : method.type().getParameterTypes()) {
VariableElement param = GeneratedVariableElement.newParameter("arg" + argCount++, paramType, element);
element.addParameter(param);
decl.addParameter(new SingleVariableDeclaration(param));
}
return decl;
}
use of com.google.devtools.j2objc.types.GeneratedExecutableElement in project j2objc by google.
the class ArrayRewriter method getMultiDimensionMethod.
private ExecutableElement getMultiDimensionMethod(TypeMirror componentType, TypeElement iosArrayType, boolean retainedResult) {
boolean isPrimitive = componentType.getKind().isPrimitive();
String selector = (retainedResult ? "newArray" : "array") + "WithDimensions:lengths:" + (isPrimitive ? "" : "type:");
GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector(selector, TypeUtil.IOS_OBJECT_ARRAY.asType(), iosArrayType).addModifiers(Modifier.PUBLIC, Modifier.STATIC);
TypeMirror intType = typeUtil.getInt();
element.addParameter(GeneratedVariableElement.newParameter("dimensions", intType, element));
element.addParameter(GeneratedVariableElement.newParameter("dimensionLengths", new PointerType(intType), element));
if (!isPrimitive) {
element.addParameter(GeneratedVariableElement.newParameter("type", TypeUtil.IOS_CLASS.asType(), element));
}
return element;
}
use of com.google.devtools.j2objc.types.GeneratedExecutableElement 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;
}
Aggregations