本文整理汇总了Java中org.eclipse.jface.text.IDocument.getLineOffset方法的典型用法代码示例。如果您正苦于以下问题:Java IDocument.getLineOffset方法的具体用法?Java IDocument.getLineOffset怎么用?Java IDocument.getLineOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.IDocument
的用法示例。
在下文中一共展示了IDocument.getLineOffset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPartitionsLinesByType
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
public static HashMap<String, Integer> getPartitionsLinesByType(IDocument document,
String partitionType) {
HashMap<String, Integer> lines = new HashMap<String, Integer>();
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
final int offset = document.getLineOffset(lineNumber);
if (document.getPartition(offset).getType().equals(partitionType)) {
lines.put(line, lineNumber);
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return lines;
}
示例2: getPartitionsInfoByType
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
public static HashMap<String, IRegion> getPartitionsInfoByType(IDocument document,
String partitionType) {
HashMap<String, IRegion> lines = new HashMap<String, IRegion>();
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
final int offset = document.getLineOffset(lineNumber);
if (document.getPartition(offset).getType().equals(partitionType)) {
lines.put(line, document.getLineInformation(lineNumber));
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return lines;
}
示例3: getLineInformationOfRegion
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
/**
* Similar to {@link IDocument#getLineInformationOfOffset(int)}, but the client can provide a text region instead of
* only an offset. If the given region spans multiple lines, all affected lines will be returned, i.e. entire line
* containing beginning of region, all lines contained in the region, and entire line containing the end of the
* region.
*/
public static IRegion getLineInformationOfRegion(IDocument doc, int offset, int length,
boolean includeLineDelimiterOfLastLine) throws BadLocationException {
// get the line containing the beginning of the given text region
final int firstLineNo = doc.getLineOfOffset(offset);
// get the line containing the end of the given text region
// (may be the same line if removal does not span multiple lines)
final int lastLineNo = doc.getLineOfOffset(offset + length);
// compute result
final int startOffset = doc.getLineOffset(firstLineNo);
final int endOffset = doc.getLineOffset(lastLineNo) + (includeLineDelimiterOfLastLine ?
doc.getLineLength(lastLineNo) // includes line delimiters!
: doc.getLineInformation(lastLineNo).getLength()); // does *not* include line delimiters!
return new Region(
startOffset,
endOffset - startOffset);
}
示例4: getOffsetAtLine
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
@Override
protected int getOffsetAtLine(int lineIndex) {
IDocument document = getTextViewer().getDocument();
try {
int lo = document.getLineOffset(lineIndex);
int ll = document.getLineLength(lineIndex);
String line = document.get(lo, ll);
return super.getOffsetAtLine(lineIndex) + getLeadingSpaces(line);
} catch (BadLocationException e) {
return -1;
}
}
示例5: toRange
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
public static Range toRange(IOpenable openable, int offset, int length) throws JavaModelException {
if (offset > 0 || length > 0) {
int[] loc = null;
int[] endLoc = null;
IBuffer buffer = openable.getBuffer();
// if (buffer != null) {
// loc = JsonRpcHelpers.toLine(buffer, offset);
// endLoc = JsonRpcHelpers.toLine(buffer, offset + length);
// }
// if (loc == null) {
// loc = new int[2];
// }
// if (endLoc == null) {
// endLoc = new int[2];
// }
// setPosition(range.getStart(), loc);
// setPosition(range.getEnd(), endLoc);
IDocument document = toDocument(buffer);
try {
int line = document.getLineOfOffset(offset);
int column = offset - document.getLineOffset(line);
return new Range(line + 1, column + 1);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// TODO Auto-generated method stub
return null;
}
示例6: getLineText
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private static String getLineText(IDocument document, int line, boolean withLineDelimiter) {
try {
int lo = document.getLineOffset(line);
int ll = document.getLineLength(line);
if (!withLineDelimiter) {
String delim = document.getLineDelimiter(line);
ll = ll - (delim != null ? delim.length() : 0);
}
return document.get(lo, ll);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例7: getAllSnippetsAnnotations
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
IDocument document = getDocument();
int curOffset = 0;
FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
try {
IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
while (startRegion != null && startRegion.getOffset() >= curOffset) {
int startLine = document.getLineOfOffset(startRegion.getOffset());
int startOffset = document.getLineOffset(startLine);
curOffset = startOffset + document.getLineLength(startLine);
IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false); //$NON-NLS-1$
if (endRegion != null) {
int endLine = document.getLineOfOffset(endRegion.getOffset());
int endOffset = document.getLineOffset(endLine);
endOffset += document.getLineLength(endLine);
curOffset = endOffset;
String text = document.get(startOffset, endOffset - startOffset);
ProjectionAnnotation annotation = new ProjectionAnnotation(true);
annotation.setText(text);
annotation.setRangeIndication(true);
annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
}
if (curOffset < document.getLength()) {
startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
}
}
} catch (BadLocationException e) {
}
return annotations;
}
示例8: getPartitionsByType
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
public static List<String> getPartitionsByType(IDocument document, String partitionType) {
List<String> lines = new ArrayList<String>();
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
final int offset = document.getLineOffset(lineNumber);
if (document.getPartition(offset).getType().equals(partitionType)) {
lines.add(line);
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return lines;
}
示例9: createJimpleBreakpoint
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private void createJimpleBreakpoint() throws CoreException, BadLocationException {
IDocument document = getDocument();
IFile file = getFile();
int lineNumber = getLineNumber();
int offset = document.getLineOffset(lineNumber - 1);
int length = document.getLineInformation(lineNumber - 1).getLength();
int charStart = offset;
int charEnd = offset + length;
try {
String unitFqn = getUnitFqn(lineNumber - 1, offset, length);
IMarker m = file.createMarker(JIMPLE_BREAKPOINT_MARKER);
m.setAttribute(IMarker.LINE_NUMBER, getLineNumber());
m.setAttribute(IMarker.MESSAGE, "Unit breakpoint: " + file.getName() + " [Line "+getLineNumber()+"]");
m.setAttribute("Jimple.file", file.getProjectRelativePath().toPortableString());
m.setAttribute("Jimple.project", file.getProject().getName());
m.setAttribute("Jimple.unit.charStart", charStart);
m.setAttribute("Jimple.unit.charEnd", charEnd);
m.setAttribute("Jimple.unit.fqn", unitFqn);
JimpleBreakpointManager.getInstance().createBreakpoint(m);
} catch(UnitNotFoundException e) {
String msg = "The selected unit couldn't be found in our Jimple model. This might be a problem related to Jimple optimizations.";
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Breakpoint could not be placed", msg);
}
}
示例10: findElementsAtSelection
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
public static IJavaElement[] findElementsAtSelection(ITypeRoot unit, int line, int column)
throws JavaModelException, BadLocationException {
if (unit == null) {
return null;
}
int offset = toDocument(unit.getBuffer()).getLineOffset(line) + column;
if (offset > -1) {
return unit.codeSelect(offset, 0);
}
if (unit instanceof IClassFile) {
IClassFile classFile = (IClassFile) unit;
String contents = disassemble(classFile);
if (contents != null) {
IDocument document = new Document(contents);
try {
offset = document.getLineOffset(line) + column;
if (offset > -1) {
String name = parse(contents, offset);
if (name == null) {
return null;
}
SearchPattern pattern = SearchPattern.createPattern(name, IJavaSearchConstants.TYPE,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH);
IJavaSearchScope scope = createSearchScope(unit.getJavaProject());
List<IJavaElement> elements = new ArrayList<>();
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
if (match.getElement() instanceof IJavaElement) {
elements.add((IJavaElement) match.getElement());
}
}
};
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern,
new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, null);
return elements.toArray(new IJavaElement[0]);
}
} catch (BadLocationException | CoreException e) {
// JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
}
return null;
}
示例11: hasSnippetsModifications
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private boolean hasSnippetsModifications() {
IDocument document = getDocument();
if (document == null) {
return false;
}
int curNbAnnotations = oldAnnotations.size();
int actualNbAnnotations = 0;
int curOffset = 0;
FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
try {
IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
while (startRegion != null && startRegion.getOffset() >= curOffset) {
int startLine = document.getLineOfOffset(startRegion.getOffset());
int startOffset = document.getLineOffset(startLine);
curOffset = startOffset + document.getLineLength(startLine);
IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false); //$NON-NLS-1$
if (endRegion != null) {
actualNbAnnotations++;
int endLine = document.getLineOfOffset(endRegion.getOffset());
int endOffset = document.getLineOffset(endLine);
endOffset += document.getLineLength(endLine);
curOffset = endOffset;
boolean contains = false;
String text = document.get(startOffset, endOffset - startOffset);
for (ProjectionAnnotation annotation : oldAnnotations.keySet()) {
Position pos = oldAnnotations.get(annotation);
if (annotation.getText().equals(text) && (startOffset == pos.getOffset())) {
contains = true;
}
}
if (!contains) {
return true;
}
}
if (curOffset < document.getLength()) {
startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
}
}
} catch (BadLocationException e) {
}
if (curNbAnnotations != actualNbAnnotations) {
return true;
}
return false;
}