Search in sources :

Example 76 with IStorage

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

the class JdtToBeBuiltComputer method updateProject.

@Override
public void updateProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    if (!project.isAccessible())
        return;
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject.exists()) {
        IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
        progress.setWorkRemaining(roots.length);
        final Map<String, Long> updated = Maps.newHashMap();
        ProjectOrder orderedProjects = workspace.computeProjectOrder(workspace.getRoot().getProjects());
        for (final IPackageFragmentRoot root : roots) {
            if (progress.isCanceled())
                throw new OperationCanceledException();
            if (shouldHandle(root) && !isBuiltByUpstream(root, project, orderedProjects.projects)) {
                Map<URI, IStorage> rootData = jdtUriMapperExtension.getAllEntries(root);
                for (Map.Entry<URI, IStorage> e : rootData.entrySet()) if (uriValidator.canBuild(e.getKey(), e.getValue())) {
                    toBeBuilt.getToBeDeleted().add(e.getKey());
                    toBeBuilt.getToBeUpdated().add(e.getKey());
                }
            }
            progress.worked(1);
        }
        synchronized (modificationStampCache) {
            modificationStampCache.projectToModificationStamp.putAll(updated);
        }
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) ProjectOrder(org.eclipse.core.resources.IWorkspace.ProjectOrder) Map(java.util.Map)

Example 77 with IStorage

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

the class WorkspaceProjectsStateTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    uri1 = createFileAndRegisterResource(project1, "file1");
    uri2 = createFileAndRegisterResource(project1, "file2");
    uri3 = createFileAndRegisterResource(project2, "file3");
    Storage2UriMapperImpl mapper = new Storage2UriMapperImpl() {

        @Override
        public boolean isValidUri(URI uri, IStorage storage) {
            return uri != null && !uri.toString().endsWith("/.project");
        }
    };
    mapper.setUriValidator(new UriValidator() {

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return true;
        }

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return true;
        }
    });
    projectsState = new WorkspaceProjectsState();
    projectsState.setMapper(mapper);
    WorkspaceProjectsStateHelper helper = new WorkspaceProjectsStateHelper();
    helper.setMapper(mapper);
    helper.setWorkspace(ResourcesPlugin.getWorkspace());
    projectsState.setHelper(helper);
}
Also used : WorkspaceProjectsState(org.eclipse.xtext.ui.containers.WorkspaceProjectsState) Storage2UriMapperImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperImpl) WorkspaceProjectsStateHelper(org.eclipse.xtext.ui.containers.WorkspaceProjectsStateHelper) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI)

Example 78 with IStorage

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

the class JavaBreakPointProvider method getJavaLineNumber.

private int getJavaLineNumber(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
    ILocationInEclipseResource javaLocation = getJavaLocation(breakpoint);
    if (javaLocation == null)
        return -1;
    IStorage storage = javaLocation.getPlatformResource();
    if (storage == null) {
        ITextRegionWithLineInformation textRegion = javaLocation.getTextRegion();
        if (textRegion == null)
            return -1;
        return textRegion.getEndLineNumber();
    } else {
        AbstractEclipseTrace sourceTrace = (AbstractEclipseTrace) traceForStorageProvider.getTraceToSource(storage);
        if (sourceTrace == null)
            return -1;
        AbstractTraceRegion rootTraceRegion = sourceTrace.getRootTraceRegion();
        if (rootTraceRegion == null)
            return -1;
        List<LineMapping> lineMappings = lineMappingProvider.getLineMapping(rootTraceRegion);
        if (lineMappings == null) {
            return -1;
        }
        for (LineMapping lineMapping : lineMappings) {
            if (lineMapping.sourceStartLine == breakpoint.getLineNumber()) {
                return lineMapping.targetEndLine + 1;
            }
        }
        return -1;
    }
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) IStorage(org.eclipse.core.resources.IStorage) AbstractEclipseTrace(org.eclipse.xtext.ui.generator.trace.AbstractEclipseTrace) LineMapping(org.eclipse.xtext.generator.trace.LineMappingProvider.LineMapping)

Example 79 with IStorage

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

the class EclipseResourceFileSystemAccess2 method getTraceFile.

/**
 * @since 2.3
 */
/* @Nullable */
protected IFile getTraceFile(IFile file) {
    IStorage traceFile = fileBasedTraceInformation.getTraceFile(file);
    if (traceFile instanceof IFile) {
        IFile result = (IFile) traceFile;
        syncIfNecessary(result);
        return result;
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) IStorage(org.eclipse.core.resources.IStorage)

Example 80 with IStorage

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

the class MarkerUpdaterImpl method processDelta.

private void processDelta(Delta delta, /* @Nullable */
ResourceSet resourceSet, IProgressMonitor monitor) throws OperationCanceledException {
    URI uri = delta.getUri();
    IResourceUIValidatorExtension validatorExtension = getResourceUIValidatorExtension(uri);
    IMarkerContributor markerContributor = getMarkerContributor(uri);
    CheckMode normalAndFastMode = CheckMode.NORMAL_AND_FAST;
    for (Pair<IStorage, IProject> pair : mapper.getStorages(uri)) {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        if (pair.getFirst() instanceof IFile) {
            IFile file = (IFile) pair.getFirst();
            if (EXTERNAL_PROJECT_NAME.equals(file.getProject().getName())) {
                // skip the marker processing of that file, as the user can't react on any markers anyway.
                continue;
            }
            if (delta.getNew() != null) {
                if (resourceSet == null)
                    throw new IllegalArgumentException("resourceSet may not be null for changed resources.");
                Resource resource = resourceSet.getResource(uri, true);
                if (validatorExtension != null) {
                    validatorExtension.updateValidationMarkers(file, resource, normalAndFastMode, monitor);
                }
                if (markerContributor != null) {
                    markerContributor.updateMarkers(file, resource, monitor);
                }
            } else {
                if (validatorExtension != null) {
                    validatorExtension.deleteValidationMarkers(file, normalAndFastMode, monitor);
                } else {
                    deleteAllValidationMarker(file, normalAndFastMode, monitor);
                }
                if (markerContributor != null) {
                    markerContributor.deleteMarkers(file, monitor);
                } else {
                    deleteAllContributedMarkers(file, monitor);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMarkerContributor(org.eclipse.xtext.ui.markers.IMarkerContributor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) CheckMode(org.eclipse.xtext.validation.CheckMode) IResourceUIValidatorExtension(org.eclipse.xtext.ui.validation.IResourceUIValidatorExtension) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

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