Search in sources :

Example 11 with SourceRelativeURI

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);
}
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 12 with SourceRelativeURI

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;
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 13 with SourceRelativeURI

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;
}
Also used : ISourceFolder(org.eclipse.xtext.workspace.ISourceFolder) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 14 with SourceRelativeURI

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;
}
Also used : ILocationData(org.eclipse.xtext.generator.trace.ILocationData) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 15 with SourceRelativeURI

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();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IContainer(org.eclipse.core.resources.IContainer) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Aggregations

SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)22 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)7 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)5 IFile (org.eclipse.core.resources.IFile)4 IPath (org.eclipse.core.runtime.IPath)4 URI (org.eclipse.emf.common.util.URI)4 AbsoluteURI (org.eclipse.xtext.generator.trace.AbsoluteURI)4 ILocationData (org.eclipse.xtext.generator.trace.ILocationData)4 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)4 InputStream (java.io.InputStream)3 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IStorage (org.eclipse.core.resources.IStorage)2 Path (org.eclipse.core.runtime.Path)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 IEditorInput (org.eclipse.ui.IEditorInput)2