diff options
Diffstat (limited to 'plugins/org.eclipse.m2m.qvt.oml/src/org/eclipse/m2m/internal/qvt/oml')
-rw-r--r-- | plugins/org.eclipse.m2m.qvt.oml/src/org/eclipse/m2m/internal/qvt/oml/ModelExtentHelper.java | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/plugins/org.eclipse.m2m.qvt.oml/src/org/eclipse/m2m/internal/qvt/oml/ModelExtentHelper.java b/plugins/org.eclipse.m2m.qvt.oml/src/org/eclipse/m2m/internal/qvt/oml/ModelExtentHelper.java index 417b85032..81e834d8e 100644 --- a/plugins/org.eclipse.m2m.qvt.oml/src/org/eclipse/m2m/internal/qvt/oml/ModelExtentHelper.java +++ b/plugins/org.eclipse.m2m.qvt.oml/src/org/eclipse/m2m/internal/qvt/oml/ModelExtentHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 R.Dvorak and others. + * Copyright (c) 2009, 2018 R.Dvorak and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Radek Dvorak - initial API and implementation + * C.Gerking/E.Willink - Bug 534077 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml; @@ -55,14 +56,14 @@ public class ModelExtentHelper { this.saveAsURI = saveAsURI; } } - - + + private final OperationalTransformation fTransformation; private final List<URI> fModelExtentURIs; private final LinkedHashMap<ModelParameter, ExtentEntry> fExtentMap; private final ResourceSet fResourceSet; - - + + public ModelExtentHelper(OperationalTransformation transformation, List<URI> modelExtentURIs, ResourceSet resSet) { if(transformation == null || modelExtentURIs == null || modelExtentURIs.contains(null)) { throw new IllegalArgumentException(); @@ -73,15 +74,15 @@ public class ModelExtentHelper { fExtentMap = new LinkedHashMap<ModelParameter, ExtentEntry>(); fResourceSet = resSet; } - + public ResourceSet getResourceSet() { return fResourceSet; }; - + public Diagnostic saveExtents(Boolean isQvtoUnparseEnabled) { BasicDiagnostic diagnostic = QvtPlugin.createDiagnostic("Save model param extents diagnostic"); - - Set<Resource> resources = new HashSet<Resource>(); + + Set<Resource> resources = new HashSet<Resource>(); for (ExtentEntry nextEntry : fExtentMap.values()) { URI saveAsURI = nextEntry.saveAsURI; @@ -89,19 +90,18 @@ public class ModelExtentHelper { resources.addAll(addExtentContentsToResources(nextEntry.extent.getContents(), fResourceSet, saveAsURI)); } } - + Map<Object, Object> options = new LinkedHashMap<Object, Object>(EmfUtil.DEFAULT_SAVE_OPTIONS); options.put(QVTEvaluationOptions.FLAG_QVTO_UNPARSE_ENABLED, isQvtoUnparseEnabled); - + for (Resource outExtent : resources) { try { EmfUtil.saveModel(outExtent, options); } catch (EmfException e) { - diagnostic.add(QvtPlugin.createErrorDiagnostic( - "Failed to save model extent uri=" + outExtent.getURI(), e)); + diagnostic.add(BasicDiagnostic.toDiagnostic(e)); } - + URIUtils.refresh(outExtent.getURI()); } @@ -113,7 +113,7 @@ public class ModelExtentHelper { if(params.size() > fModelExtentURIs.size()) { throw new DiagnosticException(QvtPlugin.createErrorDiagnostic(NLS.bind( Messages.InvalidModelParameterCountError, fModelExtentURIs - .size(), params.size()), null)); + .size(), params.size()), null)); } int i = 0; @@ -121,8 +121,8 @@ public class ModelExtentHelper { URI uri = fModelExtentURIs.get(i++); DirectionKind kind = nextParam.getKind(); URI saveAsURI = (kind != DirectionKind.IN) ? uri : null; - URI loadURI = (kind != DirectionKind.OUT) ? uri : null; - + URI loadURI = (kind != DirectionKind.OUT) ? uri : null; + ModelExtent extent; if(loadURI != null) { extent = loadExtent(nextParam, loadURI, fResourceSet); @@ -130,19 +130,19 @@ public class ModelExtentHelper { extent = new BasicModelExtent(); } - ExtentEntry entry = new ExtentEntry(extent, saveAsURI); + ExtentEntry entry = new ExtentEntry(extent, saveAsURI); fExtentMap.put(nextParam, entry); } - + return getExtents(); - } - - private ModelExtent loadExtent(ModelParameter modelParameter, URI uri, ResourceSet rs) throws DiagnosticException { + } + + private ModelExtent loadExtent(ModelParameter modelParameter, URI uri, ResourceSet rs) throws DiagnosticException { Throwable error; try { Resource res = rs.getResource(uri, true); EList<EObject> contents = res.getContents(); - + if(!res.getErrors().isEmpty()) { for (Resource.Diagnostic d : res.getErrors()) { // just take the first to manifest something is wrong @@ -150,18 +150,18 @@ public class ModelExtentHelper { d.getMessage(), null)); } } - + return new BasicModelExtent(contents); - + } catch (WrappedException e) { error = (e.getCause() != null) ? e.getCause() : e; } catch (RuntimeException e) { error = e; } - + throw new DiagnosticException(QvtPlugin.createErrorDiagnostic("Failed to load model extent uri=" + uri, error)); } - + private List<ModelExtent> getExtents() { List<ModelExtent> result = new ArrayList<ModelExtent>(fExtentMap.size()); for (ExtentEntry extentEntry : fExtentMap.values()) { @@ -169,27 +169,27 @@ public class ModelExtentHelper { } return result; } - + /** - * Adds given MOF extent (represented by 'rootContents') to all appropriate resources in given ResourceSet (represented by 'resSet'). - * Takes into account that EObject's containment hierarchy may split between different Resources. - * - * @param rootContents - * @param resSet - * @param outUri - * @return the set of affected resources - */ + * Adds given MOF extent (represented by 'rootContents') to all appropriate resources in given ResourceSet (represented by 'resSet'). + * Takes into account that EObject's containment hierarchy may split between different Resources. + * + * @param rootContents + * @param resSet + * @param outUri + * @return the set of affected resources + */ private static Set<Resource> addExtentContentsToResources(List<EObject> rootContents, ResourceSet resSet, URI outUri) { URI modelUri = outUri.trimFragment(); Resource outExtent = resSet.getResource(modelUri, false); if(outExtent == null) { - outExtent = EmfUtil.createResource(modelUri, resSet); + outExtent = EmfUtil.createResource(modelUri, resSet); resSet.getResources().add(outExtent); } - + Map<Resource, List<EObject>> linkedExtents = new LinkedHashMap<Resource, List<EObject>>(); linkedExtents.put(outExtent, rootContents); - + TreeIterator<EObject> allContents = EcoreUtil.getAllContents(rootContents, false); while (allContents.hasNext()) { EObject eObject = allContents.next(); @@ -205,12 +205,12 @@ public class ModelExtentHelper { } } } - + for (Map.Entry<Resource, List<EObject>> nextExtent : linkedExtents.entrySet()) { Resource rs = nextExtent.getKey(); mergeExtentToResource(rs, nextExtent.getValue()); } - + return linkedExtents.keySet(); } @@ -228,14 +228,14 @@ public class ModelExtentHelper { } else { Set<EObject> resolvedRootElements = EmfUtil.getResolvedContent(essentialRootElements, outExtent.getContents().get(0)); - + for (TreeIterator<EObject> it = outExtent.getAllContents(); it.hasNext();) { EObject eObject = it.next(); if (!resolvedRootElements.contains(eObject)) { eObject.eAdapters().clear(); } } - + outExtent.getContents().retainAll(resolvedRootElements); for (EObject eObject : outExtent.getContents()) { @@ -244,12 +244,12 @@ public class ModelExtentHelper { internalEObject.eSetResource((Resource.Internal) outExtent, null); } } - + resolvedRootElements.removeAll(outExtent.getContents()); addAllContents(outExtent.getContents(), resolvedRootElements); } } - + private static Set<EObject> getEssentialRootElements(List<? extends EObject> allRootElements) { Set<EObject> roots = new LinkedHashSet<EObject>(); for (EObject e : allRootElements) { @@ -262,13 +262,13 @@ public class ModelExtentHelper { return roots; } - private static void addAllContents(EList<EObject> contents, Set<EObject> elements) { - if (contents instanceof AbstractEList<?>) { - ((AbstractEList<EObject>) contents).addAllUnique(elements); - } - else { - contents.addAll(elements); - } - } - + private static void addAllContents(EList<EObject> contents, Set<EObject> elements) { + if (contents instanceof AbstractEList<?>) { + ((AbstractEList<EObject>) contents).addAllUnique(elements); + } + else { + contents.addAll(elements); + } + } + } |