use of javax.lang.model.element.VariableElement 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 javax.lang.model.element.VariableElement in project j2objc by google.
the class SuperMethodInvocationRewriter method getSuperFunctionSignature.
private static String getSuperFunctionSignature(ExecutableElement method) {
StringBuilder signature = new StringBuilder(NameTable.getPrimitiveObjCType(method.getReturnType()));
signature.append(" (*%s)(id, SEL");
for (VariableElement param : method.getParameters()) {
signature.append(", ").append(NameTable.getPrimitiveObjCType(param.asType()));
}
signature.append(")");
return signature.toString();
}
use of javax.lang.model.element.VariableElement in project j2objc by google.
the class UnsequencedExpressionRewriter method getUnsequencedAccesses.
private List<VariableAccess> getUnsequencedAccesses() {
if (!hasModification) {
return Collections.emptyList();
}
ListMultimap<VariableElement, VariableAccess> accessesByVar = MultimapBuilder.hashKeys().arrayListValues().build();
for (VariableAccess access : orderedAccesses) {
accessesByVar.put(access.variable, access);
}
Set<VariableAccess> unsequencedAccesses = Sets.newHashSet();
for (VariableElement var : accessesByVar.keySet()) {
findUnsequenced(accessesByVar.get(var), unsequencedAccesses);
}
List<VariableAccess> orderedUnsequencedAccesses = Lists.newArrayListWithCapacity(unsequencedAccesses.size());
for (VariableAccess access : orderedAccesses) {
if (unsequencedAccesses.contains(access)) {
orderedUnsequencedAccesses.add(access);
}
}
return orderedUnsequencedAccesses;
}
use of javax.lang.model.element.VariableElement in project j2objc by google.
the class VariableRenamer method collectAndRenameFields.
private void collectAndRenameFields(TypeElement type, Set<VariableElement> fields) {
if (type == null) {
return;
}
collectAndRenameFields(ElementUtil.getSuperclass(type), fields);
if (!renamedTypes.contains(type)) {
renamedTypes.add(type);
Set<String> superFieldNames = new HashSet<>();
for (VariableElement superField : fields) {
superFieldNames.add(superField.getSimpleName().toString());
}
// Look for methods that might conflict with a static variable when functionized.
Set<String> staticMethodNames = new HashSet<>();
for (ExecutableElement method : ElementUtil.getExecutables(type)) {
if (method.getParameters().size() == 0) {
staticMethodNames.add(nameTable.getFunctionName(method));
}
}
for (VariableElement field : ElementUtil.getDeclaredFields(type)) {
String fieldName = field.getSimpleName().toString();
if (ElementUtil.isGlobalVar(field)) {
if (staticMethodNames.contains(fieldName)) {
while (staticMethodNames.contains(fieldName)) {
fieldName += "_";
}
nameTable.setVariableName(field, fieldName);
}
} else if (!ElementUtil.isStatic(field) && superFieldNames.contains(fieldName)) {
fieldName += "_" + type.getSimpleName();
nameTable.setVariableName(field, fieldName);
}
}
}
for (VariableElement field : ElementUtil.getDeclaredFields(type)) {
if (!ElementUtil.isStatic(field)) {
fields.add(field);
}
}
}
use of javax.lang.model.element.VariableElement in project j2objc by google.
the class VariableRenamer method pushType.
private void pushType(TypeElement type) {
Set<VariableElement> fields = new HashSet<>();
collectAndRenameFields(type, fields);
Set<String> fullFieldNames = new HashSet<>();
for (VariableElement field : fields) {
fullFieldNames.add(nameTable.getVariableShortName(field));
}
fieldNameStack.add(fullFieldNames);
}
Aggregations