Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4b79800f3247d7b5e2a593407f72cb33df0675ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2014 Willink Transformations 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
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     E.D.Willink - initial API and implementation
 *******************************************************************************/
package org.eclipse.qvtd.pivot.qvtimperative.attributes;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.internal.scoping.AbstractAttribution;
import org.eclipse.ocl.pivot.internal.scoping.EnvironmentView;
import org.eclipse.ocl.pivot.internal.scoping.ScopeView;
import org.eclipse.qvtd.pivot.qvtbase.QVTbasePackage;
import org.eclipse.qvtd.pivot.qvtbase.Transformation;
import org.eclipse.qvtd.pivot.qvtbase.TypedModel;
import org.eclipse.qvtd.pivot.qvtimperative.Mapping;
import org.eclipse.qvtd.pivot.qvtimperative.QVTimperativePackage;
import org.eclipse.qvtd.pivot.qvtimperative.Statement;
import org.eclipse.qvtd.pivot.qvtimperative.VariableStatement;
import org.eclipse.qvtd.pivot.qvtimperative.utilities.QVTimperativeUtil;

public class MappingAttribution extends AbstractAttribution
{
	public static final MappingAttribution INSTANCE = new MappingAttribution();

	@Override
	public ScopeView computeLookup(@NonNull EObject target, @NonNull EnvironmentView environmentView, @NonNull ScopeView scopeView) {
		if ((environmentView.accepts(QVTbasePackage.Literals.TRANSFORMATION)) && (target.eContainer() == null)) {
			environmentView.addRootPackages();
			return null;
		}
		Mapping mapping = (Mapping)target;
		EStructuralFeature containmentFeature = scopeView.getContainmentFeature();
		/*		if ((containmentFeature == QVTimperativePackage.Literals.MAPPING__GUARD_PREDICATES)
				|| (containmentFeature == QVTimperativePackage.Literals.MAPPING__OWNED_PREDICATE_VARIABLES)
				|| (containmentFeature == QVTimperativePackage.Literals.MAPPING__OWNED_LOCAL_VARIABLES)) {
			EObject child = scopeView.getChild();
			for (Statement asStatement : mapping.getOwnedStatements()) {
				if (asStatement == child) {
					break;
				}
				if (asStatement instanceof VariableStatement) {
					environmentView.addNamedElement(asStatement);
				}
			}
			QVTimperativeEnvironmentUtil.addMiddleGuardVariables(environmentView, mapping);
			QVTimperativeEnvironmentUtil.addSideGuardVariables(environmentView, mapping, null);
			QVTimperativeEnvironmentUtil.addMiddleBottomVariables(environmentView, mapping);
			QVTimperativeEnvironmentUtil.addSideBottomVariables(environmentView, mapping, null);
			Transformation transformation = QVTimperativeUtil.getContainingTransformation(mapping);
			if (transformation != null) {
				for (TypedModel typedModel : transformation.getModelParameter()) {
					for (org.eclipse.ocl.pivot.Package usedPackage : typedModel.getUsedPackage()) {
						if (usedPackage != null) {
							environmentView.addNamedElement(usedPackage);
							environmentView.addAllTypes(usedPackage);
						}
					}
				}
			}

		}
		else*/ if (containmentFeature == QVTimperativePackage.Literals.MAPPING__OWNED_STATEMENTS) {
			EObject child = scopeView.getChild();
			for (Statement asStatement : mapping.getOwnedStatements()) {
				if (asStatement == child) {
					break;
				}
				if (asStatement instanceof VariableStatement) {
					environmentView.addNamedElement(asStatement);
				}
			}
			environmentView.addNamedElements(mapping.getOwnedGuardVariables());
			environmentView.addNamedElements(mapping.getInoutVariables());
			Transformation transformation = QVTimperativeUtil.getContainingTransformation(mapping);
			if (transformation != null) {
				for (TypedModel typedModel : transformation.getModelParameter()) {
					for (org.eclipse.ocl.pivot.Package usedPackage : typedModel.getUsedPackage()) {
						if (usedPackage != null) {
							environmentView.addNamedElement(usedPackage);
							environmentView.addAllTypes(usedPackage);
						}
					}
				}
			}
		}
		return scopeView.getParent();
	}
}

Back to the top