本文整理汇总了Java中org.eclipse.xtext.util.ITextRegion类的典型用法代码示例。如果您正苦于以下问题:Java ITextRegion类的具体用法?Java ITextRegion怎么用?Java ITextRegion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITextRegion类属于org.eclipse.xtext.util包,在下文中一共展示了ITextRegion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeCommentFolding
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
@Override
protected void computeCommentFolding(IXtextDocument xtextDocument,
IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor, ITypedRegion typedRegion,
boolean initiallyFolded) {
String text;
try {
text = xtextDocument.get(typedRegion.getOffset(), typedRegion.getLength());
int lines = Strings.countLines(text);
if (shouldCreateCommentFolding(lines)) {
boolean collapse = shouldCollapse(typedRegion, lines);
super.computeCommentFolding(xtextDocument, foldingRegionAcceptor, typedRegion, collapse);
}
} catch (BadLocationException e) {
log.error(e, e);
}
}
示例2: checkNoJavaStyleTypeCasting
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
protected void checkNoJavaStyleTypeCasting(INode node) {
BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator();
ILeafNode child = getFirstLeafNode(iterator);
if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) {
INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1());
EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode);
if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) {
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject;
if (featureCall.isTypeLiteral()) {
ICompositeNode parenthesizedNode = child.getParent();
ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion();
addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST);
}
}
}
}
示例3: getSignificantTextRegion
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
@Override
public ITextRegion getSignificantTextRegion(EObject element) {
if (element instanceof XAbstractFeatureCall) {
XAbstractFeatureCall typeLiteral = typeLiteralHelper.getRootTypeLiteral((XAbstractFeatureCall) element);
if (typeLiteral != null) {
if (typeLiteral instanceof XMemberFeatureCall) {
XAbstractFeatureCall target = (XAbstractFeatureCall) ((XMemberFeatureCall) typeLiteral).getMemberCallTarget();
if (target.isTypeLiteral()) {
return super.getSignificantTextRegion(typeLiteral);
}
}
INode node = NodeModelUtils.findActualNodeFor(typeLiteral);
if (node != null) {
return toZeroBasedRegion(node.getTextRegionWithLineInformation());
}
}
}
return super.getSignificantTextRegion(element);
}
示例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: shouldInclude
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
protected boolean shouldInclude(final AbstractTraceRegion region, final ILocationData location) {
SourceRelativeURI _elvis = null;
SourceRelativeURI _srcRelativePath = location.getSrcRelativePath();
if (_srcRelativePath != null) {
_elvis = _srcRelativePath;
} else {
SourceRelativeURI _associatedSrcRelativePath = region.getAssociatedSrcRelativePath();
_elvis = _associatedSrcRelativePath;
}
final ITextRegion frame = this.getRemoteFrame(_elvis);
if ((frame == null)) {
return true;
} else {
return frame.contains(location);
}
}
示例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: traceSignificant
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
public ITreeAppendable traceSignificant(final ITreeAppendable appendable, final EObject source, final boolean useForDebugging) {
ITreeAppendable _xifexpression = null;
if ((appendable instanceof TreeAppendable)) {
_xifexpression = ((TreeAppendable)appendable).trace(source, ILocationInFileProviderExtension.RegionDescription.SIGNIFICANT, useForDebugging);
} else {
ITreeAppendable _xblockexpression = null;
{
ITextRegion _significantTextRegion = this.locationProvider.getSignificantTextRegion(source);
final ITextRegionWithLineInformation it = ((ITextRegionWithLineInformation) _significantTextRegion);
ITreeAppendable _xifexpression_1 = null;
if (((it != null) && (it != ITextRegion.EMPTY_REGION))) {
int _offset = it.getOffset();
int _length = it.getLength();
int _lineNumber = it.getLineNumber();
int _endLineNumber = it.getEndLineNumber();
LocationData _locationData = new LocationData(_offset, _length, _lineNumber, _endLineNumber, null);
_xifexpression_1 = appendable.trace(_locationData, useForDebugging);
} else {
_xifexpression_1 = appendable;
}
_xblockexpression = _xifexpression_1;
}
_xifexpression = _xblockexpression;
}
return _xifexpression;
}
示例8: 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;
}
示例9: getLocationOfContainmentReference
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
/**
* @since 2.3
*/
protected ITextRegion getLocationOfContainmentReference(final EObject owner, EReference feature,
final int indexInList, RegionDescription query) {
Object referencedElement = null;
if(feature.isMany()) {
List<?> values = (List<?>) owner.eGet(feature);
if(indexInList >= values.size())
referencedElement = owner;
else
referencedElement = values.get(indexInList);
}
else {
referencedElement = owner.eGet(feature);
}
return getTextRegion((EObject) referencedElement, query);
}
示例10: testTokenRegionContainsRegion
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
@Test
public void testTokenRegionContainsRegion() throws Exception {
String modelAsString = "a1 / /* comment */ b2";
List<CommonToken> tokens = getTokens(modelAsString);
for(int length=0; length < modelAsString.length(); ++length) {
for(int offset = 0; offset + length < modelAsString.length(); ++offset) {
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(modelAsString, new TextRegion(offset, length));
// System.out.println(offset + ":" + length + " -> " + tokenRegion);
CommonToken firstToken = findTokenStartingAt(tokenRegion.getOffset(), tokens);
assertTrue(firstToken.getStartIndex() <= offset);
if(tokenRegion.getLength() != 0) {
CommonToken lastToken = findTokenStopingAt(tokenRegion.getOffset() + tokenRegion.getLength()-1, tokens);
assertTrue(lastToken.getStopIndex() >= offset + length -1);
}
}
}
}
示例11: isInRequestedRange
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
protected boolean isInRequestedRange(EObject obj) {
Collection<ITextRegion> regions = request.getRegions();
if (regions.isEmpty())
return true;
ITextRegionAccess access = request.getTextRegionAccess();
IEObjectRegion objRegion = access.regionForEObject(obj);
if (objRegion == null)
return false;
IHiddenRegion previousHidden = objRegion.getPreviousHiddenRegion();
IHiddenRegion nextHidden = objRegion.getNextHiddenRegion();
int objOffset = previousHidden != null ? previousHidden.getOffset() : 0;
int objEnd = nextHidden != null ? nextHidden.getEndOffset() : access.regionForRootEObject().getEndOffset();
for (ITextRegion region : regions) {
int regionOffset = region.getOffset();
int regionEnd = regionOffset + region.getLength();
if (regionOffset <= objEnd && regionEnd >= objOffset)
return true;
}
return false;
}
示例12: format2
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
protected List<ITextReplacement> format2(final XtextResource resource, final ITextRegion selection, final ITypedPreferenceValues preferences) {
final FormatterRequest request = this.formatterRequestProvider.get();
request.setAllowIdentityEdits(false);
request.setFormatUndefinedHiddenRegionsOnly(false);
if ((selection != null)) {
request.setRegions(Collections.<ITextRegion>unmodifiableList(CollectionLiterals.<ITextRegion>newArrayList(selection)));
}
if ((preferences != null)) {
request.setPreferences(preferences);
}
final ITextRegionAccess regionAccess = this.regionBuilder.forNodeModel(resource).create();
request.setTextRegionAccess(regionAccess);
final IFormatter2 formatter2 = this.formatter2Provider.get();
final List<ITextReplacement> replacements = formatter2.format(request);
return replacements;
}
示例13: computeObjectFolding
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
@Override
protected void computeObjectFolding(EObject eObject, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor,
boolean initiallyFolded) {
if (FOLDING_TYPES.contains(eObject.eClass())) {
super.computeObjectFolding(eObject, foldingRegionAcceptor, initiallyFolded);
}
}
示例14: add
import org.eclipse.xtext.util.ITextRegion; //导入依赖的package包/类
protected void add(final Map<SourceRelativeURI, AbstractTraceRegionToString.File> files, final SourceRelativeURI uri, final ITextRegion it, final AbstractTraceRegionToString.RegionHandle region, final AbstractTraceRegionToString.LocationHandle location) {
AbstractTraceRegionToString.File file = files.get(uri);
if ((file == null)) {
AbstractTraceRegionToString.File _file = new AbstractTraceRegionToString.File(uri);
AbstractTraceRegionToString.File _file_1 = file = _file;
files.put(uri, _file_1);
}
this.add(file, it, region, location);
}
示例15: 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);
}