Search in sources :

Example 26 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class Storage2UriMapperJavaImpl method clearCache.

protected void clearCache(IJavaProject project, Set<PackageFragmentRootData> toBeKept) {
    Collection<PackageFragmentRootData> values;
    synchronized (cachedPackageFragmentRootData) {
        values = newArrayList(cachedPackageFragmentRootData.values());
    }
    List<PackageFragmentRootData> toBeRemoved = newArrayList();
    for (PackageFragmentRootData data : values) {
        if (toBeKept.contains(data)) {
            continue;
        }
        Map<String, IPackageFragmentRoot> associatedRoots = data.associatedRoots;
        synchronized (associatedRoots) {
            Iterator<IPackageFragmentRoot> i = associatedRoots.values().iterator();
            IPackageFragmentRoot someRoot = null;
            boolean didChange = false;
            while (i.hasNext()) {
                IPackageFragmentRoot root = i.next();
                if (project.equals(root.getJavaProject())) {
                    i.remove();
                    didChange = true;
                } else if (someRoot == null) {
                    someRoot = root;
                }
            }
            if (associatedRoots.size() == 0) {
                toBeRemoved.add(data);
            } else if (didChange) {
                // get rid of cached storages that still point to roots / projects that are no longer available
                // and recompute them lazily on demand
                final IPackageFragmentRoot rootToProcess = someRoot;
                data.uri2Storage = new ForwardingMap<URI, IStorage>() {

                    Map<URI, IStorage> delegate;

                    @Override
                    protected Map<URI, IStorage> delegate() {
                        if (delegate == null) {
                            return delegate = initializeData(rootToProcess).uri2Storage;
                        }
                        return delegate;
                    }
                };
            }
        }
    }
    if (!toBeRemoved.isEmpty()) {
        synchronized (cachedPackageFragmentRootData) {
            cachedPackageFragmentRootData.values().removeAll(toBeRemoved);
        }
    }
}
Also used : ForwardingMap(com.google.common.collect.ForwardingMap) IStorage(org.eclipse.core.resources.IStorage) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ForwardingMap(com.google.common.collect.ForwardingMap) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 27 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class Storage2UriMapperJavaImpl method initializeData.

/**
 * @since 2.4
 */
protected PackageFragmentRootData initializeData(final IPackageFragmentRoot root) {
    final PackageFragmentRootData data = new PackageFragmentRootData(computeModificationStamp(root));
    data.addRoot(root);
    if (shouldHandle(root)) {
        try {
            final SourceAttachmentPackageFragmentRootWalker<Void> walker = new SourceAttachmentPackageFragmentRootWalker<Void>() {

                @Override
                protected URI getURI(IFile file, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
                    if (!uriValidator.isPossiblyManaged(file))
                        return null;
                    return super.getURI(file, state);
                }

                @Override
                protected URI getURI(IJarEntryResource jarEntry, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
                    if (!uriValidator.isPossiblyManaged(jarEntry))
                        return null;
                    final URI uri = locator.getURI(root, jarEntry, state);
                    if (!uriValidator.isValid(uri, jarEntry))
                        return null;
                    return uri;
                }

                @Override
                protected Void handle(URI uri, IStorage storage, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
                    data.uri2Storage.put(uri, storage);
                    return null;
                }
            };
            walker.traverse(root, false);
            if (walker.getBundleSymbolicName() != null)
                data.uriPrefix = URI.createPlatformResourceURI(walker.getBundleSymbolicName() + "/", true);
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
        } catch (JavaModelException e) {
            log.debug(e.getMessage(), e);
        }
    }
    return data;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource)

Example 28 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class XbaseBreakpointUtil method getBreakpointURI.

// this URI is only used for breakpoints on JARed files
public SourceRelativeURI getBreakpointURI(IEditorInput input) {
    IResource resource = Adapters.adapt(input, IResource.class);
    if (resource != null)
        return null;
    if (input instanceof IStorageEditorInput) {
        IStorage storage;
        try {
            storage = ((IStorageEditorInput) input).getStorage();
            if (storage instanceof IResource)
                return null;
            if (storage instanceof IJarEntryResource) {
                IJarEntryResource jarEntryResource = (IJarEntryResource) storage;
                if (!jarEntryResource.getPackageFragmentRoot().isArchive())
                    return null;
                Object parent = jarEntryResource.getParent();
                if (parent instanceof IPackageFragment) {
                    String path = ((IPackageFragment) parent).getElementName().replace('.', '/');
                    return new SourceRelativeURI(path + "/" + storage.getName());
                } else if (parent instanceof IPackageFragmentRoot) {
                    return new SourceRelativeURI(storage.getName());
                }
            }
        } catch (CoreException e) {
            logger.error("Error finding breakpoint URI", e);
            return null;
        }
    } else {
        IClassFile classFile = Adapters.adapt(input, IClassFile.class);
        if (classFile != null) {
            ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile);
            if (traceToSource == null)
                return null;
            for (ILocationInResource loc : traceToSource.getAllAssociatedLocations()) return loc.getSrcRelativeResourceURI();
            return null;
        }
    }
    return null;
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IClassFile(org.eclipse.jdt.core.IClassFile) IStorage(org.eclipse.core.resources.IStorage) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) CoreException(org.eclipse.core.runtime.CoreException) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) ITrace(org.eclipse.xtext.generator.trace.ITrace) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IResource(org.eclipse.core.resources.IResource)

Example 29 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class TraceEditor method updateText.

protected void updateText(EObject obj) {
    DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
    if (region == null) {
        text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
        return;
    }
    final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
    SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
    if (sourceURI == null) {
        text.setText("Could not find associated URI");
        return;
    }
    Registry registry = IResourceServiceProvider.Registry.INSTANCE;
    IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
    URI traceURI = obj.eResource().getURI();
    IStorage localStorage = getLocalStorage(serviceProvider, traceURI);
    StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
    traceProvider.setLocalStorage(localStorage);
    traceProvider.setTraceToSource(true);
    traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {

        @Override
        public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
            return trace;
        }
    });
    String newText = traceProvider.toString();
    text.setText(newText);
}
Also used : StorageAwareTrace(org.eclipse.xtext.ui.generator.trace.StorageAwareTrace) Registry(org.eclipse.xtext.resource.IResourceServiceProvider.Registry) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Example 30 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class QueuedBuildData method queueURI.

public void queueURI(URI uri) {
    Iterable<Pair<IStorage, IProject>> iterable = mapper.getStorages(uri);
    boolean associatedWithProject = false;
    for (Pair<IStorage, IProject> pair : iterable) {
        IProject project = pair.getSecond();
        if (XtextProjectHelper.hasNature(project) && XtextProjectHelper.hasBuilder(project)) {
            String projectName = project.getName();
            LinkedHashSetQueue<URI> list = projectNameToChangedResource.get(projectName);
            if (list == null) {
                list = new LinkedHashSetQueue<>();
                projectNameToChangedResource.put(projectName, list);
            }
            list.add(uri);
            associatedWithProject = true;
        }
    }
    if (!associatedWithProject) {
        this.uris.add(uri);
    }
}
Also used : IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6