@Override public void placeMatchingBlanks(IStructuredDocument document, StringBuilder result, int lineNumber, int forOffset) throws BadLocationException { final IRegion curlyOpenLine = getCurlyOpenLineInformation(document, forOffset); if (curlyOpenLine == null) { return; } int indentationBaseLineIndex = DefaultIndentationStrategy.getIndentationBaseLine(document, document.getLineOfOffset(curlyOpenLine.getOffset()), forOffset, true); final IRegion indentationBaseLine = document.getLineInformation(indentationBaseLineIndex); String blanks = ""; if (indentationBaseLine != null) { blanks = FormatterUtils.getLineBlanks(document, indentationBaseLine); } else { // if no matching bracket was found leaving the bracket as is. blanks = FormatterUtils.getLineBlanks(document, document.getLineInformationOfOffset(forOffset)); } result.append(blanks); }
public static int getIndentationBaseLine(final IStructuredDocument document, final int lineNumber, final int offset, boolean checkMultiLine) throws BadLocationException { int currLineIndex = lineNumber; while (currLineIndex >= 0) { final IRegion lineInfo = document.getLineInformation(currLineIndex); if (lineInfo.getLength() == 0) { // then its not indentation base for sure currLineIndex--; continue; } final int currLineEndOffset = lineInfo.getOffset() + lineInfo.getLength(); final boolean isIndentationBase = isIndentationBase(document, Math.min(offset, currLineEndOffset), offset, currLineIndex, checkMultiLine); if (isIndentationBase) return currLineIndex; currLineIndex--; } return 0; }
private static boolean isEndOfStatement(IStructuredDocument document, int offset, int lineNumber) { try { IRegion lineInfo = document.getLineInformation(lineNumber); ITextRegion token = getLastTokenRegion(document, lineInfo, lineInfo.getOffset() + lineInfo.getLength()); if (token == null)// comment return true; if (token.getType() == TwigRegionTypes.PHP_CURLY_CLOSE) { return true; } } catch (final BadLocationException e) { } return false; }
int lastNonEmptyLineIndex = getIndentationBaseLine(document, lineNumber, forOffset, false); final int indentationBaseLineIndex = getIndentationBaseLine(document, lineNumber, forOffset, true); final IRegion lastNonEmptyLine = document.getLineInformation(lastNonEmptyLineIndex); final IRegion indentationBaseLine = document.getLineInformation(indentationBaseLineIndex); final String blanks = FormatterUtils.getLineBlanks(document, indentationBaseLine); result.append(blanks); IRegion lineInfo = document.getLineInformation(lastNonEmptyLineIndex); String content = document.get(lineInfo.getOffset(), lineInfo.getLength()); if (content.trim().length() > 0) { IRegion lineInfo = document.getLineInformation(lastNonEmptyLineIndex); result.append(FormatterUtils.getLineBlanks(document, lineInfo)); IRegion lineInfo = document.getLineInformation(lastNonEmptyLineIndex); result.append(FormatterUtils.getLineBlanks(document, lineInfo));
final IRegion originalLineInfo = document.getLineInformation(lineNumber); final int orginalLineStart = originalLineInfo.getOffset(); final int originalLineLength = originalLineInfo.getLength();
static boolean shouldIndent(final IStructuredDocument document, int offset, final int lineNumber) { try { final IRegion lineInfo = document.getLineInformation(lineNumber);
try { IRegion lineInfo = document.getLineInformation(lineNumber); int offset = lineInfo.getOffset() + lineInfo.getLength(); final IStructuredDocumentRegion sdRegion = document.getRegionAtCharacterOffset(offset);