Search in sources :

Example 1 with ILocationData

use of org.eclipse.xtext.generator.trace.ILocationData in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method updateTraceInformation.

/**
	 * @throws CoreException if something unexpected happens during resource access
	 * @throws IOException if serialization of the trace data fails 
	 * @since 2.3
	 */
protected void updateTraceInformation(IFile traceFile, CharSequence contents, boolean derived) throws CoreException, IOException {
    if (contents instanceof ITraceRegionProvider) {
        AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
        if (sourceTraces == null) {
            sourceTraces = HashMultimap.create();
        }
        IPath tracePath = traceFile.getFullPath();
        Iterator<AbstractTraceRegion> iterator = traceRegion.treeIterator();
        while (iterator.hasNext()) {
            AbstractTraceRegion region = iterator.next();
            for (ILocationData location : region.getAssociatedLocations()) {
                URI path = location.getPath();
                if (path != null) {
                    sourceTraces.put(path, tracePath);
                }
            }
        }
        class AccessibleOutputStream extends ByteArrayOutputStream {

            byte[] internalBuffer() {
                return buf;
            }

            int internalLength() {
                return count;
            }
        }
        AccessibleOutputStream data = new AccessibleOutputStream();
        traceSerializer.writeTraceRegionTo(traceRegion, data);
        // avoid copying the byte array
        InputStream input = new ByteArrayInputStream(data.internalBuffer(), 0, data.internalLength());
        if (traceFile.exists()) {
            traceFile.setContents(input, false, true, monitor);
        } else {
            traceFile.create(input, true, monitor);
        }
        setDerived(traceFile, derived);
        return;
    }
    if (traceFile.exists()) {
        traceFile.delete(IResource.KEEP_HISTORY, monitor);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.eclipse.xtext.util.StringInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) URI(org.eclipse.emf.common.util.URI) ILocationData(org.eclipse.xtext.generator.trace.ILocationData)

Example 2 with ILocationData

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

the class CompilerTraceTest method merge.

public AbstractTraceRegion merge(final List<AbstractTraceRegion> regions) {
    boolean _isEmpty = regions.isEmpty();
    boolean _not = (!_isEmpty);
    Assert.assertTrue(_not);
    int _size = regions.size();
    boolean _greaterThan = (_size > 1);
    if (_greaterThan) {
        ITextRegionWithLineInformation rootLocation = ITextRegionWithLineInformation.EMPTY_REGION;
        ITextRegionWithLineInformation associated = ITextRegionWithLineInformation.EMPTY_REGION;
        for (final AbstractTraceRegion child : regions) {
            {
                int _myOffset = child.getMyOffset();
                int _myLength = child.getMyLength();
                int _myLineNumber = child.getMyLineNumber();
                int _myEndLineNumber = child.getMyEndLineNumber();
                TextRegionWithLineInformation _textRegionWithLineInformation = new TextRegionWithLineInformation(_myOffset, _myLength, _myLineNumber, _myEndLineNumber);
                rootLocation = rootLocation.merge(_textRegionWithLineInformation);
                ILocationData childAssociation = child.getMergedAssociatedLocation();
                if ((childAssociation != null)) {
                    associated = associated.merge(childAssociation);
                }
            }
        }
        final RootTraceRegionForTesting root = new RootTraceRegionForTesting(rootLocation, associated);
        for (final AbstractTraceRegion child_1 : regions) {
            child_1.setParent(root);
        }
        return root;
    } else {
        return IterableExtensions.<AbstractTraceRegion>head(regions);
    }
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) RootTraceRegionForTesting(org.eclipse.xtend.core.tests.compiler.RootTraceRegionForTesting) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ILocationData(org.eclipse.xtext.generator.trace.ILocationData)

Example 3 with ILocationData

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

the class TraceRegionToStringTest method oneChild.

@Test
public void oneChild() {
    final TraceRegionToStringTester tester = new TraceRegionToStringTester();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("foo bar");
    _builder.newLine();
    tester.setLocalText(_builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("baz buz");
    _builder_1.newLine();
    tester.setRemote1(_builder_1.toString());
    SourceRelativeURI _uri1 = tester.getUri1();
    TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(1, 6, _uri1);
    TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
    final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> {
        TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(2, 4);
        it.addChild(1, 6, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1)));
    };
    TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function);
    tester.setTrace(_doubleArrow);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("----- local1 ----- | ----- remote1 -----");
    _builder_2.newLine();
    _builder_2.append("[1[f[2[oo bar]2,1] | b[1[a[2[z bu]2]z]1]");
    _builder_2.newLine();
    _builder_2.append("----------------------------------------");
    _builder_2.newLine();
    _builder_2.append("1: D 0-7 Region -> Location[1,6,remote1] {");
    _builder_2.newLine();
    _builder_2.append("2: D 1-6   Region -> Location[2,4]");
    _builder_2.newLine();
    _builder_2.append("1:       }");
    _builder_2.newLine();
    this.operator_tripleEquals(tester, _builder_2);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TextRegion(org.eclipse.xtext.util.TextRegion) TraceRegionToStringTester(org.eclipse.xtext.generator.trace.TraceRegionToStringTester) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ILocationData(org.eclipse.xtext.generator.trace.ILocationData) Test(org.junit.Test)

