Search in sources :

Example 11 with Storage2UriMapperJavaImpl

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

the class Storage2UriMapperJdtImplTest method testBug463258_03c.

@Test
public void testBug463258_03c() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());
    addJarToClasspath(project, file);
    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
    fileInJar.setParent(foo);
    File jarFile = file.getLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());
    // simulate an automated refresh
    file.refreshLocal(IResource.DEPTH_ONE, null);
    URI uri = impl.getUri(fileInJar);
    assertNull(uri);
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) File(java.io.File) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 12 with Storage2UriMapperJavaImpl

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

the class Storage2UriMapperJavaImplTest method createFreshStorage2UriMapper.

protected Storage2UriMapperJavaImpl createFreshStorage2UriMapper() {
    Storage2UriMapperJavaImpl mapper = new Storage2UriMapperJavaImpl();
    mapper.setUriValidator(new UriValidator() {

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }
    });
    mapper.setLocator(new JarEntryLocator());
    mapper.setWorkspace(ResourcesPlugin.getWorkspace());
    mapper.setWorkspaceLockAccess(new WorkspaceLockAccess());
    mapper.setJavaProjectClasspathChangeAnalyzer(new JavaProjectClasspathChangeAnalyzer());
    return mapper;
}
Also used : WorkspaceLockAccess(org.eclipse.xtext.ui.workspace.WorkspaceLockAccess) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) JarEntryLocator(org.eclipse.xtext.ui.resource.JarEntryLocator) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) JavaProjectClasspathChangeAnalyzer(org.eclipse.xtext.ui.util.JavaProjectClasspathChangeAnalyzer) URI(org.eclipse.emf.common.util.URI)

Example 13 with Storage2UriMapperJavaImpl

use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl 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)

Aggregations

URI (org.eclipse.emf.common.util.URI)13 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)13 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)10 Test (org.junit.Test)10 IFile (org.eclipse.core.resources.IFile)8 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)7 TextFile (org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile)7 IStorage (org.eclipse.core.resources.IStorage)6 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)6 File (java.io.File)3 JarEntryLocator (org.eclipse.xtext.ui.resource.JarEntryLocator)3 UriValidator (org.eclipse.xtext.ui.resource.UriValidator)3 IFolder (org.eclipse.core.resources.IFolder)2 WorkspaceLockAccess (org.eclipse.xtext.ui.workspace.WorkspaceLockAccess)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 InputStream (java.io.InputStream)1 IResource (org.eclipse.core.resources.IResource)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1