Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2016-11-04 18:45:13 +0000
committerEd Willink2016-11-04 18:45:13 +0000
commit34a69114b177ad72597f6206e085078baf40bec6 (patch)
tree3ff1685d1a9e41a38d03cdd391856cb77151b074
parent5edfa664ce806455c9a056a195203fea23b80f37 (diff)
downloadorg.eclipse.qvtd-34a69114b177ad72597f6206e085078baf40bec6.tar.gz
org.eclipse.qvtd-34a69114b177ad72597f6206e085078baf40bec6.tar.xz
org.eclipse.qvtd-34a69114b177ad72597f6206e085078baf40bec6.zip
[506752] Special-case oclAsType dependencies
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/DependencyAnalyzer.java60
1 files changed, 53 insertions, 7 deletions
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 8387114e5..12bb95166 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
@@ -465,6 +465,21 @@ public class DependencyAnalyzer
return true;
}
+ public @NonNull DependencyPaths replaceReturn(@NonNull ClassDependencyStep classDependencyStep) {
+ Set<@NonNull List<@NonNull DependencyStep>> newReturnPaths = new HashSet<>();
+ for (@NonNull List<@NonNull DependencyStep> oldReturnPath : returnPaths) {
+ int size = oldReturnPath.size();
+ if (size > 0) {
+ List<@NonNull DependencyStep> newReturnPath = new ArrayList<>(oldReturnPath.subList(0, size-1));
+ newReturnPath.add(classDependencyStep);
+ if (!newReturnPaths.contains(newReturnPath)) {
+ newReturnPaths.add(newReturnPath);
+ }
+ }
+ }
+ return dependencyAnalyzer.createDependencyPaths(newReturnPaths, hiddenPaths);
+ }
+
@Override
public @NonNull String toString() {
StringBuilder s = new StringBuilder();
@@ -595,7 +610,7 @@ public class DependencyAnalyzer
for (@NonNull List<@NonNull DependencyStep> steps : sourcePaths.getReturnPaths()) {
for (@NonNull DependencyStep step : steps) {
org.eclipse.ocl.pivot.Class sourceClass = step.getElementalType();
- CompleteClass selfClass = metamodelManager.getCompleteModel().getCompleteClass(sourceClass);
+ CompleteClass selfClass = completeModel.getCompleteClass(sourceClass);
Iterable<@NonNull Operation> overrides = getOverrides(selfClass, referredOperation);
for (@NonNull Operation operation : overrides) {
OperationId operationId = operation.getOperationId();
@@ -616,6 +631,27 @@ public class DependencyAnalyzer
return result;
}
+ private @NonNull DependencyPaths analyzeOperationCallExp_oclAsType(@NonNull OperationCallExp operationCallExp, @NonNull List<@NonNull DependencyPaths> sourceAndArgumentPaths) {
+ assert sourceAndArgumentPaths.size() == 2;
+ DependencyPaths sourcePath = sourceAndArgumentPaths.get(0);
+ OCLExpression typeArgument = operationCallExp.getOwnedArguments().get(0);
+ Type typeValue = typeArgument.getTypeValue();
+ if (typeValue == null) {
+ return sourcePath;
+ }
+ CompleteClass castClass = completeModel.getCompleteClass(typeValue);
+ ClassDependencyStep classDependencyStep = createClassDependencyStep(castClass.getPrimaryClass(), operationCallExp);
+ DependencyPaths result = sourcePath.replaceReturn(classDependencyStep);
+ if (RETURN.isActive()) {
+ StringBuilder s = new StringBuilder();
+ for (@NonNull DependencyPaths paths : sourceAndArgumentPaths) {
+ s.append("\n\t=> " + paths.toString());
+ }
+ s.append("\n\t= " + result.toString());
+ RETURN.println(operationCallExp.getReferredOperation() + s.toString());
+ }
+ return result;
+ }
private @NonNull DependencyPaths analyzeOperationCallExp_oclContainer(@NonNull OperationCallExp operationCallExp, @NonNull List<@NonNull DependencyPaths> sourceAndArgumentPaths) {
assert sourceAndArgumentPaths.size() == 1;
@@ -625,8 +661,8 @@ public class DependencyAnalyzer
int size = steps.size();
assert size > 0;
DependencyStep lastStep = steps.get(size-1);
- CompleteClass sourceClass = metamodelManager.getCompleteModel().getCompleteClass(lastStep.getElementalType());
- for (@NonNull CompleteClass containerClass : scheduler.getClassRelationships().getContainerClasses(sourceClass)) {
+ CompleteClass sourceClass = completeModel.getCompleteClass(lastStep.getElementalType());
+ for (@NonNull CompleteClass containerClass : classRelationships.getContainerClasses(sourceClass)) {
ClassDependencyStep classDependencyStep = createClassDependencyStep(containerClass.getPrimaryClass(), operationCallExp);
result = result.addReturn(createDependencyPaths(classDependencyStep));
}
@@ -855,6 +891,12 @@ public class DependencyAnalyzer
CALL.println(referredOperation + s.toString());
}
//
+ // oclAsType() is a known operation - special case it.
+ //
+ if (PivotUtil.isSameOperation(referredOperation.getOperationId(), scheduler.getOclAnyOclAsTypeId())) {
+ return analyzeOperationCallExp_oclAsType(operationCallExp, allSourceAndArgumentPaths);
+ }
+ //
// Analyze each possible source type
//
DependencyPaths result = emptyDependencyPaths;
@@ -881,7 +923,7 @@ public class DependencyAnalyzer
assert size > 0;
DependencyStep lastStep = steps2.get(size-1);
org.eclipse.ocl.pivot.Class sourceClass = lastStep.getElementalType();
- CompleteClass selfClass = metamodelManager.getCompleteModel().getCompleteClass(sourceClass);
+ CompleteClass selfClass = completeModel.getCompleteClass(sourceClass);
List<@NonNull Operation> sortedOverrides = Lists.newArrayList(getOverrides(selfClass, referredOperation));
Collections.sort(sortedOverrides, ToStringComparator.INSTANCE);
for (@NonNull Operation operation : sortedOverrides) {
@@ -1193,7 +1235,7 @@ public class DependencyAnalyzer
Function function = (Function)operation;
Transformation transformation = QVTbaseUtil.getContainingTransformation(function);
if (transformation != null) {
- Variable thisVariable = QVTbaseUtil.getContextVariable(dependencyAnalyzer.metamodelManager.getStandardLibrary(), transformation);
+ Variable thisVariable = QVTbaseUtil.getContextVariable(dependencyAnalyzer.standardLibrary, transformation);
visitor.addVariable(thisVariable, ClassUtil.nonNullState(sourceAndArgumentPaths.get(0)));
}
ownedParameters = function.getOwnedParameters();
@@ -1286,8 +1328,10 @@ public class DependencyAnalyzer
private final @NonNull MetamodelManager metamodelManager;
protected final @NonNull StandardLibrary standardLibrary;
- protected final @NonNull RootDomainUsageAnalysis domainUsageAnalysis;
+ protected final @NonNull CompleteModel completeModel;
protected final @NonNull SchedulerConstants scheduler;
+ protected final @NonNull RootDomainUsageAnalysis domainUsageAnalysis;
+ protected final @NonNull ClassRelationships classRelationships;
private final @NonNull Map<@NonNull List<@Nullable Object>, @NonNull DependencyPaths> content2path = new HashMap<>();
private final @NonNull DependencyPaths emptyDependencyPaths = createDependencyPaths(null, null);
private final @NonNull Map<@NonNull OperationId, @NonNull Map<@NonNull List<@NonNull DependencyPaths>, @NonNull OperationAnalysis>> operation2paths2analysis = new HashMap<>();
@@ -1310,8 +1354,10 @@ public class DependencyAnalyzer
EnvironmentFactory environmentFactory = scheduler.getEnvironmentFactory();
this.metamodelManager = environmentFactory.getMetamodelManager();
this.standardLibrary = environmentFactory.getStandardLibrary();
- this.domainUsageAnalysis = scheduler.getDomainAnalysis();
+ this.completeModel = environmentFactory.getCompleteModel();
this.scheduler = scheduler;
+ this.domainUsageAnalysis = scheduler.getDomainAnalysis();
+ this.classRelationships = scheduler.getClassRelationships();
this.finalAnalysis = ((PivotMetamodelManager)metamodelManager).getFinalAnalysis(); //new FinalAnalysis((CompleteModelInternal) environmentFactory.getCompleteModel());
CompleteModel completeModel = environmentFactory.getCompleteModel();
this.oclVoidCompleteClass = completeModel.getCompleteClass(standardLibrary.getOclVoidType());

Back to the top