public int getLineOfOffset(int offset) { try { return doc.getLineOfOffset(offset); } catch (BadLocationException e) { return -1; } }
@Override public int getStartLine() { try { if (fDocument != null) return fDocument.getLineOfOffset(fOffset); } catch (BadLocationException x) { // ignore } return -1; }
@Override public int getStartLine() { try { if (fDocument != null) return fDocument.getLineOfOffset(fOffset); } catch (BadLocationException x) { } return -1; }
public int getLineOfOffset(int offset) { try { return doc.getLineOfOffset(offset); } 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; }
public void configureBackwardReader(IDocument document, int offset, boolean skipComments, boolean skipStrings) throws IOException { fDocument= document; fOffset= offset; fSkipComments= skipComments; fSkipStrings= skipStrings; fForward= false; try { fCachedLineNumber= fDocument.getLineOfOffset(fOffset); } catch (BadLocationException x) { throw new IOException(x.getMessage()); } }
@Override boolean isMultiline(ISelection selection) throws BadLocationException { ITextSelection ts= (ITextSelection)selection; return fDocument.getLineOfOffset(ts.getOffset()) < fDocument.getLineOfOffset(ts.getOffset() + ts.getLength()); }
@Override boolean isMultiline(ISelection selection) throws BadLocationException { ITextSelection ts= (ITextSelection)selection; return fDocument.getLineOfOffset(ts.getOffset()) < fDocument.getLineOfOffset(ts.getOffset() + ts.getLength()); }
private ILineRange getLineRange(IDocument document, ITextSelection selection) throws BadLocationException { final int offset= selection.getOffset(); int startLine= document.getLineOfOffset(offset); int endOffset= offset + selection.getLength(); int endLine= document.getLineOfOffset(endOffset); final int nLines= endLine - startLine + 1; return new LineRange(startLine, nLines); }
protected int getLine(Element element, String attName) { ElementData data = fOffsetTable.get(element); if (data != null) { try { int offset = getAttributeOffset(attName, element.getAttribute(attName), data.offset); if (offset != -1) return fTextDocument.getLineOfOffset(offset) + 1; } catch (BadLocationException e) { } } return getLine(element); }
protected int getLine(Element element, String attName) { ElementData data = (ElementData) fOffsetTable.get(element); try { int offset = getAttributeOffset(attName, element.getAttribute(attName), data.offset); if (offset != -1) return fTextDocument.getLineOfOffset(offset) + 1; } catch (BadLocationException e) { } return getLine(element); }
private static int getLineNumber(IJavaElement element, IDocument document) throws JavaModelException, BadLocationException { ISourceRange r= ((ISourceReference) element).getNameRange(); int offset= r.getOffset(); return document.getLineOfOffset(offset); }
private int getLineNumber(int start) { int lineNo = -1; try { lineNo = getDocument().getLineOfOffset(start); } catch (BadLocationException e) { Logger.logException(e); } return lineNo; }
public int getLineOfOffset(int offset) throws CoreException { if (fDocument != null) { try { return fDocument.getLineOfOffset(offset); } catch (BadLocationException e) { String message= "Illegal offset: " + offset; //$NON-NLS-1$ throw new CoreException(createError(DOCUMENT_ERROR, message, e)); } } return getScanner().getLineNumber(offset); }
public int getLineOfOffset(int offset) throws CoreException { if (fDocument != null) { try { return fDocument.getLineOfOffset(offset); } catch (BadLocationException e) { String message= "Illegal offset: " + offset; //$NON-NLS-1$ throw new CoreException(createError(DOCUMENT_ERROR, message, e)); } } return getScanner().getLineNumber(offset); }
private String getText(IDocument document, int offset, int length, int numberOfLines) throws BadLocationException { int endOffset= offset + length; try { int endLine= document.getLineOfOffset(offset) + Math.max(0, numberOfLines -1); IRegion lineInfo= document.getLineInformation(endLine); endOffset= Math.min(endOffset, lineInfo.getOffset() + lineInfo.getLength()); } catch (BadLocationException x) { } return document.get(offset, endOffset - offset); }
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; }
/** * Creates line break string containing line delimiter, line comment string if <code>isCommentedOut</code> is <code>true</code>, * and same indent string as the line that break is inserted at. * @param startOfLineOffset * @param isCommentedOut * @return line break string * @throws BadLocationException */ protected String createLineBreakString(int startOfLineOffset, boolean isCommentedOut) throws BadLocationException { return createLineBreakString(getDocument().getLineDelimiter(getDocument().getLineOfOffset(startOfLineOffset)), startOfLineOffset, isCommentedOut); }
@Override public void matchFound(PatternMatchEvent event) { try { IDocument document = fConsole.getDocument(); int lineOfOffset = document.getLineOfOffset(event.getOffset()); String delimiter = document.getLineDelimiter(lineOfOffset); int strip = delimiter==null ? 0 : delimiter.length(); Region region = new Region(event.getOffset(), event.getLength()-strip); lineAppended(region); } catch (BadLocationException e) {} }
private String formatElement(IDocument document, TypedPosition partition) throws BadLocationException { String partitionText = document.get(partition.getOffset(), partition.getLength()); IRegion line = document.getLineInformationOfOffset(partition.getOffset()); int indentLength = partition.getOffset() - line.getOffset(); String lineDelimiter = document.getLineDelimiter(document.getLineOfOffset(line.getOffset())); if (lineDelimiter == null) { lineDelimiter = TextUtilities.getDefaultLineDelimiter(document); } return XmlTagFormatter.format(partitionText, prefs, document.get(line.getOffset(), indentLength), lineDelimiter); }