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: 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 #2
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 #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: 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 #7
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 #8
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 #9
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 #10
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 #11
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 #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: 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 #15
Source File: XBuildContext.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Run the given logic on all uris with clustering enabled. */ public <T> List<T> executeClustered(Iterable<URI> uri, Function1<? super Resource, ? extends T> operation) { if (this.loader == null) { this.loader = new XClusteringStorageAwareResourceLoader(this); } return this.loader.executeClustered(Iterables.filter(uri, this::canHandle), operation); }
Example #16
Source File: JdtAwareProjectByResourceProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public IProject getProjectContext(Resource resource) { IProject result = super.getProjectContext(resource); if (result != null) { return result; } IJavaProject javaProject = javaProjectProvider.getJavaProject(resource.getResourceSet()); if (javaProject != null && javaProject.exists()) { return javaProject.getProject(); } return null; }
Example #17
Source File: GlobalizeEditor.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@Override public void notifyChanged ( Notification notification ) { if ( notification.getNotifier () instanceof Resource ) { switch ( notification.getFeatureID ( Resource.class ) ) { case Resource.RESOURCE__IS_LOADED: case Resource.RESOURCE__ERRORS: case Resource.RESOURCE__WARNINGS: { Resource resource = (Resource)notification.getNotifier (); Diagnostic diagnostic = analyzeResourceProblems ( resource, null ); if ( diagnostic.getSeverity () != Diagnostic.OK ) { resourceToDiagnosticMap.put ( resource, diagnostic ); } else { resourceToDiagnosticMap.remove ( resource ); } if ( updateProblemIndication ) { getSite ().getShell ().getDisplay ().asyncExec ( new Runnable () { public void run () { updateProblemIndication (); } } ); } break; } } } else { super.notifyChanged ( notification ); } }
Example #18
Source File: WorkflowModelServerSubscriptionListener.java From graphical-lsp with Eclipse Public License 2.0 | 5 votes |
@Override public void onFullUpdate(EObject root) { LOG.debug("Full update from model server received"); WorkflowFacade facade = modelServerAccess.getWorkflowFacade(); Resource semanticResource = facade.getSemanticResource(); semanticResource.getContents().clear(); semanticResource.getContents().add(root); Resource notationResource = facade.getNotationResource(); updateNotationResource(facade, notationResource); }
Example #19
Source File: ModelRepositoryImpl.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Activate public ModelRepositoryImpl(final @Reference SafeEMF safeEmf) { this.safeEmf = safeEmf; XtextResourceSet xtextResourceSet = new SynchronizedXtextResourceSet(); xtextResourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); this.resourceSet = xtextResourceSet; // don't use XMI as a default Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().remove("*"); }
Example #20
Source File: PartialContentAssistTestLanguageGenerator.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 #21
Source File: ESBRepositoryContentHandler.java From tesb-studio-se with Apache License 2.0 | 5 votes |
private Resource create(IProject project, ServiceItem item, IPath path, ERepositoryObjectType type) throws PersistenceException { Resource itemResource = xmiResourceManager.createItemResource(project, item, path, type, false); itemResource.getContents().add(item.getConnection()); return itemResource; }
Example #22
Source File: XPDLToProc.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public File createDiagram(URL sourceURL, IProgressMonitor progressMonitor) throws IOException { try { progressMonitor.beginTask(Messages.importFromXPDL, 3); builder = new ProcBuilder(progressMonitor); final ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xpdl", new Xpdl1ResourceFactoryImpl()); final URI sourceURI = URI.createFileURI(new File(URI.decode(sourceURL.getFile())).getAbsolutePath()); final Resource resource = resourceSet.getResource(sourceURI, true); final DocumentRoot docRoot = (DocumentRoot) resource.getContents().get(0); final PackageType xpdlPackage = docRoot.getPackage(); final String diagramName = sourceURI.lastSegment(); String version = "1.0"; if (xpdlPackage.getRedefinableHeader() != null && xpdlPackage.getRedefinableHeader().getVersion() != null) { version = xpdlPackage.getRedefinableHeader().getVersion(); } result = File.createTempFile(diagramName, ".proc"); result.deleteOnExit(); builder.createDiagram(diagramName, xpdlPackage.getName(), version, result); importFromXPDL(xpdlPackage); builder.done(); return result; } catch (final ProcBuilderException e) { BonitaStudioLog.error(e); } return null; }
Example #23
Source File: Bpmn2XMLProcessor.java From fixflow with Apache License 2.0 | 5 votes |
/** * Register for "*" and "xml" file extensions the Bpmn2ResourceFactoryImpl factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected Map<String, Resource.Factory> getRegistrations() { if (registrations == null) { super.getRegistrations(); registrations.put(XML_EXTENSION, new Bpmn2ResourceFactoryImpl()); registrations.put(STAR_EXTENSION, new Bpmn2ResourceFactoryImpl()); } return registrations; }
Example #24
Source File: ImportActorMappingAction.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public void run() { if(filePath == null){ FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN) ; dialog.setFilterExtensions(new String[]{"*.xml"}) ; filePath = dialog.open() ; } if(filePath != null){ URI uri = URI.createFileURI(filePath) ; Resource resource = new ActorMappingResourceFactoryImpl().createResource(uri) ; Map<String, String> options = new HashMap<String, String>() ; options.put(XMLResource.OPTION_ENCODING, "UTF-8"); options.put(XMLResource.OPTION_XML_VERSION, "1.0"); try { resource.load(options) ; } catch (IOException e) { BonitaStudioLog.error(e) ; } if(!resource.getContents().isEmpty()){ EObject root = resource.getContents().get(0); if(root instanceof DocumentRoot){ ActorMappingsType mappings = ((DocumentRoot) root).getActorMappings() ; for(ActorMapping mapping : mappings.getActorMapping()){ for(ActorMapping configurationMapping : configuration.getActorMappings().getActorMapping()){ if(configurationMapping.getName().equals(mapping.getName())){ configurationMapping.setGroups(mapping.getGroups()) ; configurationMapping.setRoles(mapping.getRoles()) ; configurationMapping.setUsers(mapping.getUsers()) ; configurationMapping.setMemberships(mapping.getMemberships()) ; } } } } } } }
Example #25
Source File: ResourceSetReferencingResourceSetImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Resource getResource(URI uri, boolean loadOnDemand) { Resource resource = findResourceInResourceSet(uri, this); Iterator<ResourceSet> iterator = referencedResourceSets.iterator(); while (resource == null && iterator.hasNext()) { resource = findResourceInResourceSet(uri, iterator.next()); } if (resource!=null) return load(resource,loadOnDemand); return super.getResource(uri, loadOnDemand); }
Example #26
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testHashMap_01() { String typeName = HashMap.class.getName(); JvmType type = getTypeProvider().findTypeByName(typeName); assertNotNull(type); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
Example #27
Source File: Utils.java From slr-toolkit with Eclipse Public License 1.0 | 5 votes |
/** * Returns the resource file which contains the given bibtex document. Bases * on {@link http://www.eclipse.org/forums/index.php?t=msg&th=128695/} * * @param doc * {@link Document} whom's resource is wanted * @return {@link IFile} which contains doc. <code>null</code> if nothing * was found. */ public static IFile getIFilefromEMFResource(Resource resource) { if (resource == null) { return null; } // TODO: remove logbuffer logBuffer = new StringBuffer(); URI uri = resource.getURI(); if(resource.getResourceSet() == null){ return null; } uri = resource.getResourceSet().getURIConverter().normalize(uri); String scheme = uri.scheme(); logBuffer.append("URI Scheme: " + scheme + "\n"); if ("platform".equals(scheme) && uri.segmentCount() > 1 && "resource".equals(uri.segment(0))) { StringBuffer platformResourcePath = new StringBuffer(); for (int j = 1, size = uri.segmentCount(); j < size; ++j) { platformResourcePath.append('/'); platformResourcePath.append(uri.segment(j)); } logBuffer.append("Platform path " + platformResourcePath.toString() + "\n"); IResource parent = ResourcesPlugin.getWorkspace().getRoot() .getFile(new Path(platformResourcePath.toString())); // TODO: remove syso logBuffer.append("IResource " + parent); if (parent instanceof IFile) { return (IFile) parent; } } // System.out.println(logBuffer.toString()); return null; }
Example #28
Source File: CodeBuilderFactory.java From sarl with Apache License 2.0 | 5 votes |
/** Create the appender for a Sarl SarlSpace. * @param name the name of the SarlSpace * @param resource the resource that must be used for * containing the generated resource, and resolving types from names. * @return the appender. */ @Pure public SarlSpaceSourceAppender buildSarlSpace(String name, Resource resource) { SarlSpaceSourceAppender a = new SarlSpaceSourceAppender(createSarlSpace(name, resource)); getInjector().injectMembers(a); return a; }
Example #29
Source File: ClasspathTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug337307() { String typeName = "ClassWithDefaultPackage"; JvmType type = getTypeProvider().findTypeByName(typeName); assertNotNull(type); assertTrue(type instanceof JvmGenericType); assertEquals(typeName, type.getIdentifier()); assertEquals(typeName, type.getQualifiedName()); assertEquals(typeName, type.getSimpleName()); assertNull(((JvmDeclaredType) type).getPackageName()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
Example #30
Source File: StorageAwareResourceDescriptionManager.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public IResourceDescription getResourceDescription(Resource resource) { if (resource instanceof StorageAwareResource) { IResourceDescription result = ((StorageAwareResource) resource).getResourceDescription(); if (result != null) { return result; } } return super.getResourceDescription(resource); }