本文整理匯總了Java中org.eclipse.jface.text.Position.getOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java Position.getOffset方法的具體用法?Java Position.getOffset怎麽用?Java Position.getOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.Position
的用法示例。
在下文中一共展示了Position.getOffset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: removeOldAnnotation
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
private void removeOldAnnotation(final int offset) {
this.annotationModel.connect(this.document);
final Iterator<Annotation> iter = this.annotationModel.getAnnotationIterator();
Annotation beRemoved = null;
while (iter.hasNext()) {
beRemoved = iter.next();
if (!beRemoved.getType().equals(this.MME_REASON_ANNOT_TYPE)) {
continue;
}
final Position position = this.annotationModel.getPosition(beRemoved);
if (position.getOffset() + position.getLength() == offset || position.includes(offset)) {
this.annotationModel.removeAnnotation(beRemoved);
}
}
this.annotationModel.disconnect(this.document);
}
示例2: getMarkerPosition
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* Returns the actual position of <i>marker</i> or null if the marker was
* deleted. Code inspired by
* @param marker
* @param sourceViewer
* @return
*/
private static int[] getMarkerPosition(IMarker marker, ISourceViewer sourceViewer) {
int[] p = new int[2];
p[0] = marker.getAttribute(IMarker.CHAR_START, -1);
p[1] = marker.getAttribute(IMarker.CHAR_END, -1);
// look up the current range of the marker when the document has been edited
IAnnotationModel model= sourceViewer.getAnnotationModel();
if (model instanceof AbstractMarkerAnnotationModel) {
AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model;
Position pos= markerModel.getMarkerPosition(marker);
if (pos != null && !pos.isDeleted()) {
// use position instead of marker values
p[0] = pos.getOffset();
p[1] = pos.getOffset() + pos.getLength();
}
if (pos != null && pos.isDeleted()) {
// do nothing if position has been deleted
return null;
}
}
return p;
}
示例3: findMatch
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* Finds a match for <code>tuple</code> in a collection of annotations. The positions for the
* <code>MkProjectionAnnotation</code> instances in <code>annotations</code> can be found in the
* passed <code>positionMap</code> or in the model if <code>positionMap</code> is
* <code>null</code>.
* <p>
* A tuple is said to match another if their annotations have the same category and their
* position offsets are equal.
* </p>
* <p>
* If a match is found, the annotation gets removed from <code>annotations</code>.
* </p>
*
* @param tuple the tuple for which we want to find a match
* @param annotations collection of <code>MkProjectionAnnotation</code>
* @param positionMap a <code>Map<Annotation, Position></code> or <code>null</code>
* @return a matching tuple or <code>null</code> for no match
*/
private Tuple findMatch(Tuple tuple, Collection<MkProjectionAnnotation> annotations,
Map<MkProjectionAnnotation, Position> positionMap, FoldingStructureComputationContext ctx) {
Iterator<MkProjectionAnnotation> it = annotations.iterator();
while (it.hasNext()) {
MkProjectionAnnotation annotation = it.next();
if (tuple.annotation.getCategory() == annotation.getCategory()) {
Position position = positionMap == null ? ctx.getModel().getPosition(annotation)
: positionMap.get(annotation);
if (position == null) continue;
if (tuple.position.getOffset() == position.getOffset()) {
it.remove();
return new Tuple(annotation, position);
}
}
}
return null;
}
示例4: updateMarker
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
@Override
public boolean updateMarker(IMarker marker, IDocument document, Position position) {
try {
int start = position.getOffset();
int end = position.getOffset() + position.getLength();
marker.setAttribute(IMarker.CHAR_START, start);
marker.setAttribute(IMarker.CHAR_END, end);
} catch (CoreException e) {
Log.log(e);
}
return true;
}
示例5: wasChecked
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* @param p
* @return true, if the Position is inside a region which was checked by
* the spell checker
*/
private boolean wasChecked (Position p) {
for (IRegion r : regions) {
if (p.getOffset() >= r.getOffset() &&
p.getOffset() <= r.getOffset() + r.getLength()) {
return true;
}
}
return false;
}
示例6: contains
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* Checks whether the given offset is contained within this annotation
*
* @param offset The offset inside the document that this annotation belongs to
* @return True if the offset is contained, false otherwise
*/
public boolean contains(int offset) {
Position pos = node.getPosition();
if (offset >= pos.getOffset()
&& offset < (pos.getOffset() + pos.getLength()))
return true;
return false;
}
示例7: isRulerLine
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
private boolean isRulerLine(Position position, IDocument document, int line) {
if (position.getOffset() > -1 && position.getLength() > -1) {
try {
return line == document.getLineOfOffset(position.getOffset());
} catch (BadLocationException x) {
}
}
return false;
}
示例8: createStyleRange
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
private StyleRange createStyleRange(TextAttribute attr, Position position) {
StyleRange result = new StyleRange(position.getOffset(), position.getLength(), attr.getForeground(),
attr.getBackground(), attr.getStyle());
if ((attr.getStyle() & TextAttribute.UNDERLINE) != 0) {
result.underline = true;
result.fontStyle &= ~TextAttribute.UNDERLINE;
}
if ((attr.getStyle() & TextAttribute.STRIKETHROUGH) != 0) {
result.strikeout = true;
result.fontStyle &= ~TextAttribute.STRIKETHROUGH;
}
return result;
}
開發者ID:angelozerr,項目名稱:angular-eclipse,代碼行數:14,代碼來源:HTMLAngularEditorSyntaxColoringPreferencePage.java
示例9: getFirstIndexEndingAfterOffset
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* Returns the index of the first position which ends after the given offset.
*
* @param positions the positions in linear order
* @param offset the offset
* @return the index of the first position which ends after the offset
*/
private int getFirstIndexEndingAfterOffset(Position[] positions, int offset) {
int i= -1, j= positions.length;
while (j - i > 1) {
int k= (i + j) >> 1;
Position p= positions[k];
if (p.getOffset() + p.getLength() > offset)
j= k;
else
i= k;
}
return j;
}
示例10: getFirstIndexStartingAfterOffset
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* Returns the index of the first position which starts at or after the given offset.
*
* @param positions the positions in linear order
* @param offset the offset
* @return the index of the first position which starts after the offset
*/
private int getFirstIndexStartingAfterOffset(Position[] positions, int offset) {
int i= -1, j= positions.length;
while (j - i > 1) {
int k= (i + j) >> 1;
Position p= positions[k];
if (p.getOffset() >= offset)
j= k;
else
i= k;
}
return j;
}
示例11: doApply
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* Really do apply the proposal. Assumed to be run within the prevent flickering mode.
*/
private int doApply(QualifiedName qualifiedName, String alias, IDocument document,
ConfigurableCompletionProposal proposal) throws BadLocationException {
String shortSemanticReplacementString = alias != null ? alias : lastSegmentOrDefaultHost(qualifiedName);
String shortSyntacticReplacementString = valueConverter.toString(shortSemanticReplacementString);
ImportRewriter importRewriter = importRewriterFactory.create(document, context);
ReplaceEdit replaceEdit = new ReplaceEdit(
proposal.getReplacementOffset(),
proposal.getReplacementLength(),
shortSyntacticReplacementString);
MultiTextEdit compound = new MultiTextEdit();
AliasLocation aliasLocation = null;
if (alias != null) {
aliasLocation = importRewriter.addSingleImport(qualifiedName, alias, compound);
} else {
importRewriter.addSingleImport(qualifiedName, compound);
}
compound.addChild(replaceEdit);
Position caret = new Position(proposal.getReplacementOffset(), 0);
document.addPosition(caret);
compound.apply(document);
document.removePosition(caret);
int cursorPosition = caret.getOffset();
proposal.setReplacementOffset(cursorPosition - shortSemanticReplacementString.length());
proposal.setCursorPosition(shortSemanticReplacementString.length());
if (aliasLocation != null) {
final int aliasOffset = aliasLocation.getBaseOffset() + aliasLocation.getRelativeOffset();
final int aliasLength = shortSyntacticReplacementString.length();
N4JSCompletionProposal castedProposal = (N4JSCompletionProposal) proposal;
castedProposal.setLinkedModeBuilder((appliedProposal, currentDocument) -> {
try {
LinkedPositionGroup group = new LinkedPositionGroup();
group.addPosition(new LinkedPosition(
currentDocument,
aliasOffset,
aliasLength,
LinkedPositionGroup.NO_STOP));
group.addPosition(new LinkedPosition(
currentDocument,
proposal.getReplacementOffset(),
proposal.getCursorPosition(),
LinkedPositionGroup.NO_STOP));
proposal.setSelectionStart(proposal.getReplacementOffset());
proposal.setSelectionLength(proposal.getCursorPosition());
LinkedModeModel model = new LinkedModeModel();
model.addGroup(group);
model.forceInstall();
LinkedModeUI ui = new LinkedModeUI(model, viewer);
ui.setExitPolicy(new IdentifierExitPolicy('\n'));
ui.setExitPosition(
viewer,
proposal.getCursorPosition() + proposal.getReplacementOffset(),
0,
Integer.MAX_VALUE);
ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
ui.enter();
} catch (BadLocationException e) {
logger.error(e.getMessage(), e);
}
});
}
return cursorPosition;
}
示例12: hasSnippetsModifications
import org.eclipse.jface.text.Position; //導入方法依賴的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;
}
示例13: updateMarker
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
@Override
public boolean updateMarker(final IMarker marker, final IDocument doc, final Position position) {
try {
this.markerType = marker.getType();
final int start = position.getOffset();
final int end = position.getOffset() + position.getLength();
if (!MarkUtilities.getText(marker).equals(doc.get(start, position.getLength()))) {
// text of marker is changed
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
final IServiceLocator serviceLocator = PlatformUI.getWorkbench();
final ICommandService commandService = serviceLocator.getService(ICommandService.class);
try {
final Command command =
commandService.getCommand("eu.modelwriter.marker.command.updatechangeandimpact");
command.executeWithChecks(new ExecutionEvent());
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e1) {
e1.printStackTrace();
}
}
});
}
MarkUtilities.setStart(marker, start);
MarkUtilities.setEnd(marker, end);
MarkUtilities.setLinenumber(marker, doc.getLineOfOffset(start));
MarkUtilities.setText(marker, doc.get(start, position.getLength()));
MarkerUpdater.update(marker);
// TODO When the update action completed, you must trigger the Visualization.showViz method
// for refreshing the view.
return true;
} catch (CoreException | BadLocationException e) {
return false;
}
}
示例14: endElement
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
public void endElement(String namespace, String localname, String qName)
throws SAXException {
int lineNumber = locator.getLineNumber();
int endPosition = getOffsetFromLine(lineNumber);
if (dtdElement != null) {
Position position = dtdElement.getPosition();
int length = endPosition - position.getOffset();
position.setLength(length);
dtdElement = dtdElement.getParent();
}
}
示例15: overlapsOrTouches
import org.eclipse.jface.text.Position; //導入方法依賴的package包/類
/**
* Returns <code>true</code> if the given ranges overlap with or touch each other.
*
* @param gap the first range
* @param offset the offset of the second range
* @param length the length of the second range
* @return <code>true</code> if the given ranges overlap with or touch each other
*/
private boolean overlapsOrTouches(Position gap, int offset, int length) {
return gap.getOffset() <= offset + length && offset <= gap.getOffset() + gap.getLength();
}