本文整理汇总了Java中org.eclipse.jface.text.IRegion.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java IRegion.getOffset方法的具体用法?Java IRegion.getOffset怎么用?Java IRegion.getOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.IRegion
的用法示例。
在下文中一共展示了IRegion.getOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertLineAbove
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
/**
* Insert the given string as a new line above the line at the given offset. The given string need not contain any
* line delimiters and the offset need not point to the beginning of a line. If 'sameIndentation' is set to
* <code>true</code>, the new line will be indented as the line at the given offset (i.e. same leading white space).
*/
public static IChange insertLineAbove(IXtextDocument doc, int offset, String txt, boolean sameIndentation)
throws BadLocationException {
final String NL = lineDelimiter(doc, offset);
final IRegion currLineReg = doc.getLineInformationOfOffset(offset);
String indent = "";
if (sameIndentation) {
final String currLine = doc.get(currLineReg.getOffset(), currLineReg.getLength());
int idx = 0;
while (idx < currLine.length() && Character.isWhitespace(currLine.charAt(idx))) {
idx++;
}
indent = currLine.substring(0, idx);
}
return new Replacement(getURI(doc), currLineReg.getOffset(), 0, indent + txt + NL);
}
示例2: removeText
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
/**
* Removes text of the given length at the given offset. If 'removeEntireLineIfEmpty' is set to <code>true</code>,
* the line containing the given text region will be deleted entirely iff the change would leave the line empty
* (i.e. contains only white space) <em>after</em> the removal of the text region.
*/
public static IChange removeText(IXtextDocument doc, int offset, int length, boolean removeEntireLineIfEmpty)
throws BadLocationException {
if (!removeEntireLineIfEmpty) {
// simple
return new Replacement(getURI(doc), offset, length, "");
} else {
// get entire line containing the region to be removed
// OR in case the region spans multiple lines: get *all* lines affected by the removal
final IRegion linesRegion = DocumentUtilN4.getLineInformationOfRegion(doc, offset, length, true);
final String lines = doc.get(linesRegion.getOffset(), linesRegion.getLength());
// simulate the removal
final int offsetRelative = offset - linesRegion.getOffset();
final String lineAfterRemoval = removeSubstring(lines, offsetRelative, length);
final boolean isEmptyAfterRemoval = lineAfterRemoval.trim().isEmpty();
if (isEmptyAfterRemoval) {
// remove entire line (or in case the removal spans multiple lines: remove all affected lines entirely)
return new Replacement(getURI(doc),
linesRegion.getOffset(), linesRegion.getLength(), "");
} else {
// just remove the given text region
return new Replacement(getURI(doc), offset, length, "");
}
}
}
示例3: endOfLineOf
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
/**
* Returns the end offset of the line that contains the specified offset or
* if the offset is inside a line delimiter, the end offset of the next
* line.
*
* @param offset
* the offset whose line end offset must be computed
* @return the line end offset for the given offset
* @exception BadLocationException
* if offset is invalid in the current document
*/
protected int endOfLineOf(int offset) throws BadLocationException {
IRegion info = fDocument.getLineInformationOfOffset(offset);
if (offset <= info.getOffset() + info.getLength()){
return info.getOffset() + info.getLength();
}
int line = fDocument.getLineOfOffset(offset);
try {
info = fDocument.getLineInformation(line + 1);
return info.getOffset() + info.getLength();
} catch (BadLocationException x) {
return fDocument.getLength();
}
}
示例4: getDamageRegion
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
@Override
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
try {
IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
int start = Math.max(partition.getOffset(), info.getOffset());
int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());
if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
// optimize the case of the same line
end = info.getOffset() + info.getLength();
} else{
end = endOfLineOf(end);
}
end = Math.min(partition.getOffset() + partition.getLength(), end);
return new Region(start, end - start);
} catch (BadLocationException x) {
}
}
return partition;
}
示例5: validateInsertFinalNewline
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
/**
* Validate 'insert_final_newline' if needed and update the given set of marker.
*
* @param document
* the document to validate
* @param remainingMarkers
* set of markers to update.
* @throws BadLocationException
*/
private void validateInsertFinalNewline(IDocument document, Set<IMarker> remainingMarkers)
throws BadLocationException {
boolean insertFinalNewline = preferenceStore.getBoolean(EDITOR_INSERT_FINAL_NEWLINE);
if (!insertFinalNewline) {
return;
}
// Check if there are an empty line at the end of the document.
if (document.getLength() == 0) {
return;
}
int line = document.getNumberOfLines() - 1;
IRegion region = document.getLineInformation(line);
if (region.getLength() > 0) {
int end = region.getOffset() + region.getLength();
int start = end - 1;
addOrUpdateMarker(start, end, insertFinalNewlineType, document, remainingMarkers);
}
}
示例6: detectHyperlinks
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
boolean canShowMultipleHyperlinks) {
SQLEditor editor = getAdapter(SQLEditor.class);
PgDbParser parser = editor.getParser();
int offset = region.getOffset();
List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput());
for (PgObjLocation obj : refs) {
if (offset > obj.getOffset()
&& offset < (obj.getOffset() + obj.getObjLength())) {
IHyperlink[] links = parser.getDefinitionsForObj(obj)
.map(def -> new SQLEditorHyperLink(
new Region(def.getOffset(), def.getObjLength()),
new Region(obj.getOffset(), obj.getObjLength()),
obj.getObjName(), def.getFilePath(), def.getLineNumber()))
.toArray(IHyperlink[]::new);
if (links.length != 0) {
return links;
}
}
}
return null;
}
示例7: setCommentFields
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
/**
* Sets beginCommentOffset, endCommentOffset, indent, and margin
*
* @throws org.eclipse.jface.text.BadLocationException
*/
private void setCommentFields()
throws org.eclipse.jface.text.BadLocationException {
// Following code modified by LL on 13 Apr 2011 so that it
// finds the correct beginning and end of the comment if
// if the cursor is at right after the "(" or right before
// the ")" that bracket the comment.
int searchOffset = offset;
if ((offset > 0) && text.charAt(offset - 1) == '(') {
searchOffset++;
}
beginCommentOffset = text.lastIndexOf("(*", searchOffset);
searchOffset = offset;
if (text.charAt(offset) == ')') {
searchOffset--;
}
endCommentOffset = text.indexOf("*)", searchOffset) + 2;
IRegion beginCommentLineInfo = doc
.getLineInformationOfOffset(beginCommentOffset);
indent = beginCommentOffset - beginCommentLineInfo.getOffset();
margin = Math.max(RightMargin, indent + 4);
}
示例8: getFirstCompleteLineOfRegion
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
private int getFirstCompleteLineOfRegion(IRegion region, IDocument document) {
try {
final int startLine = document.getLineOfOffset(region.getOffset());
int offset = document.getLineOffset(startLine);
if (offset >= region.getOffset()) {
return startLine;
}
final int nextLine = startLine + 1;
if (nextLine == document.getNumberOfLines()) {
return -1;
}
offset = document.getLineOffset(nextLine);
return (offset > region.getOffset() + region.getLength() ? -1 : nextLine);
} catch (BadLocationException x) {
// should not happen
}
return -1;
}
示例9: getRegionWithPreviousLine
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
/**
* Returns a new region that ends at the end of the input region and begins
* at the first character of the line before the line containing the offset
* of the input region. If the input region's offset is on the first
* line of the document, this method does nothing.
*
* @param document
* @param region
* @return
* @throws BadLocationException
*/
public static IRegion getRegionWithPreviousLine(IDocument document, IRegion region) throws BadLocationException
{
// the first line of the region
int currentFirstLine = document.getLineOfOffset(region.getOffset());
if (currentFirstLine > 0)
{
int newOffset = document.getLineOffset(currentFirstLine - 1);
return new Region(newOffset, region.getLength() + (region.getOffset() - newOffset));
} else
{
// no previous line so do nothing
return region;
}
}
示例10: detectHyperlinks
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
boolean canShowMultipleHyperlinks) {
int offset = region.getOffset();
int length = region.getLength();
if (offset == 0 && length == 0)
return null;
if (MarkerActivator.getEditor() == null || MarkerActivator.getEditor().getEditorInput() == null)
return null;
IFile file = (IFile) MarkerActivator.getEditor().getEditorInput().getAdapter(IFile.class);
List<IMarker> markedList = MarkerFactory.findMarkers(file);
for (IMarker iMarker : markedList) {
// look for keyword
// detect region containing keyword
IRegion targetRegion = new Region(MarkUtilities.getStart(iMarker),
MarkUtilities.getLength(iMarker));
if ((targetRegion.getOffset() <= offset)
&& ((targetRegion.getOffset() + targetRegion.getLength()) > offset)) {
// create link
return new IHyperlink[] {new MarkerMappingActionHyperlink(targetRegion)};
}
}
return null;
}
示例11: getHoverInfo
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
BashEditorPreferences preferences = BashEditorPreferences.getInstance();
boolean tooltipsEnabled = preferences.getBooleanPreference(P_TOOLTIPS_ENABLED);
if (!tooltipsEnabled){
return null;
}
IDocument document = textViewer.getDocument();
if (document == null) {
return "";
}
String text = document.get();
if (text == null) {
return "";
}
int offset = hoverRegion.getOffset();
String word = SimpleStringUtils.nextWordUntilWhitespace(text, offset);
if (word.isEmpty()) {
return "";
}
for (DocumentKeyWord keyword : DocumentKeyWords.getAll()) {
if (word.equals(keyword.getText())) {
return buildHoverInfo(keyword);
}
}
return "";
}
示例12: getAllSnippetsAnnotations
import org.eclipse.jface.text.IRegion; //导入方法依赖的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;
}
示例13: addNewAnnotation
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
private void addNewAnnotation(final String errored, final int line,
final IRegion lineInformationOfOffset) {
final int offset = lineInformationOfOffset.getOffset();
final int length = lineInformationOfOffset.getLength();
final String message = errored + " cannot be resolved as a relation";
final Annotation annotation = new Annotation(this.MME_REASON_ANNOT_TYPE, true, message);
this.annotationModel.connect(this.document);
this.annotationModel.addAnnotation(annotation, new Position(offset, length));
this.annotationModel.disconnect(this.document);
}
示例14: getMethodOffset
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
/**
* This method returns the offset of the method passed to it.
* @param document The document user is interacting with.
* @param method The method whose offset is required.
* @return The offset of the method.
*/
private Integer getMethodOffset(IDocument document, VFMethod method) {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(document);
try {
IRegion region = findReplaceDocumentAdapter.find(0, FindReplaceDocumentAdapter.escapeForRegExPattern(method.getSootMethod().getDeclaration()), true,
true, false, true);
return region.getOffset();
} catch (BadLocationException e) {
e.printStackTrace();
}
return 0;
}
示例15: detectHyperlinks
import org.eclipse.jface.text.IRegion; //导入方法依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
IDocument document = textViewer.getDocument();
/* Extrait le mot courant. */
ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.CONSTANT_CASE);
if (currentWordSelection == null) {
return null; // NOSONAR
}
String currentWord = currentWordSelection.getText();
if (currentWord == null) {
return null; // NOSONAR
}
IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
FileRegion fileRegion = new FileRegion(UiUtils.getCurrentEditorFile(), targetRegion.getOffset(), targetRegion.getLength());
/* Cherche un nom de DTO. */
IHyperlink[] hyperlinks = detectDtDefinitionName(currentWord, targetRegion, fileRegion);
if (hyperlinks != null) {
return hyperlinks;
}
/* Cherche un nom de Task. */
hyperlinks = detectTaskName(currentWord, targetRegion);
if (hyperlinks != null) {
return hyperlinks;
}
/* Cherche une déclaration KSP autre. */
return detectKspName(currentWord, targetRegion, fileRegion);
}