Search in sources :

Example 16 with AbstractTraceRegion

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

the class AbstractTrace method getAllTraceRegions.

protected Iterable<AbstractTraceRegion> getAllTraceRegions() {
    return new Iterable<AbstractTraceRegion>() {

        @Override
        public Iterator<AbstractTraceRegion> iterator() {
            AbstractTraceRegion root = getRootTraceRegion();
            if (root == null)
                return ImmutableSet.<AbstractTraceRegion>of().iterator();
            final Iterator<AbstractTraceRegion> result = root.leafIterator();
            return result;
        }
    };
}
Also used : AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion)

Example 17 with AbstractTraceRegion

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

the class AbstractTraceForURIProvider method getTraceToTarget.

public Trace getTraceToTarget(final SomeFile sourceFile, final AbsoluteURI absoluteSourceResource, final IProjectConfig projectConfig) {
    final List<PersistedTrace> traceFiles = findInverseTraceFiles(sourceFile);
    if (traceFiles.isEmpty() || projectConfig == null) {
        return null;
    }
    Trace result = newAbstractTrace(sourceFile);
    result.setTraceToSource(false);
    final IResourceServiceProvider serviceProvider = getServiceProvider(absoluteSourceResource);
    final ITraceURIConverter traceURIConverter = serviceProvider.get(ITraceURIConverter.class);
    result.setTraceRegionProvider(new ITraceRegionProvider() {

        @Override
        public AbstractTraceRegion getTraceRegion() {
            List<AbstractTraceRegion> result = newArrayList();
            SourceRelativeURI sourceUriForTrace = traceURIConverter.getURIForTrace(projectConfig, absoluteSourceResource);
            for (PersistedTrace traceFile : traceFiles) {
                AbsoluteURI generatedFileURI = getGeneratedLocation(traceFile);
                if (generatedFileURI == null) {
                    throw new TraceNotFoundException();
                }
                AbstractTraceRegion traceRegion = cachedTraces.getTraceRegion(traceFile);
                SourceRelativeURI generatedUriForTrace = getGeneratedUriForTrace(projectConfig, absoluteSourceResource, generatedFileURI, traceURIConverter);
                if (sourceUriForTrace != null && generatedUriForTrace != null) {
                    result.addAll(traceRegion.invertFor(sourceUriForTrace, generatedUriForTrace));
                }
            }
            if (result.isEmpty())
                throw new TraceNotFoundException();
            return AbstractTraceRegion.mergedFrom(result);
        }
    });
    return result;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) List(java.util.List) ITraceURIConverter(org.eclipse.xtext.generator.trace.ITraceURIConverter) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI)

Example 18 with AbstractTraceRegion

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

the class TracingSugarTest method testCodeGenerationWithDebug_02.

