Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2016-10-29 16:54:03 +0000
committerEd Willink2016-10-29 17:59:28 +0000
commit4a4f124c6fb0c9708a8be47bd3d7c4456c503270 (patch)
tree2f0e45b8fe89a5325ab8360bb5fb1e4ffa16c542
parentbb8223dd3e470c87629361068e71ddfd73d608c9 (diff)
downloadorg.eclipse.qvtd-4a4f124c6fb0c9708a8be47bd3d7c4456c503270.tar.gz
org.eclipse.qvtd-4a4f124c6fb0c9708a8be47bd3d7c4456c503270.tar.xz
org.eclipse.qvtd-4a4f124c6fb0c9708a8be47bd3d7c4456c503270.zip
[506716] Replace QVTp2QVTg by DatumCaches
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/ClassRelationships.java279
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DatumCaches.java (renamed from plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java)455
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DependencyAnalyzer.java6
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java23
4 files changed, 350 insertions, 413 deletions
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/ClassRelationships.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/ClassRelationships.java
index 4d47f77aa..29d414349 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/ClassRelationships.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/ClassRelationships.java
@@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * E.D.Willink - initial API and implementation
+ * Adolfo Sanchez-Barbudo Herrera - initial API and implementation
+ * E.D.Willink - use Complete model
*******************************************************************************/
package org.eclipse.qvtd.compiler.internal.qvtp2qvts;
@@ -15,7 +16,6 @@ import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -26,6 +26,9 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.CollectionType;
+import org.eclipse.ocl.pivot.CompleteClass;
+import org.eclipse.ocl.pivot.CompleteModel;
+import org.eclipse.ocl.pivot.CompletePackage;
import org.eclipse.ocl.pivot.Model;
import org.eclipse.ocl.pivot.Property;
import org.eclipse.ocl.pivot.Type;
@@ -33,29 +36,28 @@ import org.eclipse.ocl.pivot.TypedElement;
import org.eclipse.ocl.pivot.internal.manager.MetamodelManagerInternal;
import org.eclipse.ocl.pivot.utilities.ClassUtil;
import org.eclipse.ocl.pivot.utilities.EnvironmentFactory;
-import org.eclipse.ocl.pivot.utilities.MetamodelManager;
+import org.eclipse.ocl.pivot.utilities.FeatureFilter;
+import com.google.common.collect.Iterables;
/**
- * @author asbh500
- *
- * @param <C>
+ * ClassRelationships provides an analysis of all class relationships in the EnvironmentFactory's resources.
*/
-public class ClassRelationships {
- private static final @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class> EMPTY_CLASS_SET = Collections.emptySet();
-
- public static class ContainerClass {
+public class ClassRelationships
+{
+ private static final @NonNull Set<@NonNull CompleteClass> EMPTY_CLASS_SET = Collections.emptySet();
- private org.eclipse.ocl.pivot.@NonNull Class containerClass;
+ public static class ContainerClass
+ {
+ private final @NonNull CompleteClass containerClass;
+ private final @NonNull Property containmentProperty;
- private @NonNull Property containmentProperty;
-
- public ContainerClass(org.eclipse.ocl.pivot.@NonNull Class containerClass, @NonNull Property containmentProperty) {
+ public ContainerClass(@NonNull CompleteClass containerClass, @NonNull Property containmentProperty) {
this.containerClass = containerClass;
this.containmentProperty = containmentProperty;
}
- public org.eclipse.ocl.pivot.@NonNull Class getContainerClass() {
+ public @NonNull CompleteClass getContainerClass() {
return containerClass;
}
@@ -65,69 +67,93 @@ public class ClassRelationships {
@Override
public @NonNull String toString() {
-
return containerClass.getName() + " - " + containmentProperty.getName();
}
}
- private @NonNull Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class>> class2superClasses = new HashMap<>();
+ protected final @NonNull CompleteModel completeModel;
- private @NonNull Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class>> class2directSubClasses = new HashMap<>();
+ private final @NonNull Deque<@NonNull CompletePackage> packageToProcess = new LinkedList<>();
+ private final @NonNull Set<@NonNull CompletePackage> processedPackage = new HashSet<>();
- private @NonNull Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class>> class2allSubClasses = new HashMap<>();
+ private final @NonNull Map<@NonNull CompleteClass, @NonNull Set<@NonNull CompleteClass>> class2superClasses = new HashMap<>();
+ private final @NonNull Map<@NonNull CompleteClass, @NonNull Set<@NonNull CompleteClass>> class2directSubClasses = new HashMap<>();
+ private final @NonNull Map<@NonNull CompleteClass, @NonNull Set<@NonNull CompleteClass>> class2allSubClasses = new HashMap<>();
+ private final @NonNull Map<@NonNull CompleteClass, @NonNull Set<@NonNull CompleteClass>> class2containerClasses = new HashMap<>();
+ private final @NonNull Map<@NonNull CompleteClass, @NonNull Set<@NonNull ContainerClass>> class2detailedContainerClasses = new HashMap<>();
- private @NonNull Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class>> class2containerClasses = new HashMap<>();
-
- private @NonNull Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull Set<@NonNull ContainerClass>> class2detailedContainerClasses = new HashMap<>();
-
- protected @NonNull MetamodelManager mManager;
+ public ClassRelationships(@NonNull EnvironmentFactory environmentFactory) {
+ this.completeModel = environmentFactory.getCompleteModel();
+ MetamodelManagerInternal metamodelManager = (MetamodelManagerInternal)environmentFactory.getMetamodelManager();
+ metamodelManager.getASmetamodel();
+ initializeMaps(metamodelManager.getASResourceSet());
+ }
- private @NonNull Deque<org.eclipse.ocl.pivot.@NonNull Package> packageToProcess = new LinkedList<>();
+ private void addContainerClassForTypeAndSubtypes(@NonNull CompleteClass containerClass, @NonNull Property containmentProperty, @NonNull CompleteClass type) {
+ Set<@NonNull ContainerClass> detailedContainerClasses = class2detailedContainerClasses.get(type);
+ Set<@NonNull CompleteClass> containerClasses = class2containerClasses.get(type);
+ if (detailedContainerClasses == null) {
+ detailedContainerClasses = new HashSet<>();
+ class2detailedContainerClasses.put(type, detailedContainerClasses);
+ }
+ if (containerClasses == null) {
+ containerClasses = new HashSet<>();
+ class2containerClasses.put(type, containerClasses);
+ }
- private @NonNull Set<org.eclipse.ocl.pivot.@NonNull Package> processedPackage = new HashSet<>();
+ detailedContainerClasses.add(new ContainerClass(containerClass, containmentProperty));
+ containerClasses.add(containerClass);
- public ClassRelationships(@NonNull EnvironmentFactory ocl) {
- mManager = ocl.getMetamodelManager();
- ((MetamodelManagerInternal)mManager).getASmetamodel();
- initializeMaps(ocl.getMetamodelManager().getASResourceSet());
+ for (@NonNull CompleteClass subType : getDirectSubClasses(type)) {
+ addContainerClassForTypeAndSubtypes(containerClass, containmentProperty, subType);
+ }
}
- private void initializeMaps(@NonNull ResourceSet resourceSet) {
+ private void computeClass2ContainerClasses(@NonNull CompleteClass aClass) {
- for (@NonNull Resource resource : ClassUtil.nullFree(resourceSet.getResources())) {
- for (org.eclipse.ocl.pivot.@NonNull Package aPackage : getInvolvedPackages(resource)) {
- org.eclipse.ocl.pivot.Package pPackage = mManager.getPrimaryPackage(aPackage);
- if (!packageToProcess.contains(pPackage)) {
- packageToProcess.add(pPackage);;
- }
+ for (@NonNull Property property : aClass.getProperties(FeatureFilter.SELECT_NON_STATIC)) {
+ if (property.isIsComposite()) {
+ Type propType = getType(property);
+ // if (propType instanceof org.eclipse.ocl.pivot.Class) {
+ CompleteClass completeClass = getCompleteClass(propType);
+ addContainerClassForTypeAndSubtypes(aClass, property, completeClass);
+ // }
}
}
+ }
- while (!packageToProcess.isEmpty()) {
- org.eclipse.ocl.pivot.Package aPackage = packageToProcess.pop();
- computeClass2SuperClasses(aPackage);
- }
-
- for (org.eclipse.ocl.pivot.Class type : class2superClasses.keySet()) {
- computeClass2SubClasses(type);
- }
+ private void computeClass2SubClasses(@NonNull CompleteClass aClass) {
+ Set<@NonNull CompleteClass> superClasses = class2superClasses.get(aClass);
+ if (superClasses != null) {
+ for (@NonNull CompleteClass superClass : superClasses) {
+ if (Iterables.contains(aClass.getSuperCompleteClasses(), superClass)) {
+ Set<@NonNull CompleteClass> directSubClasses = class2directSubClasses.get(superClass);
+ if (directSubClasses == null) {
+ directSubClasses = new HashSet<>();
+ class2directSubClasses.put(superClass, directSubClasses);
+ }
+ directSubClasses.add(aClass);
+ }
- for (org.eclipse.ocl.pivot.Class type : class2superClasses.keySet()) { // subtypes need to be previously computed
- computeClass2ContainerClasses(type);
+ Set<@NonNull CompleteClass> allSubClasses = class2allSubClasses.get(superClass);
+ if (allSubClasses == null) {
+ allSubClasses = new HashSet<>();
+ class2allSubClasses.put(superClass, allSubClasses);
+ }
+ allSubClasses.add(aClass);
+ }
}
}
-
- private void computeClass2SuperClasses(org.eclipse.ocl.pivot.@NonNull Package p) {
-
+ private void computeClass2SuperClasses(@NonNull CompletePackage p) {
if (processedPackage.contains(p)) {
return;
}
processedPackage.add(p);
- for (org.eclipse.ocl.pivot.Class aClass : ClassUtil.nullFree(p.getOwnedClasses())) {
+ for (@NonNull CompleteClass aClass : ClassUtil.nullFree(p.getOwnedCompleteClasses())) {
computeClass2SuperClasses(aClass);
}
- for (org.eclipse.ocl.pivot.Package nestedPackage : ClassUtil.nullFree(p.getOwnedPackages())) {
+ for (@NonNull CompletePackage nestedPackage : ClassUtil.nullFree(p.getOwnedCompletePackages())) {
computeClass2SuperClasses(nestedPackage);
}
}
@@ -137,26 +163,22 @@ public class ClassRelationships {
* @param aClass
* @return a set with all the all classess
*/
- private @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class> computeClass2SuperClasses(org.eclipse.ocl.pivot.@NonNull Class aClass) {
-
- //aClass = mManager.getPrimaryClass(aClass);
- Set<org.eclipse.ocl.pivot.@NonNull Class> superRels = class2superClasses.get(aClass);
+ private @NonNull Set<@NonNull CompleteClass> computeClass2SuperClasses(@NonNull CompleteClass aClass) {
+ Set<@NonNull CompleteClass> superRels = class2superClasses.get(aClass);
if (superRels != null) {
return superRels;
} else {
- superRels = new LinkedHashSet<>();
+ superRels = new HashSet<>();
class2superClasses.put(aClass, superRels);
}
// Super class inheritance might be shortcut
- for (org.eclipse.ocl.pivot.@NonNull Class superClass : ClassUtil.nullFree(aClass.getSuperClasses())) {
- //superClass = mManager.getPrimaryClass(superClass);
+ for (@NonNull CompleteClass superClass : aClass.getProperSuperCompleteClasses()) {
superRels.add(superClass);
superRels.addAll(computeClass2SuperClasses(superClass));
}
- org.eclipse.ocl.pivot.Package classPackage = ClassUtil.nonNullState(aClass.getOwningPackage());
- org.eclipse.ocl.pivot.Package pPackage = mManager.getPrimaryPackage(classPackage);
+ CompletePackage pPackage = ClassUtil.nonNullState(aClass.getOwningCompletePackage());
if (!processedPackage.contains(pPackage) &&
! packageToProcess.contains(pPackage)) {
packageToProcess.add(pPackage);
@@ -164,54 +186,47 @@ public class ClassRelationships {
return superRels;
}
- private void computeClass2SubClasses(org.eclipse.ocl.pivot.Class aClass) {
- Set<org.eclipse.ocl.pivot.@NonNull Class> superClasses = class2superClasses.get(aClass);
- if (superClasses != null) {
- for (org.eclipse.ocl.pivot.Class superClass : superClasses) {
- if (aClass.getSuperClasses().contains(superClass)) {
- Set<org.eclipse.ocl.pivot.Class> directSubClasses = class2directSubClasses.get(superClass);
- if (directSubClasses == null) {
- directSubClasses = new LinkedHashSet<>();
- class2directSubClasses.put(superClass, directSubClasses);
- }
- directSubClasses.add(aClass);
- }
+ public @NonNull Set<@NonNull CompleteClass> getAllSubClasses(@NonNull CompleteClass type) {
+ Set<@NonNull CompleteClass> allSubClasses = class2allSubClasses.get(type);
+ return allSubClasses == null ? EMPTY_CLASS_SET
+ : ClassUtil.nonNullState(Collections.<@NonNull CompleteClass>unmodifiableSet(allSubClasses));
+ }
- Set<org.eclipse.ocl.pivot.Class> allSubClasses = class2allSubClasses.get(superClass);
- if (allSubClasses == null) {
- allSubClasses = new LinkedHashSet<>();
- class2allSubClasses.put(superClass, allSubClasses);
- }
- allSubClasses.add(aClass);
- }
- }
+ public @NonNull Set<@NonNull CompleteClass> getAllSuperClasses(@NonNull CompleteClass type) {
+ Set<@NonNull CompleteClass> allSuperClasses = class2superClasses.get(type);
+ return allSuperClasses == null ? EMPTY_CLASS_SET
+ : ClassUtil.nonNullState(Collections.<@NonNull CompleteClass>unmodifiableSet(allSuperClasses));
}
- private void computeClass2ContainerClasses(org.eclipse.ocl.pivot.@NonNull Class aClass) {
+ public @NonNull CompleteClass getCompleteClass(@NonNull Type asClass) {
+ return completeModel.getCompleteClass(asClass);
+ }
- for (@NonNull Property property : ClassUtil.nullFree(aClass.getOwnedProperties())) {
- Type propType = getType(property);
- if (property.isIsComposite() && propType instanceof org.eclipse.ocl.pivot.Class) {
- org.eclipse.ocl.pivot.Class isClass = propType.isClass();
- assert isClass != null;
- addContainerClassForTypeAndSubtypes(aClass, property, isClass);
- }
- }
+ public @NonNull Set<@NonNull CompleteClass> getContainerClasses(@NonNull CompleteClass type) {
+ Set<@NonNull CompleteClass> containerClasses = class2containerClasses.get(type);
+ return containerClasses == null ? EMPTY_CLASS_SET
+ : ClassUtil.nonNullState(Collections.<@NonNull CompleteClass>unmodifiableSet(containerClasses));
}
- public @NonNull EnvironmentFactory getEnvironmentFactory() {
- return mManager.getEnvironmentFactory();
+ public @NonNull Set<@NonNull ContainerClass> getDetailedContainerClasses(@NonNull CompleteClass type) {
+ Set<@NonNull ContainerClass> containerClasses = class2detailedContainerClasses.get(type);
+ return ClassUtil.nonNullState(containerClasses == null ? Collections.<@NonNull ContainerClass>emptySet()
+ : Collections.<@NonNull ContainerClass>unmodifiableSet(containerClasses));
}
- private @NonNull List<org.eclipse.ocl.pivot.@NonNull Package> getInvolvedPackages(@NonNull Resource resource) {
+ public @NonNull Set<@NonNull CompleteClass> getDirectSubClasses(@NonNull CompleteClass type) {
+ Set<@NonNull CompleteClass> directSubClasses = class2directSubClasses.get(type);
+ return directSubClasses == null ? EMPTY_CLASS_SET
+ : ClassUtil.nonNullState(Collections.<@NonNull CompleteClass>unmodifiableSet(directSubClasses));
+ }
+ private @NonNull List<org.eclipse.ocl.pivot.@NonNull Package> getInvolvedPackages(@NonNull Resource resource) {
List<@NonNull Model> oclRoots = new ArrayList<>();
for (EObject root : resource.getContents()) {
if (root instanceof Model) {
oclRoots.add((Model)root);
}
}
-
List<org.eclipse.ocl.pivot.@NonNull Package> result = new ArrayList<>();
for (Model root : oclRoots) {
for (org.eclipse.ocl.pivot.@NonNull Package pckg : ClassUtil.nullFree(root.getOwnedPackages())) {
@@ -221,7 +236,7 @@ public class ClassRelationships {
return result;
}
- protected @NonNull Type getType(@NonNull TypedElement typedElement) {
+ private @NonNull Type getType(@NonNull TypedElement typedElement) {
Type type = typedElement.getType();
if (type instanceof CollectionType) {
type = ((CollectionType) type).getElementType();
@@ -229,66 +244,24 @@ public class ClassRelationships {
return ClassUtil.nonNullState(type);
}
- private void addContainerClassForTypeAndSubtypes(org.eclipse.ocl.pivot.@NonNull Class containerClass, @NonNull Property containmentProperty, org.eclipse.ocl.pivot.@NonNull Class type) {
-
- //type = mManager.getPrimaryClass(type);
- Set<@NonNull ContainerClass> detailedContainerClasses = class2detailedContainerClasses.get(type);
- Set<org.eclipse.ocl.pivot.@NonNull Class> containerClasses = class2containerClasses.get(type);
- if (detailedContainerClasses == null) {
- detailedContainerClasses = new LinkedHashSet<>();
- class2detailedContainerClasses.put(type, detailedContainerClasses);
+ private void initializeMaps(@NonNull ResourceSet resourceSet) {
+ for (@NonNull Resource resource : ClassUtil.nullFree(resourceSet.getResources())) {
+ for (org.eclipse.ocl.pivot.@NonNull Package aPackage : getInvolvedPackages(resource)) {
+ CompletePackage pPackage = completeModel.getCompletePackage(aPackage);
+ if (!packageToProcess.contains(pPackage)) {
+ packageToProcess.add(pPackage);;
+ }
+ }
}
- if (containerClasses == null) {
- containerClasses = new LinkedHashSet<>();
- class2containerClasses.put(type, containerClasses);
+ while (!packageToProcess.isEmpty()) {
+ CompletePackage aPackage = packageToProcess.pop();
+ computeClass2SuperClasses(aPackage);
}
-
- detailedContainerClasses.add(new ContainerClass(containerClass, containmentProperty));
- containerClasses.add(containerClass);
-
- for (org.eclipse.ocl.pivot.Class subType : getDirectSubClasses(type)) {
- addContainerClassForTypeAndSubtypes(containerClass, containmentProperty, subType);
+ for (@NonNull CompleteClass type : class2superClasses.keySet()) {
+ computeClass2SubClasses(type);
+ }
+ for (@NonNull CompleteClass type : class2superClasses.keySet()) { // subtypes need to be previously computed
+ computeClass2ContainerClasses(type);
}
- }
- // public boolean typeIsSupertypeOf(Class t1, Class t2) {
- // Type primaryT1 = mManager.getPrimaryClass(t1);
- // Type primaryT2 = mManager.getPrimaryClass(t2);
- // return class2superClasses.get(primaryT1).contains(primaryT2);
- // }
-
-
- public @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class> getAllSuperClasses(org.eclipse.ocl.pivot.@NonNull Class type) {
- Type primaryType = mManager.getPrimaryClass(type);
- Set<org.eclipse.ocl.pivot.@NonNull Class> allSuperClasses = class2superClasses.get(primaryType);
- return allSuperClasses == null ? EMPTY_CLASS_SET
- : ClassUtil.nonNullState(Collections.<org.eclipse.ocl.pivot.@NonNull Class>unmodifiableSet(allSuperClasses));
- }
-
- public @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class> getAllSubClasses(org.eclipse.ocl.pivot.@NonNull Class type) {
- Type primaryType = mManager.getPrimaryClass(type);
- Set<org.eclipse.ocl.pivot.@NonNull Class> allSubClasses = class2allSubClasses.get(primaryType);
- return allSubClasses == null ? EMPTY_CLASS_SET
- : ClassUtil.nonNullState(Collections.<org.eclipse.ocl.pivot.@NonNull Class>unmodifiableSet(allSubClasses));
- }
-
- public @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class> getDirectSubClasses(org.eclipse.ocl.pivot.@NonNull Class type) {
- Type primaryType = mManager.getPrimaryClass(type);
- Set<org.eclipse.ocl.pivot.@NonNull Class> directSubClasses = class2directSubClasses.get(primaryType);
- return directSubClasses == null ? EMPTY_CLASS_SET
- : ClassUtil.nonNullState(Collections.<org.eclipse.ocl.pivot.@NonNull Class>unmodifiableSet(directSubClasses));
- }
-
- public @NonNull Set<org.eclipse.ocl.pivot.@NonNull Class> getContainerClasses(org.eclipse.ocl.pivot.@NonNull Class type) {
- Type primaryType = mManager.getPrimaryClass(type);
- Set<org.eclipse.ocl.pivot.@NonNull Class> containerClasses = class2containerClasses.get(primaryType);
- return containerClasses == null ? EMPTY_CLASS_SET
- : ClassUtil.nonNullState(Collections.<org.eclipse.ocl.pivot.@NonNull Class>unmodifiableSet(containerClasses));
- }
-
- public @NonNull Set<@NonNull ContainerClass> getDetailedContainerClasses(org.eclipse.ocl.pivot.@NonNull Class type) {
- Type primaryType = mManager.getPrimaryClass(type);
- Set<@NonNull ContainerClass> containerClasses = class2detailedContainerClasses.get(primaryType);
- return ClassUtil.nonNullState(containerClasses == null ? Collections.<@NonNull ContainerClass>emptySet()
- : Collections.<@NonNull ContainerClass>unmodifiableSet(containerClasses));
}
}
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DatumCaches.java
index b07e6cbe9..e20233f01 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DatumCaches.java
@@ -62,7 +62,10 @@ import org.eclipse.qvtd.pivot.schedule.PropertyDatum;
import org.eclipse.qvtd.pivot.schedule.Schedule;
import org.eclipse.qvtd.pivot.schedule.ScheduleFactory;
-public class QVTp2QVTg
+/**
+ * DatumCaches maintains the caches of ClassDatum and PropertyDatum that establish the inter-Mapping connectivity.
+ */
+public class DatumCaches
{
private final @NonNull RootDomainUsageAnalysis domainUsageAnalysis;
private final @NonNull ClassRelationships classRelationships;
@@ -73,33 +76,37 @@ public class QVTp2QVTg
private @NonNull Map<@NonNull TypedModel, @NonNull Map<org.eclipse.ocl.pivot.@NonNull CompleteClass, @NonNull ClassDatum>> typedModel2completeClass2classDatum = new HashMap<>();
private @NonNull Map<@NonNull ClassDatum, @NonNull Map<@NonNull Property, @NonNull PropertyDatum>> classDatum2property2propertyDatum = new HashMap<>();
- public QVTp2QVTg(@NonNull RootDomainUsageAnalysis domainAnalysis, @NonNull ClassRelationships classRelationships) {
+ public DatumCaches(@NonNull RootDomainUsageAnalysis domainAnalysis, @NonNull ClassRelationships classRelationships) {
this.domainUsageAnalysis = domainAnalysis;
this.classRelationships = classRelationships;
}
- private boolean assertValidTypedModel(@NonNull TypedModel typedModel, @NonNull CompleteClass completeClass) {
- org.eclipse.ocl.pivot.@NonNull Class aType = completeClass.getPrimaryClass();
- Type elementType = PivotUtil.getElementalType(aType);
- if (elementType instanceof DataType) {
- assert typedModel == domainUsageAnalysis.getPrimitiveTypeModel();
- }
- else {
- assert typedModel != null;
- /* FIXME waiting for BUG 485647
- if (typedModel != domainUsageAnalysis.getPrimitiveTypeModel()) { // Un'used' packages are primitive
- Set<org.eclipse.ocl.pivot.Package> allUsedPackages = QVTbaseUtil.getAllUsedPackages(typedModel);
- org.eclipse.ocl.pivot.Package containingPackage = PivotUtil.getContainingPackage(elementType);
- assert containingPackage != null;
- if (!Iterables.contains(allUsedPackages, containingPackage)) {
- StandardLibrary standardLibrary = classRelationships.getEnvironmentFactory().getStandardLibrary();
- assert (elementType == standardLibrary.getOclAnyType())
- || (elementType == standardLibrary.getOclElementType())
- || (elementType == standardLibrary.getOclVoidType());
+ private @NonNull Set<@NonNull PropertyDatum> analyseOclContainerCall(@NonNull TypedModel typedModel, @NonNull CompleteClass context) {
+
+ Set<@NonNull PropertyDatum> result = new HashSet<>();
+
+ for (@NonNull CompleteClass parentClass : classRelationships.getContainerClasses(context)) {
+ for (Property prop : parentClass.getProperties(FeatureFilter.SELECT_NON_STATIC)) {
+ if (prop.isIsComposite()) {
+ Set<@NonNull CompleteClass> allSuperAndSubClasses = getAllSuperAndSubClassesIncludingSelf(context);
+ if (allSuperAndSubClasses.contains(getElementClass(prop))) {
+ // self.print("\tOCL Container property for ");
+ // prop.println(" : ");
+ // FIXME I'm getting non-deterministic QVTs 2 Graphml transformations
+ // when there are references to non-navigable (inexistent) properties
+ // in .oclas. Example3: Kiama
+ // For the time being, let's create the dependency on the forward
+ // containment property
+ //var opposite = prop.opposite;
+ //result.add(opposite.getOrCreatePropertyDatum(self));
+ result.add(getPropertyDatum(typedModel, parentClass, prop));
+ }
}
- } */
+ }
+
}
- return true;
+ return result;
+
}
public void analyzeTransformation(@NonNull Transformation pTransformation) {
@@ -135,7 +142,7 @@ public class QVTp2QVTg
assert ownedSource != null;
Type type = ownedSource.getType();
assert type != null;
- CompleteClass context = getCompleteClass((org.eclipse.ocl.pivot.Class) type);
+ CompleteClass context = classRelationships.getCompleteClass(type);
requisites.addAll(getOperationPropertyDatums(opCall, context, new HashMap<>(), new HashMap<>()));
}
else if (eObj instanceof NavigationAssignment) {
@@ -155,72 +162,67 @@ public class QVTp2QVTg
return ma;
}
- public @NonNull ClassDatum getClassDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class aClass) {
- CompleteClass completeClass = getCompleteClass(aClass);
- return getClassDatum(typedModel, completeClass);
- }
-
- public @NonNull ClassDatum getClassDatum(@NonNull TypedModel typedModel, @NonNull CompleteClass completeClass) {
- assert assertValidTypedModel(typedModel, completeClass);
- Map<org.eclipse.ocl.pivot.@NonNull CompleteClass, @NonNull ClassDatum> completeClass2classDatums = typedModel2completeClass2classDatum.get(typedModel);
- if (completeClass2classDatums == null) {
- completeClass2classDatums = new HashMap<>();
- typedModel2completeClass2classDatum.put(typedModel, completeClass2classDatums);
+ private boolean assertValidTypedModel(@NonNull TypedModel typedModel, @NonNull CompleteClass completeClass) {
+ org.eclipse.ocl.pivot.@NonNull Class aType = completeClass.getPrimaryClass();
+ Type elementType = PivotUtil.getElementalType(aType);
+ if (elementType instanceof DataType) {
+ assert typedModel == domainUsageAnalysis.getPrimitiveTypeModel();
}
- ClassDatum classDatum = completeClass2classDatums.get(completeClass);
- if (classDatum == null) {
- classDatum = ScheduleFactory.eINSTANCE.createClassDatum();
- classDatum.setSchedule(schedule);
- classDatum.setCompleteClass(completeClass);
- classDatum.setTypedModel(typedModel);
- org.eclipse.ocl.pivot.@NonNull Class aClass = completeClass.getPrimaryClass();
- if (!(aClass instanceof DataType)) {
- List<ClassDatum> superClassDatums = classDatum.getSuper();
- for (@NonNull CompleteClass superCompleteClass : completeClass.getSuperCompleteClasses()) {
- if (superCompleteClass != completeClass) { // FIXME Why is OclAny its own superClass ?
- ClassDatum superClassDatum = getClassDatum(typedModel, superCompleteClass);
- superClassDatums.add(superClassDatum);
- }
+ else {
+ assert typedModel != null;
+ /* FIXME waiting for BUG 485647
+ if (typedModel != domainUsageAnalysis.getPrimitiveTypeModel()) { // Un'used' packages are primitive
+ Set<org.eclipse.ocl.pivot.Package> allUsedPackages = QVTbaseUtil.getAllUsedPackages(typedModel);
+ org.eclipse.ocl.pivot.Package containingPackage = PivotUtil.getContainingPackage(elementType);
+ assert containingPackage != null;
+ if (!Iterables.contains(allUsedPackages, containingPackage)) {
+ StandardLibrary standardLibrary = classRelationships.getEnvironmentFactory().getStandardLibrary();
+ assert (elementType == standardLibrary.getOclAnyType())
+ || (elementType == standardLibrary.getOclElementType())
+ || (elementType == standardLibrary.getOclVoidType());
}
- }
- completeClass2classDatums.put(completeClass, classDatum);
+ } */
}
- /**
- * Following check is useful for heterogeneous checking. assertValidTypedModel should be better once BUG 485647 is fixed.
- *
- TypedModel tmKey = null;
- for (TypedModel tm : typedModel2class2datum.keySet()) {
- Map<Type, ClassDatum> c2d = typedModel2class2datum.get(tm);
- if (c2d.containsKey(aType)) {
- if (tmKey == null) {
- tmKey = tm;
- }
- else if (!aType.getName().startsWith("Ocl") && !aType.getName().equals("EObject")) {
- System.out.println(aType + " is both " + tmKey + " and " + tm);
- throw new IllegalStateException(aType + " is both " + tmKey + " and " + tm);
- }
- }
- } */
- return classDatum;
+ return true;
}
- /* public @NonNull Iterable<@NonNull PropertyDatum> getAllPropertyDatums(@NonNull ClassDatum classDatum) {
- Map<@NonNull Property, @NonNull PropertyDatum> property2propertyDatums = classDatum2property2propertyDatums.get(classDatum);
- if (property2propertyDatums == null) {
- property2propertyDatums = new HashMap<>();
- classDatum2property2propertyDatums.put(classDatum, property2propertyDatums);
- for (@NonNull PropertyDatum propertyDatum : getAllPropertyDatumsInternal(new HashSet<>(), new HashSet<>(), classDatum)) {
- Property property = propertyDatum.getProperty();
- assert property != null;
- PropertyDatum oldPropertyDatum = property2propertyDatums.put(property, propertyDatum);
- assert oldPropertyDatum == null;
+ // TODO cache
+ private @NonNull Set<@NonNull CompleteClass> computeContexts(@NonNull OCLExpression oclExp, @NonNull Map<@NonNull Variable, @NonNull Set<@NonNull CompleteClass>> variable2BoundContext) {
+
+ Set<@NonNull CompleteClass> result = new HashSet<>();
+ if (oclExp instanceof VariableExp) {
+ VariableExp varExp = (VariableExp) oclExp;
+ Set<@NonNull CompleteClass> context = variable2BoundContext.get(varExp.getReferredVariable());
+ if (context != null) { // FIXME is this check needed ?
+ result.addAll(context);
+ } else {
+ result.add(classRelationships.getCompleteClass(ClassUtil.nonNullState(varExp.getType())));
+ }
+ } else if (oclExp instanceof CallExp) {
+ CallExp callExp = (CallExp) oclExp;
+ if (callExp instanceof OperationCallExp &&
+ isOclContainerOp(ClassUtil.nonNullState(((OperationCallExp)callExp).getReferredOperation()))) {
+ OCLExpression ownedSource = callExp.getOwnedSource();
+ assert ownedSource != null;
+ for (@NonNull CompleteClass oclContainerOpContext : computeContexts(ownedSource, variable2BoundContext)) {
+ result.addAll(classRelationships.getContainerClasses(oclContainerOpContext));
+ }
+ } else {
+ result.add(classRelationships.getCompleteClass(ClassUtil.nonNullState(callExp.getType())));
}
+ } else if (oclExp instanceof ShadowExp) {
+ result.add(classRelationships.getCompleteClass(ClassUtil.nonNullState(((ShadowExp)oclExp).getType())));
+
+ } else {
+ throw new IllegalStateException("OCLExpression has not been considered yet");
}
- return property2propertyDatums.values();
- } */
+ return result;
+ }
+
public @NonNull Iterable<@NonNull PropertyDatum> getAllPropertyDatums(@NonNull ClassDatum cDatum) {
return getAllPropertyDatumsInternal(new HashSet<>(), new HashSet<>(), cDatum);
}
+
private @NonNull Iterable<@NonNull PropertyDatum> getAllPropertyDatumsInternal(@NonNull Set<@NonNull ClassDatum> classDatums, @NonNull Set<@NonNull PropertyDatum> propertyDatums, @NonNull ClassDatum cDatum) {
if (classDatums.add(cDatum)) {
propertyDatums.addAll(ClassUtil.nullFree(cDatum.getPropertyDatums()));
@@ -231,62 +233,16 @@ public class QVTp2QVTg
return propertyDatums;
}
- private @NonNull PropertyDatum getPropertyDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class context, @NonNull Property property) {
- CompleteClass completeClass = getCompleteClass(context);
- return getPropertyDatum(typedModel, completeClass, property);
- }
-
- private @NonNull PropertyDatum getPropertyDatum(@NonNull TypedModel typedModel, @NonNull CompleteClass completeClass, @NonNull Property property) {
- ClassDatum classDatum = getClassDatum(typedModel, completeClass);
- return getPropertyDatum(classDatum, property);
- }
-
- public @NonNull PropertyDatum getPropertyDatum(@NonNull ClassDatum classDatum, @NonNull Property property) {
- Iterable<@NonNull PropertyDatum> allPropertyDatums = getAllPropertyDatums(classDatum);
-
- Map<@NonNull Property, @NonNull PropertyDatum> property2propertyDatum = classDatum2property2propertyDatum.get(classDatum);
- if (property2propertyDatum == null) {
- property2propertyDatum = new HashMap<>();
- classDatum2property2propertyDatum.put(classDatum, property2propertyDatum);
- }
- PropertyDatum cachedPropertyDatum = property2propertyDatum.get(property);
- if (cachedPropertyDatum != null) {
- return cachedPropertyDatum;
- }
- for (PropertyDatum propertyDatum : allPropertyDatums) {
- if (propertyDatum.getProperty().equals(property)) {
- return propertyDatum;
- }
- }
- // If not found we create it
- TypedModel typedModel = classDatum.getTypedModel();
- assert typedModel != null;
- CompleteClass targetCompleteClass = classDatum.getCompleteClass();
- org.eclipse.ocl.pivot.Class owningClass = property.getOwningClass();
- assert owningClass != null;
- CompleteClass hostCompleteClass = getCompleteClass(owningClass);
- PropertyDatum propertyDatum = ScheduleFactory.eINSTANCE.createPropertyDatum();
- propertyDatum.setTypedModel(typedModel);
- propertyDatum.setProperty(property);
- propertyDatum.setClassDatum(classDatum);
- assert targetCompleteClass.conformsTo(hostCompleteClass);
- for (@NonNull CompleteClass superCompleteClass : targetCompleteClass.getSuperCompleteClasses()) {
- if (superCompleteClass.conformsTo(hostCompleteClass)) {
- PropertyDatum superPropDatum = getPropertyDatum(typedModel, superCompleteClass, property);
- propertyDatum.getSuper().add(superPropDatum);
- }
- }
- PropertyDatum oldPropertyDatum = property2propertyDatum.put(property, propertyDatum);
- assert oldPropertyDatum == null;
- return propertyDatum;
- }
+ // Property datum analysis
- private @NonNull CompleteClass getCompleteClass(org.eclipse.ocl.pivot.@NonNull Class asClass) {
- return classRelationships.getEnvironmentFactory().getCompleteModel().getCompleteClass(asClass);
+ private @NonNull Set<@NonNull CompleteClass> getAllSuperAndSubClassesIncludingSelf(@NonNull CompleteClass context) {
+ Set<@NonNull CompleteClass> result = new HashSet<>();
+ result.addAll(classRelationships.getAllSuperClasses(context));
+ result.addAll(classRelationships.getAllSubClasses(context));
+ result.add(context);
+ return result;
}
- // Property datum analysis
-
private @NonNull Set<@NonNull PropertyDatum> getAssignedPropertyDatums(@NonNull NavigationAssignment propAssign) {
Set<@NonNull PropertyDatum> result = new HashSet<>();
Property targetProp = QVTcoreUtil.getTargetProperty(propAssign);
@@ -323,6 +279,74 @@ public class QVTp2QVTg
return result;
}
+ public @NonNull ClassDatum getClassDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class aClass) {
+ CompleteClass completeClass = classRelationships.getCompleteClass(aClass);
+ return getClassDatum(typedModel, completeClass);
+ }
+
+ public @NonNull ClassDatum getClassDatum(@NonNull TypedModel typedModel, @NonNull CompleteClass completeClass) {
+ assert assertValidTypedModel(typedModel, completeClass);
+ Map<org.eclipse.ocl.pivot.@NonNull CompleteClass, @NonNull ClassDatum> completeClass2classDatums = typedModel2completeClass2classDatum.get(typedModel);
+ if (completeClass2classDatums == null) {
+ completeClass2classDatums = new HashMap<>();
+ typedModel2completeClass2classDatum.put(typedModel, completeClass2classDatums);
+ }
+ ClassDatum classDatum = completeClass2classDatums.get(completeClass);
+ if (classDatum == null) {
+ classDatum = ScheduleFactory.eINSTANCE.createClassDatum();
+ classDatum.setSchedule(schedule);
+ classDatum.setCompleteClass(completeClass);
+ classDatum.setTypedModel(typedModel);
+ org.eclipse.ocl.pivot.@NonNull Class aClass = completeClass.getPrimaryClass();
+ if (!(aClass instanceof DataType)) {
+ List<ClassDatum> superClassDatums = classDatum.getSuper();
+ for (@NonNull CompleteClass superCompleteClass : completeClass.getSuperCompleteClasses()) {
+ if (superCompleteClass != completeClass) { // FIXME Why is OclAny its own superClass ?
+ ClassDatum superClassDatum = getClassDatum(typedModel, superCompleteClass);
+ superClassDatums.add(superClassDatum);
+ }
+ }
+ }
+ completeClass2classDatums.put(completeClass, classDatum);
+ }
+ /**
+ * Following check is useful for heterogeneous checking. assertValidTypedModel should be better once BUG 485647 is fixed.
+ *
+ TypedModel tmKey = null;
+ for (TypedModel tm : typedModel2class2datum.keySet()) {
+ Map<Type, ClassDatum> c2d = typedModel2class2datum.get(tm);
+ if (c2d.containsKey(aType)) {
+ if (tmKey == null) {
+ tmKey = tm;
+ }
+ else if (!aType.getName().startsWith("Ocl") && !aType.getName().equals("EObject")) {
+ System.out.println(aType + " is both " + tmKey + " and " + tm);
+ throw new IllegalStateException(aType + " is both " + tmKey + " and " + tm);
+ }
+ }
+ } */
+ return classDatum;
+ }
+
+ // Property datum analysis
+
+ // This is needed when analysing Property/Operation call exps so that they exploit the statically computed context
+ // carried on through the analysis.
+ // TODO cache
+ private @NonNull Set<@NonNull CompleteClass> getComputedContexts(@NonNull CallExp callExp, @NonNull Map<@NonNull Variable, @NonNull Set<@NonNull CompleteClass>> variable2BoundContext) {
+ OCLExpression source = ClassUtil.nonNullState(callExp.getOwnedSource());
+ return computeContexts(source, variable2BoundContext);
+ }
+
+ private org.eclipse.ocl.pivot.@Nullable Class getElementClass(@NonNull TypedElement tElement) {
+ Type type = tElement.getType();
+ if (type instanceof CollectionType) {
+ return ((CollectionType) type).getElementType().isClass();
+ } else {
+ return type.isClass();
+ }
+ }
+
private @NonNull Set<@NonNull PropertyDatum> getOperationPropertyDatums(@NonNull OperationCallExp opCall, @NonNull CompleteClass context,
@NonNull Map<@NonNull CompleteClass, @NonNull Set<@NonNull Operation>> type2VisitedOps,
@NonNull Map<@NonNull Variable, @NonNull Set<@NonNull CompleteClass>> variable2BoundContext) {
@@ -356,6 +380,8 @@ public class QVTp2QVTg
return result;
}
+ // Property datum analysis
+
private @NonNull Set<@NonNull PropertyDatum> getOperationPropertyDatums(@NonNull Operation op, @NonNull CompleteClass context, @NonNull Map<@NonNull CompleteClass, @NonNull Set<@NonNull Operation>> type2VisitedOps) {
Set<@NonNull PropertyDatum> result = new HashSet<>();
@@ -397,6 +423,58 @@ public class QVTp2QVTg
return result;
}
+ private @NonNull PropertyDatum getPropertyDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class context, @NonNull Property property) {
+ CompleteClass completeClass = classRelationships.getCompleteClass(context);
+ return getPropertyDatum(typedModel, completeClass, property);
+ }
+
+ private @NonNull PropertyDatum getPropertyDatum(@NonNull TypedModel typedModel, @NonNull CompleteClass completeClass, @NonNull Property property) {
+ ClassDatum classDatum = getClassDatum(typedModel, completeClass);
+ return getPropertyDatum(classDatum, property);
+ }
+
+ public @NonNull PropertyDatum getPropertyDatum(@NonNull ClassDatum classDatum, @NonNull Property property) {
+ Iterable<@NonNull PropertyDatum> allPropertyDatums = getAllPropertyDatums(classDatum);
+
+ Map<@NonNull Property, @NonNull PropertyDatum> property2propertyDatum = classDatum2property2propertyDatum.get(classDatum);
+ if (property2propertyDatum == null) {
+ property2propertyDatum = new HashMap<>();
+ classDatum2property2propertyDatum.put(classDatum, property2propertyDatum);
+ }
+ PropertyDatum cachedPropertyDatum = property2propertyDatum.get(property);
+ if (cachedPropertyDatum != null) {
+ return cachedPropertyDatum;
+ }
+ for (PropertyDatum propertyDatum : allPropertyDatums) {
+ if (propertyDatum.getProperty().equals(property)) {
+ return propertyDatum;
+ }
+ }
+ // If not found we create it
+ TypedModel typedModel = classDatum.getTypedModel();
+ assert typedModel != null;
+ CompleteClass targetCompleteClass = classDatum.getCompleteClass();
+ org.eclipse.ocl.pivot.Class owningClass = property.getOwningClass();
+ assert owningClass != null;
+ CompleteClass hostCompleteClass = classRelationships.getCompleteClass(owningClass);
+ PropertyDatum propertyDatum = ScheduleFactory.eINSTANCE.createPropertyDatum();
+ propertyDatum.setTypedModel(typedModel);
+ propertyDatum.setProperty(property);
+ propertyDatum.setClassDatum(classDatum);
+ assert targetCompleteClass.conformsTo(hostCompleteClass);
+ for (@NonNull CompleteClass superCompleteClass : targetCompleteClass.getSuperCompleteClasses()) {
+ if (superCompleteClass.conformsTo(hostCompleteClass)) {
+ PropertyDatum superPropDatum = getPropertyDatum(typedModel, superCompleteClass, property);
+ propertyDatum.getSuper().add(superPropDatum);
+ }
+ }
+ PropertyDatum oldPropertyDatum = property2propertyDatum.put(property, propertyDatum);
+ assert oldPropertyDatum == null;
+ return propertyDatum;
+ }
+
+ // Property datum analysis
+
private @NonNull TypedModel getTypedModel(@NonNull Element element) {
DomainUsage domainUsage = getUsage(element);
if (domainUsage == null) {
@@ -440,120 +518,9 @@ public class QVTp2QVTg
// return "oclContainer".equals(op.getName()) && op.getOwnedParameters().isEmpty();
}
- private @NonNull Set<@NonNull PropertyDatum> analyseOclContainerCall(@NonNull TypedModel typedModel, @NonNull CompleteClass context) {
-
- Set<@NonNull PropertyDatum> result = new HashSet<>();
-
- for (@NonNull CompleteClass parentClass : getContainingTypes(context)) {
- for (Property prop : parentClass.getProperties((FeatureFilter)null)) {
- if (prop.isIsComposite()) {
- Set<@NonNull CompleteClass> allSuperAndSubClasses = getAllSuperAndSubClassesIncludingSelf(context);
- if (allSuperAndSubClasses.contains(getElementClass(prop))) {
- // self.print("\tOCL Container property for ");
- // prop.println(" : ");
- // FIXME I'm getting non-deterministic QVTs 2 Graphml transformations
- // when there are references to non-navigable (inexistent) properties
- // in .oclas. Example3: Kiama
- // For the time being, let's create the dependency on the forward
- // containment property
- //var opposite = prop.opposite;
- //result.add(opposite.getOrCreatePropertyDatum(self));
- result.add(getPropertyDatum(typedModel, parentClass, prop));
- }
- }
- }
-
- }
- return result;
-
- }
-
-
- private void updateVariableBindings(@NonNull LetExp letExp , @NonNull Map<@NonNull Variable, @NonNull Set<@NonNull CompleteClass>> variable2BoundContext ) {
+ private void updateVariableBindings(@NonNull LetExp letExp, @NonNull Map<@NonNull Variable, @NonNull Set<@NonNull CompleteClass>> variable2BoundContext ) {
Variable variable = letExp.getOwnedVariable();
variable2BoundContext.put(variable, computeContexts(ClassUtil.nonNullState(variable.getOwnedInit()), variable2BoundContext));
}
-
- // TODO cache
- private @NonNull Set<@NonNull CompleteClass> computeContexts(@NonNull OCLExpression oclExp, @NonNull Map<@NonNull Variable, @NonNull Set<@NonNull CompleteClass>> variable2BoundContext) {
-
- Set<@NonNull CompleteClass> result = new HashSet<>();
- if (oclExp instanceof VariableExp) {
- VariableExp varExp = (VariableExp) oclExp;
- Set<@NonNull CompleteClass> context = variable2BoundContext.get(varExp.getReferredVariable());
- if (context != null) { // FIXME is this check needed ?
- result.addAll(context);
- } else {
- result.add(getCompleteClass(ClassUtil.nonNullState(varExp.getType().isClass())));
- }
- } else if (oclExp instanceof CallExp) {
- CallExp callExp = (CallExp) oclExp;
- if (callExp instanceof OperationCallExp &&
- isOclContainerOp(ClassUtil.nonNullState(((OperationCallExp)callExp).getReferredOperation()))) {
- OCLExpression ownedSource = callExp.getOwnedSource();
- assert ownedSource != null;
- for (@NonNull CompleteClass oclContainerOpContext : computeContexts(ownedSource, variable2BoundContext)) {
- result.addAll(getContainingTypes(oclContainerOpContext));
- }
- } else {
- result.add(getCompleteClass(ClassUtil.nonNullState(callExp.getType().isClass())));
- }
- } else if (oclExp instanceof ShadowExp) {
- result.add(getCompleteClass(ClassUtil.nonNullState(((ShadowExp)oclExp).getType())));
-
- } else {
- throw new IllegalStateException("OCLExpression has not been considered yet");
- }
- return result;
- }
-
- // This is needed when analysing Property/Operation call exps so that they exploit the statically computed context
- // carried on through the analysis.
- // TODO cache
- private @NonNull Set<@NonNull CompleteClass> getComputedContexts(@NonNull CallExp callExp, @NonNull Map<@NonNull Variable, @NonNull Set<@NonNull CompleteClass>> variable2BoundContext) {
- OCLExpression source = ClassUtil.nonNullState(callExp.getOwnedSource());
- return computeContexts(source, variable2BoundContext);
- }
- private @NonNull Set<@NonNull CompleteClass> getContainingTypes(@NonNull CompleteClass aClass) {
- return getCompleteClasses(classRelationships.getContainerClasses(aClass.getPrimaryClass()));
- }
-
- private @NonNull Set<@NonNull CompleteClass> getCompleteClasses(@NonNull Set<org.eclipse.ocl.pivot.@NonNull Class> containerClasses) {
- Set<@NonNull CompleteClass> result = new HashSet<>();
- for (org.eclipse.ocl.pivot.@NonNull Class containerClass : containerClasses) {
- result.add(getCompleteClass(containerClass));
- }
- return result;
- }
-
- private @NonNull Set<@NonNull CompleteClass> getAllSuperClasses(@NonNull CompleteClass context) {
- return getCompleteClasses(classRelationships.getAllSuperClasses(context.getPrimaryClass()));
- }
-
- private @NonNull Set<@NonNull CompleteClass> getAllSubClasses(@NonNull CompleteClass context) {
- return getCompleteClasses(classRelationships.getAllSubClasses(context.getPrimaryClass()));
- }
-
- private @NonNull Set<@NonNull CompleteClass> getAllSuperAndSubClasses(@NonNull CompleteClass context) {
- Set<@NonNull CompleteClass> result = new HashSet<>();
- result.addAll(getAllSuperClasses(context));
- result.addAll(getAllSubClasses(context));
- return result;
- }
-
- private @NonNull Set<@NonNull CompleteClass> getAllSuperAndSubClassesIncludingSelf(@NonNull CompleteClass context) {
- Set<@NonNull CompleteClass> result = getAllSuperAndSubClasses(context);
- result.add(context);
- return result;
- }
-
- private org.eclipse.ocl.pivot.@Nullable Class getElementClass(@NonNull TypedElement tElement) {
- Type type = tElement.getType();
- if (type instanceof CollectionType) {
- return ((CollectionType) type).getElementType().isClass();
- } else {
- return type.isClass();
- }
- }
}
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DependencyAnalyzer.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DependencyAnalyzer.java
index 81d565dcc..2d7d83cbf 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DependencyAnalyzer.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DependencyAnalyzer.java
@@ -625,9 +625,9 @@ public class DependencyAnalyzer
int size = steps.size();
assert size > 0;
DependencyStep lastStep = steps.get(size-1);
- org.eclipse.ocl.pivot.Class sourceClass = lastStep.getElementalType();
- for (org.eclipse.ocl.pivot.@NonNull Class containerClass : scheduler.getClassRelationships().getContainerClasses(sourceClass)) {
- ClassDependencyStep classDependencyStep = createClassDependencyStep(containerClass, operationCallExp);
+ CompleteClass sourceClass = metamodelManager.getCompleteModel().getCompleteClass(lastStep.getElementalType());
+ for (@NonNull CompleteClass containerClass : scheduler.getClassRelationships().getContainerClasses(sourceClass)) {
+ ClassDependencyStep classDependencyStep = createClassDependencyStep(containerClass.getPrimaryClass(), operationCallExp);
result = result.addReturn(createDependencyPaths(classDependencyStep));
}
}
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java
index ee8e01d17..0d02ffc24 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java
@@ -88,11 +88,8 @@ public abstract class SchedulerConstants
private final @NonNull Transformation transformation;
private final @NonNull ClassRelationships classRelationships;
private final @NonNull RootDomainUsageAnalysis domainAnalysis;
- private final @NonNull QVTp2QVTg qvtp2qvtg;
- /**
- * The DependencyGraph to be analyzed
- */
- // private final @NonNull Schedule zdependencyGraph;
+ private final @NonNull DatumCaches datumCaches;
+
@SuppressWarnings("unused")
private final @NonNull DomainUsage inputUsage;
@@ -141,8 +138,8 @@ public abstract class SchedulerConstants
this.classRelationships = new ClassRelationships(environmentFactory);
this.domainAnalysis = new QVTcoreDomainUsageAnalysis(environmentFactory);
domainAnalysis.analyzeTransformation(asTransformation);
- this.qvtp2qvtg = new QVTp2QVTg(domainAnalysis, classRelationships);
- qvtp2qvtg.analyzeTransformation(asTransformation);
+ this.datumCaches = new DatumCaches(domainAnalysis, classRelationships);
+ datumCaches.analyzeTransformation(asTransformation);
//
this.inputUsage = domainAnalysis.getInputUsage();
// int outputMask = ((DomainUsage.Internal)domainAnalysis.getOutputUsage()).getMask();
@@ -181,7 +178,7 @@ public abstract class SchedulerConstants
protected abstract @NonNull ClassDatumAnalysis createClassDatumAnalysis(@NonNull ClassDatum classDatum);
public @NonNull Iterable<@NonNull PropertyDatum> getAllPropertyDatums(@NonNull ClassDatum classDatum) {
- return qvtp2qvtg.getAllPropertyDatums(classDatum);
+ return datumCaches.getAllPropertyDatums(classDatum);
}
public @NonNull Property getArgumentProperty(@NonNull String argumentName) {
@@ -216,11 +213,11 @@ public abstract class SchedulerConstants
typedModel = domainUsage.getTypedModel(asTypedElement);
assert typedModel != null;
}
- return qvtp2qvtg.getClassDatum(typedModel, asType);
+ return datumCaches.getClassDatum(typedModel, asType);
}
public @NonNull ClassDatum getClassDatum(org.eclipse.ocl.pivot.@NonNull Class asType, @NonNull TypedModel typedModel) {
- return qvtp2qvtg.getClassDatum(typedModel, asType);
+ return datumCaches.getClassDatum(typedModel, asType);
}
public @NonNull ClassDatumAnalysis getClassDatumAnalysis(@NonNull ClassDatum classDatum) {
@@ -251,12 +248,12 @@ public abstract class SchedulerConstants
}
public @NonNull ClassDatumAnalysis getClassDatumAnalysis(org.eclipse.ocl.pivot.@NonNull Class type, @NonNull TypedModel typedModel) {
- ClassDatum classDatum = qvtp2qvtg.getClassDatum(typedModel, type);
+ ClassDatum classDatum = datumCaches.getClassDatum(typedModel, type);
return getClassDatumAnalysis(classDatum);
}
public @NonNull ClassDatumAnalysis getClassDatumAnalysis(@NonNull CompleteClass completeClass, @NonNull TypedModel typedModel) {
- ClassDatum classDatum = qvtp2qvtg.getClassDatum(typedModel, completeClass);
+ ClassDatum classDatum = datumCaches.getClassDatum(typedModel, completeClass);
return getClassDatumAnalysis(classDatum);
}
@@ -356,7 +353,7 @@ public abstract class SchedulerConstants
}
public @NonNull PropertyDatum getPropertyDatum(@NonNull ClassDatum classDatum, @NonNull Property property) {
- return qvtp2qvtg.getPropertyDatum(classDatum, property);
+ return datumCaches.getPropertyDatum(classDatum, property);
}
public @NonNull StandardLibrary getStandardLibrary() {

Back to the top