Java Code Examples for org.eclipse.jface.text.Document#getLineLength()
The following examples show how to use
org.eclipse.jface.text.Document#getLineLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarkerMaker.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
public IMarker makeMarker(Location loc) throws CoreException { IMarker marker = loc.resource.createMarker(XdsMarkerConstants.BUILD_PROBLEM_MARKER_TYPE); marker.setAttribute(IMarker.MESSAGE, loc.message); marker.setAttribute(IMarker.SEVERITY, loc.severity); if (loc.resource instanceof IFile) { marker.setAttribute(IMarker.LINE_NUMBER, loc.lineNumber); try { Document doc = getDoc((IFile)loc.resource); int lineOffs = doc.getLineOffset(loc.lineNumber-1); int lineLen = doc.getLineLength(loc.lineNumber-1); int markOffs = lineOffs + loc.posInLine-1; int markEnd = markOffs + getLexemLen(doc, markOffs); if (markEnd <= lineOffs + lineLen) { // hbz marker.setAttribute(IMarker.CHAR_START, markOffs); marker.setAttribute(IMarker.CHAR_END, markEnd); } } catch (Exception e) {} } marker.setAttribute(XdsMarkerConstants.VIOLATION_ATTR, loc.violation); return marker; }
Example 2
Source File: XbaseEditor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Returns the line of the given selection. It is assumed that it covers an entire line in the Java file. * * @return the line in the Java file (zero based) or <code>-1</code> if the selection does not cover a complete * line. */ protected int getLineInJavaDocument(Document document, int selectionStart, int selectionLength) throws BadLocationException { int line = document.getLineOfOffset(selectionStart); int length = document.getLineLength(line); int lineOffset = document.getLineOffset(line); if (lineOffset == selectionStart && length == selectionLength) { return line; } IRegion region = document.getLineInformation(line); if (region.getOffset() == selectionStart || region.getLength() == selectionLength) { return line; } return -1; }
Example 3
Source File: AddTokenAndImportStatementTest.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public void checkImport(String baseDoc, String importToAdd, String expectedDoc, int maxCols) throws Exception { Document document = new Document(baseDoc); char trigger = '\n'; int offset = 0; boolean addLocalImport = false; boolean addLocalImportsOnTopOfMethod = false; boolean groupImports = true; AddTokenAndImportStatement stmt = new AddTokenAndImportStatement(document, trigger, offset, addLocalImport, addLocalImportsOnTopOfMethod, groupImports, maxCols); String realImportRep = importToAdd; int fReplacementOffset = document.getLineLength(0); int fLen = 0; String indentString = ""; String fReplacementString = ""; boolean appliedWithTrigger = false; int importLen = 0; ComputedInfo computedInfo = new ComputedInfo(realImportRep, fReplacementOffset, fLen, indentString, fReplacementString, appliedWithTrigger, importLen, document); stmt.createTextEdit(computedInfo); for (ReplaceEdit edit : computedInfo.replaceEdit) { try { edit.apply(document); } catch (Exception e) { Log.log(e); } } assertEquals(expectedDoc, document.get()); }