public GenericObject deepClone() { final GenericObject retValue = new GenericObject(parent, name); for (WritableObject obj : allWritable) { if (obj instanceof GenericObject) { GenericObject go = ((GenericObject) obj).deepClone(); retValue.addChild(go); } else if (obj instanceof GenericList) { GenericList gl = ((GenericList) obj).clone(); retValue.addList(gl); } else if (obj instanceof ObjectVariable) { ObjectVariable ov = ((ObjectVariable) obj).clone(); retValue.values.add(ov); retValue.allWritable.add(ov); } else if (obj instanceof InlineComment) { Comment com = ((InlineComment) obj).clone(); retValue.generalComments.add(com); retValue.allWritable.add(com); } } if (headComment != null) retValue.setHeadComment(headComment.getComment()); if (inlineComment != null) retValue.setInlineComment(inlineComment.getComment()); return retValue; }
@Override public void toFileString(final BufferedWriter bw, int depth, Style style) throws IOException { if (name.equals("root")) { toFileString(bw, style); return; } final boolean parentSameLine = style.isInline(parent); final boolean sameLine = parentSameLine || style.isInline(this); if (!parentSameLine && headComment != null) { headComment.toFileString(bw, depth, style); } final String localtab = (parentSameLine ? "" : style.getTab(depth)); bw.write(localtab); if (!"".equals(name)) { bw.write(name); style.printEqualsSign(bw, depth); style.printOpeningBrace(bw, depth); } else { style.printOpeningBrace(bw, depth); } if (!sameLine) bw.newLine(); for (WritableObject obj : allWritable) { if (obj instanceof ObjectVariable || obj instanceof Comment) { if (!sameLine) { style.printTab(bw, depth + 1); } } obj.toFileString(bw, depth + 1, style); if (sameLine) bw.write(' '); else bw.newLine(); } if (parentSameLine) { bw.write('}'); } else if (sameLine) { bw.write("} "); if (inlineComment != null) inlineComment.toFileString(bw, depth, style); } else { bw.write(localtab + "}"); if (inlineComment != null) { bw.write(" "); inlineComment.toFileString(bw, depth, style); } if (style.newLineAfterObject()) bw.newLine(); } }
/** * Creates and returns a shallow copy of this object. Note that children are not cloned, but the * lists of children are. * * @return a shallow copy of this object. */ @Override public GenericObject clone() { final GenericObject retValue = new GenericObject(parent, name); retValue.children.addAll(children); retValue.lists.addAll(lists); retValue.values.addAll(values); retValue.generalComments.addAll(generalComments); retValue.allWritable.addAll(allWritable); if (headComment != null) retValue.setHeadComment(headComment.getComment()); if (inlineComment != null) retValue.setInlineComment(inlineComment.getComment()); return retValue; }
public void addHeadComment(String comment) { if (headComment == null) headComment = new HeaderComment(comment); else headComment.appendComment(comment); }
public String getHeadComment() { return headComment == null ? "" : headComment.getComment(); }