private void handleNoFormatTag(int start, int end, boolean isOpeningTag) { if (isOpeningTag) { if (this.noFormatTagOpenStart < 0) this.noFormatTagOpenStart = start; } else if (this.noFormatTagOpenStart >= 0) { int openingTagIndex = tokenStartingAt(this.noFormatTagOpenStart); int closingTagIndex = tokenEndingAt(end); if (openingTagIndex < closingTagIndex) { disableFormatting(openingTagIndex, closingTagIndex); closingTagIndex = tokenEndingAt(end); } cleanupHTMLElement(openingTagIndex, closingTagIndex, false); this.noFormatTagOpenStart = -1; } }
private void handleNoFormatTag(int start, int end, boolean isOpeningTag) { if (isOpeningTag) { if (this.noFormatTagOpenStart < 0) this.noFormatTagOpenStart = start; } else if (this.noFormatTagOpenStart >= 0) { int openingTagIndex = tokenStartingAt(this.noFormatTagOpenStart); int closingTagIndex = tokenEndingAt(end); if (openingTagIndex < closingTagIndex) { disableFormatting(openingTagIndex, closingTagIndex); closingTagIndex = tokenEndingAt(end); } cleanupHTMLElement(openingTagIndex, closingTagIndex, false); this.noFormatTagOpenStart = -1; } }
private void handleNoFormatTag(int start, int end, boolean isOpeningTag) { if (isOpeningTag) { if (this.noFormatTagOpenStart < 0) this.noFormatTagOpenStart = start; } else if (this.noFormatTagOpenStart >= 0) { int openingTagIndex = tokenStartingAt(this.noFormatTagOpenStart); int closingTagIndex = tokenEndingAt(end); if (openingTagIndex < closingTagIndex) { disableFormatting(openingTagIndex, closingTagIndex); closingTagIndex = tokenEndingAt(end); } cleanupHTMLElement(openingTagIndex, closingTagIndex, false); this.noFormatTagOpenStart = -1; } }
private void handleBreakAfterTag(int start, int end) { int tokenIndex = tokenEndingAt(end); this.ctm.get(tokenIndex).breakAfter(); }
private void handleBreakAfterTag(int start, int end) { int tokenIndex = tokenEndingAt(end); this.ctm.get(tokenIndex).breakAfter(); }
private void handleBreakAfterTag(int start, int end) { int tokenIndex = tokenEndingAt(end); this.ctm.get(tokenIndex).breakAfter(); }
private void handleStringLiterals(String text, int textStartPosition) { Matcher matcher = STRING_LITERAL_PATTERN.matcher(text); while (matcher.find()) { int startPosition = textStartPosition + matcher.start(); int startIndex = this.ctm.findIndex(startPosition, -1, false); int endPosition = textStartPosition + matcher.end() - 1; int endIndex = this.ctm.findIndex(endPosition, -1, false); if (startIndex != endIndex) { startIndex = tokenStartingAt(startPosition); endIndex = tokenEndingAt(endPosition); disableFormatting(startIndex, endIndex); } noSubstituteWrapping(startPosition, endPosition); } }
private void handleStringLiterals(String text, int textStartPosition) { Matcher matcher = STRING_LITERAL_PATTERN.matcher(text); while (matcher.find()) { int startPosition = textStartPosition + matcher.start(); int startIndex = this.ctm.findIndex(startPosition, -1, false); int endPosition = textStartPosition + matcher.end() - 1; int endIndex = this.ctm.findIndex(endPosition, -1, false); if (startIndex != endIndex) { startIndex = tokenStartingAt(startPosition); endIndex = tokenEndingAt(endPosition); disableFormatting(startIndex, endIndex); } noSubstituteWrapping(startPosition, endPosition); } }
private void handleStringLiterals(String text, int textStartPosition) { Matcher matcher = STRING_LITERAL_PATTERN.matcher(text); while (matcher.find()) { int startPosition = textStartPosition + matcher.start(); int startIndex = this.ctm.findIndex(startPosition, -1, false); int endPosition = textStartPosition + matcher.end() - 1; int endIndex = this.ctm.findIndex(endPosition, -1, false); if (startIndex != endIndex) { startIndex = tokenStartingAt(startPosition); endIndex = tokenEndingAt(endPosition); disableFormatting(startIndex, endIndex); } noSubstituteWrapping(startPosition, endPosition); } }
private void formatCode(int javadocNoFormatCloseStart, int javadocNoFormatCloseEnd) { int openingTagLastIndex = tokenEndingAt(this.formatCodeTagOpenEnd); int closingTagFirstIndex = tokenStartingAt(javadocNoFormatCloseStart); int codeStartPosition = this.formatCodeTagOpenEnd + 1; int codeEndPosition = javadocNoFormatCloseStart - 1; StringBuilder codeBuilder = new StringBuilder(codeEndPosition - codeStartPosition + 1); int[] positionMapping = new int[codeEndPosition - codeStartPosition + 1]; // ^ index: original source position (minus startPosition), value: position in code string getCodeToFormat(codeStartPosition, codeEndPosition, codeBuilder, positionMapping); List<Token> formattedTokens = getCommentCodeFormatter().prepareFormattedCode(codeBuilder.toString()); if (formattedTokens == null) { disableFormattingExclusively(openingTagLastIndex, closingTagFirstIndex); closingTagFirstIndex = tokenStartingAt(javadocNoFormatCloseStart); cleanupHTMLElement(openingTagLastIndex, closingTagFirstIndex, false); return; } formattedTokens = translateFormattedTokens(codeStartPosition, formattedTokens, positionMapping, null); // there are too few linebreaks at the start and end Token start = formattedTokens.get(0); start.putLineBreaksBefore(start.getLineBreaksBefore() + 1); Token end = formattedTokens.get(formattedTokens.size() - 1); end.putLineBreaksAfter(end.getLineBreaksAfter() + 1); // and there may be too many line breaks before closing tag this.ctm.get(closingTagFirstIndex).clearLineBreaksBefore(); List<Token> tokensToReplace = this.commentStructure.subList(openingTagLastIndex + 1, closingTagFirstIndex); tokensToReplace.clear(); tokensToReplace.addAll(formattedTokens); cleanupHTMLElement(openingTagLastIndex, openingTagLastIndex + formattedTokens.size() + 1, true); }
private void formatCode(int javadocNoFormatCloseStart, int javadocNoFormatCloseEnd) { int openingTagLastIndex = tokenEndingAt(this.formatCodeTagOpenEnd); int closingTagFirstIndex = tokenStartingAt(javadocNoFormatCloseStart); int codeStartPosition = this.formatCodeTagOpenEnd + 1; int codeEndPosition = javadocNoFormatCloseStart - 1; StringBuilder codeBuilder = new StringBuilder(codeEndPosition - codeStartPosition + 1); int[] positionMapping = new int[codeEndPosition - codeStartPosition + 1]; // ^ index: original source position (minus startPosition), value: position in code string getCodeToFormat(codeStartPosition, codeEndPosition, codeBuilder, positionMapping); List<Token> formattedTokens = getCommentCodeFormatter().prepareFormattedCode(codeBuilder.toString()); if (formattedTokens == null) { disableFormattingExclusively(openingTagLastIndex, closingTagFirstIndex); closingTagFirstIndex = tokenStartingAt(javadocNoFormatCloseStart); cleanupHTMLElement(openingTagLastIndex, closingTagFirstIndex, false); return; } formattedTokens = translateFormattedTokens(codeStartPosition, formattedTokens, positionMapping, null); // there are too few linebreaks at the start and end Token start = formattedTokens.get(0); start.putLineBreaksBefore(start.getLineBreaksBefore() + 1); Token end = formattedTokens.get(formattedTokens.size() - 1); end.putLineBreaksAfter(end.getLineBreaksAfter() + 1); // and there may be too many line breaks before closing tag this.ctm.get(closingTagFirstIndex).clearLineBreaksBefore(); List<Token> tokensToReplace = this.commentStructure.subList(openingTagLastIndex + 1, closingTagFirstIndex); tokensToReplace.clear(); tokensToReplace.addAll(formattedTokens); cleanupHTMLElement(openingTagLastIndex, openingTagLastIndex + formattedTokens.size() + 1, true); }
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 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); } } }
private void handleFormatCodeTag(int startPos, int endPos, boolean isOpeningTag) { if (!this.options.comment_format_source) { handleNoFormatTag(startPos, endPos, isOpeningTag); return; } // add empty lines before opening and after closing token handleSeparateLineTag(startPos, endPos); if (isOpeningTag) { int startIndex = tokenStartingAt(startPos); if (startIndex > 1) this.ctm.get(startIndex).putLineBreaksBefore(2); if (this.formatCodeTagOpenEnd < 0) this.formatCodeTagOpenEnd = endPos; } else if (this.formatCodeTagOpenEnd >= 0) { int endTagIndex = tokenEndingAt(endPos); if (endTagIndex < this.ctm.size() - 2) this.ctm.get(endTagIndex).putLineBreaksAfter(2); formatCode(startPos, endPos); this.formatCodeTagOpenEnd = -1; this.lastFormatCodeClosingTagIndex = this.ctm.findIndex(startPos, -1, true); } }
private void handleFormatCodeTag(int startPos, int endPos, boolean isOpeningTag) { if (!this.options.comment_format_source) { handleNoFormatTag(startPos, endPos, isOpeningTag); return; } // add empty lines before opening and after closing token handleSeparateLineTag(startPos, endPos); if (isOpeningTag) { int startIndex = tokenStartingAt(startPos); if (startIndex > 1) this.ctm.get(startIndex).putLineBreaksBefore(2); if (this.formatCodeTagOpenEnd < 0) this.formatCodeTagOpenEnd = endPos; } else if (this.formatCodeTagOpenEnd >= 0) { int endTagIndex = tokenEndingAt(endPos); if (endTagIndex < this.ctm.size() - 2) this.ctm.get(endTagIndex).putLineBreaksAfter(2); formatCode(startPos, endPos); this.formatCodeTagOpenEnd = -1; this.lastFormatCodeClosingTagIndex = this.ctm.findIndex(startPos, -1, true); } }
private void handleFormatCodeTag(int startPos, int endPos, boolean isOpeningTag) { if (!this.options.comment_format_source) { handleNoFormatTag(startPos, endPos, isOpeningTag); return; } // add empty lines before opening and after closing token handleSeparateLineTag(startPos, endPos); if (isOpeningTag) { int startIndex = tokenStartingAt(startPos); if (startIndex > 1) this.ctm.get(startIndex).putLineBreaksBefore(2); if (this.formatCodeTagOpenEnd < 0) this.formatCodeTagOpenEnd = endPos; } else if (this.formatCodeTagOpenEnd >= 0) { int endTagIndex = tokenEndingAt(endPos); if (endTagIndex < this.ctm.size() - 2) this.ctm.get(endTagIndex).putLineBreaksAfter(2); formatCode(startPos, endPos); this.formatCodeTagOpenEnd = -1; this.lastFormatCodeClosingTagIndex = this.ctm.findIndex(startPos, -1, true); } }