Search in sources :

Example 1 with TraceRegionSerializer

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

the class JavaIoFileSystemAccessTest method testTraceIsCreated.

@Test
public void testTraceIsCreated() throws Exception {
    File file = null;
    try {
        JavaIoFileSystemAccess fileSystemAccess = new JavaIoFileSystemAccess(IResourceServiceProvider.Registry.INSTANCE, new IEncodingProvider.Runtime(), new TraceFileNameProvider(), new TraceRegionSerializer());
        File tmpDir = configureFileSystemAccess(fileSystemAccess);
        SourceRelativeURI uri = new SourceRelativeURI(URI.createURI("foo/bar"));
        CharSequenceTraceWrapper wrapper = new CharSequenceTraceWrapper();
        fileSystemAccess.generateFile("tmp/X", wrapper.wrapWithTraceData("XX", uri, 0, 10, 0, 1));
        file = new File(tmpDir, "tmp/X");
        assertTrue(file.exists());
        assertTrue(file.isFile());
        assertEquals("XX", fileSystemAccess.readTextFile("tmp/X"));
        file = new File(tmpDir, "tmp/.X._trace");
        assertTrue(file.exists());
        assertTrue(file.isFile());
    } finally {
        if (file != null)
            file.delete();
    }
}
Also used : TraceFileNameProvider(org.eclipse.xtext.generator.trace.TraceFileNameProvider) CharSequenceTraceWrapper(org.eclipse.xtext.generator.trace.CharSequenceTraceWrapper) TraceRegionSerializer(org.eclipse.xtext.generator.trace.TraceRegionSerializer) IEncodingProvider(org.eclipse.xtext.parser.IEncodingProvider) File(java.io.File) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) Test(org.junit.Test)

Example 2 with TraceRegionSerializer

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

the class TraceResourceFactory method createResource.

@Override
public Resource createResource(URI uri) {
    Resource result = new ResourceImpl(uri) {

        @Override
        protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOException {
            TraceRegionSerializer serializer = new TraceRegionSerializer();
            DebugTraceRegion result = serializer.doReadFrom(inputStream, new Strategy());
            getContents().add(result);
        }

        @Override
        protected void doSave(OutputStream outputStream, Map<?, ?> options) throws IOException {
            TraceRegionSerializer serializer = new TraceRegionSerializer();
            serializer.doWriteTo(new Strategy(), (DebugTraceRegion) getContents().get(0), outputStream);
        }
    };
    return result;
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) InputStream(java.io.InputStream) TraceRegionSerializer(org.eclipse.xtext.generator.trace.TraceRegionSerializer) OutputStream(java.io.OutputStream) Resource(org.eclipse.emf.ecore.resource.Resource) Map(java.util.Map)

Aggregations

TraceRegionSerializer (org.eclipse.xtext.generator.trace.TraceRegionSerializer)2 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Map (java.util.Map)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)1 CharSequenceTraceWrapper (org.eclipse.xtext.generator.trace.CharSequenceTraceWrapper)1 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)1 TraceFileNameProvider (org.eclipse.xtext.generator.trace.TraceFileNameProvider)1 IEncodingProvider (org.eclipse.xtext.parser.IEncodingProvider)1 Test (org.junit.Test)1