Example 4 with ILocationData

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

the class TraceRegionToStringTest method simple.

@Test
public void simple() {
    final TraceRegionToStringTester tester = new TraceRegionToStringTester();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("foo bar");
    _builder.newLine();
    tester.setLocalText(_builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("baz buz");
    _builder_1.newLine();
    tester.setRemote1(_builder_1.toString());
    SourceRelativeURI _uri1 = tester.getUri1();
    TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(4, 2, _uri1);
    TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(1, 2, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
    tester.setTrace(_region);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("-- local1 --- | -- remote1 --");
    _builder_2.newLine();
    _builder_2.append("f[1[oo]1] bar | baz [1[bu]1]z");
    _builder_2.newLine();
    _builder_2.append("-----------------------------");
    _builder_2.newLine();
    _builder_2.append("1: D 1-2 Region -> Location[4,2,remote1]");
    _builder_2.newLine();
    this.operator_tripleEquals(tester, _builder_2);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TextRegion(org.eclipse.xtext.util.TextRegion) TraceRegionToStringTester(org.eclipse.xtext.generator.trace.TraceRegionToStringTester) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ILocationData(org.eclipse.xtext.generator.trace.ILocationData) Test(org.junit.Test)

Example 5 with ILocationData

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

the class TracingSugarTest method _generateProperty.

@Traced
public IGeneratorNode _generateProperty(final Property it) {
    ILocationData _location = this._myExtensions.location(it);
    CompositeGeneratorNode _traceNode = this._myExtensions.trace(_location, false);
    this._myExtensions.appendTemplate(_traceNode, __generateProperty(it));
    return _traceNode;
}
Also used : CompositeGeneratorNode(org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode) ILocationData(org.eclipse.xtext.generator.trace.ILocationData) Traced(org.eclipse.xtext.generator.trace.node.Traced)

Aggregations

ILocationData (org.eclipse.xtext.generator.trace.ILocationData)19 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 TraceRegionToStringTester (org.eclipse.xtext.generator.trace.TraceRegionToStringTester)7 TextRegion (org.eclipse.xtext.util.TextRegion)7 Test (org.junit.Test)7 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)5 CompositeGeneratorNode (org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode)5 Traced (org.eclipse.xtext.generator.trace.node.Traced)5 ITextRegionWithLineInformation (org.eclipse.xtext.util.ITextRegionWithLineInformation)3 LocationData (org.eclipse.xtext.generator.trace.LocationData)2 ITextRegion (org.eclipse.xtext.util.ITextRegion)2 AbstractIterator (com.google.common.collect.AbstractIterator)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1 IPath (org.eclipse.core.runtime.IPath)1 URI (org.eclipse.emf.common.util.URI)1