Search in sources :

Example 31 with IStorage

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

the class PreferenceStoreWhitespaceInformationProvider method getLineSeparatorPreference.

protected String getLineSeparatorPreference(URI uri) {
    if (uri.isPlatformResource()) {
        IFile file = workspace.getRoot().getFile(new Path(uri.toPlatformString(true)));
        String delimiter = senseLineDelimiter(file);
        if (delimiter != null)
            return delimiter;
    }
    IProject project = null;
    if (uri.isPlatformResource()) {
        project = workspace.getRoot().getProject(uri.segment(1));
    } else {
        for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(uri)) {
            project = storage.getSecond();
            break;
        }
    }
    if (project != null) {
        String result = getLineSeparatorPreference(new ProjectScope(project));
        if (result != null)
            return result;
    }
    @SuppressWarnings("all") String result = getLineSeparatorPreference(new InstanceScope());
    if (result != null)
        return result;
    return System.getProperty("line.separator");
}
Also used : Path(org.eclipse.core.runtime.Path) ProjectScope(org.eclipse.core.resources.ProjectScope) IFile(org.eclipse.core.resources.IFile) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject)

Example 32 with IStorage

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

the class XbaseResourceForEditorInputFactoryTest method testValidationIsDisabled_03.

@Test
public void testValidationIsDisabled_03() throws Exception {
    IProject project = AbstractXbaseUITestCase.createPluginProject("my.plugin.project");
    IJavaProject jp = JavaCore.create(project);
    boolean wasTested = false;
    for (IPackageFragmentRoot pfr : jp.getAllPackageFragmentRoots()) {
        if (pfr.isArchive()) {
            for (Object o : pfr.getNonJavaResources()) {
                if (o instanceof IStorage) {
                    assertTrue(isValidationDisabled((IStorage) o));
                    wasTested = true;
                }
            }
        }
    }
    assertTrue(wasTested);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 33 with IStorage

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

the class EclipseGeneratorConfigProvider method get.

@Override
public GeneratorConfig get(EObject context) {
    GeneratorConfig result = new GeneratorConfig();
    IProject project = null;
    if (context.eResource() != null) {
        Pair<IStorage, IProject> pair = Iterables.getFirst(storage2UriMapper.getStorages(context.eResource().getURI()), null);
        if (pair != null) {
            project = pair.getSecond();
        }
    }
    xbaseBuilderPreferenceAccess.loadBuilderPreferences(result, project);
    return result;
}
Also used : GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject)

Example 34 with IStorage

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

the class StorageAwareTrace method findStorage.

@Override
protected IStorage findStorage(SourceRelativeURI uri, IProject project) {
    AbsoluteURI resolvePath = resolvePath(uri);
    Iterable<Pair<IStorage, IProject>> allStorages = getStorage2uriMapper().getStorages(resolvePath.getURI());
    for (Pair<IStorage, IProject> storage : allStorages) {
        if (project.equals(storage.getSecond())) {
            return storage.getFirst();
        }
    }
    return null;
}
Also used : IStorage(org.eclipse.core.resources.IStorage) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Example 35 with IStorage

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

the class DerivedResourceMarkerBasedOpenerContributor method collectSourceFileOpeners.

@Override
public boolean collectSourceFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) {
    IStorage storage = getStorage(editor);
    if (storage instanceof IResource) {
        IResource resource = (IResource) storage;
        try {
            Set<URI> uris = Sets.newHashSet();
            IMarker[] markers = derivedResourceMarkers.findDerivedResourceMarkers(resource);
            for (IMarker marker : markers) {
                String source = derivedResourceMarkers.getSource(marker);
                if (source != null)
                    uris.add(URI.createURI(source));
            }
            for (URI uri : uris) for (Pair<IStorage, IProject> destination : storage2UriMapper.getStorages(uri)) acceptor.accept(createOpener(destination.getFirst()));
            return true;
        } catch (CoreException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource) 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