Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2013-09-11 17:09:59 +0000
committerAnsgar Radermacher2013-09-11 17:09:59 +0000
commitfc19e3d5c70b7b321ad237651a7e75efcd252c68 (patch)
treec53d6821a1731861397d910ad8eb5687f6f9edc0 /extraplugins
parent379f22556e2d58fa2ef0eeca92d326ca7d7b4518 (diff)
downloadorg.eclipse.papyrus-fc19e3d5c70b7b321ad237651a7e75efcd252c68.tar.gz
org.eclipse.papyrus-fc19e3d5c70b7b321ad237651a7e75efcd252c68.tar.xz
org.eclipse.papyrus-fc19e3d5c70b7b321ad237651a7e75efcd252c68.zip
- Added //$NON-NLS-1$ tags
- Added hasStereotypeTree funtion to GenUtils
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java8
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java81
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.mtl20
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath2
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF2
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java2
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java12
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.java3
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.mtl2
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java5
10 files changed, 98 insertions, 39 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java
index e669f023ec3..e65c8d81f40 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java
@@ -231,7 +231,9 @@ public class AcceleoDriver {
if(!templateStr.startsWith("[module")) {
templateStr = "[module dummyMod('http://www.eclipse.org/uml2/4.0.0/UML')/]\n\n" + templateStr;
}
-
+ // workaround for Acceleo bug
+ templateStr.replace("http://www.eclipse.org/uml2/4.0.0/UML", "http://www.eclipse.org/uml2/3.0.0/UML");
+
// Strategy:
// 1. Use AcceleoParser to transform text (OpaqueExpression) into Module
// => list of dependencies via explicit import statements
@@ -304,7 +306,7 @@ public class AcceleoDriver {
* @return
*/
public static String evaluateURI(String moduleName, Element element) {
- int index = moduleName.lastIndexOf("::");
+ int index = moduleName.lastIndexOf("::"); //$NON-NLS-1$
String templateName = (index == -1) ? moduleName : moduleName.substring(index + 2);
return evaluateURI(moduleName, templateName, element);
}
@@ -336,7 +338,7 @@ public class AcceleoDriver {
Resource resource = acceleoResourceSet.getResource(uri, true);
if(resource != null) {
- return evaluateResource(resource, element, templateName, "");
+ return evaluateResource(resource, element, templateName, ""); //$NON-NLS-1$
}
return null;
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java
index 20eeca7da89..2b1f3ac247a 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java
@@ -28,6 +28,7 @@ import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.DirectedRelationship;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.OpaqueBehavior;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Package;
@@ -396,17 +397,17 @@ public class GenUtils {
* such as C_Cpp::Include is passed as EClass and we therefore use this operation from Acceleo.
*
* @param element
- * @param eClass The eClass associated with the stereotype name
+ * @param definition The eClass associated with the stereotype name (its definition)
* @return
*/
- public static boolean hasStereotypeA(Element element, EClass eClass) {
+ public static boolean hasStereotypeA(Element element, EClass definition) {
if(element == null) {
// make query more robust
return false;
}
for(EObject stereoApplication : element.getStereotypeApplications()) {
// check whether the stereotype application has the right eClass
- if(stereoApplication.eClass() == eClass) {
+ if(stereoApplication.eClass() == definition) {
return true;
}
}
@@ -414,25 +415,49 @@ public class GenUtils {
}
/**
- * Return the stereotype application by passing an element of the static profile
+ * Verify if an Element or its parent Elements have a stereotype. Pass the class associated with a stereotype
*
- * @param element
- * the UML model element
+ * @param elt
+ * Element used.
* @param clazz
- * the class of an element of a static profile. Compatible sub-types will be returned as well
- * @return the stereotype application or null
+ * the class associated with a stereotype in a static profile
+ *
+ * @return true if found. false otherwise
*/
- @SuppressWarnings("unchecked")
- public static <T extends EObject> T getApplication(Element element, java.lang.Class<T> clazz) {
- for(EObject stereoApplication : element.getStereotypeApplications()) {
- // check whether the stereotype is an instance of the passed parameter clazz
- if(clazz.isInstance(stereoApplication)) {
- return (T)stereoApplication;
- }
- }
- return null;
+ public static boolean hasStereotypeTree(Element elt, java.lang.Class<? extends EObject> clazz)
+ {
+ Element owner;
+
+ if(hasStereotype(elt, clazz))
+ return true;
+ else if((owner = elt.getOwner()) != null)
+ return hasStereotypeTree(owner, clazz);
+ else
+ return false;
+ }
+
+ /**
+ * Verify if an Element or its parent Elements have a stereotype. Pass the definition of the stereotype
+ *
+ * @param elt
+ * Element used.
+ * @param definition
+ * The stereotype definition
+ * @return true if found. false otherwise
+ */
+ public static boolean hasStereotypeTree(Element elt, EClass definition)
+ {
+ Element owner;
+
+ if(hasStereotypeA(elt, definition))
+ return true;
+ else if((owner = elt.getOwner()) != null)
+ return hasStereotypeTree(owner, definition);
+ else
+ return false;
}
+
/**
* Return a stereotype application when given the eClass of that application.
* In case of Java, we use the class above (without the A) prefix. In case of Acceleo, a stereotype
@@ -502,4 +527,26 @@ public class GenUtils {
}
return str;
}
+
+ /**
+ * Return the relative path of ne2 as seen from ne1
+ * (might not always be useful, if includes are always done from a common root)
+ *
+ * @param ne1 a named element
+ * @param ne2 a named element
+ * @return
+ */
+ public static String getRelativePath(NamedElement ne1, NamedElement ne2) {
+ // get common prefix
+ EList<Namespace> ne1namespaces = ne1.allNamespaces();
+ String path = "";
+ for (Namespace ns : ne2.allNamespaces()) {
+ if (ne1namespaces.contains(ns)) {
+ // ns is a common prefix
+ return ne2.getName();
+ }
+ path += "../";
+ }
+ return null;
+ }
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.mtl b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.mtl
index 78c5b0f9afa..989c289308e 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.mtl
+++ b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.mtl
@@ -73,10 +73,14 @@
= invoke('org.eclipse.papyrus.acceleo.GenUtils', 'hasStereotype(org.eclipse.uml2.uml.Element, java.lang.String)', Sequence{arg0, arg1})
/]
-[query public hasStereotype(arg0 : Element, arg1 : OclAny) : Boolean
- = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'hasStereotypeA(org.eclipse.uml2.uml.Element, org.eclipse.emf.ecore.EClass)', Sequence{arg0, arg1})
+[comment use OclAny instead of EClass, since Acceleo does not consider a passed stereotype (such as C_Cpp::Ptr) as EClass compatible - although the passed value is technically an eclass /]
+[query public hasStereotype(arg0 : Element, definition : OclAny) : Boolean
+ = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'hasStereotypeA(org.eclipse.uml2.uml.Element, org.eclipse.emf.ecore.EClass)', Sequence{arg0, definition})
/]
+[query public hasStereotypeTree(arg0 : Element, definition : OclAny) : Boolean
+ = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'hasStereotypeTree(org.eclipse.uml2.uml.Element, org.eclipse.emf.ecore.EClass)', Sequence{arg0, definition}) /]
+
[query public getApplication(arg0 : Element, arg1 : OclAny) : OclAny
= invoke('org.eclipse.papyrus.acceleo.GenUtils', 'getApplicationA(org.eclipse.uml2.uml.Element, org.eclipse.emf.ecore.EClass)', Sequence{arg0, arg1})
/]
@@ -85,11 +89,15 @@
= invoke('org.eclipse.papyrus.acceleo.GenUtils', 'getBody(org.eclipse.uml2.uml.Operation, java.lang.String)', Sequence{arg0, arg1})
/]
-[query public cleanCR(arg0 : String) : String
- = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'cleanCR(java.lang.String)', Sequence{arg0})
+[query public cleanCR(str : String) : String
+ = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'cleanCR(java.lang.String)', Sequence{str})
+/]
+
+[query public maskNull(str : String) : String
+ = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'maskNull(java.lang.String)', Sequence{str})
/]
-[query public maskNull(arg0 : String) : String
- = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'maskNull(java.lang.String)', Sequence{arg0})
+[query public getRelativePath(ne1 : NamedElement, ne2 : NamedElement) : String
+ = invoke('org.eclipse.papyrus.acceleo.GenUtils', 'getRelativePath(org.eclipse.uml2.uml.NamedElement, org.eclipse.uml2.uml.NamedElement)', Sequence{ne1, ne2})
/]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath
index ad32c83a788..64c5e31b7a2 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF
index b229e0de01d..26e0331ae70 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF
@@ -10,7 +10,7 @@ Export-Package: org.eclipse.papyrus.cpp.codegen;uses:="org.eclipse.ui.plugin,org
Bundle-ActivationPolicy: lazy
Bundle-Name: %pluginName
Bundle-Localization: plugin
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jface.text,
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java
index b27a63cd525..16e8aec7fed 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java
@@ -11,7 +11,7 @@
package org.eclipse.papyrus.cpp.codegen;
-import org.eclipse.papyrus.cpp.codegen.utils.GenUtils;
+import org.eclipse.papyrus.acceleo.GenUtils;
import org.eclipse.uml2.uml.Element;
public class StdStereo {
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java
index d9986d37fc9..70dce57d00f 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java
@@ -22,15 +22,15 @@ import org.eclipse.papyrus.C_Cpp.ManualGeneration;
import org.eclipse.papyrus.C_Cpp.NoCodeGen;
import org.eclipse.papyrus.C_Cpp.Template;
import org.eclipse.papyrus.acceleo.AcceleoDriver;
+import org.eclipse.papyrus.acceleo.GenUtils;
import org.eclipse.papyrus.acceleo.ModelElementsCreator;
import org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils;
-import org.eclipse.papyrus.cpp.codegen.utils.GenUtils;
-import org.eclipse.papyrus.cpp.profile.StUtils;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.util.UMLUtil;
@@ -99,10 +99,10 @@ public class CppModelElementsCreator extends ModelElementsCreator {
// treat case of manual code generation
if(GenUtils.hasStereotype(classifier, ManualGeneration.class)) {
- ManualGeneration mg = StUtils.getApplication(classifier, ManualGeneration.class);
- Include cppInclude = StUtils.getApplication(classifier, Include.class);
+ ManualGeneration mg = UMLUtil.getStereotypeApplication(classifier, ManualGeneration.class);
+ Include cppInclude = UMLUtil.getStereotypeApplication(classifier, Include.class);
String fileContent = commentHeader + cppInclude.getHeader();
- createFile(container, classifier.getName() + "." + hppExt, fileContent, true);
+ createFile(container, classifier.getName() + "." + hppExt, fileContent, true); //$NON-NLS-1$
String manualURI = "TODO"; // fileContent = AcceleoDriver.evaluateURI(new URI(CppPackageHeader)), classifier);
@@ -115,7 +115,7 @@ public class CppModelElementsCreator extends ModelElementsCreator {
}
// Only generate when no CppNoCodeGen stereotype is applied to the class
- else if((!GenUtils.hasStereotype(classifier, NoCodeGen.class)) && (!GenUtils.hasStereotype(classifier, External.class)) && (!GenUtils.hasStereotype(classifier, Template.class))) {
+ else if((!GenUtils.hasStereotypeTree(classifier, NoCodeGen.class)) && (!GenUtils.hasStereotype(classifier, External.class)) && (!GenUtils.hasStereotype(classifier, Template.class))) {
// Template Bound Class
if(GenUtils.isTemplateBoundElement(classifier)) {
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.java
index 3fa445e0adb..0b74e6c3570 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.java
@@ -33,6 +33,7 @@ import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.ParameterableElement;
import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.TemplateParameter;
+import org.eclipse.uml2.uml.util.UMLUtil;
@@ -276,7 +277,7 @@ public class CppGenUtils {
*/
public static String getGeneralizationVisibility(Element element) {
// get visibility and target name
- Visibility cppVisibility = GenUtils.getApplication(element, Visibility.class);
+ Visibility cppVisibility = UMLUtil.getStereotypeApplication(element, Visibility.class);
if(cppVisibility != null) {
return cppVisibility.getValue();
} else {
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.mtl
index 85a8711232e..98dedb83e9f 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.mtl
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/CppGenUtils.mtl
@@ -14,7 +14,7 @@
/]
[query public getTemplateTypeName(arg0 : TemplateParameter) : String
- = invoke('org.eclipse.papyrus.cpp.codegen.utils.CppGenUtils', 'getType(org.eclipse.uml2.uml.TemplateParameter)', Sequence{arg0})
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.CppGenUtils', 'getTemplateTypeName(org.eclipse.uml2.uml.TemplateParameter)', Sequence{arg0})
/]
[query public getNamespace(arg0 : NamedElement) : String
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
index 81389c8a0de..adc21bc8024 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
@@ -24,6 +24,7 @@ import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Parameter;
import org.eclipse.uml2.uml.ParameterDirectionKind;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.util.UMLUtil;
/**
@@ -71,7 +72,7 @@ public class Modifier {
public static void update(Element propertyOperationOrParameter) {
// Pointer
- Ptr cppPtr = GenUtils.getApplication(propertyOperationOrParameter, Ptr.class);
+ Ptr cppPtr = UMLUtil.getStereotypeApplication(propertyOperationOrParameter, Ptr.class);
if(cppPtr != null) {
ptr = (cppPtr.getDeclaration() != null) ? cppPtr.getDeclaration() : "*"; //$NON-NLS-1$
} else {
@@ -88,7 +89,7 @@ public class Modifier {
GenUtils.hasStereotype(propertyOperationOrParameter, Ptr.class);
// Array
- Array cppArray = GenUtils.getApplication(propertyOperationOrParameter, Array.class);
+ Array cppArray = UMLUtil.getStereotypeApplication(propertyOperationOrParameter, Array.class);
if(cppArray != null) {
// explicit array definition
array = (cppArray.getDefinition() != null) ? cppArray.getDefinition() : "[]"; //$NON-NLS-1$

Back to the top