use of org.eclipse.xtext.generator.trace.SourceRelativeURI 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.SourceRelativeURI in project xtext-core by eclipse.
the class AbstractTrace method mergeRegions.
protected ILocationInResource mergeRegions(AbstractTraceRegion left, AbstractTraceRegion right) {
if (left == null) {
if (right != null) {
return getMergedLocationInResource(right);
}
return null;
}
if (right == null || left.equals(right)) {
return getMergedLocationInResource(left);
} else {
SourceRelativeURI leftToPath = left.getAssociatedSrcRelativePath();
SourceRelativeURI rightToPath = right.getAssociatedSrcRelativePath();
if (ObjectExtensions.operator_equals(leftToPath, rightToPath)) {
ITextRegionWithLineInformation leftRegion = left.getMyRegion();
ITextRegionWithLineInformation rightRegion = right.getMyRegion();
if (leftRegion.contains(rightRegion)) {
return getMergedLocationInResource(left);
} else if (rightRegion.contains(leftRegion)) {
return getMergedLocationInResource(right);
} else {
AbstractTraceRegion parent = left.getParent();
AbstractTraceRegion leftChild = left;
while (parent != null) {
if (parent.getMyRegion().contains(rightRegion)) {
break;
}
leftChild = parent;
parent = parent.getParent();
}
if (parent != null) {
AbstractTraceRegion rightChild = right;
while (!parent.equals(rightChild.getParent())) {
rightChild = rightChild.getParent();
if (rightChild == null) {
return getMergedLocationInResource(leftChild);
}
}
SourceRelativeURI path = leftToPath;
if (path == null) {
path = leftChild.getAssociatedSrcRelativePath();
}
ITextRegionWithLineInformation merged = parent.getMergedAssociatedLocation();
if (merged != null) {
return createLocationInResource(merged, path);
}
}
}
}
}
// TODO the remaining cases have yet to be implemented
return null;
}
use of org.eclipse.xtext.generator.trace.SourceRelativeURI in project xtext-core by eclipse.
the class AbsoluteURI method deresolve.
public SourceRelativeURI deresolve(final IProjectConfig projectConfig) {
final ISourceFolder sourceFolder = projectConfig.findSourceFolderContaining(this.getURI());
SourceRelativeURI _deresolve = null;
if (sourceFolder != null) {
_deresolve = this.deresolve(sourceFolder);
}
return _deresolve;
}
use of org.eclipse.xtext.generator.trace.SourceRelativeURI 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;
}
use of org.eclipse.xtext.generator.trace.SourceRelativeURI in project xtext-eclipse by eclipse.
the class JDTAwareEclipseResourceFileSystemAccess2 method flushSourceTraces.
/**
* Since sourceTraces are relative the URI has to be computed with the currentSource as context
*/
@Override
public void flushSourceTraces(String generatorName) throws CoreException {
Multimap<SourceRelativeURI, IPath> sourceTraces = getSourceTraces();
if (sourceTraces != null) {
Set<SourceRelativeURI> keys = sourceTraces.keySet();
String source = getCurrentSource();
IContainer container = Strings.isEmpty(source) ? getProject() : getProject().getFolder(source);
for (SourceRelativeURI uri : keys) {
if (uri != null && source != null) {
Collection<IPath> paths = sourceTraces.get(uri);
IFile sourceFile = container.getFile(new Path(uri.getURI().path()));
if (sourceFile.exists()) {
IPath[] tracePathArray = paths.toArray(new IPath[paths.size()]);
getTraceMarkers().installMarker(sourceFile, generatorName, tracePathArray);
}
}
}
}
resetSourceTraces();
}
Aggregations