Search in sources :

Example 1 with AbstractTraceRegion

use of org.eclipse.xtext.generator.trace.AbstractTraceRegion 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 AbstractTraceRegion

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

the class LineNumberMappingTests method getTraceRegion.

public AbstractTraceRegion getTraceRegion(final CharSequence xtendCode) {
    try {
        final XtendClass clazz = super.clazz(xtendCode.toString());
        final AbstractTraceRegionFSA fsa = new AbstractTraceRegionFSA();
        this.generator.doGenerate(clazz.eResource(), fsa);
        final AbstractTraceRegion result = ((ITraceRegionProvider) fsa.charSequence).getTraceRegion();
        this.print(result, fsa.charSequence.toString());
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : AbstractTraceRegionFSA(org.eclipse.xtend.core.tests.debug.AbstractTraceRegionFSA) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Example 3 with AbstractTraceRegion

use of org.eclipse.xtext.generator.trace.AbstractTraceRegion 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 4 with AbstractTraceRegion

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

the class AbstractXtendInstallDebugInfoMojo method installTrace.

protected void installTrace(File traceFile, Collection<File> classFiles) throws FileNotFoundException, IOException {
    ITraceToBytecodeInstaller traceToBytecodeInstaller = createTraceToBytecodeInstaller();
    InputStream in = new FileInputStream(traceFile);
    try {
        AbstractTraceRegion traceRegion = traceRegionSerializer.readTraceRegionFrom(in);
        traceToBytecodeInstaller.setTrace(traceFileNameProvider.getJavaFromTrace(traceFile.getName()), traceRegion);
        if (getLog().isDebugEnabled())
            getLog().debug("Installing trace " + traceFile + " into:");
        for (File classFile : classFiles) {
            if (getLog().isDebugEnabled())
                getLog().debug("  " + classFile);
            byte[] bytecodeWithTraces = traceToBytecodeInstaller.installTrace(Files.toByteArray(classFile));
            if (bytecodeWithTraces != null)
                Files.write(bytecodeWithTraces, classFile);
        }
    } finally {
        in.close();
    }
}
Also used : ITraceToBytecodeInstaller(org.eclipse.xtext.generator.trace.ITraceToBytecodeInstaller) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with AbstractTraceRegion

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

the class TracingSugarTest method testCodeGenerationWithDebug.

@Test
public void testCodeGenerationWithDebug() {
    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 __generateTypeWithDebugging = TracingSugarTest.this._generateTypeWithDebugging(t);
                        _builder.append(__generateTypeWithDebugging);
                        _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=true] 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=true] 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=false] 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=false] 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)

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