本文整理汇总了Java中org.eclipse.xtext.util.ITextRegion.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java ITextRegion.getLength方法的具体用法?Java ITextRegion.getLength怎么用?Java ITextRegion.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.util.ITextRegion
的用法示例。
在下文中一共展示了ITextRegion.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLocationData
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
private static ILocationData createLocationData(ITraceURIConverter converter, ILocationInFileProvider locationProvider, EObject object, ILocationInFileProviderExtension.RegionDescription query, boolean skipEmpty) {
ITextRegion textRegion = locationProvider instanceof ILocationInFileProviderExtension ?
((ILocationInFileProviderExtension) locationProvider).getTextRegion(object, query) : locationProvider.getFullTextRegion(object);
if (!(textRegion instanceof ITextRegionWithLineInformation)) {
if (log.isDebugEnabled())
log.debug("location provider returned text region without line information.", new Exception());
if (textRegion != null)
textRegion = new TextRegionWithLineInformation(textRegion.getOffset(), textRegion.getLength(), 0, 0);
else
return null;
}
// usually we want to skip empty regions but if the root region is empty, we want to use it to store the path information along
// with the empty offset / length pair
if (skipEmpty && textRegion == ITextRegion.EMPTY_REGION) {
return null;
}
ILocationData newData = createLocationData(converter, object, (ITextRegionWithLineInformation) textRegion);
return newData;
}
示例2: toTextRegionWithLineInformation
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
protected ITextRegionWithLineInformation toTextRegionWithLineInformation(final EObject obj, final ITextRegion textRegion) {
if ((textRegion == null)) {
return ITextRegionWithLineInformation.EMPTY_REGION;
}
if ((textRegion instanceof ITextRegionWithLineInformation)) {
return ((ITextRegionWithLineInformation)textRegion);
}
final ICompositeNode node = NodeModelUtils.getNode(obj);
if ((node == null)) {
int _offset = textRegion.getOffset();
int _length = textRegion.getLength();
return new TextRegionWithLineInformation(_offset, _length, 0, 0);
}
int _line = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset()).getLine();
final int startLine = (_line - 1);
int _offset_1 = textRegion.getOffset();
int _length_1 = textRegion.getLength();
int _plus = (_offset_1 + _length_1);
int _line_1 = NodeModelUtils.getLineAndColumn(node, _plus).getLine();
final int endLine = (_line_1 - 1);
int _offset_2 = textRegion.getOffset();
int _length_2 = textRegion.getLength();
return new TextRegionWithLineInformation(_offset_2, _length_2, startLine, endLine);
}
示例3: getCrossReferenceNode
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
/**
* @since 2.1
*/
public INode getCrossReferenceNode(XtextResource resource, ITextRegion region) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset());
INode crossRefNode = findCrossReferenceNode(leaf);
// if not a cross reference position and the cursor is at the beginning of a node try the previous one.
if (crossRefNode == null && leaf != null && region.getLength()==0 && leaf.getOffset() == region.getOffset()) {
leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset() - 1);
return findCrossReferenceNode(leaf);
} else if (crossRefNode != null && crossRefNode.getEndOffset() >= region.getOffset() + region.getLength()) {
return crossRefNode;
}
}
return null;
}
示例4: isModified
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
@Override
public boolean isModified(ITextRegion region) {
int offset = region.getOffset();
int endOffset = offset + region.getLength();
for (RewriteAction action : rewrites) {
int rwOffset = action.originalFirst.getOffset();
int rwEndOffset = action.originalLast.getEndOffset();
if (rwOffset <= offset && offset < rwEndOffset) {
return true;
}
if (rwOffset < endOffset && endOffset <= rwEndOffset) {
return true;
}
}
return false;
}
示例5: format
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
@Override
public IFormattedRegion format(final ICompositeNode root, final int offset, final int length) {
final TokenStringBuffer buf = new TokenStringBuffer();
final ITokenStream out = offset == 0 ? buf : new FilterStream(buf);
final ITokenStream formatStream = formatter.createFormatterStream(null, out, false);
if (!(formatStream instanceof IDelegatingTokenStream)) {
return super.format(root, offset, length);
}
try {
ITextRegion range;
if (offset > 0) {
int noffset = root.getText().lastIndexOf('\n', offset) + 1; // Keep the new line
int nlength = length + (offset - noffset); // Always start in the beginning of the line
range = nodeModelStreamer.feedTokenStream(formatStream, root, noffset, nlength);
} else {
range = nodeModelStreamer.feedTokenStream(formatStream, root, offset, length);
}
return new FormattedRegion(range.getOffset(), range.getLength(), buf.toString());
} catch (IOException e) {
// this should never happen since TokenStringBuffer doesn't throw IOEs.
throw new RuntimeException(e); // NOPMD
}
}
示例6: format
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
@Override
public IFormattedRegion format(ICompositeNode root, int offset, int length) {
String indent = getIndentation(root, offset);
TokenStringBuffer buf = new TokenStringBuffer();
ITokenStream out = offset == 0 ? buf : new FilterFirstWhitespaceStream(buf);
ITokenStream fmt;
if (formatter instanceof IFormatterExtension) {
EObject semanticElement = NodeModelUtils.findActualSemanticObjectFor(root);
if (semanticElement != null)
fmt = ((IFormatterExtension) formatter).createFormatterStream(semanticElement, indent, out, false);
else {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=380406
ITextRegion rootRegion = root.getTextRegion();
return new FormattedRegion(rootRegion.getOffset(), rootRegion.getLength(), root.getText());
}
} else
fmt = formatter.createFormatterStream(indent, out, false);
try {
ITextRegion range = nodeModelStreamer.feedTokenStream(fmt, root, offset, length);
return new FormattedRegion(range.getOffset(), range.getLength(), buf.toString());
} catch (IOException e) {
// this should never happen since TokenStringBuffer doesn't throw IOEs.
throw new RuntimeException(e);
}
}
示例7: isDocumentHighlightAvailableFor
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
/**
* Returns with {@code true} if the AST element selected from the resource
* can provide document highlights, otherwise returns with {@code false}.
*
* <p>
* Clients may override this method to change the default behavior.
*
* @param selectedElemnt
* the selected element resolved via the offset from the
* resource. Can be {@code null}.
* @param resource
* the resource for the document.
* @param offset
* the offset of the selection.
*
* @return {@code true} if the document highlight is available for the
* selected element, otherwise {@code false}.
*
*/
protected boolean isDocumentHighlightAvailableFor(final EObject selectedElemnt, final XtextResource resource,
final int offset) {
if (selectedElemnt == null || !getSelectedElementFilter().apply(selectedElemnt)) {
return false;
}
final EObject containedElement = offsetHelper.resolveContainedElementAt(resource, offset);
// Special handling to avoid such cases when the selection is not
// exactly on the desired element.
if (selectedElemnt == containedElement) {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(containedElement);
return !isNullOrEmpty(region)
// Region is comparable to a selection in an editor,
// therefore the end position is exclusive.
&& (region.contains(offset) || (region.getOffset() + region.getLength()) == offset);
}
return true;
}
示例8: trace
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
@Override
public ITreeAppendable trace(EObject object, EStructuralFeature feature, int indexInList) {
ITextRegion textRegion = locationProvider.getFullTextRegion(object, feature, indexInList);
if (!(textRegion instanceof ITextRegionWithLineInformation)) {
if (log.isDebugEnabled())
log.debug("location provider returned text region without line information. Synthesized dummy data.", new Exception());
textRegion = new TextRegionWithLineInformation(textRegion.getOffset(), textRegion.getLength(), 0, 0);
}
if (textRegion == ITextRegion.EMPTY_REGION) {
return this;
}
ILocationData newData = createLocationData(traceURIConverter, object, (ITextRegionWithLineInformation) textRegion);
return trace(Collections.singleton(newData), false);
}
示例9: addLeadingWhitespace
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
public ITextRegion addLeadingWhitespace(ITextRegion textRegion, XtextResource resource) {
String text = resource.getParseResult().getRootNode().getText();
int offset = textRegion.getOffset();
int length = textRegion.getLength();
while(offset > 0 && Character.isWhitespace(text.charAt(offset-1)) ){
--offset;
++length;
}
return new TextRegion(offset, length);
}
示例10: addTrailingWhitespace
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
public ITextRegion addTrailingWhitespace(ITextRegion textRegion, XtextResource resource) {
String text = resource.getParseResult().getRootNode().getText();
int offset = textRegion.getOffset();
int length = textRegion.getLength();
while(offset + length < text.length() && Character.isWhitespace(text.charAt(offset+length))) {
++length;
}
return new TextRegion(offset, length);
}
示例11: addTrailingSingleWhitespace
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
public ITextRegion addTrailingSingleWhitespace(ITextRegion textRegion, String lineSeparator, XtextResource resource) {
String text = resource.getParseResult().getRootNode().getText();
String theFollowing = text.substring(textRegion.getOffset() + textRegion.getLength());
if(!isEmpty(theFollowing)) {
if(theFollowing.startsWith(lineSeparator))
return new TextRegion(textRegion.getOffset(), textRegion.getLength() + lineSeparator.length());
else if(Character.isWhitespace(theFollowing.charAt(0)))
return new TextRegion(textRegion.getOffset(), textRegion.getLength() + 1);
}
return textRegion;
}
示例12: findActualSemanticObjectFor
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
public EObject findActualSemanticObjectFor(final ICompositeNode rootNode, final ITextRegion textRegion) {
ILeafNode leafNodeAtOffset = NodeModelUtils.findLeafNodeAtOffset(rootNode, textRegion.getOffset());
EObject semanticElementOffset = leafNodeAtOffset.getSemanticElement();
ICompositeNode actualOffsetNode = NodeModelUtils.findActualNodeFor(semanticElementOffset);
int _offset = textRegion.getOffset();
int _length = textRegion.getLength();
final int endOffset = (_offset + _length);
while (((actualOffsetNode.getParent() != null) && (actualOffsetNode.getTotalEndOffset() < endOffset))) {
actualOffsetNode = actualOffsetNode.getParent();
}
final EObject actualSemanticObj = actualOffsetNode.getSemanticElement();
return actualSemanticObj;
}
示例13: addImportDeclaration
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
protected boolean addImportDeclaration(final ContentAssistEntry entry, final ITextRegion importSectionRegion, final ITypeDescriptor typeDesc, final String qualifiedName, final ContentAssistContext context) {
boolean _xblockexpression = false;
{
int _offset = importSectionRegion.getOffset();
int _length = importSectionRegion.getLength();
final int insertionOffset = (_offset + _length);
final String declaration = ("\nimport " + qualifiedName);
ArrayList<ReplaceRegion> _textReplacements = entry.getTextReplacements();
ReplaceRegion _replaceRegion = new ReplaceRegion(insertionOffset, 0, declaration);
_xblockexpression = _textReplacements.add(_replaceRegion);
}
return _xblockexpression;
}
示例14: getBestAssociatedLocation
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
@Override
public ILocationInResource getBestAssociatedLocation(ITextRegion region) {
AbstractTraceRegion right = findTraceRegionAtRightOffset(region.getOffset() + region.getLength());
if (right != null && encloses(right, region.getOffset(), true)) {
if (right.getMyOffset() + right.getMyLength() == region.getOffset() + region.getLength())
return getMergedLocationInResource(right);
}
AbstractTraceRegion left = findTraceRegionAtLeftOffset(region.getOffset());
return mergeRegions(left, right);
}
示例15: getTokenReplaceRegion
import org.eclipse.xtext.util.ITextRegion; //导入方法依赖的package包/类
public ReplaceRegion getTokenReplaceRegion(String changedText, ReplaceRegion replaceRegion) {
int lengthDelta = replaceRegion.getText().length() - replaceRegion.getLength();
ITextRegion tokenRegion = getTokenRegion(changedText, new TextRegion(replaceRegion.getOffset(), replaceRegion
.getText().length()));
if (tokenRegion.getOffset() == replaceRegion.getOffset()
&& tokenRegion.getLength() == replaceRegion.getText().length())
return replaceRegion;
else
return new ReplaceRegion(tokenRegion.getOffset(), tokenRegion.getLength() - lengthDelta,
changedText.substring(tokenRegion.getOffset(), tokenRegion.getOffset() + tokenRegion.getLength()));
}