Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 47a247d0e3454cf3426a3e6ab32af225eb2332f2 (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
96
97
98
99
100
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST.
 *
 *
 * 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:
 *  Ansgar Radermacher  ansgar.radermacher@cea.fr
 *
 *****************************************************************************/

package org.eclipse.papyrus.qompass.designer.core.transformations;

import org.eclipse.papyrus.qompass.designer.core.templates.TemplateInstantiation;
import org.eclipse.papyrus.qompass.designer.core.templates.TemplateUtils;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.TemplateBinding;

/**
 * Return information about the current values in the context of a transformation
 * e.g. the current instance, the current port (container transformation), ...
 *
 * TODO: clean separation ContainerContext? (e.g. port should only be in the latter)
 *
 * @author ansgar
 *
 */
public class TransformationContext {

	public static InstanceSpecification instance;

	public static InstanceSpecification getInstance() {
		return instance;
	}

	public static Port port;

	public static Port getPort() {
		return port;
	}

	public static Package sourceRoot;

	public static Package getSourceRoot() {
		return sourceRoot;
	}

	public static Classifier formalParameter;

	public static Classifier getFormalParameter() {
		return formalParameter;
	}

	// the element, to which transformations are currently applied.
	public static Classifier classifier;

	public static Classifier getClassifier() {
		return classifier;
	}

	/**
	 * Set sat and binding context for pkgTemplateParameter function
	 *
	 * @param sat
	 * @param binding
	 */
	public static void setTemplateInstantiation(TemplateInstantiation ti) {
		TransformationContext.ti = ti;
	}

	public static TemplateInstantiation ti;

	/**
	 * Return actual (in the current binding context) from a named package template parameter
	 * Used during template instantiation: code can access actual template parameter via formal
	 *
	 * @param formal
	 *            the name of the formal parameter
	 * @return the actual
	 */
	public static String pkgTemplateParameter(String formal) {
		Classifier actual = TemplateUtils.getActualFromBinding(ti.binding, formal);
		if (actual != null) {
			return actual.getQualifiedName();
		}
		else {
			return ""; //$NON-NLS-1$
		}
	}

	public static TemplateBinding getBinding() {
		return ti.binding;
	}
}

Back to the top