@Override public int getLineOffset(int line) { try { return doc.getLineOffset(line); } catch (BadLocationException e) { return -1; } } };
public int getLineOffset(int line) { try { return doc.getLineOffset(line); } catch (BadLocationException e) { return -1; } } };
public int getLineOffset(int line) { try { return doc.getLineOffset(line); } catch (BadLocationException e) { return -1; } } };
@Override public int getOffset(int line, int column) throws BadLocationException { return fDocument.getLineOffset(line - 1) + column - 1; }
public int getLineOffset(int line) { try { return doc.getLineOffset(line); } catch (BadLocationException e) { return -1; } } };
@Override public int getColumn() { if (fColumn == UNDEFINED) { try { int line= fDocument.getLineOfOffset(fOffset); int start= fDocument.getLineOffset(line); fColumn= fOffset - start; } catch (BadLocationException ex) { } } return fColumn; }
private int getNonWhitespaceOffset(int line, int column) throws BadLocationException { int offset = fDocument.getLineOffset(line - 1) + column - 1; while (Character.isWhitespace(fDocument.getChar(offset))) { offset++; } return offset; }
public static int getInsertOffset(IDocument doc) { int offset = doc.getLength(); for (int i = doc.getNumberOfLines() - 1; i >= 0; i--) { try { if (doc.get(doc.getLineOffset(i), doc.getLineLength(i)).trim().length() > 0) { break; } offset = doc.getLineOffset(i); } catch (BadLocationException e) { } } return offset; }
public static Position convertToCharacterPosition(Position linePosition, IDocument doc) throws BadLocationException { int lineOffset= linePosition.getOffset(); int lineLength= linePosition.getLength(); int charOffset= doc.getLineOffset(lineOffset); int charLength= 0; if (lineLength > 0) { int lastLine= lineOffset+lineLength-1; int endPosition= doc.getLineOffset(lastLine)+doc.getLineLength(lastLine); charLength= endPosition-charOffset; } return new Position(charOffset, charLength); }
public static Position convertToCharacterPosition(Position linePosition, IDocument doc) throws BadLocationException { int lineOffset= linePosition.getOffset(); int lineLength= linePosition.getLength(); int charOffset= doc.getLineOffset(lineOffset); int charLength= 0; if (lineLength > 0) { int lastLine= lineOffset+lineLength-1; int endPosition= doc.getLineOffset(lastLine)+doc.getLineLength(lastLine); charLength= endPosition-charOffset; } return new Position(charOffset, charLength); }
private IRegion getRegion(IDocument document, ILineRange lineRange) throws BadLocationException { final int startLine= lineRange.getStartLine(); int offset= document.getLineOffset(startLine); final int numberOfLines= lineRange.getNumberOfLines(); if (numberOfLines < 1) return new Region(offset, 0); int endLine= startLine + numberOfLines - 1; int endOffset= document.getLineOffset(endLine) + document.getLineLength(endLine); return new Region(offset, endOffset - offset); }
public static boolean isNewlineNeeded(IDocument doc) throws BadLocationException { int line = doc.getLineOfOffset(getInsertOffset(doc)); return doc.get(doc.getLineOffset(line), doc.getLineLength(line)).trim().length() > 0; }
public static boolean isNewlineNeeded(IDocument doc) throws BadLocationException { int line = doc.getLineOfOffset(getInsertOffset(doc)); return doc.get(doc.getLineOffset(line), doc.getLineLength(line)).trim().length() > 0; }
private void addFoldingRegions(Set<Position> regions, IManifestHeader header, IDocument document) throws BadLocationException { if (header == null) return; int startLine = document.getLineOfOffset(header.getOffset()); int endLine = document.getLineOfOffset(header.getOffset() + header.getLength() - 1); if (startLine < endLine) { int start = document.getLineOffset(startLine); int end = document.getLineOffset(endLine) + document.getLineLength(endLine); Position position = new Position(start, end - start); regions.add(position); fPositionToElement.put(position, header); } }
@Override public Position getPosition(Annotation annotation) { if (fRightDocument != null && annotation instanceof DiffRegion) { QuickDiffRangeDifference difference= ((DiffRegion)annotation).getDifference(); try { int offset= fRightDocument.getLineOffset(difference.rightStart()); return new Position(offset, fRightDocument.getLineOffset(difference.rightEnd() - 1) + fRightDocument.getLineLength(difference.rightEnd() - 1) - offset); } catch (BadLocationException e) { // ignore and return null; } } return null; }
private String getIndentOfLine(IDocument d, int line) throws BadLocationException { if (line > -1) { int start= d.getLineOffset(line); int end= start + d.getLineLength(line) - 1; int whiteEnd= findEndOfWhiteSpace(d, start, end); return d.get(start, whiteEnd - start); } else { return ""; //$NON-NLS-1$ } }
private static Position createPosition(IDocument document, int offset) { Position start = new Position(); try { int lineOfOffset = document.getLineOfOffset(offset); start.setLine(Integer.valueOf(lineOfOffset)); start.setCharacter(Integer.valueOf(offset - document.getLineOffset(lineOfOffset))); } catch (BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return start; }
private int getOffset(TextDocumentPositionParams param, ITypeRoot typeRoot) { int offset = 0; try { IDocument document = JsonRpcHelpers.toDocument(typeRoot.getBuffer()); offset = document.getLineOffset(param.getPosition().getLine()) + param.getPosition().getCharacter(); } catch (JavaModelException | BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return offset; }
private IRegion getRegion(Range range, IDocument document) { try { int offset = document.getLineOffset(range.getStart().getLine()) + range.getStart().getCharacter(); int endOffset = document.getLineOffset(range.getEnd().getLine()) + range.getEnd().getCharacter(); int length = endOffset - offset; return new Region(offset, length); } catch (BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return null; }
public void doubleClicked(ITextViewer viewer) { try { IDocument doc = viewer.getDocument(); int caretOffset = viewer.getSelectedRange().x; int lineNum = doc.getLineOfOffset(caretOffset); int start = doc.getLineOffset(lineNum); int length = doc.getLineLength(lineNum); viewer.setSelectedRange(start, length); } catch (BadLocationException e) { JDIDebugUIPlugin.log(e); } } };