Search in sources :

Example 6 with UriValidator

use of org.eclipse.xtext.ui.resource.UriValidator in project xtext-eclipse by eclipse.

the class AbstractJavaProjectsStateTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    javaProject1 = makeJavaProject(project1);
    addSourceFolder(javaProject1, "src2");
    uri1 = createFileAndRegisterResource(project1, "src/file1");
    uri2 = createFileAndRegisterResource(project1, "src/file2");
    uri3 = createFileAndRegisterResource(project2, "src2/file3");
    IResource member = javaProject1.getProject().findMember("src");
    srcRoot = javaProject1.getPackageFragmentRoot(member);
    Storage2UriMapperImpl mapper = new Storage2UriMapperImpl() {

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

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return "name".equals(uri.fileExtension());
        }

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return "name".equals(storage.getFullPath().getFileExtension());
        }
    };
    mapper.setUriValidator(uriValidator);
    Storage2UriMapperJavaImpl contribution = new Storage2UriMapperJavaImpl();
    contribution.setUriValidator(uriValidator);
    contribution.setJdtHelper(new JdtHelper());
    contribution.setWorkspaceLockAccess(new WorkspaceLockAccess());
    contribution.setLocator(new JarEntryLocator());
    contribution.setHost(mapper);
    mapper.setContribution(contribution);
    projectsState = createProjectsState(mapper);
}
Also used : WorkspaceLockAccess(org.eclipse.xtext.ui.workspace.WorkspaceLockAccess) Storage2UriMapperImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperImpl) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) JdtHelper(org.eclipse.xtext.ui.shared.JdtHelper) JarEntryLocator(org.eclipse.xtext.ui.resource.JarEntryLocator) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource)

Example 7 with UriValidator

use of org.eclipse.xtext.ui.resource.UriValidator in project xtext-eclipse by eclipse.

the class Storage2UriMapperTest method testSimpleFileInProject.

@Test
public void testSimpleFileInProject() throws Exception {
    IFile file = createFile("foo/bar/baz.txt", "");
    Storage2UriMapperImpl mapper = new Storage2UriMapperImpl() {

        @Override
        public boolean isValidUri(URI uri, IStorage storage) {
            return true;
        }
    };
    mapper.setUriValidator(new UriValidator() {

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

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return true;
        }
    });
    URI uri = mapper.getUri(file);
    assertEquals(URI.createPlatformResourceURI(file.getFullPath().toString(), true), uri);
    assertEquals(file, mapper.getStorages(uri).iterator().next().getFirst());
}
Also used : IFile(org.eclipse.core.resources.IFile) Storage2UriMapperImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperImpl) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Aggregations

UriValidator (org.eclipse.xtext.ui.resource.UriValidator)7 IStorage (org.eclipse.core.resources.IStorage)6 URI (org.eclipse.emf.common.util.URI)6 Storage2UriMapperImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperImpl)4 JarEntryLocator (org.eclipse.xtext.ui.resource.JarEntryLocator)3 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)3 WorkspaceProjectsState (org.eclipse.xtext.ui.containers.WorkspaceProjectsState)2 WorkspaceProjectsStateHelper (org.eclipse.xtext.ui.containers.WorkspaceProjectsStateHelper)2 WorkspaceLockAccess (org.eclipse.xtext.ui.workspace.WorkspaceLockAccess)2 Test (org.junit.Test)2 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 ProjectDescriptionBasedContainerManager (org.eclipse.xtext.resource.containers.ProjectDescriptionBasedContainerManager)1 StateBasedContainerManager (org.eclipse.xtext.resource.containers.StateBasedContainerManager)1 JdtHelper (org.eclipse.xtext.ui.shared.JdtHelper)1 JavaProjectClasspathChangeAnalyzer (org.eclipse.xtext.ui.util.JavaProjectClasspathChangeAnalyzer)1 ReflectExtensions (org.eclipse.xtext.xbase.lib.util.ReflectExtensions)1