Search in sources :

Example 1 with TraceNotFoundException

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

the class TraceEditor method updateText.

protected void updateText(EObject obj) {
    DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
    if (region == null) {
        text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
        return;
    }
    final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
    SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
    if (sourceURI == null) {
        text.setText("Could not find associated URI");
        return;
    }
    Registry registry = IResourceServiceProvider.Registry.INSTANCE;
    IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
    URI traceURI = obj.eResource().getURI();
    IStorage localStorage = getLocalStorage(serviceProvider, traceURI);
    StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
    traceProvider.setLocalStorage(localStorage);
    traceProvider.setTraceToSource(true);
    traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {

        @Override
        public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
            return trace;
        }
    });
    String newText = traceProvider.toString();
    text.setText(newText);
}
Also used : StorageAwareTrace(org.eclipse.xtext.ui.generator.trace.StorageAwareTrace) Registry(org.eclipse.xtext.resource.IResourceServiceProvider.Registry) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Example 2 with TraceNotFoundException

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

the class TraceForTypeRootProvider method getTraceToSource.

public IEclipseTrace getTraceToSource(final IClassFile classFile) {
    IPath sourcePath = getSourcePath(classFile);
    if (sourcePath == null)
        return null;
    IProject project = classFile.getJavaProject().getProject();
    final String javaSimpleFileName = getJavaSimpleFileName(classFile);
    SourceRelativeURI localURI = getPathInFragmentRoot(classFile, javaSimpleFileName);
    class TraceRegionProvider implements ITraceRegionProvider {

        private AbstractTraceWithoutStorage trace;

        TraceRegionProvider(AbstractTraceWithoutStorage trace) {
            this.trace = trace;
        }

        @Override
        public AbstractTraceRegion getTraceRegion() {
            if (javaSimpleFileName == null)
                throw new TraceNotFoundException();
            String traceSimpleFileName = traceFileNameProvider.getTraceFromJava(javaSimpleFileName);
            SourceRelativeURI traceURI = getPathInFragmentRoot(classFile, traceSimpleFileName);
            try {
                InputStream contents = trace.getContents(traceURI, trace.getLocalProject());
                if (contents != null)
                    try {
                        return traceRegionSerializer.readTraceRegionFrom(contents);
                    } finally {
                        contents.close();
                    }
            } catch (IOException e) {
                log.error("Error finding trace region", e);
            }
            throw new TraceNotFoundException();
        }
    }
    if (isZipFile(sourcePath)) {
        ZipFileAwareTrace zipFileAwareTrace = zipFileAwareTraceProvider.get();
        zipFileAwareTrace.setProject(project);
        zipFileAwareTrace.setZipFilePath(sourcePath);
        zipFileAwareTrace.setLocalURI(localURI);
        zipFileAwareTrace.setEncoding(getSourceEncoding(classFile));
        zipFileAwareTrace.setTraceRegionProvider(new TraceRegionProvider(zipFileAwareTrace));
        return zipFileAwareTrace;
    } else {
        FolderAwareTrace folderAwareTrace = folderAwareTraceProvider.get();
        folderAwareTrace.setProject(project);
        folderAwareTrace.setRootFolder(sourcePath.toString());
        folderAwareTrace.setLocalURI(localURI);
        folderAwareTrace.setEncoding(getSourceEncoding(classFile));
        folderAwareTrace.setTraceRegionProvider(new TraceRegionProvider(folderAwareTrace));
        return folderAwareTrace;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) IOException(java.io.IOException) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) IProject(org.eclipse.core.resources.IProject)

Example 3 with TraceNotFoundException

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

the class JavaIoFileSystemAccess method generateTrace.

protected void generateTrace(String generatedFile, String outputConfigName, CharSequence contents) {
    try {
        if (contents instanceof ITraceRegionProvider) {
            OutputStream out = null;
            try {
                AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
                String traceFileName = traceFileNameProvider.getTraceFromJava(generatedFile);
                File traceFile = getFile(traceFileName, outputConfigName);
                out = new BufferedOutputStream(new FileOutputStream(traceFile));
                traceSerializer.writeTraceRegionTo(traceRegion, out);
                if (callBack != null)
                    callBack.fileAdded(traceFile);
            } catch (TraceNotFoundException e) {
            // ok
            } finally {
                if (out != null) {
                    out.close();
                }
            }
        }
    } catch (FileNotFoundException e) {
        throw new RuntimeIOException(e);
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with TraceNotFoundException

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

the class AbstractTraceForURIProvider method getTraceToSource.

public Trace getTraceToSource(final SomeFile generatedFile) {
    final PersistedTrace persistedTrace = findPersistedTrace(generatedFile);
    if (persistedTrace == null || !persistedTrace.exists()) {
        return null;
    }
    Trace result = newAbstractTrace(generatedFile);
    result.setTraceToSource(true);
    result.setTraceRegionProvider(new ITraceRegionProvider() {

        @Override
        public AbstractTraceRegion getTraceRegion() {
            AbstractTraceRegion traceRegion = cachedTraces.getTraceRegion(persistedTrace);
            if (traceRegion == null) {
                throw new TraceNotFoundException();
            }
            return traceRegion;
        }
    });
    return result;
}
Also used : TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Example 5 with TraceNotFoundException

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

Aggregations

ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)7 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)7 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)5 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)4 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 IPath (org.eclipse.core.runtime.IPath)2 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)2 RuntimeIOException (org.eclipse.xtext.util.RuntimeIOException)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 IStorage (org.eclipse.core.resources.IStorage)1