/** * If the given resource is a {@link LazyLinkingResource} the implementation delegates * to {@link LazyLinkingResource#resolveLazyCrossReferences(CancelIndicator)} otherwise to * {@link EcoreUtil2#resolveAll(Resource, CancelIndicator)}. */ public static void resolveLazyCrossReferences(Resource resource, CancelIndicator monitor) { if (resource instanceof LazyLinkingResource) { ((LazyLinkingResource) resource).resolveLazyCrossReferences(monitor); } else { resolveAll(resource, monitor); } }
public Model extract(final String modelName) { FunctionblockPackage.eINSTANCE.eClass(); InformationModelPackage.eINSTANCE.eClass(); ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(this.zipFile)); ZipEntry entry = null; FunctionblockStandaloneSetup.doSetup(); Injector injector = new InformationModelStandaloneSetup().createInjectorAndDoEMFRegistration(); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); Resource infoModelResource = null; try { while ((entry = zis.getNextEntry()) != null) { Resource resource = resourceSet.createResource(URI.createURI("fake:/" + entry.getName())); resource.load(new ByteArrayInputStream(copyStream(zis, entry)), resourceSet.getLoadOptions()); if (((Model) resource.getContents().get(0)).getName().equals(modelName)) { infoModelResource = resource; } } } catch (Exception ex) { ex.printStackTrace(); } EcoreUtil2.resolveAll(resourceSet); return (Model)infoModelResource.getContents().get(0); }
ex.printStackTrace(); EcoreUtil2.resolveAll(resourceSet); for (Resource resource : resourceSet.getResources()) { if (resource.getContents().get(0) instanceof MappingModel) {
static JvmParameterizedTypeReference parseType(Notifier context, String typeName, AbstractBuilder caller) { ResourceSet resourceSet = toResource(context).getResourceSet(); URI uri = caller.computeUnusedUri(resourceSet); Resource resource = caller.getResourceFactory().createResource(uri); resourceSet.getResources().add(resource); try (StringInputStream is = new StringInputStream(generateTypenameCode(typeName))) { resource.load(is, null); SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0); SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0); SarlField member = (SarlField) topElement.getMembers().get(0); JvmTypeReference reference = member.getType(); if (reference instanceof JvmParameterizedTypeReference) { final JvmParameterizedTypeReference pref = (JvmParameterizedTypeReference) reference; if (!pref.getArguments().isEmpty()) { EcoreUtil2.resolveAll(resource); return pref; } } } catch (Exception exception) { throw new TypeNotPresentException(typeName, exception); } finally { resourceSet.getResources().remove(resource); } throw new TypeNotPresentException(typeName, null); }
public T exec(XtextResource state) throws Exception { String original = document.get(); DocumentChangeListener documentChangeListener = new DocumentChangeListener(); T result; try { document.addDocumentListener(documentChangeListener); // lazy linking URIs might change, so resolve everything before applying any changes EcoreUtil2.resolveAll(state, CancelIndicator.NullImpl); composer.beginRecording(state); result = work.exec(state); final TextEdit edit = composer.endRecording(); if (edit != null) { if(documentChangeListener.hasDocumentChanged()) throw new IllegalStateException("Cannot modify document textually and semantically within the same unit of work"); edit.apply(document); } } catch (RuntimeException e) { document.set(original); throw e; } catch (Exception e) { document.set(original); throw new RuntimeException(e); } finally { document.removeDocumentListener(documentChangeListener); } return result; }