@Test
public void testCodeGenerationWithDebug_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type String {}");
        _builder.newLine();
        _builder.append("type Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("String name;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final Model root = this.parseHelper.parse(LineDelimiters.toUnix(_builder.toString()));
        final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                {
                    EList<Type> _types = root.getTypes();
                    for (final Type t : _types) {
                        IGeneratorNode __generateTypeWithDebugging02 = TracingSugarTest.this._generateTypeWithDebugging02(t);
                        _builder.append(__generateTypeWithDebugging02);
                        _builder.newLineIfNotEmpty();
                    }
                }
            }
        };
        this._myExtensions.generateTracedFile(fsa, "foo/bar.txt", root, _client);
        final CharSequence generated = fsa.getTextFiles().get((IFileSystemAccess.DEFAULT_OUTPUT + "foo/bar.txt"));
        StringConcatenation _builder_1 = new StringConcatenation();
        {
            EList<Type> _types = root.getTypes();
            for (final Type t : _types) {
                CharSequence _generateTypeWithDebugging = this.generateTypeWithDebugging(t);
                _builder_1.append(_generateTypeWithDebugging);
                _builder_1.newLineIfNotEmpty();
            }
        }
        Assert.assertEquals(LineDelimiters.toUnix(_builder_1.toString()), generated.toString());
        final AbstractTraceRegion trace = ((ITraceRegionProvider) generated).getTraceRegion();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("CompletableTraceRegion [myOffset=0, myLength=55, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [0:41][lineNumber=0, endLineNumber=3]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("CompletableTraceRegion [myOffset=0, myLength=17, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [0:14][lineNumber=0, endLineNumber=0]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=6, myLength=6, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [5:6][lineNumber=0, endLineNumber=0]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("CompletableTraceRegion [myOffset=17, myLength=38, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [15:26][lineNumber=1, endLineNumber=3]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=23, myLength=3, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [20:3][lineNumber=1, endLineNumber=1]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=30, myLength=24, useForDebugging=true] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [27:12][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("CompletableTraceRegion [myOffset=39, myLength=4, useForDebugging=true] associations={");
        _builder_2.newLine();
        _builder_2.append("        ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [34:4][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("CompletableTraceRegion [myOffset=46, myLength=6, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("        ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [27:6][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("}");
        Assert.assertEquals(LineDelimiters.toUnix(_builder_2.toString()), trace.toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IGeneratorNode(org.eclipse.xtext.generator.trace.node.IGeneratorNode) Type(org.eclipse.xtext.linking.lazy.lazyLinking.Type) EList(org.eclipse.emf.common.util.EList) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) InMemoryFileSystemAccess(org.eclipse.xtext.generator.InMemoryFileSystemAccess) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) Test(org.junit.Test)

Example 19 with AbstractTraceRegion

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

the class URIBasedFileSystemAccess method generateTrace.

protected void generateTrace(final String generatedFile, final String outputConfigName, final CharSequence contents) {
    try {
        if ((this.isGenerateTraces() && (contents instanceof ITraceRegionProvider))) {
            try {
                AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
                String traceFileName = this.traceFileNameProvider.getTraceFromJava(generatedFile);
                final ByteArrayOutputStream out = new ByteArrayOutputStream();
                this.traceRegionSerializer.writeTraceRegionTo(traceRegion, out);
                byte[] _byteArray = out.toByteArray();
                ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
                this.generateFile(traceFileName, outputConfigName, _byteArrayInputStream);
            } catch (final Throwable _t) {
                if (_t instanceof TraceNotFoundException) {
                } else {
                    throw Exceptions.sneakyThrow(_t);
                }
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Example 20 with AbstractTraceRegion

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

the class AbstractTraceRegionToString method collect.

protected int collect(final AbstractTraceRegion reg, final int nextID, final AbstractTraceRegionToString.File lFile, final Map<SourceRelativeURI, AbstractTraceRegionToString.File> rFiles, final List<AbstractTraceRegionToString.RegionHandle> result) {
    int i = nextID;
    List<AbstractTraceRegionToString.RegionHandle> childResult = result;
    boolean _shouldInclude = this.shouldInclude(reg);
    if (_shouldInclude) {
        int _plusPlus = i++;
        final AbstractTraceRegionToString.RegionHandle regHandle = new AbstractTraceRegionToString.RegionHandle(_plusPlus, reg);
        result.add(regHandle);
        childResult = regHandle.children;
        this.add(lFile, reg.getMyRegion(), regHandle, null);
        final Function1<ILocationData, Boolean> _function = (ILocationData it) -> {
            return Boolean.valueOf(this.shouldInclude(reg, it));
        };
        final List<ILocationData> locs = IterableExtensions.<ILocationData>toList(IterableExtensions.<ILocationData>filter(reg.getAssociatedLocations(), _function));
        for (int j = 0; (j < locs.size()); j++) {
            {
                final ILocationData loc = locs.get(j);
                int _xifexpression = (int) 0;
                int _size = locs.size();
                boolean _greaterThan = (_size > 1);
                if (_greaterThan) {
                    _xifexpression = (j + 1);
                } else {
                    _xifexpression = (-1);
                }
                final AbstractTraceRegionToString.LocationHandle locHandle = new AbstractTraceRegionToString.LocationHandle(regHandle, _xifexpression, loc);
                regHandle.locations.add(locHandle);
                SourceRelativeURI _elvis = null;
                SourceRelativeURI _srcRelativePath = loc.getSrcRelativePath();
                if (_srcRelativePath != null) {
                    _elvis = _srcRelativePath;
                } else {
                    SourceRelativeURI _associatedSrcRelativePath = reg.getAssociatedSrcRelativePath();
                    _elvis = _associatedSrcRelativePath;
                }
                final SourceRelativeURI path = _elvis;
                this.add(rFiles, path, loc, regHandle, locHandle);
            }
        }
    }
    List<AbstractTraceRegion> _nestedRegions = reg.getNestedRegions();
    for (final AbstractTraceRegion child : _nestedRegions) {
        i = this.collect(child, i, lFile, rFiles, childResult);
    }
    return i;
}
Also used : ILocationData(org.eclipse.xtext.generator.trace.ILocationData) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Aggregations

AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)21 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)10 ILocationData (org.eclipse.xtext.generator.trace.ILocationData)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)4 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)4 EList (org.eclipse.emf.common.util.EList)3 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)3 InMemoryFileSystemAccess (org.eclipse.xtext.generator.InMemoryFileSystemAccess)3 IGeneratorNode (org.eclipse.xtext.generator.trace.node.IGeneratorNode)3 Model (org.eclipse.xtext.linking.lazy.lazyLinking.Model)3 Type (org.eclipse.xtext.linking.lazy.lazyLinking.Type)3 ITextRegionWithLineInformation (org.eclipse.xtext.util.ITextRegionWithLineInformation)3 Test (org.junit.Test)3 AbstractIterator (com.google.common.collect.AbstractIterator)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 List (java.util.List)2