Java Code Examples for org.eclipse.xtext.resource.XtextResourceSet#setClasspathURIContext()
The following examples show how to use
org.eclipse.xtext.resource.XtextResourceSet#setClasspathURIContext() .
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: FindReferencesTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testFindReferencesTypeLiteral() throws Exception { createFile("find.references.test/src/Test." + fileExtension, "com.acme.OtherwiseUnused::m()"); waitForBuild(); XtextResourceSet set = get(XtextResourceSet.class); set.setClasspathURIContext(JavaCore.create(project)); Resource resource = set.getResource(URI.createPlatformResourceURI("find.references.test/src/Test." + fileExtension, true), true); // obtain reference to type XMemberFeatureCall expression = (XMemberFeatureCall) resource.getContents().get(0); JvmType lookup = (JvmType) ((XAbstractFeatureCall) expression.getMemberCallTarget()).getFeature(); final MockAcceptor mockAcceptor = new MockAcceptor(); mockAcceptor.expect(expression.getMemberCallTarget(), lookup, XABSTRACT_FEATURE_CALL__FEATURE); findReferencesTester.checkFindReferences(lookup, "Java References to com.acme.OtherwiseUnused", mockAcceptor); }
Example 2
Source File: AbstractIncrementalBuilderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected BuildRequest newBuildRequest(Procedure1<? super BuildRequest> init) { BuildRequest result = new BuildRequest(); ResourceDescriptionsData newIndex = indexState.getResourceDescriptions().copy(); result.setBaseDir(uri("")); XtextResourceSet rs = resourceSetProvider.get(); rs.getURIConverter().getURIHandlers().clear(); rs.getURIConverter().getURIHandlers().add(inMemoryURIHandler); rs.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader()); ProjectDescription projectDescription = new ProjectDescription(); projectDescription.setName("test-project"); projectDescription.attachToEmfObject(rs); ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), rs); index.setContainer(projectDescription.getName(), newIndex); result.setResourceSet(rs); result.setDirtyFiles(new ArrayList<>()); result.setDeletedFiles(new ArrayList<>()); result.setAfterValidate((uri, issues) -> { Iterables.addAll(this.issues, issues); return Iterables.isEmpty(issues); }); result.setAfterDeleteFile(f -> deleted.add(f)); result.setAfterGenerateFile((source, target) -> generated.put(source, target)); result.setState(new IndexState(newIndex, indexState.getFileMappings().copy())); init.apply(result); return result; }
Example 3
Source File: Bug437669Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected Type getContext() { XtextResourceSet resourceSet = get(XtextResourceSet.class); resourceSet.setClasspathURIContext(getClass().getClassLoader()); URI uri = URI.createURI("classpath:/org/eclipse/xtext/linking/02.importuritestlanguage"); Resource resource = resourceSet.getResource(uri, true); Main main = (Main) resource.getContents().get(0); return main.getTypes().get(0); }
Example 4
Source File: DefaultResourceDescription2Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testClasspathURIIsNormalized() { XtextResourceSet xtextResourceSet = new XtextResourceSet(); xtextResourceSet.setClasspathURIContext(this); URI classpathURI = URI.createURI("classpath:/org/eclipse/xtext/XtextGrammarTestLanguage.ecore"); Resource resource = xtextResourceSet.getResource(classpathURI, true); IResourceDescription ecoreResourceDescription = createResourceDescription(resource); assertNotSame(classpathURI, ecoreResourceDescription.getURI()); assertEquals(xtextResourceSet.getURIConverter().normalize(classpathURI), ecoreResourceDescription.getURI()); }
Example 5
Source File: AbstractXtextTests.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected XtextResource doGetResource(InputStream in, URI uri) throws Exception { XtextResourceSet rs = get(XtextResourceSet.class); rs.setClasspathURIContext(getClass()); XtextResource resource = (XtextResource) getResourceFactory().createResource(uri); rs.getResources().add(resource); resource.load(in, null); if (resource instanceof LazyLinkingResource) { ((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl); } else { EcoreUtil.resolveAll(resource); } return resource; }
Example 6
Source File: AbstractPortableURIsTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { globalStateMemento = GlobalRegistries.makeCopyOfGlobalState(); EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE); resourceSet = new XtextResourceSet(); resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); resourceSet.getPackageRegistry().put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("genmodel", new EcoreResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/")); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); resourceSet.getLoadOptions().put(XMLResource.OPTION_URI_HANDLER, this); resourceSet.setClasspathURIContext(getClasspathURIContext()); }
Example 7
Source File: Xtext2EcoreTransformerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testEcoreReference_01() throws Exception { XtextResourceSet resourceSet = new XtextResourceSet(); Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap(); uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformPluginURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext.tests/src/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); uriMap.put(URI.createPlatformResourceURI("org.eclipse.xtext.tests/src/", false), URI.createURI("classpath:/")); resourceSet.setClasspathURIContext(this.getClass()); uriMap.put(URI.createURI("platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore"), URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore")); Assert.assertFalse( resourceSet.getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"), true) .getContents().isEmpty()); Assert.assertFalse(resourceSet.getResource(URI.createURI( "platform:/plugin/org.eclipse.xtext.tests/src/org/eclipse/xtext/metamodelreferencing/tests/EcorePerNsURI.ecore"), true).getContents().isEmpty()); Assert.assertFalse(resourceSet.getResource(URI.createURI( "platform:/plugin/org.eclipse.xtext.tests/src/org/eclipse/xtext/metamodelreferencing/tests/EcorePerPlatformResource.ecore"), true).getContents().isEmpty()); Assert.assertFalse(resourceSet.getResource(URI.createURI( "platform:/plugin/org.eclipse.xtext.tests/src/org/eclipse/xtext/metamodelreferencing/tests/EcorePerPlatformPlugin.ecore"), true).getContents().isEmpty()); Resource resource = resourceSet.getResource( URI.createURI( "classpath:/org/eclipse/xtext/metamodelreferencing/tests/EcoreReferenceTestLanguage.xtext"), true); XtextResource xtextResource = (XtextResource) resource; Assert.assertTrue(Joiner.on("\n").join(xtextResource.getErrors()), xtextResource.getErrors().isEmpty()); }
Example 8
Source File: Bug378261Test.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testReplaceResourceURIs() { XtextResourceSet xtextResourceSet = get(XtextResourceSet.class); xtextResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); xtextResourceSet.setClasspathURIContext(this); Resource grammarResource = xtextResourceSet.getResource(URI.createURI("classpath:/org/eclipse/xtext/generator/grammarAccess/GrammarAccessTestLanguage.xtext"), true); EcoreUtil.resolveAll(grammarResource); Grammar grammar = (Grammar) grammarResource.getContents().get(0); EPackage ePackage = grammar.getMetamodelDeclarations().get(0).getEPackage(); assertFalse(ePackage.eResource().getURI().equals(URI.createURI(ePackage.getNsURI()))); fragment.replaceResourceURIsWithNsURIs(grammar, xtextResourceSet); assertEquals(ePackage.eResource().getURI(), URI.createURI(ePackage.getNsURI())); }
Example 9
Source File: FragmentFakingEcoreResourceTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); XtextResourceSet set = new XtextResourceSet(); set.setClasspathURIContext(getClass()); Resource resource = set.getResource(URI.createURI("classpath:/org/eclipse/xtext/generator/grammarAccess/ametamodel.ecore"), true); metamodel = (EPackage) resource.getContents().get(0); }
Example 10
Source File: NoJRESmokeTester.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void processFile(String data) throws Exception { XtextResourceSet resourceSet = new XtextResourceSet(); NoOpClassLoader classLoader = new NoOpClassLoader(); resourceSet.setClasspathURIContext(classLoader); ClasspathTypeProviderFactory factory = new ClasspathTypeProviderFactory(classLoader, typeResourceServices); factory.createTypeProvider(resourceSet); EObject parsed = parseHelperNoJRE.parse(data, resourceSet); EcoreUtil.resolveAll(parsed); checkNoErrorsInValidator(data, (XtextResource) parsed.eResource()); }
Example 11
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected XtextResource getResourceFromString(String model, String uriString, XtextResourceSet rs) throws IOException { rs.setClasspathURIContext(getClasspathURIContext()); XtextResource resource = (XtextResource) getResourceFactory().createResource(URI.createURI(uriString)); rs.getResources().add(resource); resource.load(getAsStream(model), null); if (resource instanceof LazyLinkingResource) { ((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl); } else { EcoreUtil.resolveAll(resource); } return resource; }
Example 12
Source File: ReusedTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); if (ReusedTypeProviderTest.typeProvider == null) { String pathToSources = "/org/eclipse/xtext/common/types/testSetups"; List<String> files = ReusedTypeProviderTest.readResource(pathToSources + "/files.list"); ResourceDescriptionsData part = new ResourceDescriptionsData(Collections.emptySet()); XtextResourceSet resourceSet = resourceSetProvider.get(); ProjectDescription projectDesc = new ProjectDescription(); projectDesc.setName("my-test-project"); projectDesc.attachToEmfObject(resourceSet); ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), resourceSet); index.setContainer(projectDesc.getName(), part); resourceSet.setClasspathURIContext(ReusedTypeProviderTest.class.getClassLoader()); typeProviderFactory.createTypeProvider(resourceSet); BuildRequest buildRequest = new BuildRequest(); for (String file : files) { if (file != null) { String fullPath = pathToSources + "/" + file; URL url = ReusedTypeProviderTest.class.getResource(fullPath); buildRequest.getDirtyFiles().add(URI.createURI(url.toExternalForm())); } } buildRequest.setResourceSet(resourceSet); buildRequest.setState(new IndexState(part, new Source2GeneratedMapping())); builder.build(buildRequest, (URI it) -> { return resourceServiceProviderRegistry.getResourceServiceProvider(it); }); ReusedTypeProviderTest.typeProvider = typeProviderFactory.findTypeProvider(resourceSet); } }
Example 13
Source File: UriBasedReader.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void setClasspathURIContext(Object class1) { final XtextResourceSet resourceSet = new XtextResourceSet(); resourceSet.setClasspathURIContext(class1); setResourceSetProvider(new Provider<ResourceSet>() { @Override public ResourceSet get() { return resourceSet; } }); }
Example 14
Source File: AbstractContentAssistTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void initializeTypeProvider(final XtextResourceSet set) { final JdtTypeProviderFactory typeProviderFactory = new JdtTypeProviderFactory(this); typeProviderFactory.findOrCreateTypeProvider(set); set.setClasspathURIContext(getJavaProject(set)); }
Example 15
Source File: AbstractXbaseQuickfixTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public XtextResourceSet getResourceSet() { XtextResourceSet set = get(XtextResourceSet.class); set.setClasspathURIContext(getJavaProject(set)); return set; }
Example 16
Source File: AbstractURIHandlerTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public XtextResourceSet getNewResourceSet() { XtextResourceSet result = resourceSetProvider.get(); result.setClasspathURIContext(classLoader); return result; }
Example 17
Source File: AbstractXtendTestCase.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected XtextResourceSet getResourceSet() { XtextResourceSet set = resourceSetProvider.get(); set.setClasspathURIContext(getClass().getClassLoader()); return set; }
Example 18
Source File: AbstractXtendTestCase.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected XtextResourceSet getResourceSet() { XtextResourceSet set = resourceSetProvider.get(); set.setClasspathURIContext(getClass().getClassLoader()); return set; }
Example 19
Source File: CompilationTestHelper.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
private XtextResourceSet newResourceSetWithUTF8Encoding() { XtextResourceSet result = resourceSetProvider.get(); result.setClasspathURIContext(classpathUriContext); result.getLoadOptions().put(XtextResource.OPTION_ENCODING, StandardCharsets.UTF_8.name()); return result; }
Example 20
Source File: AbstractCheckContentAssistBugTest.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * Initializes the type provider used for accessing JvmTypes. * * @param set * the resource set */ protected void initializeTypeProvider(final XtextResourceSet set) { IJvmTypeProvider.Factory typeProviderFactory = new JdtTypeProviderFactory(this); typeProviderFactory.findOrCreateTypeProvider(set); set.setClasspathURIContext(getJavaProject(set)); }