@Override public DefaultTokenWriter writeln() { printerHelper.writeln(); return this; }
static void printCommentContent(PrinterHelper printer, CtComment comment, Function<String, String> transfo) { CtComment.CommentType commentType = comment.getCommentType(); String content = comment.getContent(); String[] lines = LINE_SEPARATORS_RE.split(content); for (String com : lines) { if (commentType == CtComment.CommentType.BLOCK) { printer.write(com); if (lines.length > 1) { printer.write(CtComment.LINE_SEPARATOR); } } else { printer.write(transfo.apply(com)).writeln(); // removing spaces at the end of the space } } if (comment instanceof CtJavaDoc) { List<CtJavaDocTag> tags = null; Collection<CtJavaDocTag> javaDocTags = ((CtJavaDoc) comment).getTags(); if (javaDocTags != null && javaDocTags.isEmpty() == false) { printer.write(transfo.apply("")).writeln(); for (CtJavaDocTag docTag : javaDocTags) { printJavaDocTag(printer, docTag, transfo); } } } }
static void printJavaDocTag(PrinterHelper printer, CtJavaDocTag docTag, Function<String, String> transfo) { printer.write(transfo.apply(CtJavaDocTag.JAVADOC_TAG_PREFIX)); printer.write(docTag.getType().name().toLowerCase()); printer.write(" "); if (docTag.getType().hasParam()) { printer.write(docTag.getParam()).writeln(); } String[] tagLines = LINE_SEPARATORS_RE.split(docTag.getContent()); for (int i = 0; i < tagLines.length; i++) { String com = tagLines[i]; if (docTag.getType().hasParam()) { printer.write(transfo.apply("\t\t")); } printer.write(com.trim()).writeln(); } } }
private String getSubstitutionRequestsDescription(CtElement ele, List<ParamOnElement> requestsOnPos) { //sort requestsOnPos by their path Map<String, ParamOnElement> reqByPath = new TreeMap<>(); StringBuilder sb = new StringBuilder(); for (ParamOnElement reqPos : requestsOnPos) { sb.setLength(0); appendPathIn(sb, reqPos.sourceElement, ele); if (reqPos.role != null) { sb.append("/").append(reqPos.role.getCamelCaseName()); } String path = sb.toString(); reqByPath.put(path, reqPos); } PrinterHelper printer = new PrinterHelper(getFactory().getEnvironment()); //all comments in Spoon are using \n as separator printer.setLineSeparator("\n"); printer.write(getElementTypeName(ele)).incTab(); for (Map.Entry<String, ParamOnElement> e : reqByPath.entrySet()) { printer.writeln(); printer.write(e.getKey()).write('/'); printer.write(" <= ").write(e.getValue().node.toString()); } return printer.toString(); }
public PrinterHelper adjustEndPosition(CtElement e) { if (env.isPreserveLineNumbers() && e.getPosition().isValidPosition()) { // let's add lines if required while (line < e.getPosition().getEndLine()) { writeln(); } } return this; }
/** writes as many newlines as needed to align the line number again between the element position and the current line number */ public PrinterHelper adjustStartPosition(CtElement e) { if (!e.isImplicit() && e.getPosition().isValidPosition()) { // we should add some lines while (line < e.getPosition().getLine()) { writeln(); } // trying to remove some lines while (line > e.getPosition().getLine()) { if (!removeLine()) { break; } } } return this; }