@Override public boolean visit(EnumConstantDeclaration node) { WrapPreparator.this.tm.firstTokenIn(node, -1).setWrapPolicy(null); return true; } });
@Override public boolean visit(EnumConstantDeclaration node) { WrapPreparator.this.tm.firstTokenIn(node, -1).setWrapPolicy(null); return true; } });
@Override public boolean visit(EnumConstantDeclaration node) { WrapPreparator.this.tm.firstTokenIn(node, -1).setWrapPolicy(null); return true; } });
private void handleCompilerTags(Token commentToken, int commentIndex) { final String commentText = this.tm.toString(commentToken); final List<Token> structure = commentToken.getInternalStructure(); if (commentText.startsWith("//$FALL-THROUGH$") //$NON-NLS-1$ || commentText.startsWith("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ structure.get(1).clearSpaceBefore(); } if (commentText.contains("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ // make sure the whole line is not broken Token token = commentToken; for (int i = commentIndex; i > 0; i--) { Token left = this.tm.get(i - 1); if (this.tm.countLineBreaksBetween(left, token) > 0) break; token.clearLineBreaksBefore(); left.clearLineBreaksAfter(); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); token = left; } } }
private void handleCompilerTags(Token commentToken, int commentIndex) { final String commentText = this.tm.toString(commentToken); final List<Token> structure = commentToken.getInternalStructure(); if (commentText.startsWith("//$FALL-THROUGH$") //$NON-NLS-1$ || commentText.startsWith("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ structure.get(1).clearSpaceBefore(); } if (commentText.contains("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ // make sure the whole line is not broken Token token = commentToken; for (int i = commentIndex; i > 0; i--) { Token left = this.tm.get(i - 1); if (this.tm.countLineBreaksBetween(left, token) > 0) break; token.clearLineBreaksBefore(); left.clearLineBreaksAfter(); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); token = left; } } }
private void handleCompilerTags(Token commentToken, int commentIndex) { final String commentText = this.tm.toString(commentToken); final List<Token> structure = commentToken.getInternalStructure(); if (commentText.startsWith("//$FALL-THROUGH$") //$NON-NLS-1$ || commentText.startsWith("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ structure.get(1).clearSpaceBefore(); } if (commentText.contains("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ // make sure the whole line is not broken Token token = commentToken; for (int i = commentIndex; i > 0; i--) { Token left = this.tm.get(i - 1); if (this.tm.countLineBreaksBetween(left, token) > 0) break; token.clearLineBreaksBefore(); left.clearLineBreaksAfter(); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); token = left; } } }
private void setTokenWrapPolicy(int index, WrapPolicy policy, boolean wrapPreceedingComments) { if (wrapPreceedingComments) { for (int i = index - 1; i >= 0; i--) { Token previous = this.tm.get(i); if (!previous.isComment()) break; if (previous.getLineBreaksAfter() == 0 && i == index - 1) index = i; if (previous.getLineBreaksBefore() > 0) previous.setWrapPolicy(policy); } } Token token = this.tm.get(index); if (token.getWrapPolicy() != WrapPolicy.DISABLE_WRAP) token.setWrapPolicy(policy); if (this.options.join_wrapped_lines && token.tokenType == TokenNameCOMMENT_BLOCK) { // allow wrap preparator to decide if this comment should be wrapped token.clearLineBreaksBefore(); } }
private void addSubstituteWraps() { int commentStart = this.ctm.get(0).originalStart; for (int i = 1; i < this.ctm.size() - 1; i++) { Token token = this.ctm.get(i); boolean touchesPrevious = token.originalStart == this.ctm.get(i - 1).originalEnd + 1; if (touchesPrevious && token.getWrapPolicy() == null && token.getLineBreaksBefore() == 0) { boolean allowWrap = this.allowSubstituteWrapping[token.originalStart - commentStart]; token.setWrapPolicy(allowWrap ? WrapPolicy.SUBSTITUTE_ONLY : WrapPolicy.DISABLE_WRAP); } for (int pos = token.originalStart + 1; pos < token.originalEnd; pos++) { if (!this.allowSubstituteWrapping[pos - commentStart]) continue; char c = this.ctm.charAt(pos); if (!ScannerHelper.isJavaIdentifierPart(c)) { this.ctm.get(tokenStartingAt(pos)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); this.ctm.get(tokenStartingAt(pos + 1)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); } } } }
private void addSubstituteWraps() { int commentStart = this.ctm.get(0).originalStart; for (int i = 1; i < this.ctm.size() - 1; i++) { Token token = this.ctm.get(i); boolean touchesPrevious = token.originalStart == this.ctm.get(i - 1).originalEnd + 1; if (touchesPrevious && token.getWrapPolicy() == null && token.getLineBreaksBefore() == 0) { boolean allowWrap = this.allowSubstituteWrapping[token.originalStart - commentStart]; token.setWrapPolicy(allowWrap ? WrapPolicy.SUBSTITUTE_ONLY : WrapPolicy.DISABLE_WRAP); } for (int pos = token.originalStart + 1; pos < token.originalEnd; pos++) { if (!this.allowSubstituteWrapping[pos - commentStart]) continue; char c = this.ctm.charAt(pos); if (!ScannerHelper.isJavaIdentifierPart(c)) { this.ctm.get(tokenStartingAt(pos)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); this.ctm.get(tokenStartingAt(pos + 1)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); } } } }
private void addSubstituteWraps() { Token previous = this.ctm.get(0); int commentStart = previous.originalStart; for (int i = 1; i < this.ctm.size() - 1; i++) { Token token = this.ctm.get(i); boolean touchesPrevious = token.originalStart == this.ctm.get(i - 1).originalEnd + 1; if (touchesPrevious && token.getLineBreaksBefore() == 0 && previous.getLineBreaksAfter() == 0 && token.getWrapPolicy() == null) { boolean allowWrap = this.allowSubstituteWrapping[token.originalStart - commentStart]; token.setWrapPolicy(allowWrap ? WrapPolicy.SUBSTITUTE_ONLY : WrapPolicy.DISABLE_WRAP); } for (int pos = token.originalStart + 1; pos < token.originalEnd; pos++) { if (!this.allowSubstituteWrapping[pos - commentStart]) continue; char c = this.ctm.charAt(pos); if (!ScannerHelper.isJavaIdentifierPart(c)) { this.ctm.get(tokenStartingAt(pos)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); this.ctm.get(tokenStartingAt(pos + 1)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); } } previous = token; } }
private void handleBreakBeforeTag(int start, int end, boolean isOpeningTag) { int firstPartIndex = tokenStartingAt(start); int lastPartIndex = tokenEndingAt(end); Token firstPartToken = this.ctm.get(firstPartIndex); firstPartToken.setWrapPolicy(null); if (isOpeningTag) { firstPartToken.breakBefore(); this.ctm.get(lastPartIndex + 1).clearSpaceBefore(); } else { firstPartToken.clearSpaceBefore(); } }
private void handleBreakBeforeTag(int start, int end, boolean isOpeningTag) { int firstPartIndex = tokenStartingAt(start); int lastPartIndex = tokenEndingAt(end); Token firstPartToken = this.ctm.get(firstPartIndex); firstPartToken.setWrapPolicy(null); if (isOpeningTag) { firstPartToken.breakBefore(); this.ctm.get(lastPartIndex + 1).clearSpaceBefore(); } else { firstPartToken.clearSpaceBefore(); } }
private void handleBreakBeforeTag(int start, int end, boolean isOpeningTag) { int firstPartIndex = tokenStartingAt(start); int lastPartIndex = tokenEndingAt(end); Token firstPartToken = this.ctm.get(firstPartIndex); firstPartToken.setWrapPolicy(null); if (isOpeningTag) { firstPartToken.breakBefore(); this.ctm.get(lastPartIndex + 1).clearSpaceBefore(); } else { firstPartToken.clearSpaceBefore(); } }
private void checkSeparateLinesOnWrap(final int separateLinesOnWrapFrom) throws WrapRestartThrowable { if (separateLinesOnWrapFrom < 0) return; Token next = this.tm.get(separateLinesOnWrapFrom + 1); Token end = this.tm.get(separateLinesOnWrapFrom).getSeparateLinesOnWrapUntil(); if (next.getLineBreaksBefore() > 0 && end.getLineBreaksBefore() > 0) return; if (next.getWrapPolicy() == null || next.getWrapPolicy().wrapMode == WrapMode.FORCED) { next.setWrapPolicy(new WrapPolicy(WrapMode.WHERE_NECESSARY, separateLinesOnWrapFrom, this.options.indentation_size)); } next.breakBefore(); if (end.getWrapPolicy() == null || end.getWrapPolicy().wrapMode == WrapMode.FORCED) { end.setWrapPolicy(new WrapPolicy(WrapMode.WHERE_NECESSARY, separateLinesOnWrapFrom, 0)); } end.breakBefore(); throw new WrapRestartThrowable(-1); }
private void splitToken(Token token, int tokenIndex, int splitPosition) { assert splitPosition > token.originalStart && splitPosition <= token.originalEnd; Token part1 = new Token(token.originalStart, splitPosition - 1, token.tokenType); Token part2 = new Token(splitPosition, token.originalEnd, token.tokenType); if (token.isSpaceBefore()) part1.spaceBefore(); part1.putLineBreaksBefore(token.getLineBreaksBefore()); if (token.isSpaceAfter()) part2.spaceAfter(); part2.putLineBreaksAfter(token.getLineBreaksAfter()); part1.setIndent(token.getIndent()); part2.setIndent(token.getIndent()); part1.setWrapPolicy(token.getWrapPolicy()); this.commentStructure.set(tokenIndex, part1); this.commentStructure.add(tokenIndex + 1, part2); }
private void splitToken(Token token, int tokenIndex, int splitPosition) { assert splitPosition > token.originalStart && splitPosition <= token.originalEnd; Token part1 = new Token(token.originalStart, splitPosition - 1, token.tokenType); Token part2 = new Token(splitPosition, token.originalEnd, token.tokenType); if (token.isSpaceBefore()) part1.spaceBefore(); part1.putLineBreaksBefore(token.getLineBreaksBefore()); if (token.isSpaceAfter()) part2.spaceAfter(); part2.putLineBreaksAfter(token.getLineBreaksAfter()); part1.setIndent(token.getIndent()); part2.setIndent(token.getIndent()); part1.setWrapPolicy(token.getWrapPolicy()); this.commentStructure.set(tokenIndex, part1); this.commentStructure.add(tokenIndex + 1, part2); }
private void splitToken(Token token, int tokenIndex, int splitPosition) { assert splitPosition > token.originalStart && splitPosition <= token.originalEnd; Token part1 = new Token(token.originalStart, splitPosition - 1, token.tokenType); Token part2 = new Token(splitPosition, token.originalEnd, token.tokenType); if (token.isSpaceBefore()) part1.spaceBefore(); part1.putLineBreaksBefore(token.getLineBreaksBefore()); if (token.isSpaceAfter()) part2.spaceAfter(); part2.putLineBreaksAfter(token.getLineBreaksAfter()); part1.setIndent(token.getIndent()); part2.setIndent(token.getIndent()); part1.setWrapPolicy(token.getWrapPolicy()); this.commentStructure.set(tokenIndex, part1); this.commentStructure.add(tokenIndex + 1, part2); }
private void handleReference(ASTNode node) { ASTNode parent = node.getParent(); if ((parent instanceof TagElement) && ((TagElement) parent).isNested()) { int firstIndex = tokenStartingAt(node.getStartPosition()); int lastIndex = tokenEndingAt(node.getStartPosition() + node.getLength() - 1); if (this.ctm.charAt(this.ctm.get(lastIndex + 1).originalStart) == '}') lastIndex++; for (int i = firstIndex; i <= lastIndex; i++) { Token token = this.ctm.get(i); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); } } }
private void handleReference(ASTNode node) { ASTNode parent = node.getParent(); if ((parent instanceof TagElement) && ((TagElement) parent).isNested()) { int firstIndex = tokenStartingAt(node.getStartPosition()); int lastIndex = tokenEndingAt(node.getStartPosition() + node.getLength() - 1); if (this.ctm.charAt(this.ctm.get(lastIndex + 1).originalStart) == '}') lastIndex++; for (int i = firstIndex; i <= lastIndex; i++) { Token token = this.ctm.get(i); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); } } }
private void handleReference(ASTNode node) { ASTNode parent = node.getParent(); if ((parent instanceof TagElement) && ((TagElement) parent).isNested()) { int firstIndex = tokenStartingAt(node.getStartPosition()); int lastIndex = tokenEndingAt(node.getStartPosition() + node.getLength() - 1); if (this.ctm.charAt(this.ctm.get(lastIndex + 1).originalStart) == '}') lastIndex++; for (int i = firstIndex; i <= lastIndex; i++) { Token token = this.ctm.get(i); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); } } }