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);
}
}
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);
}
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);
}
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;
}
Aggregations