use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class RegionComparator method compare.
@Override
public int compare(T t1, T t2) {
ITextRegion o1 = regionAccess.apply(t1);
ITextRegion o2 = regionAccess.apply(t2);
int cmp1 = o1.getOffset() - o2.getOffset();
if (cmp1 != 0)
return cmp1;
int cmp2 = o1.getLength() - o2.getLength();
if (cmp2 != 0)
return cmp2;
return 0;
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TokenRegionProviderTest method testBug486454.
@Test
public void testBug486454() throws Exception {
String model = "t";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
assertEquals(0, tokenRegion.getOffset());
assertEquals(1, tokenRegion.getLength());
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class AbstractFormatter2 method isInRequestedRange.
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;
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class MultiLineJavaDocTypeReferenceProvider method computeEObjectReferencedInComment.
/**
* {@inheritDoc}
*/
@Override
public EObjectInComment computeEObjectReferencedInComment(XtextResource resource, int offset) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
INode rootNode = parseResult.getRootNode();
INode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
if (semanticObject != null) {
EReference reference = getEReference(semanticObject, node, offset);
if (reference != null) {
IScope scope = getScope(semanticObject, reference, node, offset);
List<ReplaceRegion> eObjectReferences = computeTypeRefRegions(node);
for (ReplaceRegion eObjectReference : eObjectReferences) {
if (eObjectReference.getOffset() <= offset && offset <= eObjectReference.getEndOffset()) {
String eObjectReferenceText = eObjectReference.getText();
if (!Strings.isNullOrEmpty(eObjectReferenceText)) {
ITextRegion region = new TextRegion(eObjectReference.getOffset(), eObjectReference.getLength());
IEObjectDescription candidate = getElementFromScope(scope, node, region, eObjectReferenceText);
if (candidate != null) {
EObject eObject = candidate.getEObjectOrProxy();
if (eObject != null) {
return new EObjectInComment(eObject, region);
}
}
}
}
}
}
}
}
return null;
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TracingSugar method location.
/**
* @param obj
* the EObject containing the feature
* @param feature
* the EStructuralFeature to trace
* @param idx
* the index of the value to trace, in case the feature contains a list, should be <code>-1</code>
* otherwise.
*
* @return ILocationData covering the <code>fullTextRegion</code> of the given feature in the given EObject.
*/
public ILocationData location(EObject obj, EStructuralFeature feature, int idx) {
ITextRegion region = locationProvider.getFullTextRegion(obj, feature, idx);
SourceRelativeURI uri = traceURIConverter.getURIForTrace(obj.eResource());
return new LocationData((ITextRegionWithLineInformation) region, uri);
}
Aggregations