use of org.eclipse.xtext.generator.trace.AbstractTraceRegion in project xtext-core by eclipse.
the class AbstractTrace method getAllTraceRegions.
protected Iterable<AbstractTraceRegion> getAllTraceRegions() {
return new Iterable<AbstractTraceRegion>() {
@Override
public Iterator<AbstractTraceRegion> iterator() {
AbstractTraceRegion root = getRootTraceRegion();
if (root == null)
return ImmutableSet.<AbstractTraceRegion>of().iterator();
final Iterator<AbstractTraceRegion> result = root.leafIterator();
return result;
}
};
}
use of org.eclipse.xtext.generator.trace.AbstractTraceRegion 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;
}
use of org.eclipse.xtext.generator.trace.AbstractTraceRegion in project xtext-core by eclipse.
the class TracingSugarTest method testCodeGenerationWithDebug_02.
@Test
public void testCodeGenerationWithDebug_02() {
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 __generateTypeWithDebugging02 = TracingSugarTest.this._generateTypeWithDebugging02(t);
_builder.append(__generateTypeWithDebugging02);
_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=false] 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=false] 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=true] 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=true] 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);
}
}
use of org.eclipse.xtext.generator.trace.AbstractTraceRegion in project xtext-core by eclipse.
the class URIBasedFileSystemAccess method generateTrace.
protected void generateTrace(final String generatedFile, final String outputConfigName, final CharSequence contents) {
try {
if ((this.isGenerateTraces() && (contents instanceof ITraceRegionProvider))) {
try {
AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
String traceFileName = this.traceFileNameProvider.getTraceFromJava(generatedFile);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
this.traceRegionSerializer.writeTraceRegionTo(traceRegion, out);
byte[] _byteArray = out.toByteArray();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
this.generateFile(traceFileName, outputConfigName, _byteArrayInputStream);
} catch (final Throwable _t) {
if (_t instanceof TraceNotFoundException) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.generator.trace.AbstractTraceRegion in project xtext-core by eclipse.
the class AbstractTraceRegionToString method collect.
protected int collect(final AbstractTraceRegion reg, final int nextID, final AbstractTraceRegionToString.File lFile, final Map<SourceRelativeURI, AbstractTraceRegionToString.File> rFiles, final List<AbstractTraceRegionToString.RegionHandle> result) {
int i = nextID;
List<AbstractTraceRegionToString.RegionHandle> childResult = result;
boolean _shouldInclude = this.shouldInclude(reg);
if (_shouldInclude) {
int _plusPlus = i++;
final AbstractTraceRegionToString.RegionHandle regHandle = new AbstractTraceRegionToString.RegionHandle(_plusPlus, reg);
result.add(regHandle);
childResult = regHandle.children;
this.add(lFile, reg.getMyRegion(), regHandle, null);
final Function1<ILocationData, Boolean> _function = (ILocationData it) -> {
return Boolean.valueOf(this.shouldInclude(reg, it));
};
final List<ILocationData> locs = IterableExtensions.<ILocationData>toList(IterableExtensions.<ILocationData>filter(reg.getAssociatedLocations(), _function));
for (int j = 0; (j < locs.size()); j++) {
{
final ILocationData loc = locs.get(j);
int _xifexpression = (int) 0;
int _size = locs.size();
boolean _greaterThan = (_size > 1);
if (_greaterThan) {
_xifexpression = (j + 1);
} else {
_xifexpression = (-1);
}
final AbstractTraceRegionToString.LocationHandle locHandle = new AbstractTraceRegionToString.LocationHandle(regHandle, _xifexpression, loc);
regHandle.locations.add(locHandle);
SourceRelativeURI _elvis = null;
SourceRelativeURI _srcRelativePath = loc.getSrcRelativePath();
if (_srcRelativePath != null) {
_elvis = _srcRelativePath;
} else {
SourceRelativeURI _associatedSrcRelativePath = reg.getAssociatedSrcRelativePath();
_elvis = _associatedSrcRelativePath;
}
final SourceRelativeURI path = _elvis;
this.add(rFiles, path, loc, regHandle, locHandle);
}
}
}
List<AbstractTraceRegion> _nestedRegions = reg.getNestedRegions();
for (final AbstractTraceRegion child : _nestedRegions) {
i = this.collect(child, i, lFile, rFiles, childResult);
}
return i;
}
Aggregations