| 112 | } |
| 113 | |
| 114 | void WriteSetAttrDirective(const AttributeSpec& attr, bool optional, |
| 115 | SourceWriter* writer) { |
| 116 | string var_name = optional ? "opts." + attr.var().name() : attr.var().name(); |
| 117 | if (attr.iterable()) { |
| 118 | string array_name = attr.var().name() + "Array"; |
| 119 | writer->AppendType(attr.jni_type()) |
| 120 | .Append("[] " + array_name + " = new ") |
| 121 | .AppendType(attr.jni_type()) |
| 122 | .Append("[" + var_name + ".size()];") |
| 123 | .EndLine() |
| 124 | .BeginBlock("for (int i = 0; i < " + array_name + ".length; ++i)") |
| 125 | .Append(array_name + "[i] = "); |
| 126 | if (attr.type().kind() == Type::GENERIC) { |
| 127 | writer->Append("DataType.fromClass(" + var_name + ".get(i));"); |
| 128 | } else { |
| 129 | writer->Append(var_name + ".get(i);"); |
| 130 | } |
| 131 | writer->EndLine() |
| 132 | .EndBlock() |
| 133 | .Append("opBuilder.setAttr(\"" + attr.op_def_name() + "\", ") |
| 134 | .Append(array_name + ");") |
| 135 | .EndLine(); |
| 136 | } else { |
| 137 | writer->Append("opBuilder.setAttr(\"" + attr.op_def_name() + "\", "); |
| 138 | if (attr.var().type().name() == "Class") { |
| 139 | writer->Append("DataType.fromClass(" + var_name + "));"); |
| 140 | } else { |
| 141 | writer->Append(var_name + ");"); |
| 142 | } |
| 143 | writer->EndLine(); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void RenderSecondaryFactoryMethod(const OpSpec& op, const Type& op_class, |
| 148 | std::map<string, Type> default_types, |