Search in sources :

Example 1 with ITextRegion

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);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 2 with ITextRegion

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);
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 3 with ITextRegion

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);
            }
        }
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Example 4 with ITextRegion

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());
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 5 with ITextRegion

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));
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) AstSelectionProvider(org.eclipse.xtext.ui.editor.selection.AstSelectionProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

ITextRegion (org.eclipse.xtext.util.ITextRegion)118 TextRegion (org.eclipse.xtext.util.TextRegion)43 EObject (org.eclipse.emf.ecore.EObject)30 Test (org.junit.Test)20 XtextResource (org.eclipse.xtext.resource.XtextResource)19 INode (org.eclipse.xtext.nodemodel.INode)18 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)13 BadLocationException (org.eclipse.jface.text.BadLocationException)10 XExpression (org.eclipse.xtext.xbase.XExpression)9 CoreException (org.eclipse.core.runtime.CoreException)7 Resource (org.eclipse.emf.ecore.resource.Resource)7 Region (org.eclipse.jface.text.Region)7 IOException (java.io.IOException)6 ITextSelection (org.eclipse.jface.text.ITextSelection)6 IParseResult (org.eclipse.xtext.parser.IParseResult)6 Collection (java.util.Collection)5 IRegion (org.eclipse.jface.text.IRegion)5 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)5 TextSelection (org.eclipse.jface.text.TextSelection)4