protected int countExistingLeadingNewlines() { if (leadingWS == null) return -1; int c = 0, i = -1; while ((i = leadingWS.indexOf(getLineSeparator(), i + 1)) >= 0) c++; return c; }
protected int countCharactersInLastLine() { int lastNLIndex = value.lastIndexOf(getLineSeparator()); if (lastNLIndex >= 0) return (value.length() - lastNLIndex) - getLineSeparator().length(); if (preserveSpaces && leadingWS != null) { int lastNLIndexInLeadingWs = leadingWS.lastIndexOf(getLineSeparator()); if (lastNLIndexInLeadingWs >= 0) // TODO Moritz: replaced -1 by -getLineSeparator.length() // is that correct? return ((leadingWS.length() - lastNLIndexInLeadingWs) + value.length()) - getLineSeparator().length(); } return -1; }
protected String wrap(int lines, String indent) { StringBuffer result = new StringBuffer(lines + indent.length()); for (int i = 0; i < lines; i++) result.append(getLineSeparator()); // do not indent too deep as there would be no space left // for semantic information int indentLength = indent.length(); while ((cfg.getCharsPerLine() * 2 / 3) < indentLength) { indentLength = indentLength - cfg.getCharsPerLine() / 2; } if (indentLength != indent.length()) indent = indent.substring(0, indentLength); result.append(indent); return result.toString(); }
protected boolean isBreakable() { if (leadingLocators == null) return false; for (ElementLocator e : leadingLocators) { if (e instanceof LinewrapLocator && ((LinewrapLocator) e).getMaxWrap() == 0) return false; if (e instanceof SpaceLocator) return false; } return hiddenTokenHelper.getWhitespaceRuleFor(hiddenTokenDefinition, getLineSeparator()) != null; }
protected void addSpacesToTotalLength(LineEntry lineEntry, boolean first) { Pair<AbstractRule, String> spaces = getSpaces(lineEntry, first); if (spaces != null) { int lastIndexOfNL = spaces.getSecond().lastIndexOf(getLineSeparator()); if (lastIndexOfNL >= 0) totalLength += spaces.getSecond().length() - lastIndexOfNL; else totalLength += spaces.getSecond().length(); } }