use of com.google.devtools.j2objc.types.GeneratedVariableElement 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.GeneratedVariableElement in project j2objc by google.
the class MethodTranslator method visitVariableDeclaration.
@Override
public TreeNode visitVariableDeclaration(com.strobel.decompiler.languages.java.ast.VariableDeclarationStatement node, Void data) {
VariableDeclarationStatement varDecl = new VariableDeclarationStatement().setModifiers(ElementUtil.fromModifierSet(new HashSet<>(node.getModifiers())));
AstType astType = node.getType();
Type type = (Type) astType.acceptVisitor(this, null);
for (VariableInitializer init : node.getVariables()) {
Expression expr = (Expression) init.acceptVisitor(this, null);
String varName = init.getName();
GeneratedVariableElement elem = GeneratedVariableElement.newLocalVar(varName, type.getTypeMirror(), executableElement);
elem.addModifiers(node.getModifiers());
localVariableTable.put(varName, elem);
varDecl.addFragment(new VariableDeclarationFragment(elem, expr));
}
return varDecl;
}
use of com.google.devtools.j2objc.types.GeneratedVariableElement in project j2objc by google.
the class JavaToIOSMethodTranslator method addCopyWithZoneMethod.
private void addCopyWithZoneMethod(TypeDeclaration node, boolean singleton) {
TypeElement type = node.getTypeElement();
// Create copyWithZone: method.
GeneratedExecutableElement copyElement = GeneratedExecutableElement.newMethodWithSelector("copyWithZone:", TypeUtil.ID_TYPE, type);
MethodDeclaration copyDecl = new MethodDeclaration(copyElement);
copyDecl.setHasDeclaration(false);
// Add NSZone *zone parameter.
GeneratedVariableElement zoneParam = GeneratedVariableElement.newParameter("zone", NSZONE_TYPE, copyElement);
copyElement.addParameter(zoneParam);
copyDecl.addParameter(new SingleVariableDeclaration(zoneParam));
Block block = new Block();
copyDecl.setBody(block);
if (singleton) {
block.addStatement(new ReturnStatement(new ThisExpression(type.asType())));
} else {
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.GeneratedVariableElement in project j2objc by google.
the class NumberMethodRewriter method addEqualsMethod.
private void addEqualsMethod(TypeDeclaration node) {
TypeElement typeElement = node.getTypeElement();
GeneratedExecutableElement equalsElement = GeneratedExecutableElement.newMethodWithSelector("isEqual:", typeUtil.getBoolean(), typeElement);
GeneratedVariableElement paramElement = GeneratedVariableElement.newParameter("obj", typeUtil.getJavaObject().asType(), equalsElement);
equalsElement.addParameter(paramElement);
node.addBodyDeclaration(new MethodDeclaration(equalsElement).addParameter(new SingleVariableDeclaration(paramElement)).setBody(new Block().addStatement(new NativeStatement("return self == obj;"))).setModifiers(Modifier.PUBLIC));
}
use of com.google.devtools.j2objc.types.GeneratedVariableElement 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);
element.addAnnotationMirrors(method.element().getAnnotationMirrors());
MethodDeclaration decl = new MethodDeclaration(element);
if (!declaringClass.getKind().isInterface()) {
unit.setHasIncompleteImplementation();
}
int argCount = 0;
for (VariableElement param : method.element().getParameters()) {
GeneratedVariableElement newParam = GeneratedVariableElement.newParameter("arg" + argCount++, param.asType(), element);
newParam.addAnnotationMirrors(param.getAnnotationMirrors());
element.addParameter(newParam);
decl.addParameter(new SingleVariableDeclaration(newParam));
}
return decl;
}
Aggregations