blob: a8e25cbbf12a2d21ad64349ddd67da096c3cc29e (
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
|
/*****************************************************************************
* 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.modellibs.core.bindinghelpers;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.C_Cpp.Include;
import org.eclipse.papyrus.FCM.util.IBindingHelper;
import org.eclipse.papyrus.qompass.designer.core.listeners.PostCopyListener;
import org.eclipse.papyrus.qompass.designer.core.templates.TemplateUtils;
import org.eclipse.papyrus.qompass.designer.core.templates.TextTemplateBinding;
import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier;
import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationContext;
import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.TemplateBinding;
import org.eclipse.uml2.uml.util.UMLUtil;
/**
* Instantiate (bind Acceleo template) the text within a C++Include stereotype.
*
* The actual is the first actual within the template binding. This function does not check
* whether the classifier has the template stereotype.
*
* Note: this function is C++ specific, but many parts of the model library are C++ specific as well
*
*/
public class BindCppIncludeToFirstActual implements PostCopyListener, IBindingHelper {
@Override
public void postCopyEObject(LazyCopier copy, EObject targetEObj) {
// if (copy.get(sourceEObj) isWithinTemplate)
if (targetEObj instanceof Classifier) {
Classifier targetCl = (Classifier) targetEObj;
try {
Classifier actual = TemplateUtils.getFirstActualFromBinding(binding);
Include cppInclude = UMLUtil.getStereotypeApplication(targetCl, Include.class);
if ((actual != null) && (cppInclude != null)) {
TransformationContext.classifier = targetCl;
String newBody = TextTemplateBinding.bind(cppInclude.getBody(), actual, null);
String newPreBody = TextTemplateBinding.bind(cppInclude.getPreBody(), actual, null);
String newHeader = TextTemplateBinding.bind(cppInclude.getHeader(), actual, null);
cppInclude.setBody(newBody);
cppInclude.setPreBody(newPreBody);
cppInclude.setHeader(newHeader);
}
} catch (TransformationException e) {
// create nested exception
throw new RuntimeException(e);
}
}
}
protected TemplateBinding binding;
@Override
public void handleElement(TemplateBinding binding, Element object) {
this.binding = binding;
}
}
|