use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class ContentFormatter method initRequest.
protected void initRequest(IXtextDocument document, IRegion region, XtextResource resource, FormatterRequest request) {
ITextRegion textRegion = new TextRegion(region.getOffset(), region.getLength());
request.setAllowIdentityEdits(false);
request.setFormatUndefinedHiddenRegionsOnly(false);
request.setRegions(singletonList(textRegion));
ITextRegionAccess tokenAccess = regionBuilder.forNodeModel(resource).create();
IPreferenceValues preferenceValues = preferencesProvider.getPreferenceValues(resource);
request.setPreferences(TypedPreferenceValues.castOrWrap(preferenceValues));
request.setTextRegionAccess(tokenAccess);
if (tokenAccess.hasSyntaxError())
request.setExceptionHandler(ExceptionAcceptor.IGNORING);
else
request.setExceptionHandler(ExceptionAcceptor.LOGGING);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class HyperlinkHelper method createHyperlinksTo.
/**
* Produces hyperlinks for the given {@code node} which is associated with a cross reference
* that points to the referenced {@code target}.
*
* @see #createHyperlinksTo(XtextResource, Region, EObject, IHyperlinkAcceptor)
*
* @since 2.4
*/
protected void createHyperlinksTo(XtextResource resource, INode node, EObject target, IHyperlinkAcceptor acceptor) {
ITextRegion textRegion = node.getTextRegion();
Region region = new Region(textRegion.getOffset(), textRegion.getLength());
createHyperlinksTo(resource, region, target, acceptor);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class JavaSearchHelper method accept.
protected void accept(IReferenceDescription referenceDescription) {
URI sourceResourceURI = referenceDescription.getSourceEObjectUri().trimFragment();
Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(sourceResourceURI);
Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
while (iterator.hasNext()) {
Pair<IStorage, IProject> pair = iterator.next();
IStorage storage = pair.getFirst();
IProject project = pair.getSecond();
if (project != null && !project.isHidden()) {
ResourceSet resourceSet = getResourceSet(project);
EObject sourceEObject = resourceSet.getEObject(referenceDescription.getSourceEObjectUri(), true);
if (sourceEObject != null) {
ITextRegion region = getLocation(sourceEObject, referenceDescription.getEReference(), referenceDescription.getIndexInList());
acceptMatch(storage, region);
} else {
acceptMatch(referenceDescription, null);
}
}
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class LinkedModelCalculatorIntegrationTest method selectElementInEditor.
protected void selectElementInEditor(EObject targetElement, final URI targetElementURI, final XtextEditor editor, XtextResource editorResource) {
if (targetElementURI != null && targetElementURI.trimFragment().equals(editorResource.getURI())) {
ITextRegion region = locationInFileProvider.getSignificantTextRegion(targetElement);
editor.selectAndReveal(region.getOffset(), region.getLength());
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class AstSelectionProviderTest method testSelectEnclosing.
@Test
public void testSelectEnclosing() throws Exception {
String zonk = "zonk{}";
String zink = "zink{}";
String baz = "baz{" + zonk + zink + "}";
String bar = "bar{}";
String all = "foo(baz){" + bar + baz + "}";
EObject model = super.getModel(all);
AstSelectionProvider provider = get(AstSelectionProvider.class);
final XtextResource res = (XtextResource) model.eResource();
int indexOfZonk = all.indexOf(zonk);
ITextRegion selection = provider.selectEnclosing(res, new TextRegion(indexOfZonk, 0));
assertEquals(region(all, "zonk"), selection);
selection = provider.selectEnclosing(res, selection);
assertEquals(region(all, zonk), selection);
selection = provider.selectEnclosing(res, selection);
assertEquals(region(all, baz), selection);
selection = provider.selectEnclosing(res, selection);
assertEquals(region(all, all), selection);
assertEquals(ITextRegion.EMPTY_REGION, provider.selectEnclosing(res, selection));
}
Aggregations