Search in sources :

Example 1 with AbsoluteURI

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

the class ResourceStorageTest method testDecodeURI.

@Test
public void testDecodeURI() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypack");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public def void foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final IFile file = this.helper.createFile("mypack/MyClass Foo.xtend", _builder.toString());
        IResourcesSetupUtil.waitForBuild();
        final ResourceStorageTest.TestableStorageAwareTrace storageAwareTrace = new ResourceStorageTest.TestableStorageAwareTrace();
        this.getInjector().injectMembers(storageAwareTrace);
        storageAwareTrace.setLocalStorage(file);
        URI _createURI = URI.createURI("mypack/MyClass%20Foo.xtend");
        SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI(_createURI);
        AbsoluteURI result = storageAwareTrace.resolvePath(_sourceRelativeURI);
        Assert.assertEquals("platform:/resource/test.project/src/mypack/MyClass%20Foo.xtend", result.toString());
        IProject _project = this.helper.getProject();
        URI _createURI_1 = URI.createURI("src/mypack/MyClass%20Foo.xtend");
        SourceRelativeURI _sourceRelativeURI_1 = new SourceRelativeURI(_createURI_1);
        result = storageAwareTrace.resolvePath(_project, _sourceRelativeURI_1);
        Assert.assertEquals("platform:/resource/test.project/src/mypack/MyClass%20Foo.xtend", result.toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) URI(org.eclipse.emf.common.util.URI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 2 with AbsoluteURI

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

the class AbstractTraceForURIProvider method getGeneratedLocation.

/**
 * Compute the location of the generated file from the given trace file.
 */
protected AbsoluteURI getGeneratedLocation(PersistedTrace trace) {
    AbsoluteURI path = trace.getPath();
    String fileName = traceFileNameProvider.getJavaFromTrace(path.getURI().toString());
    return new AbsoluteURI(fileName);
}
Also used : AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI)

Example 3 with AbsoluteURI

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

the class AbstractTraceForURIProvider method asFile.

protected SomeFile asFile(SourceRelativeURI srcRelativeDerivedResource, IProjectConfig project) {
    String[] pathSegments = srcRelativeDerivedResource.getURI().segments();
    Set<? extends ISourceFolder> sourceFolders = project.getSourceFolders();
    for (ISourceFolder folder : sourceFolders) {
        URI srcFolderPath = folder.getPath();
        URI absoluteURI = srcFolderPath.appendSegments(pathSegments);
        SomeFile result = asFile(new AbsoluteURI(absoluteURI), project);
        if (result != null) {
            return result;
        }
    }
    URI fromRoot = project.getPath().appendSegments(pathSegments);
    return asFile(new AbsoluteURI(fromRoot), project);
}
Also used : ISourceFolder(org.eclipse.xtext.workspace.ISourceFolder) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI)

Example 4 with AbsoluteURI

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

AbsoluteURI (org.eclipse.xtext.generator.trace.AbsoluteURI)4 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)3 URI (org.eclipse.emf.common.util.URI)2 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)1 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)1 ITraceURIConverter (org.eclipse.xtext.generator.trace.ITraceURIConverter)1 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 ISourceFolder (org.eclipse.xtext.workspace.ISourceFolder)1 Test (org.junit.Test)1