org.eclipse.emf.ecore.resource.Resource Java Examples
The following examples show how to use
org.eclipse.emf.ecore.resource.Resource.
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: AbstractConstantExpressionsInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected String getOperator(final XAbstractFeatureCall call) { String _switchResult = null; Resource _eResource = call.eResource(); final Resource res = _eResource; boolean _matched = false; if (res instanceof StorageAwareResource) { boolean _isLoadedFromStorage = ((StorageAwareResource)res).isLoadedFromStorage(); if (_isLoadedFromStorage) { _matched=true; QualifiedName _operator = this.operatorMapping.getOperator(QualifiedName.create(call.getFeature().getSimpleName())); String _string = null; if (_operator!=null) { _string=_operator.toString(); } return _string; } } if (!_matched) { _switchResult = call.getConcreteSyntaxFeatureName(); } return _switchResult; }
Example #2
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testMemberCount_12() { String typeName = Fields.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); int constructorCount = Fields.class.getDeclaredConstructors().length; assertEquals(1, constructorCount); // default constructor int fieldCount = Fields.class.getDeclaredFields().length; assertEquals(7, fieldCount); int nestedCount = Fields.class.getDeclaredClasses().length; assertEquals(1, nestedCount); assertEquals(nestedCount + constructorCount + fieldCount, type.getMembers().size()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
Example #3
Source File: ExternalContentSupportTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testCreateResource_02() throws IOException { String grammarInstead = "grammar org.foo.bar with org.eclipse.xtext.common.Terminals\n" + "generate something 'http://something'\n" + "Model: name=ID;"; XtextResourceSet resourceSet = get(XtextResourceSet.class); resourceSet.setClasspathURIContext(getClass()); URI normalized = resourceSet.getURIConverter().normalize(URI.createURI("classpath:/org/eclipse/xtext/Xtext.xtext")); uriToContent.put(normalized, grammarInstead); support.configureResourceSet(resourceSet, this); Resource resource = resourceSet.createResource(normalized); assertNotNull(resource); assertFalse(resource.isLoaded()); resource.load(Collections.emptyMap()); assertEquals(1, resource.getContents().size()); assertEquals("org.foo.bar", ((Grammar) resource.getContents().get(0)).getName()); }
Example #4
Source File: Xtext2EcoreTransformer.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public void removeGeneratedPackages() { final ResourceSet resourceSet = grammar.eResource().getResourceSet(); final List<Resource> resources = resourceSet.getResources(); final Collection<EPackage> packages = getGeneratedPackages(); for(int i = 0; i < resources.size(); i++) { Resource r = resources.get(i); if (!(r instanceof GrammarResource)) { CONTENT: for (EObject content : r.getContents()) { if (content instanceof EPackage && packages.contains(content) || generatedEPackages != null && generatedEPackages.containsValue(content)) { clearPackage(r, (EPackage) content); break CONTENT; } } } } }
Example #5
Source File: ProcessNavigatorActionProvider.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * @generated */ private static IEditorInput getEditorInput(Diagram diagram) { Resource diagramResource = diagram.eResource(); for (EObject nextEObject : diagramResource.getContents()) { if (nextEObject == diagram) { return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource)); } if (nextEObject instanceof Diagram) { break; } } URI uri = EcoreUtil.getURI(diagram); String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram); IEditorInput editorInput = new URIEditorInput(uri, editorName); return editorInput; }
Example #6
Source File: DeploymentEditor.java From neoscada with Eclipse Public License 1.0 | 6 votes |
/** * This returns whether something has been persisted to the URI of the specified resource. * The implementation uses the URI converter from the editor's resource set to try to open an input stream. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected boolean isPersisted ( Resource resource ) { boolean result = false; try { InputStream stream = editingDomain.getResourceSet ().getURIConverter ().createInputStream ( resource.getURI () ); if ( stream != null ) { result = true; stream.close (); } } catch ( IOException e ) { // Ignore } return result; }
Example #7
Source File: ComponentEditor.java From neoscada with Eclipse Public License 1.0 | 6 votes |
/** * This is the method called to load a resource into the editing domain's resource set based on the editor's input. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void createModel () { URI resourceURI = EditUIUtil.getURI ( getEditorInput (), editingDomain.getResourceSet ().getURIConverter () ); Exception exception = null; Resource resource = null; try { // Load the resource through the editing domain. // resource = editingDomain.getResourceSet ().getResource ( resourceURI, true ); } catch ( Exception e ) { exception = e; resource = editingDomain.getResourceSet ().getResource ( resourceURI, false ); } Diagnostic diagnostic = analyzeResourceProblems ( resource, exception ); if ( diagnostic.getSeverity () != Diagnostic.OK ) { resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) ); } editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter ); }
Example #8
Source File: SARLJvmModelInferrer.java From sarl with Apache License 2.0 | 6 votes |
private JvmTypeReference ensureValidType(Resource targetResource, JvmTypeReference returnType) { // No return type could be inferred => assume "void" if (returnType == null) { return this._typeReferenceBuilder.typeRef(Void.TYPE); } // The given type is not associated to the target resource => force relocation. final Resource returnTypeResource = returnType.eResource(); if (returnTypeResource != null && !Objects.equal(returnType.eResource(), targetResource)) { return this.typeBuilder.cloneWithProxies(returnType); } // A return type was inferred => use it as-is because it is not yet resolved to the concrete type. if (InferredTypeIndicator.isInferred(returnType)) { return returnType; } // A return was inferred and resolved => use it. return this.typeBuilder.cloneWithProxies(returnType); }
Example #9
Source File: DelegatingReferenceFinderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testExcludeLocalRefs() throws Exception { Resource refResource = loadResource("ref.refactoringtestlanguage", "D { ref A }"); EObject elementD = refResource.getContents().get(0).eContents().get(0); findRefs(elementA, resource, null); acceptor.assertFinished(); acceptor.expect(new DefaultReferenceDescription(elementD, elementA, RefactoringPackage.Literals.ELEMENT__REFERENCED, 0, EcoreUtil2.getPlatformResourceOrNormalizedURI(elementD))); findAllRefs(elementA, null); acceptor.assertFinished(); acceptor.expect(new DefaultReferenceDescription(elementD, elementA, RefactoringPackage.Literals.ELEMENT__REFERENCED, 0, EcoreUtil2.getPlatformResourceOrNormalizedURI(elementD))); findRefs(elementA, refResource, null); acceptor.assertFinished(); }
Example #10
Source File: ProcessDocumentProvider.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * @generated */ protected void updateCache(Object element) throws CoreException { ResourceSetInfo info = getResourceSetInfo(element); if (info != null) { for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) { Resource nextResource = it.next(); IFile file = WorkspaceSynchronizer.getFile(nextResource); if (file != null && file.isReadOnly()) { info.setReadOnly(true); info.setModifiable(false); return; } } info.setReadOnly(false); info.setModifiable(true); return; } }
Example #11
Source File: CrossflowNavigatorLinkHelper.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * @generated */ private static IEditorInput getEditorInput(Diagram diagram) { Resource diagramResource = diagram.eResource(); for (EObject nextEObject : diagramResource.getContents()) { if (nextEObject == diagram) { return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource)); } if (nextEObject instanceof Diagram) { break; } } URI uri = EcoreUtil.getURI(diagram); String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram); IEditorInput editorInput = new URIEditorInput(uri, editorName); return editorInput; }
Example #12
Source File: CrossflowDocumentProvider.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * @generated */ private long computeModificationStamp(ResourceSetInfo info) { int result = 0; for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) { Resource nextResource = it.next(); IFile file = WorkspaceSynchronizer.getFile(nextResource); if (file != null) { if (file.getLocation() != null) { result += file.getLocation().toFile().lastModified(); } else { result += file.getModificationStamp(); } } } return result; }
Example #13
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testFindTypeByName_javaLangNumber_01() { String typeName = Number.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertFalse("toplevel type is not static", type.isStatic()); assertEquals(type.getSuperTypes().toString(), 2, type.getSuperTypes().size()); JvmType objectType = type.getSuperTypes().get(0).getType(); assertFalse("isProxy: " + objectType, objectType.eIsProxy()); assertEquals(Object.class.getName(), objectType.getIdentifier()); JvmType serializableType = type.getSuperTypes().get(1).getType(); assertFalse("isProxy: " + serializableType, serializableType.eIsProxy()); assertEquals(Serializable.class.getName(), serializableType.getIdentifier()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
Example #14
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 #15
Source File: LabellingReferenceQueryExecutor.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected String getResourceName(EObject primaryTarget) { Resource resource = primaryTarget.eResource(); if (resource == null) return null; if (N4Scheme.isResourceWithN4Scheme(resource)) { return resource.getURI().lastSegment(); } return super.getResourceName(primaryTarget); }
Example #16
Source File: IndentationAwareUiTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { // Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); // Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { // // @Override // public String apply(Greeting greeting) { // return greeting.getName(); // } // }); // fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #17
Source File: Bug307519TestLanguageStandaloneSetupGenerated.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void register(Injector injector) { if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/ui/common/tests/2010/bug307519TestLanguage")) { EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/ui/common/tests/2010/bug307519TestLanguage", Bug307519TestLanguagePackage.eINSTANCE); } IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class); IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug307519testlanguage", resourceFactory); IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug307519testlanguage", serviceProvider); }
Example #18
Source File: GenconfUtilsTests.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
@Test public void getResolvedURINullResourceURI() { final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration(); final Resource resource = new ResourceImpl(); resource.getContents().add(generation); final URI uri = GenconfUtils.getResolvedURI(generation, URI.createURI("test")); assertEquals("test", uri.toString()); }
Example #19
Source File: IncrementalBuilder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Validate the resource and return true, if the build should proceed for the current state. */ protected boolean validate(Resource resource) { IResourceValidator resourceValidator = getResourceServiceProvider(resource).getResourceValidator(); if (resourceValidator == null) { return true; } List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, request.getCancelIndicator()); return request.getAfterValidate().afterValidate(resource.getURI(), validationResult); }
Example #20
Source File: ImplicitReferencesAdapter.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Returns all inferred and implicit references registered with this adapter. * * @return implicit references */ public Iterable<IReferenceDescription> getImplicitReferences() { final URI contextURI = ((Resource) getTarget()).getURI().appendFragment(IMPLICIT_FRAGMENT); final Set<IReferenceDescription> result = Sets.newHashSet(Iterables.transform(implicitReferences, new Function<URI, IReferenceDescription>() { @Override public IReferenceDescription apply(final URI target) { return new ReferenceDescription(contextURI, target.hasFragment() ? target : target.appendFragment(IMPLICIT_FRAGMENT), EcorePackage.Literals.EFACTORY__EPACKAGE, null, -1); } })); for (final URI uri : inferenceDependencies) { result.add(new ReferenceDescription(contextURI, uri.appendFragment(INFERRED_FRAGMENT), EcorePackage.Literals.EFACTORY__EPACKAGE, null, -1)); } return result; }
Example #21
Source File: PureXbaseJvmModelInferrer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public String name(final Resource res) { final String s = res.getURI().lastSegment(); int _length = s.length(); int _length_1 = ".xbase".length(); int _minus = (_length - _length_1); return s.substring(0, _minus); }
Example #22
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 #23
Source File: Bug302128TestLanguageStandaloneSetupGenerated.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void register(Injector injector) { IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class); IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug302128testlanguage", resourceFactory); IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug302128testlanguage", serviceProvider); if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2009/tmf/xtext/tests/bug302123")) { EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2009/tmf/xtext/tests/bug302123", Bug302128Package.eINSTANCE); } }
Example #24
Source File: ExtensionsEditor.java From ifml-editor with MIT License | 5 votes |
@Override protected void unsetTarget(Resource target) { basicUnsetTarget(target); resourceToDiagnosticMap.remove(target); if (updateProblemIndication) { getSite().getShell().getDisplay().asyncExec (new Runnable() { public void run() { updateProblemIndication(); } }); } }
Example #25
Source File: DefaultReferenceFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void findLocalReferencesInResource(final Predicate<URI> targetURIs, Resource resource, final IAcceptor<IReferenceDescription> acceptor) { Map<EObject, URI> exportedElementsMap = createExportedElementsMap(resource); for(EObject content: resource.getContents()) { findLocalReferencesFromElement(targetURIs, content, resource, acceptor, null, exportedElementsMap); } }
Example #26
Source File: CodetemplatesStandaloneSetupGenerated.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void register(Injector injector) { if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/codetemplate/Codetemplates")) { EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/codetemplate/Codetemplates", TemplatesPackage.eINSTANCE); } IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class); IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("codetemplates", resourceFactory); IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("codetemplates", serviceProvider); }
Example #27
Source File: GlobalRegistries.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static void initializeDefaults() { //EMF Standalone setup if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "ecore", new EcoreResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xmi", new XMIResourceFactoryImpl()); if (!EPackage.Registry.INSTANCE.containsKey(EcorePackage.eNS_URI)) EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE); }
Example #28
Source File: AbstractUnresolvableReferenceWithNode.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Resource.Diagnostic createDiagnostic(DiagnosticMessage message) { Diagnostic diagnostic = new XtextLinkingDiagnostic( node, message.getMessage(), message.getIssueCode(), message.getIssueData()); return diagnostic; }
Example #29
Source File: JvmModelTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testResourceDescriptionsAreCorrect() throws Exception { Resource resource = newResource("return s.toUpperCase"); boolean initialized = reflectExtensions.<Boolean> get(resource, "fullyInitialized").booleanValue(); Assert.assertFalse(initialized); IResourceDescription desc = manager.getResourceDescription(resource); List<Iterable<IEObjectDescription>> list = Lists.<Iterable<IEObjectDescription>> newArrayList(desc.getExportedObjects()); Assert.assertEquals(1, list.size()); Assert.assertFalse(reflectExtensions.<Boolean> get(resource, "fullyInitialized").booleanValue()); }
Example #30
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void diagnose(EObject object, String... expectedUnresolvedProxies) { Resource resource = object.eResource(); for (EObject content : resource.getContents()) { Diagnostic diagnostic = diagnostician.validate(content); if (diagnostic.getSeverity() != Diagnostic.OK) { URI[] expectedUnresolvedProxyURIs = new URI[expectedUnresolvedProxies.length]; for (int i = 0; i < expectedUnresolvedProxies.length; i++) { expectedUnresolvedProxyURIs[i] = URI.createURI(expectedUnresolvedProxies[i]); } diagnose(diagnostic, expectedUnresolvedProxyURIs); } } }