/** * Creates a plain text representation of a typedef union. * * @param field The 'typedeffed' union. * @param indent The indentation to draw. * @param type The complete type. */ private void drawTypedefUnion(MetaUnion field, String indent, MetaType type) { String typedefName = type.getFieldTypedefName(field.getDiscriminator()); if (typedefName != null) { writer.write( indent + "union " + field.getTypeName() + " switch(" + typedefName + ") {" + newLine); } else { writer.write( indent + "union " + field.getTypeName() + " switch(" + field.getDiscriminator().getTypeName() + ") {" + newLine); } MetaUnionCase[] cases = field.getCases(); ArrayList labels; for (int i = 0; i < cases.length; i++) { labels = cases[i].getLabels(); for (int j = 0; j < labels.size(); j++) { if ("".equals(labels.get(j))) { writer.write(indent + tab + "default :" + newLine); } else { writer.write(indent + tab + "case " + labels.get(j) + ":" + newLine); } } this.drawMetaField(cases[i].getField(), indent + tab + tab, type); } writer.write(indent + "}"); }
/** * Creates a plain text representation of a primitive. * * @param field The primitive to create the plain text representation of. * @param indent The indentation to draw. * @param type The complete type. */ private void drawPrimitive(MetaPrimitive field, String indent, MetaType type) { String typedefName = type.getFieldTypedefName(field); if (typedefName != null) { writer.write(indent + typedefName + " " + field.getName() + ";" + newLine + separator); } else { writer.write( indent + field.getTypeName() + " " + field.getName() + ";" + newLine + separator); } }
/** * Creates a plain text representation of a structure. * * @param field The structure to create the plain text representation of. * @param indent The indentation to draw. * @param type The complete type. */ private void drawStruct(MetaStruct field, String indent, MetaType type) { String typedefName = type.getFieldTypedefName(field); if (typedefName != null) { writer.write(indent + typedefName + " " + field.getName() + ";" + newLine + separator); } else { writer.write(indent + "struct " + field.getTypeName() + " {" + newLine); MetaField[] fields = field.getFields(); for (int i = 0; i < fields.length; i++) { this.drawMetaField(fields[i], indent + tab, type); } writer.write(indent + "} " + field.getName() + ";" + newLine + separator); } }
/** * Creates a plain text representation of a enumeration. * * @param field The enumeration to create the plain text representation of. * @param indent The indentation to draw. * @param type The complete type. */ private void drawEnum(MetaEnum field, String indent, MetaType type) { String typedefName = type.getFieldTypedefName(field); if (typedefName != null) { writer.write(indent + typedefName + " " + field.getName() + ";" + newLine + separator); } else { writer.write(indent + "enum " + field.getTypeName() + " {" + newLine); String[] posValues = field.getPosValues(); for (int i = 0; i < posValues.length; i++) { if (i != (posValues.length - 1)) { writer.write(indent + tab + posValues[i] + ", " + newLine); } else { writer.write(indent + tab + posValues[i] + newLine); } } writer.write(indent + "} " + field.getName() + ";" + newLine + separator); } }