diff options
author | Ed Willink | 2017-08-16 15:21:44 +0000 |
---|---|---|
committer | Ed Willink | 2017-08-18 09:45:54 +0000 |
commit | 62cece163f9aedc49cc1433361ea230e1d1af630 (patch) | |
tree | 372f8ed4c6f74ac0e417f835f40e6e530aa167b8 | |
parent | c3a96d827e4fb9bd1cd8589a7057aed1443c3937 (diff) | |
download | org.eclipse.ocl-62cece163f9aedc49cc1433361ea230e1d1af630.tar.gz org.eclipse.ocl-62cece163f9aedc49cc1433361ea230e1d1af630.tar.xz org.eclipse.ocl-62cece163f9aedc49cc1433361ea230e1d1af630.zip |
[520847] Install imports between declaration/reference passes
3 files changed, 60 insertions, 39 deletions
diff --git a/plugins/org.eclipse.ocl.pivot.uml/src/org/eclipse/ocl/pivot/uml/internal/es2as/UML2AS.java b/plugins/org.eclipse.ocl.pivot.uml/src/org/eclipse/ocl/pivot/uml/internal/es2as/UML2AS.java index 3f2d0bb126..30e9ef9fe6 100644 --- a/plugins/org.eclipse.ocl.pivot.uml/src/org/eclipse/ocl/pivot/uml/internal/es2as/UML2AS.java +++ b/plugins/org.eclipse.ocl.pivot.uml/src/org/eclipse/ocl/pivot/uml/internal/es2as/UML2AS.java @@ -601,6 +601,8 @@ public abstract class UML2AS extends AbstractExternal2AS } } installImports(); + installAliases(asResource); + metamodelManager.installResource(asResource); installReferencers(); modelAnalysis.installStereotypes(); installProperties(); @@ -616,8 +618,6 @@ public abstract class UML2AS extends AbstractExternal2AS if (errors != null) { asResource.getErrors().addAll(errors); } - installAliases(asResource); - metamodelManager.installResource(asResource); ResourceSet resourceSet = umlResource.getResourceSet(); if (resourceSet != null) { environmentFactory.addExternalResources(resourceSet); // FIXME redundant ?? -- no updates URIResourceMap diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java index 197686e3c5..9c9c3d41a2 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java @@ -341,19 +341,6 @@ public class Ecore2AS extends AbstractExternal2AS if (pivotModel2 == null) { loadImports(ecoreResource); pivotModel2 = pivotModel = importObjects(ClassUtil.nonNullEMF(ecoreResource.getContents()), createPivotURI()); - @SuppressWarnings("null") @NonNull Resource asResource = pivotModel2.eResource(); - AliasAdapter ecoreAdapter = AliasAdapter.findAdapter(ecoreResource); - if (ecoreAdapter != null) { - Map<EObject, String> ecoreAliasMap = ecoreAdapter.getAliasMap(); - AliasAdapter pivotAdapter = AliasAdapter.getAdapter(asResource); - Map<EObject, String> pivotAliasMap = pivotAdapter.getAliasMap(); - for (EObject eObject : ecoreAliasMap.keySet()) { - String alias = ecoreAliasMap.get(eObject); - Element element = newCreateMap.get(eObject); - pivotAliasMap.put(element, alias); - } - } - metamodelManager.installResource(asResource); installImports(); } return pivotModel2; @@ -944,6 +931,18 @@ public class Ecore2AS extends AbstractExternal2AS } } PivotUtilInternal.refreshList(pivotModel.getOwnedPackages(), newPackages); + AliasAdapter ecoreAdapter = AliasAdapter.findAdapter(ecoreResource); + if (ecoreAdapter != null) { + Map<EObject, String> ecoreAliasMap = ecoreAdapter.getAliasMap(); + AliasAdapter pivotAdapter = AliasAdapter.getAdapter(asResource); + Map<EObject, String> pivotAliasMap = pivotAdapter.getAliasMap(); + for (EObject eObject : ecoreAliasMap.keySet()) { + String alias = ecoreAliasMap.get(eObject); + Element element = newCreateMap.get(eObject); + pivotAliasMap.put(element, alias); + } + } + metamodelManager.installResource(asResource); Map<@NonNull String, @NonNull Type> resolvedSpecializations = new HashMap<@NonNull String, @NonNull Type>(); for (@NonNull EGenericType eGenericType : genericTypes) { Type pivotType = resolveType(resolvedSpecializations, eGenericType); diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java index 76837520d5..a38513be0d 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java @@ -280,7 +280,7 @@ public class PivotMetamodelManager implements MetamodelManagerInternal.Metamodel * The resource of the Standard Library defined by loadDefaultLibrary. If the URI corresponds to a * registered library, the registered library is loaded, else the first library in asLibraries with a matching * URI is installed. Once asLibraryResource is determined all types libraries in asLibraries and all future - * asLibraries are automatically merged into the Standard LIbrary. + * asLibraries are automatically merged into the Standard Library. */ protected @Nullable Resource asLibraryResource = null; @@ -394,7 +394,10 @@ public class PivotMetamodelManager implements MetamodelManagerInternal.Metamodel /** * Assign xmi:id values to referenceable elements in the libraries. + * + * @deprecated only used by AS2XMIid which is no longer used. */ + @Deprecated public void assignLibraryIds(@NonNull AS2XMIid as2xmIid, @Nullable Map<@NonNull String, @Nullable Object> options) { for (@NonNull Library asLibrary : asLibraries) { Resource eResource = asLibrary.eResource(); @@ -1746,6 +1749,32 @@ public class PivotMetamodelManager implements MetamodelManagerInternal.Metamodel } /** + * @since 1.4 + */ + protected void installLibrary(@NonNull Library asLibrary) { + if (!asLibraries.contains(asLibrary)) { + String uri = asLibrary.getURI(); + if (asLibraries.isEmpty()) { + if (uri == null) { + throw new IllegalLibraryException(PivotMessagesInternal.MissingLibraryURI_ERROR_); + } + if (!standardLibrary.isExplicitDefaultStandardLibraryURI()) { + for (org.eclipse.ocl.pivot.Class asClass : asLibrary.getOwnedClasses()) { + if ("OclAny".equals(asClass.getName())) { + standardLibrary.setDefaultStandardLibraryURI(uri); + break; + } + } + } + } + asLibraries.add(asLibrary); + if (asLibraryResource != null) { + installLibraryContents(asLibrary); + } + } + } + + /** * Merge all types in asLibrary into the overall Standard Library. */ protected void installLibraryContents(@NonNull Library asLibrary) { @@ -1842,26 +1871,8 @@ public class PivotMetamodelManager implements MetamodelManagerInternal.Metamodel } completeModel.getPartialModels().add(pivotModel); for (org.eclipse.ocl.pivot.Package asPackage : ownedPackages) { - if ((asPackage instanceof Library) && !asLibraries.contains(asPackage)) { - Library asLibrary = (Library)asPackage; - String uri = asLibrary.getURI(); - if (asLibraries.isEmpty()) { - if (uri == null) { - throw new IllegalLibraryException(PivotMessagesInternal.MissingLibraryURI_ERROR_); - } - if (!standardLibrary.isExplicitDefaultStandardLibraryURI()) { - for (org.eclipse.ocl.pivot.Class asClass : asLibrary.getOwnedClasses()) { - if ("OclAny".equals(asClass.getName())) { - standardLibrary.setDefaultStandardLibraryURI(uri); - break; - } - } - } - } - asLibraries.add(asLibrary); - if (asLibraryResource != null) { - installLibraryContents(asLibrary); - } + if (asPackage instanceof Library) { + installLibrary((Library)asPackage); } } for (Import asImport : ownedImports) { @@ -1966,8 +1977,8 @@ public class PivotMetamodelManager implements MetamodelManagerInternal.Metamodel /** * Load the Standard Library for a given uri. If the uri corresponds to a registered library, that library - * is isntalled, otherwise the already loaded asLibraries are examined and the fuirst library with a matching - * URI is used. Return the resource of tghe library, and merges all types of all libraries into the overall + * is installed, otherwise the already loaded asLibraries are examined and the first library with a matching + * URI is used. Return the resource of the library, and merges all types of all libraries into the overall * stnadard library. */ public @Nullable Resource loadDefaultLibrary(@Nullable String uri) { @@ -2014,7 +2025,18 @@ public class PivotMetamodelManager implements MetamodelManagerInternal.Metamodel // FIXME alias not used URI resourceURI = uri.trimFragment(); if (PivotUtilInternal.isASURI(resourceURI)) { - return getASElement(uri); + Element asElement = getASElement(uri); + if (asElement instanceof Model) { + for (EObject eObject : ((Model)asElement).getOwnedPackages()) { + if (eObject instanceof Library) { + if (asLibraries.isEmpty() && (asLibraryResource == null)) { + asLibraryResource = asElement.eResource(); + installLibrary((Library)eObject); + } + } + } + } + return asElement; } // if (EPackage.Registry.INSTANCE.containsKey(resourceOrNsURI)) // return EPackage.Registry.INSTANCE.getEPackage(resourceOrNsURI); |