Java Code Examples for org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#getResource()
The following examples show how to use
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#getResource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractResourceSetTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testResourceLocatorIsUsed() { ResourceSetImpl rs = this.createEmptyResourceSet(); XtextResource resource = new XtextResource(); resource.setURI(URI.createFileURI(new File("foo").getAbsolutePath())); new ResourceSetImpl.ResourceLocator(rs) { @Override public Resource getResource(URI uri, boolean loadOnDemand) { if (Objects.equal(uri, resource.getURI())) { return resource; } throw new IllegalArgumentException(uri.toString()); } }; Assert.assertSame(resource, rs.getResource(resource.getURI(), true)); Assert.assertTrue(rs.getResources().isEmpty()); Assert.assertNull(resource.getResourceSet()); try { rs.getResource(resource.getURI().appendSegment("doesNotExist"), true); Assert.fail(); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("doesNotExist")); } }
Example 2
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * https://bugs.eclipse.org/bugs/show_bug.cgi?id=261630 */ @Test public void testBug261630_duplicateImports() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' import 'bar.importuritestlanguage' import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2"); models.addModel("bar.importuritestlanguage", "type bar type bar2 extends bar"); Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true); Main main = (Main) resource.getContents().get(0); assertEquals("bar", main.getTypes().get(0).getExtends().getName()); assertEquals("bar2", main.getTypes().get(0).getExtends().getExtends().getName()); assertEquals("bar", main.getTypes().get(0).getExtends().getExtends().getExtends().getName()); assertNull(main.getTypes().get(0).getExtends().getExtends().getExtends().getExtends()); }
Example 3
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testSimple() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar"); models.addModel("bar.importuritestlanguage", "type bar"); Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true); Main main = (Main) resource.getContents().get(0); assertEquals("bar", main.getTypes().get(0).getExtends().getName()); }
Example 4
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testRelativeScope() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("testfile://my/folder/foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2"); models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar"); Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true); Main main = (Main) resource.getContents().get(0); assertEquals("bar", main.getTypes().get(0).getExtends().getName()); assertEquals("bar2", main.getTypes().get(0).getExtends().getExtends().getName()); assertEquals("bar", main.getTypes().get(0).getExtends().getExtends().getExtends().getName()); assertNull(main.getTypes().get(0).getExtends().getExtends().getExtends().getExtends()); }
Example 5
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testRelativeScopeWithPath() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("testfile://my/folder/foo.importuritestlanguage", "import './../folder/bar.importuritestlanguage' type foo extends bar type bar extends bar2"); models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar"); Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true); Main main = (Main) resource.getContents().get(0); assertEquals("bar", main.getTypes().get(0).getExtends().getName()); assertEquals("bar2", main.getTypes().get(0).getExtends().getExtends().getName()); assertEquals("bar", main.getTypes().get(0).getExtends().getExtends().getExtends().getName()); assertNull(main.getTypes().get(0).getExtends().getExtends().getExtends().getExtends()); }
Example 6
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testScopeFileName() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2"); models.addModel("bar.importuritestlanguage", "type bar type bar2 extends bar"); Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true); Main main = (Main) resource.getContents().get(0); assertEquals("bar", main.getTypes().get(0).getExtends().getName()); assertEquals("bar2", main.getTypes().get(0).getExtends().getExtends().getName()); assertEquals("bar", main.getTypes().get(0).getExtends().getExtends().getExtends().getName()); assertNull(main.getTypes().get(0).getExtends().getExtends().getExtends().getExtends()); }
Example 7
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testUnresolvableImport() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("testfile://my/folder/foo.importuritestlanguage", "import 'unknownfile.importuritestlanguage' type foo extends bar type bar extends bar2"); Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true); assertNotNull(resource); }
Example 8
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCircularImport() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar"); models.addModel("bar.importuritestlanguage", "import 'foo.importuritestlanguage' type bar extends foo"); Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true); Main main = (Main) resource.getContents().get(0); assertEquals("bar", main.getTypes().get(0).getExtends().getName()); assertEquals("foo", main.getTypes().get(0).getExtends().getExtends().getName()); assertSame(main.getTypes().get(0).getExtends().getExtends(), main.getTypes().get(0)); }
Example 9
Source File: SimpleNameScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetAllContents() throws Exception { SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter(); ResourceSetImpl rs = new ResourceSetImpl(); rs.setURIConverter(models); models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type Foo"); models.addModel("bar.importuritestlanguage", "type A type B type C"); Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true); IScope scope = getScopeProvider().getScope(((Main)resource.getContents().get(0)).getTypes().get(0), ImportedURIPackage.Literals.TYPE__EXTENDS); HashSet<IEObjectDescription> set = Sets.newHashSet(scope.getAllElements()); assertEquals(4,set.size()); }
Example 10
Source File: PapyrusModelCreatorTest.java From txtUML with Eclipse Public License 1.0 | 5 votes |
@Test public void testSetUpUML() { IProject sourceproject = ProjectUtils.createProject("sourceProject"); String modelFilename = "dummy"; String tmpfolder = sourceproject.getLocation().toString(); URI uri = URI.createURI(tmpfolder).appendSegment(modelFilename).appendFileExtension(UMLResource.FILE_EXTENSION); URI urifile = URI.createFileURI(uri.toString()); String modelname = "TestModel"; createUMLFile(urifile, modelname); creator.setUpUML(urifile.toString()); IFile file = project.getFile("test."+UMLResource.FILE_EXTENSION); assertTrue(file.exists()); assertTrue(file.getFileExtension().equals(UMLResource.FILE_EXTENSION)); /* uml model asserts */ ResourceSetImpl RESOURCE_SET = new ResourceSetImpl(); Resource resource = RESOURCE_SET.getResource(urifile, true); org.eclipse.uml2.uml.Package package_ = (org.eclipse.uml2.uml.Package) EcoreUtil .getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE); assertTrue(package_ instanceof Model); assertTrue(package_.getName().equals(modelname)); }