Search in sources :

Example 1 with ILocationInResource

use of org.eclipse.xtext.generator.trace.ILocationInResource in project xtext-xtend by eclipse.

the class DerivedSourceView method selectAndReveal.

@Override
protected void selectAndReveal(IWorkbenchPartSelection workbenchPartSelection) {
    if (selectedSource != null) {
        IAnnotationModel annotationModel = getSourceViewer().getAnnotationModel();
        TextRegion localRegion = mapTextRegion(workbenchPartSelection);
        IEclipseTrace trace = traceInformation.getTraceToTarget(getEditorResource(workbenchPartSelection));
        if (trace != null) {
            Iterable<? extends ILocationInEclipseResource> allAssociatedLocations = trace.getAllAssociatedLocations(localRegion, selectedSource);
            ILocationInResource firstLocationInResource = Iterables.getFirst(allAssociatedLocations, null);
            if (firstLocationInResource != null) {
                ITextRegion textRegion = firstLocationInResource.getTextRegion();
                if (textRegion != null) {
                    openEditorAction.setSelectedRegion(textRegion);
                    getSourceViewer().revealRange(textRegion.getOffset(), textRegion.getLength());
                }
            }
            for (ILocationInResource locationInResource : allAssociatedLocations) {
                ITextRegion textRegion = locationInResource.getTextRegion();
                if (textRegion != null) {
                    annotationModel.addAnnotation(new Annotation(SEARCH_ANNOTATION_TYPE, true, null), new Position(textRegion.getOffset(), textRegion.getLength()));
                }
            }
        }
    }
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) Position(org.eclipse.jface.text.Position) ITextRegion(org.eclipse.xtext.util.ITextRegion) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource) Annotation(org.eclipse.jface.text.source.Annotation)

Example 2 with ILocationInResource

use of org.eclipse.xtext.generator.trace.ILocationInResource in project xtext-core by eclipse.

the class AbstractTrace method toLocations.

protected Iterable<? extends ILocationInResource> toLocations(final Iterable<AbstractTraceRegion> allTraceRegions) {
    return new Iterable<ILocationInResource>() {

        @Override
        public Iterator<ILocationInResource> iterator() {
            return new AbstractIterator<ILocationInResource>() {

                private Iterator<AbstractTraceRegion> delegate = allTraceRegions.iterator();

                private AbstractTraceRegion region;

                private Iterator<ILocationData> locationDelegate;

                @Override
                protected ILocationInResource computeNext() {
                    while (true) {
                        if (locationDelegate == null || !locationDelegate.hasNext()) {
                            if (delegate.hasNext()) {
                                region = delegate.next();
                                locationDelegate = region.getAssociatedLocations().iterator();
                                if (!locationDelegate.hasNext()) {
                                    continue;
                                }
                            }
                        }
                        if (locationDelegate != null && locationDelegate.hasNext()) {
                            ILocationData locationData = locationDelegate.next();
                            ILocationInResource result = createLocationInResourceFor(locationData, region);
                            if (result != null) {
                                return result;
                            }
                            continue;
                        }
                        return endOfData();
                    }
                }
            };
        }
    };
}
Also used : Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) AbstractIterator(com.google.common.collect.AbstractIterator) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource) ILocationData(org.eclipse.xtext.generator.trace.ILocationData)

Example 3 with ILocationInResource

use of org.eclipse.xtext.generator.trace.ILocationInResource in project xtext-xtend by eclipse.

the class CompilerTraceTest method tracesTo.

public void tracesTo(final CharSequence xtend, final CharSequence java) {
    try {
        final String xtendWithSpaces = ((" " + xtend) + " ");
        final Matcher xtendMatcher = this.p.matcher(xtendWithSpaces);
        Assert.assertTrue("xtendMatcher.matches", xtendMatcher.matches());
        final String xtendGroup1 = xtendMatcher.group(1);
        final String xtendGroup2 = xtendMatcher.group(2);
        final String xtendGroup3 = xtendMatcher.group(3);
        final String actualXtendCode = ((xtendGroup1 + xtendGroup2) + xtendGroup3);
        final XtendFile file = this.file(actualXtendCode, true);
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        final JvmGenericType inferredType = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        CharSequence compiledCode = this.generator.generateType(inferredType, this.generatorConfigProvider.get(inferredType));
        compiledCode = this.postProcessor.postProcess(null, compiledCode);
        final Matcher javaMatcher = this.p.matcher(java.toString());
        Assert.assertTrue("javaMatcher.matches", javaMatcher.matches());
        final String javaGroup1 = javaMatcher.group(1);
        final String javaGroup2 = javaMatcher.group(2);
        final String javaGroup3 = javaMatcher.group(3);
        final String actualJavaExpectation = ((javaGroup1 + javaGroup2) + javaGroup3);
        Assert.assertEquals(actualJavaExpectation, compiledCode.toString());
        AbstractTraceRegion _traceRegion = ((ITraceRegionProvider) compiledCode).getTraceRegion();
        URI _createURI = URI.createURI(file.eResource().getURI().path());
        SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI(_createURI);
        URI _createURI_1 = URI.createURI(file.eResource().getURI().path());
        SourceRelativeURI _sourceRelativeURI_1 = new SourceRelativeURI(_createURI_1);
        AbstractTraceRegion _merge = this.merge(_traceRegion.invertFor(_sourceRelativeURI, _sourceRelativeURI_1));
        final SimpleTrace trace = new SimpleTrace(_merge);
        int _length = xtendGroup1.length();
        int _length_1 = xtendGroup2.length();
        TextRegion _textRegion = new TextRegion(_length, _length_1);
        final Iterable<? extends ILocationInResource> locations = trace.getAllAssociatedLocations(_textRegion);
        int _length_2 = javaGroup1.length();
        int _length_3 = javaGroup2.length();
        final TextRegion expectedRegion = new TextRegion(_length_2, _length_3);
        Assert.assertFalse(IterableExtensions.isEmpty(locations));
        for (final ILocationInResource location : locations) {
            ITextRegionWithLineInformation _textRegion_1 = location.getTextRegion();
            boolean _equals = Objects.equal(_textRegion_1, expectedRegion);
            if (_equals) {
                return;
            }
        }
        Assert.fail(((("locations did not match expectation: " + locations) + " / ") + expectedRegion));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) TextRegion(org.eclipse.xtext.util.TextRegion) Matcher(java.util.regex.Matcher) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) SimpleTrace(org.eclipse.xtend.core.tests.compiler.SimpleTrace) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Aggregations

ILocationInResource (org.eclipse.xtext.generator.trace.ILocationInResource)3 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)2 TextRegion (org.eclipse.xtext.util.TextRegion)2 AbstractIterator (com.google.common.collect.AbstractIterator)1 Iterator (java.util.Iterator)1 Matcher (java.util.regex.Matcher)1 URI (org.eclipse.emf.common.util.URI)1 Position (org.eclipse.jface.text.Position)1 Annotation (org.eclipse.jface.text.source.Annotation)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 SimpleTrace (org.eclipse.xtend.core.tests.compiler.SimpleTrace)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)1 ILocationData (org.eclipse.xtext.generator.trace.ILocationData)1 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)1 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)1 IEclipseTrace (org.eclipse.xtext.ui.generator.trace.IEclipseTrace)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1