Search in sources :

Example 21 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile 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 22 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.

the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_03b.

@Test(expected = CoreException.class)
public void testBug463258_03b() throws Throwable {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.testlanguage", "//empty")), true, monitor());
    IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
    fileInJar.setParent(foo);
    File jarFile = file.getLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());
    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    try {
        factory.createResource(editorInput);
    } catch (WrappedException e) {
        throw e.getCause();
    }
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) WrappedException(org.eclipse.emf.common.util.WrappedException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) File(java.io.File) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IFile(org.eclipse.core.resources.IFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Example 23 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.

the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_01.

@Test
public void testBug463258_01() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/A.testlanguage", "//empty")), true, monitor());
    addJarToClasspath(project, file);
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("A.testlanguage");
    fileInJar.setParent(foo);
    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    Resource resource = factory.createResource(editorInput);
    assertNotNull(resource);
    resource.load(null);
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) NonJavaResource(org.eclipse.jdt.internal.core.NonJavaResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Aggregations

IFile (org.eclipse.core.resources.IFile)23 IJavaProject (org.eclipse.jdt.core.IJavaProject)23 TextFile (org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile)23 Test (org.junit.Test)23 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)12 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)10 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)10 URI (org.eclipse.emf.common.util.URI)7 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)7 File (java.io.File)6 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)5 XtextReadonlyEditorInput (org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput)5 AbstractWorkbenchTest (org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)5 IProject (org.eclipse.core.resources.IProject)3 IResource (org.eclipse.core.resources.IResource)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 NonJavaResource (org.eclipse.jdt.internal.core.NonJavaResource)3 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)3 IOException (java.io.IOException)2 IStorage (org.eclipse.core.resources.IStorage)2